FireBot/commands.py

273 lines
8.5 KiB
Python
Raw Normal View History

2023-11-20 23:52:18 +00:00
#!/usr/bin/python3
2023-11-07 05:19:40 +00:00
from subprocess import run, PIPE
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
def fpmp(bot: bare.bot, chan: str, name: str, message: str) -> None:
bot.msg("Firepup's master playlist", chan)
bot.msg("https://open.spotify.com/playlist/4ctNy3O0rOwhhXIKyLvUZM", chan)
2024-04-07 05:38:49 +00:00
def version(bot: bare.bot, chan: str, name: str, message: str) -> None:
bot.msg("Version: " + bot.__version__, chan)
2024-04-07 05:38:49 +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(
2024-03-06 18:33:04 +00:00
f"Hi! I'm FireBot (https://git.amcforum.wiki/Firepup650/fire-ircbot)! {'My admins on this server are' + str(bot.adminnames) + '.' if bot.adminnames else ''}", # pyright: ignore [reportOperatorIssue]
2023-11-07 13:06:55 +00:00
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(
2024-02-15 03:17:08 +00:00
f"{'Yes' if checks.admin(bot, name) else 'No'}",
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)
2024-02-15 03:17:08 +00:00
if checks.admin(bot, name):
2023-11-07 05:19:59 +00:00
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]
2024-04-07 05:38:49 +00:00
qfilter = query.replace(
" ", "\s"
) # pyright: ignore [reportInvalidStringEscapeSequence]
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:
q =[]
try:
q = list(filter(lambda x: re.search(qfilter, x), mm.readlines()))
except re.error:
q = ['Sorry, your query is invalid regex. Please try again.']
2023-11-21 02:11:44 +00:00
if q == []:
q = [f'No results for "{query}" ']
sel = conf.decode_escapes(
2024-02-20 22:02:26 +00:00
r.sample(q, 1)[0].replace("\\n", "").replace("\n", "")
2023-11-21 02:11:44 +00:00
)
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,
2024-04-07 05:38:49 +00:00
"ADMINS": str(bot.adminnames) + " (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-23 18:27:21 +00:00
if name in bot.npallowed and not bot.current == "bridge":
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
2024-04-07 04:45:38 +00:00
def fmpull(bot: bare.bot, chan: str, name: str, message: str) -> None:
song = None
2024-04-07 04:45:38 +00:00
try:
song = bot.lastfmLink.get_user("Firepup650").get_now_playing()
2024-04-07 04:45:38 +00:00
except:
2024-04-07 05:38:49 +00:00
bot.msg(
"Sorry, the music api isn't cooperating, please try again in a minute", chan
)
if song:
bot.msg(
2024-04-12 02:45:40 +00:00
"Firepup is currently listening to: " + song.__str__(),
chan,
)
else:
bot.msg("Firepup currently has his music stopped :/", chan)
2024-04-07 05:38:49 +00:00
2024-04-07 04:45:38 +00:00
2023-11-18 02:27:06 +00:00
def whoami(bot: bare.bot, chan: str, name: str, message: str) -> None:
2024-04-07 05:38:49 +00:00
bot.msg(
2024-04-29 21:31:05 +00:00
f"I think you are {name}{' (bridge)' if bot.current == 'bridge' else '@'+bot.tmpHost}",
2024-04-07 05:38:49 +00:00
chan,
)
2023-11-18 02:27:06 +00:00
2023-11-07 05:19:59 +00:00
def markov(bot: bare.bot, chan: str, name: str, message: str) -> None:
word = None
if " " in message:
word = message.split()[1]
proposed = bot.markov.generate_text(word)
if proposed == word:
proposed = f"Chain failed. (Firepup has never been recorded saying \"{word}\")"
bot.msg(proposed, chan)
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]
2024-04-12 02:45:40 +00:00
"restart": {
"prefix": True,
"aliases": ["reboot", "stop", "hardreload", "hr"],
"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},
2024-04-07 05:38:49 +00:00
"debug": {"prefix": True, "aliases": ["dbg", "d"], "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"]},
"goat.mode.activate": {"prefix": True, "aliases": ["g.m.a"], "check": checks.admin},
2024-04-07 05:38:49 +00:00
"goat.mode.deactivate": {
"prefix": True,
"aliases": ["g.m.d"],
"check": checks.admin,
},
"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": []},
"fpmp": {"prefix": True, "aliases": []},
2024-04-07 05:38:49 +00:00
"version": {"prefix": True, "aliases": ["ver", "v"]},
2024-04-07 04:45:38 +00:00
"np": {"prefix": True, "aliases": []},
"markov": {"prefix": True, "aliases": ["m"]}
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,
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,
"fpmp": fpmp,
"version": version,
2024-04-07 04:45:38 +00:00
"np": fmpull,
"markov": markov,
2023-11-07 05:19:59 +00:00
}