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
23
main.py
23
main.py
|
|
@ -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,15 +127,19 @@ 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")
|
||||||
|
|
||||||
with open("/tmp/.command", "r") as f:
|
try:
|
||||||
output = f.read()
|
with open("/tmp/.command", "r") as f:
|
||||||
|
output = f.read()
|
||||||
output = output.strip()
|
output = output.strip()
|
||||||
print(output)
|
print(output)
|
||||||
output = output.split("\n")
|
output = output.split("\n")
|
||||||
for line in output:
|
for line in output:
|
||||||
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue