mirror of
https://github.com/a-bad-dev/irc2bash.git
synced 2026-06-09 00:51:32 +00:00
Fix invalid UTF-8 bytes in output crashing the script
This commit is contained in:
parent
c2f78d79d8
commit
216afac3f2
1 changed files with 14 additions and 9 deletions
7
main.py
7
main.py
|
|
@ -106,6 +106,7 @@ class IRC2BASH:
|
|||
#
|
||||
|
||||
command_list = []
|
||||
command_noescapes = command
|
||||
for letter in command:
|
||||
match letter:
|
||||
case "\\":
|
||||
|
|
@ -126,9 +127,9 @@ class IRC2BASH:
|
|||
print(f"{channel}: <{username}> {command}")
|
||||
os.system(f"/bin/bash -c \"{command}\" >/tmp/.command 2>&1")
|
||||
|
||||
try:
|
||||
with open("/tmp/.command", "r") as f:
|
||||
output = f.read()
|
||||
|
||||
output = output.strip()
|
||||
print(output)
|
||||
output = output.split("\n")
|
||||
|
|
@ -136,5 +137,9 @@ class IRC2BASH:
|
|||
IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :{line}")
|
||||
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__":
|
||||
IRC2BASH.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue