put the calling module in Server.message too

This commit is contained in:
xfnw 2022-04-23 12:41:03 -04:00
parent 3a3519764a
commit bd6198c49d
7 changed files with 53 additions and 53 deletions

6
bot.py
View File

@ -52,7 +52,7 @@ def rawm(rname):
async def message(self, channel, msg): async def message(self, channel, msg):
modname = os.path.splitext(os.path.basename(inspect.stack()[1].filename))[0] modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0]
await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"])) await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
@ -82,9 +82,9 @@ class Server(BaseServer):
asyncio.create_task(m.init(self)) asyncio.create_task(m.init(self))
shared.modules[i] = m shared.modules[i] = m
# depricated, to support old modules
async def message(self, channel, msg): async def message(self, channel, msg):
await self.send(build("PRIVMSG", [channel, msg])) modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0]
await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
async def on_privmsg(self, line): async def on_privmsg(self, line):
if line.tags and "batch" in line.tags and line.tags["batch"] == "1": if line.tags and "batch" in line.tags and line.tags["batch"] == "1":

View File

@ -19,7 +19,7 @@ async def quit(self, chan, source, msg):
async def reloadmods(self, chan, source, msg): async def reloadmods(self, chan, source, msg):
await self.message(chan, "[\x036admin\x0f] reloading modules...") await self.message(chan, "reloading modules...")
shared.oldcmd = shared.commands shared.oldcmd = shared.commands
shared.commands = {} shared.commands = {}
shared.rawm = {} shared.rawm = {}
@ -29,14 +29,14 @@ async def reloadmods(self, chan, source, msg):
for i in shared.modules: for i in shared.modules:
importlib.reload(shared.modules[i]) importlib.reload(shared.modules[i])
await shared.modules[i].init(self) await shared.modules[i].init(self)
# await self.message(chan, '[\x036admin\x0f] load {} sucess!'.format(i)) # await self.message(chan, 'load {} sucess!'.format(i))
await self.message( await self.message(
chan, chan,
"[\x036admin\x0f] done! {} modules reloaded!".format(len(shared.modules)), "done! {} modules reloaded!".format(len(shared.modules)),
) )
except: except:
await self.message( await self.message(
chan, "[\x036admin\x0f] reload failed... attempting to recover..." chan, "reload failed... attempting to recover..."
) )
shared.commands = shared.oldcmd shared.commands = shared.oldcmd
@ -46,14 +46,14 @@ async def rawcmd(self, chan, source, msg):
async def joins(self, chan, source, msg): async def joins(self, chan, source, msg):
await self.message(chan, "[\x036admin\x0f] joining slowly as to not flood...") await self.message(chan, "joining slowly as to not flood...")
for i in self.chandb.all(): for i in self.chandb.all():
await self.send(build("JOIN", [i["name"]])) await self.send(build("JOIN", [i["name"]]))
await asyncio.sleep(1) await asyncio.sleep(1)
print("joined {}".format(i["name"])) print("joined {}".format(i["name"]))
await self.message( await self.message(
chan, chan,
"[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...", "Sucess! i may be laggy for a bit while i sort through all these channels...",
) )
@ -70,74 +70,74 @@ async def ev(self, chan, source, msg):
try: try:
await self.message( await self.message(
chan, chan,
"[\x036admin\x0f] ok, output: {}".format( "ok, output: {}".format(
str(await aexec(self, " ".join(msg)))[:400] str(await aexec(self, " ".join(msg)))[:400]
), ),
) )
except: except:
await self.message(chan, "[\x036admin\x0f] exception in eval!") await self.message(chan, "exception in eval!")
async def send(self, c, n, m): async def send(self, c, n, m):
msg = m.split(" ") msg = m.split(" ")
await self.message(msg.pop(0), " ".join(msg)) await self.message(msg.pop(0), " ".join(msg))
await self.message(c, "[\x036admin\x0f] sent") await self.message(c, "sent")
async def shut(self, c, n, m): async def shut(self, c, n, m):
shared.qtime[c] = time.time() + (60 * 10) shared.qtime[c] = time.time() + (60 * 10)
await self.message(c, "[\x036admin\x0f] Ok, il be back in 10 minutes") await self.message(c, "Ok, il be back in 10 minutes")
async def schans(self, c, n, m): async def schans(self, c, n, m):
self.chandb.delete() self.chandb.delete()
for i in self.channels: for i in self.channels:
self.chandb.insert(dict(name=i)) self.chandb.insert(dict(name=i))
await self.message(c, "[\x036admin\x0f] Ok") await self.message(c, "Ok")
async def addalias(self, c, n, m): async def addalias(self, c, n, m):
al = m.split(" ")[0] al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in self.cmd: if al in self.cmd:
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy") await self.message(c, "no dont overwrite a command dummy")
return return
self.cmd[al] = Alias(m).alias self.cmd[al] = Alias(m).alias
await self.message(c, '[\x036admin\x0f] added "{}" alias for "{}"'.format(al, m)) await self.message(c, 'added "{}" alias for "{}"'.format(al, m))
async def addot(self, c, n, m): async def addot(self, c, n, m):
al = m.split(" ")[0] al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm: if al in shared.rawm:
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy") await self.message(c, "no dont overwrite a command dummy")
return return
shared.rawm[al] = Ot(m, al).ot shared.rawm[al] = Ot(m, al).ot
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m)) await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
async def addspook(self, c, n, m): async def addspook(self, c, n, m):
al = m.split(" ")[0] al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm: if al in shared.rawm:
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy") await self.message(c, "no dont overwrite a command dummy")
return return
shared.rawm[al] = Spook(m, al).spook shared.rawm[al] = Spook(m, al).spook
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m)) await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
async def addtrigger(self, c, n, m): async def addtrigger(self, c, n, m):
al = m.split(" ")[0] al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm: if al in shared.rawm:
await self.message(c, "[\x036admin\x0f] no dont overwrite a command dummy") await self.message(c, "no dont overwrite a command dummy")
return return
shared.rawm[al] = Trigger(m, al).trigger shared.rawm[al] = Trigger(m, al).trigger
await self.message(c, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m)) await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
class Ot: class Ot:
@ -214,7 +214,7 @@ commands = {
async def adminHandle(self, chan, source, msg): async def adminHandle(self, chan, source, msg):
msg = msg.split(" ") msg = msg.split(" ")
if len(msg) < 1 or not msg[0] in commands: if len(msg) < 1 or not msg[0] in commands:
await self.message(chan, "[\x036admin\x0f] Invalid command") await self.message(chan, "Invalid command")
return return
print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0])) print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0]))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg))) asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg)))

View File

@ -6,7 +6,7 @@ modulename = "botlist"
@rawm("botlist") @rawm("botlist")
async def botlist(s, c, n, m): async def botlist(s, c, n, m):
if m == "!botlist": if m == "!botlist":
await message(s, modulename, c, "hi im balun ; prefix . ; owner xfnw") await message(s, c, "hi im balun ; prefix . ; owner xfnw")
async def init(self): async def init(self):

View File

@ -31,17 +31,17 @@ async def bal(self):
async def send(self, c, n, m): async def send(self, c, n, m):
m = m.split(" ") m = m.split(" ")
if len(m) < 2: if len(m) < 2:
await self.message(c, "[\x036coin\x0f] invalid syntax") await self.message(c, "invalid syntax")
return return
try: try:
to = self.users[m.pop(0).lower()].account to = self.users[m.pop(0).lower()].account
except: except:
await self.message( await self.message(
c, c,
"[\x036coin\x0f] that user is not logged in. refusing so coins are not lost", "that user is not logged in. refusing so coins are not lost",
) )
if to == "": if to == "":
await self.message(c, "[\x036coin\x0f] they must authenticate with nickserv.") await self.message(c, "they must authenticate with nickserv.")
return return
amount = round(float(m.pop(0)), 2) amount = round(float(m.pop(0)), 2)
message = " ".join(m) message = " ".join(m)
@ -50,7 +50,7 @@ async def send(self, c, n, m):
self.ledger.insert(dict(to=to, sender=sender, amount=amount, message=message)) self.ledger.insert(dict(to=to, sender=sender, amount=amount, message=message))
await self.message( await self.message(
c, "[\x036coin\x0f] added transaction to ledger, check balances to verify" c, "added transaction to ledger, check balances to verify"
) )
@ -70,7 +70,7 @@ async def balance(self, c, n, m):
if latest: if latest:
await self.message( await self.message(
c, c,
"[\x036coin\x0f] {}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format( "{}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format(
m[:1], m[:1],
m[1:], m[1:],
round(bals[m], 2), round(bals[m], 2),
@ -83,7 +83,7 @@ async def balance(self, c, n, m):
else: else:
await self.message( await self.message(
c, c,
"[\x036coin\x0f] {}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format( "{}\u200c{}'s balance is {} BUTT (Balun Useless Trading Tokens), {}% of the total supply".format(
m[:1], m[:1],
m[1:], m[1:],
round(bals[m], 2), round(bals[m], 2),
@ -91,7 +91,7 @@ async def balance(self, c, n, m):
), ),
) )
else: else:
await self.message(c, "[\x036coin\x0f] this user has never made a transaction") await self.message(c, "this user has never made a transaction")
async def richest(self, c, n, m): async def richest(self, c, n, m):
@ -101,7 +101,7 @@ async def richest(self, c, n, m):
await self.message( await self.message(
c, c,
"[\x036coin\x0f] richest users: " "richest users: "
+ ", ".join( + ", ".join(
[ [
i[0][:1] + "\u200c" + i[0][1:] + ": " + str(round(i[1], 2)) i[0][:1] + "\u200c" + i[0][1:] + ": " + str(round(i[1], 2))

View File

@ -5,7 +5,7 @@ import json, requests
@command("lookup") @command("lookup")
async def lookup(self, c, n, m): async def lookup(self, c, n, m):
if len(m) < 1: if len(m) < 1:
await self.message(c, "[\x036ham\x0f] you need the callsign lol") await self.message(c, "you need the callsign lol")
return return
res = requests.get("https://callook.info/{}/json".format(m)) res = requests.get("https://callook.info/{}/json".format(m))
if res.status_code: if res.status_code:
@ -13,7 +13,7 @@ async def lookup(self, c, n, m):
if js["status"] == "VALID": if js["status"] == "VALID":
await self.message( await self.message(
c, c,
"[\x036ham\x0f] {}, name: {} grid: {}, expires: {}".format( "{}, name: {} grid: {}, expires: {}".format(
js["current"]["operClass"], js["current"]["operClass"],
js["name"], js["name"],
js["location"]["gridsquare"], js["location"]["gridsquare"],
@ -21,9 +21,9 @@ async def lookup(self, c, n, m):
), ),
) )
return return
await self.message(c, "[\x036ham\x0f] invalid callsign") await self.message(c, "invalid callsign")
else: else:
await self.message(c, "[\x036ham\x0f] something went wrong...") await self.message(c, "something went wrong...")
async def init(self): async def init(self):

View File

@ -12,9 +12,9 @@ async def getkeep(self, c, n, m):
[i["keep"] for i in self.keepdb.find(keep={"like": "%{}%".format(m)})] [i["keep"] for i in self.keepdb.find(keep={"like": "%{}%".format(m)})]
) )
except IndexError: except IndexError:
await self.message(c, "[\x036keep\x0f] No keeps found.") await self.message(c, "No keeps found.")
return return
await self.message(c, "[\x036keep\x0f] {}".format(keep)) await self.message(c, keep)
async def grabkeep(self, c, n, m): async def grabkeep(self, c, n, m):
@ -27,7 +27,7 @@ async def grabkeep(self, c, n, m):
if c in self.owolog: if c in self.owolog:
backlog = [i for i in self.owolog[c] if m[0] == i[0]] backlog = [i for i in self.owolog[c] if m[0] == i[0]]
if len(backlog) < 1: if len(backlog) < 1:
await self.message(c, "[\x036keep\x0f] nothing found to keep") await self.message(c, "nothing found to keep")
return return
try: try:
ms = backlog[0 - int(m[1])] ms = backlog[0 - int(m[1])]
@ -35,23 +35,23 @@ async def grabkeep(self, c, n, m):
ms = backlog[-1] ms = backlog[-1]
m = "<{}> {}".format(ms[0], ms[1]) m = "<{}> {}".format(ms[0], ms[1])
self.keepdb.insert(dict(channel=c, nick=n, keep=m)) self.keepdb.insert(dict(channel=c, nick=n, keep=m))
await self.message(c, "[\x036keep\x0f] keep added!") await self.message(c, "keep added!")
return return
if c in self.owolog and len(self.owolog[c]) >= back: if c in self.owolog and len(self.owolog[c]) >= back:
ms = self.owolog[c][0 - back] ms = self.owolog[c][0 - back]
m = "<{}> {}".format(ms[0], ms[1]) m = "<{}> {}".format(ms[0], ms[1])
else: else:
await self.message( await self.message(
c, "[\x036keep\x0f] My backlog does not go back that far ;_;]" c, "My backlog does not go back that far ;_;]"
) )
return return
self.keepdb.insert(dict(channel=c, nick=n, keep=m)) self.keepdb.insert(dict(channel=c, nick=n, keep=m))
await self.message(c, "[\x036keep\x0f] keep added!") await self.message(c, "keep added!")
async def addkeep(self, c, n, m): async def addkeep(self, c, n, m):
self.keepdb.insert(dict(channel=c, nick=n, keep=m)) self.keepdb.insert(dict(channel=c, nick=n, keep=m))
await self.message(c, "[\x036keep\x0f] keep added!") await self.message(c, "keep added!")
async def rmkeep(self, c, n, m): async def rmkeep(self, c, n, m):
@ -61,7 +61,7 @@ async def rmkeep(self, c, n, m):
): ):
co = m.strip().split(" ") co = m.strip().split(" ")
if len(co) < 2: if len(co) < 2:
await self.message(c, "[\x036keep\x0f] wrong syntax") await self.message(c, "wrong syntax")
return return
crit = co.pop(0) crit = co.pop(0)
filt = " ".join(co) filt = " ".join(co)
@ -70,13 +70,13 @@ async def rmkeep(self, c, n, m):
elif crit == "quote" or crit == "q": elif crit == "quote" or crit == "q":
ou = self.keepdb.delete(keep={"like": filt}) ou = self.keepdb.delete(keep={"like": filt})
else: else:
await self.message(c, "[\x036keep\x0f] invalid criterea") await self.message(c, "invalid criterea")
if ou: if ou:
await self.message(c, "[\x036keep\x0f] removed some keep(s)") await self.message(c, "removed some keep(s)")
else: else:
await self.message(c, "[\x036keep\x0f] did not remove any") await self.message(c, "did not find any to remove")
else: else:
await self.message(c, f"[\x036keep\x0f] you must have +o in {self.rmkeepchan}") await self.message(c, f"you must have +o in {self.rmkeepchan}")
async def init(self): async def init(self):

View File

@ -62,17 +62,17 @@ async def rpninp(self, chan, nick, msg):
elif msg == "r": elif msg == "r":
if chan in self.rpnprint: if chan in self.rpnprint:
await self.message( await self.message(
chan, "[\x036rpn\x0f] {}".format(str(self.rpnhist[chan])) chan, str(self.rpnhist[chan])
) )
return return
else: else:
return return
except OverflowError: except OverflowError:
if chan in self.rpnprint: if chan in self.rpnprint:
await self.message(chan, "[\x036rpn\x0f] no u ur numbers are too phat") await self.message(chan, "no u ur numbers are too big chonk")
return return
if chan in self.rpnprint: if chan in self.rpnprint:
await self.message(chan, "[\x036rpn\x0f] " + str(self.rpnhist[chan][0])) await self.message(chan, str(self.rpnhist[chan][0]))
async def rpntinp(self, chan, nick, msg): async def rpntinp(self, chan, nick, msg):
@ -88,10 +88,10 @@ async def rpntinp(self, chan, nick, msg):
async def rpntoggle(self, chan, nick, msg): async def rpntoggle(self, chan, nick, msg):
if chan in self.rpnprint: if chan in self.rpnprint:
self.rpnprint.remove(chan) self.rpnprint.remove(chan)
await self.message(chan, "[\x036rpn\x0f] rpn outputting has been disabled") await self.message(chan, "rpn outputting has been disabled")
else: else:
self.rpnprint.append(chan) self.rpnprint.append(chan)
await self.message(chan, "[\x036rpn\x0f] rpn outputting has been enabled") await self.message(chan, "rpn outputting has been enabled")
async def init(self): async def init(self):