mirror of
https://github.com/a-bad-dev/irc2bash.git
synced 2026-06-09 00:51:32 +00:00
Make commands multithreaded
This commit is contained in:
parent
216afac3f2
commit
74b3b0d0c4
1 changed files with 18 additions and 15 deletions
33
main.py
33
main.py
|
|
@ -31,6 +31,23 @@ class IRC2BASH:
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
IRC2BASH.send(f"PING :{IRC2BASH.ip}")
|
IRC2BASH.send(f"PING :{IRC2BASH.ip}")
|
||||||
|
|
||||||
|
def run_command(command: str) -> None:
|
||||||
|
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")
|
||||||
|
for line in output:
|
||||||
|
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.")
|
||||||
|
|
||||||
def receive_messages(sock) -> None:
|
def receive_messages(sock) -> None:
|
||||||
while True:
|
while True:
|
||||||
data = sock.recv(1024)
|
data = sock.recv(1024)
|
||||||
|
|
@ -125,21 +142,7 @@ class IRC2BASH:
|
||||||
command_list = None
|
command_list = None
|
||||||
|
|
||||||
print(f"{channel}: <{username}> {command}")
|
print(f"{channel}: <{username}> {command}")
|
||||||
os.system(f"/bin/bash -c \"{command}\" >/tmp/.command 2>&1")
|
_thread.start_new_thread(IRC2BASH.run_command, (command,))
|
||||||
|
|
||||||
try:
|
|
||||||
with open("/tmp/.command", "r") as f:
|
|
||||||
output = f.read()
|
|
||||||
output = output.strip()
|
|
||||||
print(output)
|
|
||||||
output = output.split("\n")
|
|
||||||
for line in output:
|
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
IRC2BASH.main()
|
IRC2BASH.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue