Fix invalid UTF-8 bytes in output crashing the script

This commit is contained in:
a-bad-dev 2026-02-20 23:28:56 -04:00
commit 216afac3f2

View file

@ -106,6 +106,7 @@ class IRC2BASH:
# #
command_list = [] command_list = []
command_noescapes = command
for letter in command: for letter in command:
match letter: match letter:
case "\\": case "\\":
@ -126,9 +127,9 @@ class IRC2BASH:
print(f"{channel}: <{username}> {command}") print(f"{channel}: <{username}> {command}")
os.system(f"/bin/bash -c \"{command}\" >/tmp/.command 2>&1") os.system(f"/bin/bash -c \"{command}\" >/tmp/.command 2>&1")
try:
with open("/tmp/.command", "r") as f: with open("/tmp/.command", "r") as f:
output = f.read() output = f.read()
output = output.strip() output = output.strip()
print(output) print(output)
output = output.split("\n") output = output.split("\n")
@ -136,5 +137,9 @@ class IRC2BASH:
IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :{line}") IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :{line}")
time.sleep(0.75) time.sleep(0.75)
except UnicodeDecodeError:
print(f"UnicodeDecodeError: invalid bytes, caused by: {command_noescapes}")
IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :Invalid bytes in response.")
if __name__ == "__main__": if __name__ == "__main__":
IRC2BASH.main() IRC2BASH.main()