import socket import sys import psutil import subprocess import requests import platform import distro from time import sleep busy = False class bot_irc: irc_socket = socket.socket() def __init__(self): self.irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def send_irc(self, channel, msg): self.irc_socket.send(bytes("PRIVMSG " + channel + " :" + msg + " \n", "UTF-8")) def connect_irc(self, server, port, channel, bot_nick, bot_pass, bot_nickpass): print("Server connection: " + server) self.irc_socket.connect((server, port)) self.irc_socket.send( bytes( "USER " + bot_nick + " " + bot_nick + " " + bot_nick + " :SweeBot, a very cool bot made by Swee :3\n", "UTF-8", ) ) self.irc_socket.send(bytes("NICK " + bot_nick + "\n", "UTF-8")) self.irc_socket.send( #bytes("NICKSERV IDENTIFY " + bot_nickpass + " " + bot_pass + "\n", "UTF-8") bytes("PASS " + bot_nickpass + ":" + bot_pass + "\n", "UTF-8") ) for i in channel: self.irc_socket.send(bytes("JOIN " + i + "\n", "UTF-8")) def response_irc(self): r = self.irc_socket.recv(2040).decode("UTF-8") if r.find("PING") != -1: self.irc_socket.send( bytes("PONG " + r.split()[1] + "\r\n", "UTF-8") ) return r server_irc = "127.0.0.1" port_irc = 5000 channels = ["##sweezero","##","##rudechat","##mintHTML","##elysium","##gnu/crack"] botnick_irc = "sweeBot" botnickpass_irc = "sweeBot" botpass_irc = "swee15cool" irc = bot_irc() irc.connect_irc( server_irc, port_irc, channels, botnick_irc, botpass_irc, botnickpass_irc ) re = "http://192.168.12.225:1337/" def rA(): try: requests.get(re + "os") return True except: return False while True: text = irc.response_irc() try: channel_irc = str(text).split(" ")[2] except: continue command = str(text).split(":") command = command[len(command) - 1][:-2].split(" ") try: print(text) except: print("Unable to print text, possible unicode?") if command[0] == "": continue if "PRIVMSG" in text and channel_irc in channels and command[0][0] == "$": username = str(text).split(" ")[0].split("@")[1] nick = str(text).split(" ")[0].split("@")[0][1:].split("!")[0] print(command) if not busy: busy = True if command[0] == "$hello": if rA(): irc.send_irc(channel_irc, "Greetings " + nick + ", I am SweeBot!") else: irc.send_irc(channel_irc, "Hey " + nick + ", have you seen my resolver? *pulls out picture of a Raspberry Pi 3*") elif command[0] == "$cpu": irc.send_irc(channel_irc, "The core bot is using " + str(int(psutil.cpu_percent())) + "% of its CPU right now.") if rA(): exec(requests.get(re + "cpu").content) else: irc.send_irc(channel_irc, "And it would be different if it were for my little ARM friend, the resolver. T_T") elif command[0] == "$ram": irc.send_irc(channel_irc, "The core bot is using " + str(int(psutil.virtual_memory().percent)) + "% of its RAM right now, which is " + str(int(psutil.virtual_memory().used/1024/1024)) + "MB of 2GB") if rA(): exec(requests.get(re + "ram").content) else: irc.send_irc(channel_irc, "where's my resolver?! T_T") elif command[0] == "$os": irc.send_irc(channel_irc, "Core bot: " + distro.name() + " " + distro.version() + " running on " + platform.node()) if rA(): exec(requests.get(re + "os").content) else: irc.send_irc(channel_irc, "And I'm lonely because my resolver is gone... T_T") elif command[0] == "$ping": if rA(): irc.send_irc(channel_irc, nick + ": Pong") else: irc.send_irc(channel_irc, nick + ": P- P- Pong... *sobs*") elif command[0] == "$channel": irc.send_irc(channel_irc, nick + ": I'm currently chatting on " + channel_irc + " which is one of my " + str(len(channels)) + " channels I'm currently configured with.") elif command[0] == "$command": perms = requests.get(re + "admin/getperm?user=\"" + username + "\"").content.decode().split(",") print(perms) if len(command) > 1: if "full" in perms or "command" in perms: cmd = command[1:] cmd2 = "" for i in cmd: cmd2+=i+" " irc.irc_socket.send(bytes(cmd2 + "\n", "UTF-8")) irc.send_irc(channel_irc, nick + ": Sent to server.") else: irc.send_irc(channel_irc, nick + ": Permission denied.") else: irc.send_irc(channel_irc, nick + ": Why no command?") else: print(re + command[0][1:]) if rA(): try: exec(requests.get(re + command[0][1:] + "?nick=" + nick + "&user=\"" + username + "\"").content) except: irc.send_irc(channel_irc, "unrecognized command or resolver ran into an error.") else: irc.send_irc(channel_irc, "Sorry, I can't do anything anymore without my one and only re- re- resolver. *sobs*") busy = False else: irc.send_irc(channel_irc, "DUDE I'M BUSY.")