FireBot/commands.py

188 lines
5.7 KiB
Python
Raw Normal View History

2023-11-07 05:19:40 +00:00
from subprocess import run, PIPE
2023-11-07 13:53:14 +00:00
from config import npbase, su, decode_escapes
import random as r
2023-11-07 05:19:59 +00:00
2023-11-07 05:19:40 +00:00
def goat(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
def botlist(bot, chan: str, name: str, message: str) -> None:
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-07 05:19:40 +00:00
def bugs(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-07 05:19:40 +00:00
def hi(bot, chan: str, name: str, message: str) -> None:
2023-11-07 05:19:59 +00:00
bot.msg(f"Hello {name}!", chan)
2023-11-07 05:19:40 +00:00
def op(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-07 05:19:40 +00:00
def ping(bot, chan: str, name: str, message: str) -> None:
2023-11-07 05:19:59 +00:00
bot.msg(
f"{name}: pong",
chan,
)
2023-11-07 05:19:40 +00:00
def uptime(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-07 05:19:40 +00:00
def isAdmin(bot, chan: str, name: str, message: str) -> None:
2023-11-07 05:19:59 +00:00
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)
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-07 05:19:59 +00:00
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)
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-07 05:19:40 +00:00
def goatOn(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-07 05:19:40 +00:00
def goatOff(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-07 05:19:40 +00:00
def quote(bot, chan: str, name: str, message: str) -> None:
2023-11-07 05:19:59 +00:00
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()
2023-11-07 05:19:40 +00:00
def join(bot, chan: str, name: str, message: str) -> None:
newchan = message.split(" ", 1)[1].strip()
2023-11-07 13:06:55 +00:00
bot.join(newchan, chan)
2023-11-07 05:19:59 +00:00
2023-11-07 05:19:40 +00:00
def eball(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-07 05:19:40 +00:00
def debug(bot, chan: str, name: str, message: str) -> None:
2023-11-07 15:05:23 +00:00
bot.msg(f"[DEBUG] VERSION={bot.__version__}", chan)
2023-11-07 13:53:14 +00:00
bot.msg(f"[DEBUG] NICKLEN={bot.nicklen}", chan)
bot.msg(f"[DEBUG] ADMINS={bot.adminnames}", chan)
bot.msg(f"[DEBUG] CHANNELS={bot.channels}", chan)
2023-11-07 05:19:59 +00:00
2023-11-07 05:19:40 +00:00
def raw(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-07 05:19:40 +00:00
def reboot(bot, chan: str, name: str, message: str) -> None:
2023-11-07 13:06:55 +00:00
bot.send("QUIT :Rebooting\n")
bot.exit("Reboot")
2023-11-07 05:19:59 +00:00
2023-11-07 05:19:40 +00:00
def sudo(bot, chan: str, name: str, message: str) -> None:
2023-11-07 05:19:59 +00:00
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)
2023-11-07 05:19:40 +00:00
def nowplaying(bot, chan: str, name: str, message: str) -> None:
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-07 00:18:52 +00:00
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
chan,
)
2023-11-07 05:19:59 +00:00
data = {
"!botlist": {"prefix": False, "aliases": []},
"bugs bugs bugs": {"prefix": False, "aliases": []},
"hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]},
2023-11-07 13:06:55 +00:00
# [npbase, su]
2023-11-07 15:05:23 +00:00
"restart": {"prefix": True, "aliases": ["reboot"], "admin": True},
2023-11-07 13:06:55 +00:00
"uptime": {"prefix": True, "aliases": []},
2023-11-07 15:05:23 +00:00
"raw ": {"prefix": True, "aliases": ["cmd "], "admin": True},
"debug": {"prefix": True, "aliases": ["dbg"], "admin": True},
2023-11-07 13:06:55 +00:00
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
2023-11-07 15:05:23 +00:00
"join ": {"prefix": True, "aliases": [], "admin": True},
2023-11-07 13:53:14 +00:00
"quote": {"prefix": True, "aliases": ["q"]},
2023-11-07 15:05:23 +00:00
"goat.mode.activate": {"prefix": True, "aliases": [], "admin": True},
"goat.mode.deactivate": {"prefix": True, "aliases": [], "admin": True},
2023-11-07 13:06:55 +00:00
"help": {"prefix": True, "aliases": []},
"amIAdmin": {"prefix": True, "aliases": []},
"ping": {"prefix": True, "aliases": []},
2023-11-07 15:05:23 +00:00
"op me": {"prefix": False, "aliases": [], "admin": True},
2023-11-07 05:19:59 +00:00
}
2023-11-07 13:06:55 +00:00
checks = [npbase, su]
2023-11-07 05:19:59 +00:00
call = {
"!botlist": botlist,
"bugs bugs bugs": bugs,
"hi $BOTNICK": hi,
2023-11-07 13:06:55 +00:00
npbase: nowplaying,
su: sudo,
"restart": reboot,
"uptime": uptime,
"raw ": raw,
"debug": debug,
"8ball": eball,
"join ": join,
"quote": quote,
"goat.mode.activate": goatOn,
"goat.mode.decativate": goatOff,
"help": help,
"amIAdmin": isAdmin,
"ping": ping,
"op me": op,
2023-11-07 05:19:59 +00:00
}