Formatting

This commit is contained in:
Firepup Sixfifty 2023-11-06 23:19:59 -06:00
parent ed5b9c47e8
commit 8e2edcf79f
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
2 changed files with 126 additions and 86 deletions

22
bot.py
View file

@ -7,6 +7,7 @@ from typing import NoReturn
from config import npbase, servers, __version__
import commands as cmds
class bot:
def __init__(self, server: str):
self.gmode = False
@ -218,7 +219,7 @@ class bot:
elif chan not in channels:
self.log(
f"Channel not in channels ({chan} not in {channels})",
"WARN"
"WARN",
)
else:
channels[chan] += 1
@ -226,14 +227,22 @@ class bot:
cmds.goat(self, chan)
handled = False
for cmd in cmds.data:
if mfind(message, cmd.replace("$BOTNICK", self.nick), cmds.data[cmd]["prefix"]):
if mfind(
message,
cmd.replace("$BOTNICK", self.nick),
cmds.data[cmd]["prefix"],
):
cmds.call[cmd](self, chan, name)
handled = True
break
if not handled:
for cmd in cmds.data:
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, message)
handled = True
break
@ -241,7 +250,12 @@ class bot:
break
if not handled:
for check in cmds.checks:
if re.search(check.replace("$MAX", self.nicklen).replace("$BOTNICK", self.nick), message):
if re.search(
check.replace("$MAX", self.nicklen).replace(
"$BOTNICK", self.nick
),
message,
):
cmds.call[check](self, chan, name, message)
handled = True
break

View file

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