2023-11-20 23:52:18 +00:00
|
|
|
#!/usr/bin/python3
|
2023-11-07 05:19:40 +00:00
|
|
|
from subprocess import run, PIPE
|
2023-11-15 04:44:54 +00:00
|
|
|
import config as conf
|
2023-11-07 13:53:14 +00:00
|
|
|
import random as r
|
2023-11-13 21:42:46 +00:00
|
|
|
from typing import Any, Callable
|
2023-11-20 23:52:18 +00:00
|
|
|
import bare, re, checks
|
2023-11-07 05:19:59 +00:00
|
|
|
|
2023-11-08 02:30:35 +00:00
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def goat(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 00:18:52 +00:00
|
|
|
bot.log("GOAT DETECTED")
|
|
|
|
bot.msg("Hello Goat", chan)
|
2023-11-07 15:05:23 +00:00
|
|
|
bot.gmode = False
|
2023-11-07 13:06:55 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def botlist(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 13:06:55 +00:00
|
|
|
bot.msg(
|
|
|
|
f"Hi! I'm FireBot (https://git.amcforum.wiki/Firepup650/fire-ircbot)! My admins on this server are {bot.adminnames}.",
|
|
|
|
chan,
|
|
|
|
)
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def bugs(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.msg(
|
|
|
|
f"\x01ACTION realizes {name} looks like a bug, and squashes {name}\x01",
|
|
|
|
chan,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def hi(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.msg(f"Hello {name}!", chan)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def op(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:22:36 +00:00
|
|
|
bot.op(name, chan)
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def ping(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.msg(
|
|
|
|
f"{name}: pong",
|
|
|
|
chan,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def uptime(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
uptime = run(["uptime", "-p"], stdout=PIPE).stdout.decode().strip()
|
|
|
|
bot.msg(
|
|
|
|
f"Uptime: {uptime}",
|
|
|
|
chan,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def isAdmin(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.msg(
|
2023-11-20 23:52:18 +00:00
|
|
|
f"{checks.admin(bot, name)} (hostname is not checked)",
|
2023-11-07 05:19:59 +00:00
|
|
|
chan,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def help(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-09 03:20:50 +00:00
|
|
|
helpErr = False
|
2023-11-20 23:52:18 +00:00
|
|
|
if bot.current == "bridge":
|
2023-11-09 03:20:50 +00:00
|
|
|
helpErr = True
|
2023-11-07 05:19:59 +00:00
|
|
|
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)
|
2023-11-07 05:19:40 +00:00
|
|
|
bot.msg(
|
2023-11-07 05:19:59 +00:00
|
|
|
f"{bot.prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
|
|
|
|
name,
|
2023-11-07 00:18:52 +00:00
|
|
|
)
|
2023-11-09 03:20:50 +00:00
|
|
|
bot.msg(f"(hi,hello) {bot.nick} - The bot says hi to you", name)
|
2023-11-07 05:19:59 +00:00
|
|
|
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)
|
2023-11-07 05:19:40 +00:00
|
|
|
bot.msg(
|
2023-11-07 05:19:59 +00:00
|
|
|
f"{bot.prefix}join [channel(s)] - Joins the bot to the specified channel(s)",
|
2023-11-07 00:18:52 +00:00
|
|
|
name,
|
|
|
|
)
|
2023-11-07 05:19:59 +00:00
|
|
|
else:
|
|
|
|
bot.msg("Sorry, I can't send help to bridged users.", chan)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def goatOn(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.log("GOAT DETECTION ACTIVATED")
|
|
|
|
bot.gmode = True
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def goatOff(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.log("GOAT DETECTION DEACTIVATED")
|
|
|
|
bot.gmode = False
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def quote(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-21 02:11:44 +00:00
|
|
|
qfilter = ""
|
|
|
|
query = ""
|
2023-11-18 02:24:36 +00:00
|
|
|
if " " in message:
|
|
|
|
query = message.split(" ", 1)[1]
|
2023-11-21 02:11:44 +00:00
|
|
|
qfilter = query.replace(" ", "\s")
|
2023-11-07 05:19:59 +00:00
|
|
|
r.seed()
|
2023-11-21 02:11:44 +00:00
|
|
|
with open("mastermessages.txt", "r") as mm:
|
2023-11-21 02:15:08 +00:00
|
|
|
q = list(filter(lambda x: re.search(qfilter, x), mm.readlines()))
|
2023-11-21 02:11:44 +00:00
|
|
|
if q == []:
|
|
|
|
q = [f'No results for "{query}" ']
|
|
|
|
sel = conf.decode_escapes(
|
|
|
|
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
|
|
|
|
)
|
|
|
|
bot.msg(sel, chan)
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def join(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-08 02:30:35 +00:00
|
|
|
newchan = message.split(" ", 1)[1].strip()
|
|
|
|
bot.join(newchan, chan)
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def eball(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:59 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def debug(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-08 03:23:59 +00:00
|
|
|
dbg_out = {
|
|
|
|
"VERSION": bot.__version__,
|
|
|
|
"NICKLEN": bot.nicklen,
|
|
|
|
"NICK": bot.nick,
|
2023-11-15 05:26:02 +00:00
|
|
|
"ADMINS": str(conf.servers[bot.server]["admins"])
|
|
|
|
+ " (Does not include hostname checks)",
|
2023-11-08 03:23:59 +00:00
|
|
|
"CHANNELS": bot.channels,
|
|
|
|
}
|
2023-11-08 02:49:44 +00:00
|
|
|
bot.msg(f"[DEBUG] {dbg_out}", chan)
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def raw(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 15:20:56 +00:00
|
|
|
bot.sendraw(message.split(" ", 1)[1])
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def reboot(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-08 02:30:35 +00:00
|
|
|
bot.send("QUIT :Rebooting\n")
|
|
|
|
bot.exit("Reboot")
|
2023-11-07 05:19:59 +00:00
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def sudo(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-20 23:52:18 +00:00
|
|
|
if checks.admin(bot, name):
|
2023-11-07 05:19:59 +00:00
|
|
|
bot.msg("Error - system failure, contact system operator", chan)
|
|
|
|
elif "bot" in name.lower():
|
|
|
|
bot.log("lol, no.")
|
|
|
|
else:
|
|
|
|
bot.msg("Access Denied", chan)
|
|
|
|
|
|
|
|
|
2023-11-13 21:42:46 +00:00
|
|
|
def nowplaying(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
2023-11-07 05:19:40 +00:00
|
|
|
if name in bot.npallowed:
|
2023-11-07 00:18:52 +00:00
|
|
|
x02 = "\x02"
|
2023-11-07 05:19:40 +00:00
|
|
|
bot.msg(
|
2023-11-13 21:42:46 +00:00
|
|
|
f"f.sp {message.split(x02)[1]}",
|
2023-11-07 00:18:52 +00:00
|
|
|
chan,
|
|
|
|
)
|
|
|
|
|
2023-11-18 03:24:10 +00:00
|
|
|
|
2023-11-18 02:27:06 +00:00
|
|
|
def whoami(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
|
|
|
bot.msg(f"I think you are {name}", chan)
|
|
|
|
|
2023-11-07 05:19:59 +00:00
|
|
|
|
2023-11-09 03:20:50 +00:00
|
|
|
data: dict[str, dict[str, Any]] = {
|
2023-11-07 05:19:59 +00:00
|
|
|
"!botlist": {"prefix": False, "aliases": []},
|
|
|
|
"bugs bugs bugs": {"prefix": False, "aliases": []},
|
|
|
|
"hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]},
|
2023-11-08 02:30:35 +00:00
|
|
|
# [npbase, su]
|
2023-11-20 23:52:18 +00:00
|
|
|
"restart": {"prefix": True, "aliases": ["reboot"], "check": checks.admin},
|
2023-11-07 13:06:55 +00:00
|
|
|
"uptime": {"prefix": True, "aliases": []},
|
2023-11-20 23:52:18 +00:00
|
|
|
"raw ": {"prefix": True, "aliases": ["cmd "], "check": checks.admin},
|
|
|
|
"debug": {"prefix": True, "aliases": ["dbg"], "check": checks.admin},
|
2023-11-07 13:06:55 +00:00
|
|
|
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
|
2023-11-20 23:52:18 +00:00
|
|
|
"join ": {"prefix": True, "aliases": [], "check": checks.admin},
|
2023-11-07 13:53:14 +00:00
|
|
|
"quote": {"prefix": True, "aliases": ["q"]},
|
2023-11-20 23:52:18 +00:00
|
|
|
"goat.mode.activate": {"prefix": True, "aliases": [], "check": checks.admin},
|
|
|
|
"goat.mode.deactivate": {"prefix": True, "aliases": [], "check": checks.admin},
|
2023-11-07 13:06:55 +00:00
|
|
|
"help": {"prefix": True, "aliases": []},
|
2023-11-15 04:47:51 +00:00
|
|
|
"amiadmin": {"prefix": True, "aliases": []},
|
2023-11-07 13:06:55 +00:00
|
|
|
"ping": {"prefix": True, "aliases": []},
|
2023-11-20 23:52:18 +00:00
|
|
|
"op me": {"prefix": False, "aliases": [], "check": checks.admin},
|
2023-11-18 02:27:06 +00:00
|
|
|
"whoami": {"prefix": True, "aliases": []},
|
2023-11-07 05:19:59 +00:00
|
|
|
}
|
2023-11-20 23:52:18 +00:00
|
|
|
regexes: list[str] = [conf.npbase, conf.su]
|
2023-11-13 21:42:46 +00:00
|
|
|
call: dict[str, Callable[[bare.bot, str, str, str], None]] = {
|
2023-11-07 05:19:59 +00:00
|
|
|
"!botlist": botlist,
|
|
|
|
"bugs bugs bugs": bugs,
|
|
|
|
"hi $BOTNICK": hi,
|
2023-11-15 04:44:54 +00:00
|
|
|
conf.npbase: nowplaying,
|
|
|
|
conf.su: sudo,
|
2023-11-07 13:06:55 +00:00
|
|
|
"restart": reboot,
|
|
|
|
"uptime": uptime,
|
|
|
|
"raw ": raw,
|
|
|
|
"debug": debug,
|
|
|
|
"8ball": eball,
|
|
|
|
"join ": join,
|
|
|
|
"quote": quote,
|
|
|
|
"goat.mode.activate": goatOn,
|
|
|
|
"goat.mode.decativate": goatOff,
|
|
|
|
"help": help,
|
2023-11-15 04:47:51 +00:00
|
|
|
"amiadmin": isAdmin,
|
2023-11-07 13:06:55 +00:00
|
|
|
"ping": ping,
|
|
|
|
"op me": op,
|
2023-11-18 03:24:10 +00:00
|
|
|
"whoami": whoami,
|
2023-11-07 05:19:59 +00:00
|
|
|
}
|