Formatting
This commit is contained in:
parent
ed5b9c47e8
commit
8e2edcf79f
2 changed files with 126 additions and 86 deletions
22
bot.py
22
bot.py
|
@ -7,6 +7,7 @@ from typing import NoReturn
|
||||||
from config import npbase, servers, __version__
|
from config import npbase, servers, __version__
|
||||||
import commands as cmds
|
import commands as cmds
|
||||||
|
|
||||||
|
|
||||||
class bot:
|
class bot:
|
||||||
def __init__(self, server: str):
|
def __init__(self, server: str):
|
||||||
self.gmode = False
|
self.gmode = False
|
||||||
|
@ -218,7 +219,7 @@ class bot:
|
||||||
elif chan not in channels:
|
elif chan not in channels:
|
||||||
self.log(
|
self.log(
|
||||||
f"Channel not in channels ({chan} not in {channels})",
|
f"Channel not in channels ({chan} not in {channels})",
|
||||||
"WARN"
|
"WARN",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
channels[chan] += 1
|
channels[chan] += 1
|
||||||
|
@ -226,14 +227,22 @@ class bot:
|
||||||
cmds.goat(self, chan)
|
cmds.goat(self, chan)
|
||||||
handled = False
|
handled = False
|
||||||
for cmd in cmds.data:
|
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)
|
cmds.call[cmd](self, chan, name)
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
if not handled:
|
if not handled:
|
||||||
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, message)
|
cmds.call[cmd](self, chan, name, message)
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
|
@ -241,7 +250,12 @@ class bot:
|
||||||
break
|
break
|
||||||
if not handled:
|
if not handled:
|
||||||
for check in cmds.checks:
|
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)
|
cmds.call[check](self, chan, name, message)
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
|
|
190
commands.py
190
commands.py
|
@ -1,5 +1,6 @@
|
||||||
from subprocess import run, PIPE
|
from subprocess import run, PIPE
|
||||||
|
|
||||||
|
|
||||||
def goat(bot, chan: str, name: str, message: 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)
|
||||||
|
@ -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}.",
|
f"Hi! I'm FireBot (https://git.amcforum.wiki/Firepup650/fire-ircbot)! My admins on this server are {adminnames}.",
|
||||||
chan,
|
chan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def bugs(bot, chan: str, name: str, message: str) -> None:
|
def bugs(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.msg(
|
bot.msg(
|
||||||
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def hi(bot, chan: str, name: str, message: str) -> None:
|
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:
|
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:
|
def ping(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.msg(
|
bot.msg(
|
||||||
f"{name}: pong",
|
f"{name}: pong",
|
||||||
chan,
|
chan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def uptime(bot, chan: str, name: str, message: str) -> None:
|
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()
|
bot.msg(
|
||||||
)
|
f"Uptime: {uptime}",
|
||||||
bot.msg(
|
chan,
|
||||||
f"Uptime: {uptime}",
|
)
|
||||||
chan,
|
|
||||||
)
|
|
||||||
def isAdmin(bot, chan: str, name: str, message: str) -> None:
|
def isAdmin(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.msg(
|
bot.msg(
|
||||||
f"{name.lower()} in {bot.adminnames} == {name.lower() in bot.adminnames}",
|
f"{name.lower()} in {bot.adminnames} == {name.lower() in bot.adminnames}",
|
||||||
chan,
|
chan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def help(bot, chan: str, name: str, message: str) -> None:
|
def help(bot, chan: str, name: str, message: str) -> None:
|
||||||
if not helpErr:
|
if not helpErr:
|
||||||
bot.msg("Command list needs rework", name)
|
bot.msg("Command list needs rework", name)
|
||||||
return
|
return
|
||||||
bot.msg("List of commands:", name)
|
bot.msg("List of commands:", name)
|
||||||
bot.msg(f'Current bot.prefix is "{bot.prefix}"', 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}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(
|
bot.msg(
|
||||||
f"{bot.prefix}quote - Sends a random firepup quote", name
|
f"{bot.prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
|
||||||
)
|
|
||||||
bot.msg(
|
|
||||||
f"{bot.prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
|
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
bot.msg(
|
else:
|
||||||
f"(hi,hello) {botnick} - The bot says hi to you", name
|
bot.msg("Sorry, I can't send help to bridged users.", chan)
|
||||||
)
|
|
||||||
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)
|
|
||||||
def goatOn(bot, chan: str, name: str, message: str) -> None:
|
def goatOn(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.log("GOAT DETECTION ACTIVATED")
|
bot.log("GOAT DETECTION ACTIVATED")
|
||||||
bot.gmode = True
|
bot.gmode = True
|
||||||
|
|
||||||
|
|
||||||
def goatOff(bot, chan: str, name: str, message: str) -> None:
|
def goatOff(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.log("GOAT DETECTION DEACTIVATED")
|
bot.log("GOAT DETECTION DEACTIVATED")
|
||||||
bot.gmode = False
|
bot.gmode = False
|
||||||
|
|
||||||
|
|
||||||
def quote(bot, chan: str, name: str, message: str) -> None:
|
def quote(bot, chan: str, name: str, message: str) -> None:
|
||||||
r.seed()
|
r.seed()
|
||||||
mm = open("mastermessages.txt", "r")
|
mm = open("mastermessages.txt", "r")
|
||||||
q = mm.readlines()
|
q = mm.readlines()
|
||||||
sel = decode_escapes(
|
sel = decode_escapes(str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"'))
|
||||||
str(r.sample(q, 1))
|
bot.msg(sel, chan)
|
||||||
.strip("[]'")
|
mm.close()
|
||||||
.replace("\\n", "")
|
|
||||||
.strip('"')
|
|
||||||
)
|
|
||||||
bot.msg(sel, chan)
|
|
||||||
mm.close()
|
|
||||||
def join(bot, chan: str, name: str, message: str) -> None:
|
def join(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
if name.lower() in bot.adminnames:
|
||||||
newchan = message.split(" ", 1)[1].strip()
|
newchan = message.split(" ", 1)[1].strip()
|
||||||
channels = bot.join(newchan, chan)
|
channels = bot.join(newchan, chan)
|
||||||
|
|
||||||
|
|
||||||
def eball(bot, chan: str, name: str, message: str) -> None:
|
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()
|
||||||
sel = (
|
sel = str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
|
||||||
str(r.sample(q, 1))
|
bot.msg(f"The magic eightball says: {sel}", chan)
|
||||||
.strip("[]'")
|
eb.close()
|
||||||
.replace("\\n", "")
|
else:
|
||||||
.strip('"')
|
bot.msg("Please pose a Yes or No question.", chan)
|
||||||
)
|
|
||||||
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:
|
def debug(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
if name.lower() in bot.adminnames:
|
||||||
bot.msg(f"[DEBUG] NICKLEN={nicklen}", chan)
|
bot.msg(f"[DEBUG] NICKLEN={nicklen}", chan)
|
||||||
bot.msg(f"[DEBUG] ADMINS={adminnames}", chan)
|
bot.msg(f"[DEBUG] ADMINS={adminnames}", chan)
|
||||||
bot.msg(f"[DEBUG] CHANNELS={channels}", chan)
|
bot.msg(f"[DEBUG] CHANNELS={channels}", chan)
|
||||||
|
|
||||||
|
|
||||||
def raw(bot, chan: str, name: str, message: str) -> None:
|
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:
|
def reboot(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
if name.lower() in bot.adminnames:
|
||||||
send("QUIT :Rebooting\n")
|
send("QUIT :Rebooting\n")
|
||||||
exit("Reboot")
|
exit("Reboot")
|
||||||
|
|
||||||
|
|
||||||
def sudo(bot, chan: str, name: str, message: str) -> None:
|
def sudo(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
if name.lower() in bot.adminnames:
|
||||||
bot.msg(
|
bot.msg("Error - system failure, contact system operator", chan)
|
||||||
"Error - system failure, contact system operator", chan
|
elif "bot" in name.lower():
|
||||||
)
|
bot.log("lol, no.")
|
||||||
elif "bot" in name.lower():
|
else:
|
||||||
bot.log("lol, no.")
|
bot.msg("Access Denied", chan)
|
||||||
else:
|
|
||||||
bot.msg("Access Denied", chan)
|
|
||||||
def nowplaying(bot, chan: str, name: str, message: str) -> None:
|
def nowplaying(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name in bot.npallowed:
|
if name in bot.npallowed:
|
||||||
x02 = "\x02"
|
x02 = "\x02"
|
||||||
|
@ -129,5 +146,14 @@ def nowplaying(bot, chan: str, name: str, message: str) -> None:
|
||||||
chan,
|
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,
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue