MAJOR MIGRATION 4

This commit is contained in:
Firepup Sixfifty 2023-11-06 23:19:40 -06:00
parent 33eefbbd77
commit ed5b9c47e8
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
2 changed files with 95 additions and 107 deletions

31
bot.py
View file

@ -234,8 +234,37 @@ class bot:
for cmd in cmds.data: for cmd in cmds.data:
for alias in cmds.data[cmd]["aliases"]: for alias in cmds.data[cmd]["aliases"]:
if mfind(message, alias.replace("$BOTNICK", self.nick), cmds.data[cmd]["prefix"]): if mfind(message, alias.replace("$BOTNICK", self.nick), cmds.data[cmd]["prefix"]):
cmds.call[cmd](self, chan, name) cmds.call[cmd](self, chan, name, message)
handled = True handled = True
break break
if handled: if handled:
break break
if not handled:
for check in cmds.checks:
if re.search(check.replace("$MAX", self.nicklen).replace("$BOTNICK", self.nick), message):
cmds.call[check](self, chan, name, message)
handled = True
break
if not handled and len(message.split("\x01")) == 3:
if not self.CTCP(message, name):
CTCP = message.split("\x01")[1]
if CTCP == "ACTION ducks":
self.msg("\x01ACTION gets hit by a duck\x01", chan)
elif CTCP.startswith("ACTION ducks"):
self.msg(
f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01",
chan,
)
if chan in self.channels and self.channels[chan] >= self.interval:
r.seed()
self.channels[chan] = 0
mm = open("mastermessages.txt", "r")
q = mm.readlines()
sel = decode_escapes(
str(r.sample(q, 1))
.strip("[]'")
.replace("\\n", "")
.strip('"')
)
self.msg(f"[QUOTE] {sel}", chan)
mm.close()

View file

@ -1,6 +1,6 @@
#TODO: Finish this from subprocess import run, PIPE
def goat(bot, chan: str, name: str) -> None: def goat(bot, chan: str, name: str, message: str) -> None:
bot.log("GOAT DETECTED") bot.log("GOAT DETECTED")
bot.msg("Hello Goat", chan) bot.msg("Hello Goat", chan)
if mfind( if mfind(
@ -8,85 +8,70 @@ def goat(bot, chan: str, name: str) -> None:
["!botlist"], ["!botlist"],
False, False,
): ):
sendmsg( bot.msg(
f"Hi! I'm FireBot (https://git.amcforum.wiki/Firepup650/fire-ircbot)! My admins on this server are {adminnames}.", f"Hi! I'm FireBot (https://git.amcforum.wiki/Firepup650/fire-ircbot)! My admins on this server are {adminnames}.",
chan, chan,
) )
if mfind( def bugs(bot, chan: str, name: str, message: str) -> None:
message.lower(), bot.msg(
["bugs bugs bugs"],
False,
):
sendmsg(
f"\x01ACTION realizes {name} looks like a bug, and squashes {name}\x01", f"\x01ACTION realizes {name} looks like a bug, and squashes {name}\x01",
chan, chan,
) )
if mfind( def hi(bot, chan: str, name: str, message: str) -> None:
message.lower(), bot.msg(f"Hello {name}!", chan)
[f"hi {botnick.lower()}", f"hello {botnick.lower()}"], def op(bot, chan: str, name: str, message: str) -> None:
False,
):
sendmsg(f"Hello {name}!", chan)
elif (
mfind(message, ["op me"], False) and name.lower() in adminnames
):
op(name, chan) op(name, chan)
elif mfind(message, ["ping"]): def ping(bot, chan: str, name: str, message: str) -> None:
sendmsg( bot.msg(
f"{name}: pong", f"{name}: pong",
chan, chan,
) )
elif mfind(message, ["uptime"]): def uptime(bot, chan: str, name: str, message: str) -> None:
uptime = ( uptime = (
run(["uptime", "-p"], stdout=PIPE).stdout.decode().strip() run(["uptime", "-p"], stdout=PIPE).stdout.decode().strip()
) )
sendmsg( bot.msg(
f"Uptime: {uptime}", f"Uptime: {uptime}",
chan, chan,
) )
elif mfind(message, ["amIAdmin"]): def isAdmin(bot, chan: str, name: str, message: str) -> None:
sendmsg( bot.msg(
f"{name.lower()} in {adminnames} == {name.lower() in adminnames}", f"{name.lower()} in {bot.adminnames} == {name.lower() in bot.adminnames}",
chan, chan,
) )
elif mfind(message, ["help"]): def help(bot, chan: str, name: str, message: str) -> None:
if not helpErr: if not helpErr:
sendmsg("Command list needs rework", name) bot.msg("Command list needs rework", name)
continue return
sendmsg("List of commands:", name) bot.msg("List of commands:", name)
sendmsg(f'Current prefix is "{prefix}"', name) bot.msg(f'Current bot.prefix is "{bot.prefix}"', name)
sendmsg(f"{prefix}help - Sends this help list", name) bot.msg(f"{bot.prefix}help - Sends this help list", name)
sendmsg( bot.msg(
f"{prefix}quote - Sends a random firepup quote", name f"{bot.prefix}quote - Sends a random firepup quote", name
) )
sendmsg( bot.msg(
f"{prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question", f"{bot.prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
name, name,
) )
sendmsg( bot.msg(
f"(hi,hello) {botnick} - The bot says hi to you", name f"(hi,hello) {botnick} - The bot says hi to you", name
) )
if name.lower() in adminnames: if name.lower() in bot.adminnames:
sendmsg(f"reboot {rebt} - Restarts the bot", name) bot.msg(f"reboot {bot.rebt} - Restarts the bot", name)
sendmsg(exitcode + " - Shuts down the bot", name) bot.msg("op me - Makes the bot try to op you", name)
sendmsg("op me - Makes the bot try to op you", name) bot.msg(
sendmsg( f"{bot.prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
f"{prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
name, name,
) )
else: else:
sendmsg("Sorry, I can't send help to bridged users.", chan) bot.msg("Sorry, I can't send help to bridged users.", chan)
elif name.lower() in adminnames and mfind( def goatOn(bot, chan: str, name: str, message: str) -> None:
message, ["goat.mode.activate"] bot.log("GOAT DETECTION ACTIVATED")
): bot.gmode = True
log("GOAT DETECTION ACTIVATED", server) def goatOff(bot, chan: str, name: str, message: str) -> None:
gmode = True bot.log("GOAT DETECTION DEACTIVATED")
elif name.lower() in adminnames and mfind( bot.gmode = False
message, ["goat.mode.deactivate"] def quote(bot, chan: str, name: str, message: str) -> None:
):
log("GOAT DETECTION DEACTIVATED", server)
gmode = False
elif mfind(message, ["quote"]):
r.seed() r.seed()
mm = open("mastermessages.txt", "r") mm = open("mastermessages.txt", "r")
q = mm.readlines() q = mm.readlines()
@ -96,12 +81,13 @@ def goat(bot, chan: str, name: str) -> None:
.replace("\\n", "") .replace("\\n", "")
.strip('"') .strip('"')
) )
sendmsg(sel, chan) bot.msg(sel, chan)
mm.close() mm.close()
elif mfind(message, ["join "]) and name.lower() in adminnames: def join(bot, chan: str, name: str, message: str) -> None:
newchan = message.split(" ")[1].strip() if name.lower() in bot.adminnames:
channels = joinchan(newchan, chan, channels) newchan = message.split(" ", 1)[1].strip()
elif mfind(message, ["eightball", "8ball", "8b"]): channels = bot.join(newchan, chan)
def eball(bot, chan: str, name: str, message: str) -> None:
if message.endswith("?"): if message.endswith("?"):
eb = open("eightball.txt", "r") eb = open("eightball.txt", "r")
q = eb.readlines() q = eb.readlines()
@ -111,64 +97,37 @@ def goat(bot, chan: str, name: str) -> None:
.replace("\\n", "") .replace("\\n", "")
.strip('"') .strip('"')
) )
sendmsg(f"The magic eightball says: {sel}", chan) bot.msg(f"The magic eightball says: {sel}", chan)
eb.close() eb.close()
else: else:
sendmsg("Please pose a Yes or No question.", chan) bot.msg("Please pose a Yes or No question.", chan)
elif ( def debug(bot, chan: str, name: str, message: str) -> None:
mfind(message, ["debug", "dbg"]) and name.lower() in adminnames if name.lower() in bot.adminnames:
): bot.msg(f"[DEBUG] NICKLEN={nicklen}", chan)
sendmsg(f"[DEBUG] NICKLEN={nicklen}", chan) bot.msg(f"[DEBUG] ADMINS={adminnames}", chan)
sendmsg(f"[DEBUG] ADMINS={adminnames}", chan) bot.msg(f"[DEBUG] CHANNELS={channels}", chan)
sendmsg(f"[DEBUG] CHANNELS={channels}", chan) def raw(bot, chan: str, name: str, message: str) -> None:
elif (
mfind(message, ["raw ", "cmd "]) and name.lower() in adminnames
):
sendraw(message.split(" ", 1)[1]) sendraw(message.split(" ", 1)[1])
elif ( def reboot(bot, chan: str, name: str, message: str) -> None:
mfind(message, [f"reboot {rebt}", f"reboot {gblrebt}"], False) if name.lower() in bot.adminnames:
or mfind(message, ["restart", "reboot"])
) and name.lower() in adminnames:
send("QUIT :Rebooting\n") send("QUIT :Rebooting\n")
exit("Reboot") exit("Reboot")
elif sucheck(message): def sudo(bot, chan: str, name: str, message: str) -> None:
if name.lower() in adminnames: if name.lower() in bot.adminnames:
sendmsg( bot.msg(
"Error - system failure, contact system operator", chan "Error - system failure, contact system operator", chan
) )
elif "bot" in name.lower(): elif "bot" in name.lower():
log("lol, no.", server) bot.log("lol, no.")
else: else:
sendmsg("Access Denied", chan) bot.msg("Access Denied", chan)
elif np.search(message) and name in npallowed: def nowplaying(bot, chan: str, name: str, message: str) -> None:
if name in bot.npallowed:
x02 = "\x02" x02 = "\x02"
sendmsg( bot.msg(
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}", f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
chan, chan,
) )
elif len(message.split("\x01")) == 3:
if not CTCPHandler(message, name):
CTCP = message.split("\x01")[1]
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
mm = open("mastermessages.txt", "r")
q = mm.readlines()
sel = decode_escapes(
str(r.sample(q, 1))
.strip("[]'")
.replace("\\n", "")
.strip('"')
)
sendmsg(f"[QUOTE] {sel}", chan)
mm.close()
data = {"!botlist": {"prefix": False, "aliases": []}, "bugs bugs bugs": {"prefix": False, "aliases": []}, "hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]}, } data = {"!botlist": {"prefix": False, "aliases": []}, "bugs bugs bugs": {"prefix": False, "aliases": []}, "hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]}, }
call = {"!botlist": botlist, "bugs bugs bugs": bugs, "hi $BOTNICK": hi, } call = {"!botlist": botlist, "bugs bugs bugs": bugs, "hi $BOTNICK": hi, }