idk what all I did really.

This commit is contained in:
Firepup Sixfifty 2023-10-27 23:20:18 -05:00
parent 616e149d57
commit 895721d05e
2 changed files with 197 additions and 167 deletions

View file

@ -21,12 +21,14 @@ def is_dead(thr):
thr.join(timeout=0) thr.join(timeout=0)
return not thr.is_alive() return not thr.is_alive()
def start(server): def start(server):
t = Thread(target=launch, args=(server,)) t = Thread(target=launch, args=(server,))
t.daemon = True t.daemon = True
t.start() t.start()
return t return t
if __name__ == "__main__": if __name__ == "__main__":
print("[LOG][CORE] Begin initialization") print("[LOG][CORE] Begin initialization")
for server in servers: for server in servers:

362
ircbot.py
View file

@ -57,8 +57,9 @@ e = encoding
adminnames = servers[server]["admins"] adminnames = servers[server]["admins"]
exitcode = f"bye {botnick.lower()}" exitcode = f"bye {botnick.lower()}"
ircmsg = "" ircmsg = ""
blanks = 0
np = re.compile( np = re.compile(
"\[\x0303last\.fm\x03\] [A-Za-z0-9_]+ (is listening|last listened) to: \x02.+ - .+\x02 \([0-9]+ plays\)" "\[\x0303last\.fm\x03\] [A-Za-z0-9_]+ (is listening|last listened) to: \x02.+ - .+\x02 \([0-9]+ plays\)( \[.*\])?"
) )
ESCAPE_SEQUENCE_RE = re.compile( ESCAPE_SEQUENCE_RE = re.compile(
@ -82,7 +83,7 @@ def decode_escapes(s):
def sucheck(message): def sucheck(message):
return re.search("^(su|sudo).*", message) return re.search("^(su|sudo|(su .*|sudo .*))$", message)
def ping(ircmsg): def ping(ircmsg):
@ -127,7 +128,8 @@ def CTCPHandler(msg: str, sender: str = "", isRaw: bool = False):
return True return True
elif CTCP == "SOURCE": elif CTCP == "SOURCE":
notice( notice(
"\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", sender, "\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01",
sender,
True, True,
) )
return True return True
@ -156,12 +158,12 @@ def joinserver():
global nicklen global nicklen
nicklen = int(ircmsg.split("NICKLEN=")[1].split(" ")[0]) nicklen = int(ircmsg.split("NICKLEN=")[1].split(" ")[0])
print(f"[LOG][{server}] NICKLEN set to {nicklen}") print(f"[LOG][{server}] NICKLEN set to {nicklen}")
if ircmsg.find("Nickname is already in use") != -1: if ircmsg.find("Nickname already in use") != -1:
print(f"[LOG][{server}] My nickname's in use? lemme try that again...") print(f"[LOG][{server}] My nickname's in use? lemme try that again...")
ircsock.send( ircsock.send(
bytes(f"USER {botnick} {botnick} {botnick} {botnick}\n", e) bytes(f"USER {botnick} {botnick} {botnick} {botnick}\n", e)
) )
ircsock.send(bytes(f"NICK {botnick}\n", e)) ircsock.send(bytes(f"NICK {botnick+r.randint(0,1000)}\n", e))
if ircmsg.find("PING :") != -1: if ircmsg.find("PING :") != -1:
# pong = "PONG :" + input("Ping?:") + "\n" # pong = "PONG :" + input("Ping?:") + "\n"
# pong = pong.replace("\\\\", "\\") # pong = pong.replace("\\\\", "\\")
@ -233,7 +235,7 @@ def op(name, chan):
def main(): def main():
try: try:
global ircmsg, channels, e, gmode, prefix, rebt, gblrebt, lrebt, lgblrebt global ircmsg, channels, e, gmode, prefix, rebt, gblrebt, lrebt, lgblrebt, blanks
joinserver() joinserver()
if "pass" in servers[server]: if "pass" in servers[server]:
sendmsg(f"IDENTIFY {servers[server]['pass']}", "NickServ") sendmsg(f"IDENTIFY {servers[server]['pass']}", "NickServ")
@ -244,179 +246,205 @@ def main():
global ircmsg, gmode global ircmsg, gmode
raw = bytes(ircsock.recv(2048).strip(b"\r\n")) raw = bytes(ircsock.recv(2048).strip(b"\r\n"))
ircmsg = raw.decode() ircmsg = raw.decode()
if ircmsg != "": if ircmsg == "":
exit(f"[EXIT][{server}] Probably a netsplit")
else:
print(raw.lazy_decode(), sep="\n") print(raw.lazy_decode(), sep="\n")
if ircmsg.find("PRIVMSG") != -1: if ircmsg.find("PRIVMSG") != -1:
# Format of ":[Nick]!~[hostname]@[IP Address] PRIVMSG [channel] :[message]” # Format of ":[Nick]!~[hostname]@[IP Address] PRIVMSG [channel] :[message]”
name = ircmsg.split("!", 1)[0][1:] name = ircmsg.split("!", 1)[0][1:]
helpErr = False helpErr = False
if (name.startswith("saxjax") and server == "efnet") or ( if (name.startswith("saxjax") and server == "efnet") or (
name == "ReplIRC" and server == "replirc" name == "ReplIRC" and server == "replirc"
): ):
if ircmsg.find("<") != -1 and ircmsg.find(">") != -1: if ircmsg.find("<") != -1 and ircmsg.find(">") != -1:
Nname = ircmsg.split("<", 1)[1].split(">", 1)[0].strip() Nname = ircmsg.split("<", 1)[1].split(">", 1)[0].strip()
if name == "ReplIRC": if name == "ReplIRC":
name = Nname[4:] name = Nname[4:]
else:
name = Nname
message = ircmsg.split(">", 1)[1].strip()
helpErr = True
else: else:
name = Nname message = (
message = ircmsg.split(">", 1)[1].strip() ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
helpErr = True
else:
message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
else:
message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
if name.endswith("dsc"):
helpErr = True
chan = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[0].strip()
print(
f'[LOG][{server}] Got "{bytes(message.encode()).lazy_decode()}" from "{name}" in "{chan}"'
)
if "goat" in name.lower() and gmode == True:
print(f"[LOG][{server}] GOAT DETECTED")
sendmsg("Hello Goat", chan)
gmode = False
if len(name) < nicklen and chan in channels:
channels[chan] += 1
elif len(name) > nicklen:
print(f"[LOG][{server}] Name too long ({len(name)} > {nicklen})")
continue
elif chan not in channels:
print(
f"[LOG][{server}] Channel not in channels ({chan} not in {channels})"
)
continue
if mfind(
message.lower(),
[f"hi {botnick.lower()}", f"hello {botnick.lower()}"],
False,
):
sendmsg(f"Hello {name}!", chan)
elif mfind(message, ["op me"], False) and name.lower() in adminnames:
op(name, chan)
elif mfind(message, ["amIAdmin"]):
sendmsg(
f"{name.lower()} in {adminnames} == {name.lower() in adminnames}",
chan,
)
elif mfind(message, ["help"]):
if not helpErr:
sendmsg("List of commands:", name)
sendmsg(f'Current prefix is "{prefix}"', name)
sendmsg(f"{prefix}help - Sends this help list", name)
sendmsg(f"{prefix}quote - Sends a random firepup quote", name)
sendmsg(
f"{prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
name,
)
sendmsg(f"(hi,hello) {botnick} - The bot says hi to you", name)
if name.lower() in adminnames:
sendmsg(f"reboot {rebt} - Restarts the bot", name)
sendmsg(exitcode + " - Shuts down the bot", name)
sendmsg("op me - Makes the bot try to op you", name)
sendmsg(
f"{prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
name,
) )
else: else:
sendmsg("Sorry, I can't send help to bridged users.", chan) message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
elif name.lower() in adminnames and mfind( if name.endswith("dsc"):
message, ["goat.mode.activate"] helpErr = True
): chan = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[0].strip()
print(f"[LOG][{server}] GOAT DETECTION ACTIVATED") print(
gmode = True f'[LOG][{server}] Got "{bytes(message.encode()).lazy_decode()}" from "{name}" in "{chan}"'
elif name.lower() in adminnames and mfind(
message, ["goat.mode.deactivate"]
):
print(f"[LOG][{server}] GOAT DETECTION DEACTIVATED")
gmode = False
elif mfind(message, ["quote"]):
r.seed()
log = open("mastermessages.txt", "r")
q = log.readlines()
sel = decode_escapes(
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
) )
sendmsg(sel, chan) if "goat" in name.lower() and gmode == True:
log.close() print(f"[LOG][{server}] GOAT DETECTED")
elif mfind(message, ["join "]) and name.lower() in adminnames: sendmsg("Hello Goat", chan)
newchan = message.split(" ")[1].strip() gmode = False
channels = joinchan(newchan, chan, channels) if len(name) < nicklen and chan in channels:
elif mfind(message, ["eightball", "8ball", "8b"]): channels[chan] += 1
if message.endswith("?"): elif len(name) > nicklen:
log = open("eightball.txt", "r") print(
f"[LOG][{server}] Name too long ({len(name)} > {nicklen})"
)
continue
elif chan not in channels:
print(
f"[LOG][{server}] Channel not in channels ({chan} not in {channels})"
)
continue
if mfind(
message.lower(),
[f"hi {botnick.lower()}", f"hello {botnick.lower()}"],
False,
):
sendmsg(f"Hello {name}!", chan)
elif (
mfind(message, ["op me"], False) and name.lower() in adminnames
):
op(name, chan)
elif mfind(message, ["amIAdmin"]):
sendmsg(
f"{name.lower()} in {adminnames} == {name.lower() in adminnames}",
chan,
)
elif mfind(message, ["help"]):
if not helpErr:
sendmsg("List of commands:", name)
sendmsg(f'Current prefix is "{prefix}"', name)
sendmsg(f"{prefix}help - Sends this help list", name)
sendmsg(
f"{prefix}quote - Sends a random firepup quote", name
)
sendmsg(
f"{prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
name,
)
sendmsg(
f"(hi,hello) {botnick} - The bot says hi to you", name
)
if name.lower() in adminnames:
sendmsg(f"reboot {rebt} - Restarts the bot", name)
sendmsg(exitcode + " - Shuts down the bot", name)
sendmsg("op me - Makes the bot try to op you", name)
sendmsg(
f"{prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
name,
)
else:
sendmsg("Sorry, I can't send help to bridged users.", chan)
elif name.lower() in adminnames and mfind(
message, ["goat.mode.activate"]
):
print(f"[LOG][{server}] GOAT DETECTION ACTIVATED")
gmode = True
elif name.lower() in adminnames and mfind(
message, ["goat.mode.deactivate"]
):
print(f"[LOG][{server}] GOAT DETECTION DEACTIVATED")
gmode = False
elif mfind(message, ["quote"]):
r.seed()
log = open("mastermessages.txt", "r")
q = log.readlines() q = log.readlines()
sel = ( sel = decode_escapes(
str(r.sample(q, 1)) str(r.sample(q, 1))
.strip("[]'") .strip("[]'")
.replace("\\n", "") .replace("\\n", "")
.strip('"') .strip('"')
) )
sendmsg(f"The magic eightball says: {sel}", chan) sendmsg(sel, chan)
log.close() log.close()
else: elif mfind(message, ["join "]) and name.lower() in adminnames:
sendmsg("Please pose a Yes or No question.", chan) newchan = message.split(" ")[1].strip()
elif mfind(message, ["debug", "dbg"]) and name.lower() in adminnames: channels = joinchan(newchan, chan, channels)
sendmsg(f"[DEBUG] NICKLEN={nicklen}", chan) elif mfind(message, ["eightball", "8ball", "8b"]):
sendmsg(f"[DEBUG] ADMINS={adminnames}", chan) if message.endswith("?"):
sendmsg(f"[DEBUG] CHANNELS={channels}", chan) log = open("eightball.txt", "r")
elif ( q = log.readlines()
mfind(message, [f"reboot {rebt}", f"reboot {gblrebt}"], False) sel = (
and name.lower() in adminnames str(r.sample(q, 1))
): .strip("[]'")
for i in channels: .replace("\\n", "")
sendmsg("Rebooting...", i) .strip('"')
ircsock.send(bytes("QUIT :Rebooting\n", e)) )
__import__("os").system(f"python3 -u ircbot.py {server}") sendmsg(f"The magic eightball says: {sel}", chan)
exit(f"[EXIT][{server}] Inner layer exited or crashed") log.close()
elif ( else:
name.lower() in adminnames and message.rstrip().lower() == exitcode sendmsg("Please pose a Yes or No question.", chan)
): elif (
sendmsg("oh...okay. :'(", chan) mfind(message, ["debug", "dbg"]) and name.lower() in adminnames
for i in channels: ):
# print(f'[LOG][{server}] i="{i}" vs chan="{chan}"') sendmsg(f"[DEBUG] NICKLEN={nicklen}", chan)
if i != chan.strip(): sendmsg(f"[DEBUG] ADMINS={adminnames}", chan)
sendmsg("goodbye... :'(", i) sendmsg(f"[DEBUG] CHANNELS={channels}", chan)
ircsock.send(bytes("QUIT :Shutting down\n", "UTF-8")) elif (
print(f"[LOG][{server}] QUIT") mfind(message, [f"reboot {rebt}", f"reboot {gblrebt}"], False)
exit(f"[EXIT][{server}] goodbye :'(") and name.lower() in adminnames
# raise EOFError ):
elif sucheck(message): for i in channels:
if name.lower() in adminnames: sendmsg("Rebooting...", i)
sendmsg("Error - system failure, contact system operator", chan) ircsock.send(bytes("QUIT :Rebooting\n", e))
elif "bot" in name.lower(): __import__("os").system(f"python3 -u ircbot.py {server}")
print(f"[LOG][{server}] lol, no.") exit(f"[EXIT][{server}] Inner layer exited or crashed")
else: elif (
sendmsg("Access Denied", chan) name.lower() in adminnames
elif np.search(message) and name == "FireBitBot": and message.rstrip().lower() == exitcode
x02 = "\x02" ):
sendmsg( sendmsg("oh...okay. :'(", chan)
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}", for i in channels:
chan, # print(f'[LOG][{server}] i="{i}" vs chan="{chan}"')
) if i != chan.strip():
elif len(message.split("\x01")) == 3: sendmsg("goodbye... :'(", i)
if not CTCPHandler(message, name): ircsock.send(bytes("QUIT :Shutting down\n", "UTF-8"))
CTCP = message.split("\x01")[1] print(f"[LOG][{server}] QUIT")
if CTCP == "ACTION ducks": exit(f"[EXIT][{server}] goodbye :'(")
sendmsg("\x01ACTION gets hit by a duck\x01", chan) # raise EOFError
elif CTCP.startswith("ACTION ducks"): elif sucheck(message):
sendmsg(f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01", chan) if name.lower() in adminnames:
if chan in channels and channels[chan] >= interval: sendmsg(
r.seed() "Error - system failure, contact system operator", chan
channels[chan] = 0 )
log = open("mastermessages.txt", "r") elif "bot" in name.lower():
q = log.readlines() print(f"[LOG][{server}] lol, no.")
sel = decode_escapes( else:
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"') sendmsg("Access Denied", chan)
) elif np.search(message):
sendmsg(f"[QUOTE] {sel}", chan) x02 = "\x02"
log.close() sendmsg(
else: f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
if ircmsg.find("PING") != -1: chan,
ping(ircmsg) )
if ircmsg.find("Closing Link") != -1: elif len(message.split("\x01")) == 3:
exit(f"[EXIT][{server}] I got killed :'(") if not CTCPHandler(message, name):
if ircmsg.find("ERROR :Ping timeout: ") != -1: CTCP = message.split("\x01")[1]
exit(f"[EXIT][{server} Ping timeout]") if CTCP == "ACTION ducks":
sendmsg("\x01ACTION gets hit by a duck\x01", chan)
elif CTCP.startswith("ACTION ducks"):
sendmsg(
f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01",
chan,
)
if chan in channels and channels[chan] >= interval:
r.seed()
channels[chan] = 0
log = open("mastermessages.txt", "r")
q = log.readlines()
sel = decode_escapes(
str(r.sample(q, 1))
.strip("[]'")
.replace("\\n", "")
.strip('"')
)
sendmsg(f"[QUOTE] {sel}", chan)
log.close()
else:
if ircmsg.find("PING") != -1:
ping(ircmsg)
if ircmsg.find("Closing Link") != -1:
exit(f"[EXIT][{server}] I got killed :'(")
if ircmsg.find("ERROR :Ping timeout: ") != -1:
exit(f"[EXIT][{server} Ping timeout]")
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass