Last active 5 days ago

Modified May 16, 2024. I have no idea where the resolver code is.

swee revised this gist 5 days ago. Go to revision

2 files changed, 153 insertions

sweebot-launcher.py(file created)

@@ -0,0 +1,7 @@
1 + #!/usr/bin/python3
2 + import os
3 + from time import sleep
4 + while True:
5 + code = os.system("python /home/swee/sweebot.py")
6 + print("Exit code: " + str(code))
7 + sleep(5)

sweebot.py(file created)

@@ -0,0 +1,146 @@
1 + import socket
2 + import sys
3 + import psutil
4 + import subprocess
5 + import requests
6 + import platform
7 + import distro
8 + from time import sleep
9 + busy = False
10 + class bot_irc:
11 +
12 + irc_socket = socket.socket()
13 +
14 + def __init__(self):
15 + self.irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16 +
17 + def send_irc(self, channel, msg):
18 + self.irc_socket.send(bytes("PRIVMSG " + channel + " :" + msg + " \n", "UTF-8"))
19 +
20 + def connect_irc(self, server, port, channel, bot_nick, bot_pass, bot_nickpass):
21 + print("Server connection: " + server)
22 + self.irc_socket.connect((server, port))
23 +
24 + self.irc_socket.send(
25 + bytes(
26 + "USER " + bot_nick + " " + bot_nick + " " + bot_nick + " :SweeBot, a very cool bot made by Swee :3\n",
27 + "UTF-8",
28 + )
29 + )
30 + self.irc_socket.send(bytes("NICK " + bot_nick + "\n", "UTF-8"))
31 + self.irc_socket.send(
32 + #bytes("NICKSERV IDENTIFY " + bot_nickpass + " " + bot_pass + "\n", "UTF-8")
33 + bytes("PASS " + bot_nickpass + ":" + bot_pass + "\n", "UTF-8")
34 + )
35 + for i in channel:
36 + self.irc_socket.send(bytes("JOIN " + i + "\n", "UTF-8"))
37 +
38 + def response_irc(self):
39 + r = self.irc_socket.recv(2040).decode("UTF-8")
40 + if r.find("PING") != -1:
41 + self.irc_socket.send(
42 + bytes("PONG " + r.split()[1] + "\r\n", "UTF-8")
43 + )
44 + return r
45 +
46 + server_irc = "127.0.0.1"
47 + port_irc = 5000
48 + channels = ["##sweezero","##","##rudechat","##mintHTML","##elysium","##gnu/crack"]
49 + botnick_irc = "sweeBot"
50 + botnickpass_irc = "sweeBot"
51 + botpass_irc = "swee15cool"
52 + irc = bot_irc()
53 + irc.connect_irc(
54 + server_irc, port_irc, channels, botnick_irc, botpass_irc, botnickpass_irc
55 + )
56 + re = "http://192.168.12.225:1337/"
57 + def rA():
58 + try:
59 + requests.get(re + "os")
60 + return True
61 + except:
62 + return False
63 + while True:
64 + text = irc.response_irc()
65 + try:
66 + channel_irc = str(text).split(" ")[2]
67 + except:
68 + continue
69 + command = str(text).split(":")
70 + command = command[len(command) - 1][:-2].split(" ")
71 + try:
72 + print(text)
73 + except:
74 + print("Unable to print text, possible unicode?")
75 + if command[0] == "":
76 + continue
77 + if "PRIVMSG" in text and channel_irc in channels and command[0][0] == "$":
78 +
79 + username = str(text).split(" ")[0].split("@")[1]
80 + nick = str(text).split(" ")[0].split("@")[0][1:].split("!")[0]
81 + print(command)
82 + if not busy:
83 + busy = True
84 + if command[0] == "$hello":
85 + if rA():
86 + irc.send_irc(channel_irc, "Greetings " + nick + ", I am SweeBot!")
87 + else:
88 + irc.send_irc(channel_irc, "Hey " + nick + ", have you seen my resolver? *pulls out picture of a Raspberry Pi 3*")
89 +
90 + elif command[0] == "$cpu":
91 + irc.send_irc(channel_irc, "The core bot is using " + str(int(psutil.cpu_percent())) + "% of its CPU right now.")
92 + if rA():
93 + exec(requests.get(re + "cpu").content)
94 + else:
95 + irc.send_irc(channel_irc, "And it would be different if it were for my little ARM friend, the resolver. T_T")
96 +
97 + elif command[0] == "$ram":
98 + 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")
99 + if rA():
100 + exec(requests.get(re + "ram").content)
101 + else:
102 + irc.send_irc(channel_irc, "where's my resolver?! T_T")
103 +
104 + elif command[0] == "$os":
105 + irc.send_irc(channel_irc, "Core bot: " + distro.name() + " " + distro.version() + " running on " + platform.node())
106 + if rA():
107 + exec(requests.get(re + "os").content)
108 + else:
109 + irc.send_irc(channel_irc, "And I'm lonely because my resolver is gone... T_T")
110 +
111 + elif command[0] == "$ping":
112 + if rA():
113 + irc.send_irc(channel_irc, nick + ": Pong")
114 + else:
115 + irc.send_irc(channel_irc, nick + ": P- P- Pong... *sobs*")
116 +
117 + elif command[0] == "$channel":
118 + 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.")
119 + elif command[0] == "$command":
120 + perms = requests.get(re + "admin/getperm?user=\"" + username + "\"").content.decode().split(",")
121 + print(perms)
122 + if len(command) > 1:
123 + if "full" in perms or "command" in perms:
124 + cmd = command[1:]
125 + cmd2 = ""
126 + for i in cmd:
127 + cmd2+=i+" "
128 + irc.irc_socket.send(bytes(cmd2 + "\n", "UTF-8"))
129 + irc.send_irc(channel_irc, nick + ": Sent to server.")
130 + else:
131 + irc.send_irc(channel_irc, nick + ": Permission denied.")
132 + else:
133 + irc.send_irc(channel_irc, nick + ": Why no command?")
134 +
135 + else:
136 + print(re + command[0][1:])
137 + if rA():
138 + try:
139 + exec(requests.get(re + command[0][1:] + "?nick=" + nick + "&user=\"" + username + "\"").content)
140 + except:
141 + irc.send_irc(channel_irc, "unrecognized command or resolver ran into an error.")
142 + else:
143 + irc.send_irc(channel_irc, "Sorry, I can't do anything anymore without my one and only re- re- resolver. *sobs*")
144 + busy = False
145 + else:
146 + irc.send_irc(channel_irc, "DUDE I'M BUSY.")
Newer Older