min/modules/admin.py

261 lines
7.6 KiB
Python
Raw Normal View History

2021-01-31 02:05:34 +00:00
import importlib, time, asyncio, random
from bot import *
quitmessages = [
2022-01-27 02:26:57 +00:00
"time to die",
"you can hide, but you can not run!",
"you're next",
"bye",
"the balun has been popped.",
]
2021-01-31 02:05:34 +00:00
2020-04-05 23:27:06 +00:00
2020-04-05 23:52:31 +00:00
async def commit(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
await self.quit("{} told me to commit {}".format(source, msg))
2020-04-05 23:52:31 +00:00
2020-04-05 23:27:06 +00:00
2022-01-27 02:26:57 +00:00
async def quit(self, chan, source, msg):
await self.send(build("QUIT", [random.choice(quitmessages)]))
2020-04-05 23:52:31 +00:00
2020-04-05 23:27:06 +00:00
async def reloadmods(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
await self.message(chan, "[\x036admin\x0f] reloading modules...")
shared.oldcmd = shared.commands
shared.commands = {}
shared.rawm = {}
shared.listeners = []
shared.help = {}
try:
for i in shared.modules:
importlib.reload(shared.modules[i])
await shared.modules[i].init(self)
# await self.message(chan, '[\x036admin\x0f] load {} sucess!'.format(i))
await self.message(
chan,
"[\x036admin\x0f] done! {} modules reloaded!".format(len(shared.modules)),
)
except:
await self.message(
chan, "[\x036admin\x0f] reload failed... attempting to recover..."
)
shared.commands = shared.oldcmd
2020-04-06 20:32:51 +00:00
2021-01-31 02:05:34 +00:00
async def rawcmd(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
await self.send_raw(msg)
2020-04-05 23:27:06 +00:00
2020-04-06 20:32:51 +00:00
async def joins(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
await self.message(chan, "[\x036admin\x0f] joining slowly as to not flood...")
for i in self.chandb.all():
await self.send(build("JOIN", [i["name"]]))
await asyncio.sleep(1)
print("joined {}".format(i["name"]))
await self.message(
chan,
"[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...",
)
2020-04-06 20:32:51 +00:00
2020-04-24 16:13:46 +00:00
async def aexec(self, code):
# Make an async function with the code and `exec` it
2022-01-27 02:26:57 +00:00
exec(f"async def __ex(self): " + "".join(f"\n {l}" for l in code.split("\n")))
2020-04-24 16:13:46 +00:00
# Get `__ex` from local variables, call it and return the result
2022-01-27 02:26:57 +00:00
return await locals()["__ex"](self)
2020-04-24 16:13:46 +00:00
2020-04-06 20:32:51 +00:00
async def ev(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
msg = msg.split(" ")
try:
await self.message(
chan,
"[\x036admin\x0f] ok, output: {}".format(
str(await aexec(self, " ".join(msg)))[:400]
),
)
except:
await self.message(chan, "[\x036admin\x0f] exception in eval!")
2020-04-06 20:32:51 +00:00
2020-04-17 20:12:50 +00:00
async def send(self, c, n, m):
2022-01-27 02:26:57 +00:00
msg = m.split(" ")
await self.message(msg.pop(0), " ".join(msg))
await self.message(c, "[\x036admin\x0f] sent")
2020-04-17 20:12:50 +00:00
async def shut(self, c, n, m):
2022-01-27 02:26:57 +00:00
shared.qtime[c] = time.time() + (60 * 10)
await self.message(c, "[\x036admin\x0f] Ok, il be back in 10 minutes")
2020-07-12 12:21:53 +00:00
async def schans(self, c, n, m):
2022-01-27 02:26:57 +00:00
self.chandb.delete()
for i in self.channels:
self.chandb.insert(dict(name=i))
await self.message(c, "[\x036admin\x0f] Ok")
async def addalias(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
2020-10-04 16:26:20 +00:00
if al in self.cmd:
2022-01-27 02:26:57 +00:00
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
2020-10-04 16:26:20 +00:00
return
2022-01-27 02:26:57 +00:00
self.cmd[al] = Alias(m).alias
2020-10-04 16:26:20 +00:00
2022-01-27 02:26:57 +00:00
await self.message(c, '[\x036admin\x0f] added "{}" alias for "{}"'.format(al, m))
2020-10-04 16:26:20 +00:00
2022-01-27 02:26:57 +00:00
async def addot(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
2021-11-12 01:16:32 +00:00
if al in shared.rawm:
2022-01-27 02:26:57 +00:00
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
2021-01-31 02:05:34 +00:00
return
2022-01-27 02:26:57 +00:00
shared.rawm[al] = Ot(m, al).ot
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
async def addspook(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
2021-11-12 01:16:32 +00:00
if al in shared.rawm:
2022-01-27 02:26:57 +00:00
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
2021-11-12 01:16:32 +00:00
return
2022-01-27 02:26:57 +00:00
shared.rawm[al] = Spook(m, al).spook
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
2021-11-12 01:16:32 +00:00
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
async def addtrigger(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
2021-11-12 01:16:32 +00:00
if al in shared.rawm:
2022-01-27 02:26:57 +00:00
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy")
2021-01-31 02:05:34 +00:00
return
2022-01-27 02:26:57 +00:00
shared.rawm[al] = Trigger(m, al).trigger
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
class Ot:
2021-01-31 02:05:34 +00:00
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
2022-01-27 02:26:57 +00:00
async def ot(alself, self, c, n, m):
2021-01-31 02:05:34 +00:00
if alself.al in m and n != self.nickname:
2022-01-27 02:26:57 +00:00
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
2021-11-12 01:16:32 +00:00
shared.rawm.pop(alself.al)
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
class Spook:
2021-11-12 01:16:32 +00:00
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
2022-01-27 02:26:57 +00:00
async def spook(alself, self, c, n, m):
2021-11-12 01:16:32 +00:00
if alself.al in m and n != self.nickname:
2022-01-27 02:26:57 +00:00
asyncio.create_task(self.message(c, alself.ms.format(m)))
2021-11-12 01:16:32 +00:00
shared.rawm.pop(alself.al)
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
class Trigger:
2021-01-31 02:05:34 +00:00
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
2022-01-27 02:26:57 +00:00
async def trigger(alself, self, c, n, m):
2021-01-31 02:05:34 +00:00
if alself.al in m:
2022-01-27 02:26:57 +00:00
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
2021-01-31 02:05:34 +00:00
2022-01-27 02:26:57 +00:00
class Alias:
2020-10-04 16:26:20 +00:00
def __init__(self, ms):
self.ms = str(ms)
2020-07-12 12:21:53 +00:00
2022-01-27 02:26:57 +00:00
async def alias(alself, self, c, n, m):
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
2020-07-12 12:21:53 +00:00
2020-04-05 23:27:06 +00:00
commands = {
2022-01-27 02:26:57 +00:00
"quit": quit,
"reload": reloadmods,
"commit": commit,
"raw": rawcmd,
"eval": ev,
"send": send,
"joins": joins,
"shut": shut,
"schans": schans,
"addalias": addalias,
"addtrigger": addtrigger,
"addot": addot,
"addspook": addspook,
2020-04-05 23:27:06 +00:00
}
2020-04-05 23:05:07 +00:00
2022-01-27 02:26:57 +00:00
@command("admin")
2021-01-31 02:05:34 +00:00
@is_admin
2020-04-05 23:05:07 +00:00
async def adminHandle(self, chan, source, msg):
2022-01-27 02:26:57 +00:00
msg = msg.split(" ")
2020-04-05 23:27:06 +00:00
if len(msg) < 1 or not msg[0] in commands:
2022-01-27 02:26:57 +00:00
await self.message(chan, "[\x036admin\x0f] Invalid command")
return
print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0]))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg)))
2020-04-05 23:05:07 +00:00
async def init(self):
2022-01-27 02:26:57 +00:00
self.chandb = shared.db["chan"]
self.admins = ["xfnw"]
return
self.cmd["admin"] = adminHandle
self.help["admin"] = [
"admin - various bot owner commands (more for subcommands)",
"sub-commands of admin, for more info do help admin <command>: quit reload commit part join joins eval send",
]
self.help["admin quit"] = ["admin quit <message> - make the bot disconnect", "no"]
self.help["admin reload"] = [
"admin reload - reload the modules and configs",
"nothing to see here",
]
self.help["admin commit"] = [
"admin commit <action> - oh no (more)",
"suggested with <3 by khux",
]
self.help["admin part"] = ["admin part <channel> - leave a channel", ":o"]
self.help["admin join"] = [
"admin join <channel> - make the bot join a channel",
"...",
]
self.help["admin joins"] = [
"admin joins - join more channels",
"dont reconnect to a bunch of chans when the bots crashing etc",
]
self.help["admin eval"] = [
"admin eval <command> - absolute power corrupts absolutely",
"lmao",
]
self.help["admin send"] = [
"admin send <channel> <message> - send a message",
"lmao",
]
self.help["admin schans"] = ["admin schans - save the commands to join", ";p;"]