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):
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}"]))
@ -82,9 +82,9 @@ class Server(BaseServer):
asyncio.create_task(m.init(self))
shared.modules[i] = m
# depricated, to support old modules
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):
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):
await self.message(chan, "[\x036admin\x0f] reloading modules...")
await self.message(chan, "reloading modules...")
shared.oldcmd = shared.commands
shared.commands = {}
shared.rawm = {}
@ -29,14 +29,14 @@ async def reloadmods(self, chan, source, msg):
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, 'load {} sucess!'.format(i))
await self.message(
chan,
"[\x036admin\x0f] done! {} modules reloaded!".format(len(shared.modules)),
"done! {} modules reloaded!".format(len(shared.modules)),
)
except:
await self.message(
chan, "[\x036admin\x0f] reload failed... attempting to recover..."
chan, "reload failed... attempting to recover..."
)
shared.commands = shared.oldcmd
@ -46,14 +46,14 @@ async def rawcmd(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():
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...",
"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:
await self.message(
chan,
"[\x036admin\x0f] ok, output: {}".format(
"ok, output: {}".format(
str(await aexec(self, " ".join(msg)))[:400]
),
)
except:
await self.message(chan, "[\x036admin\x0f] exception in eval!")
await self.message(chan, "exception in eval!")
async def send(self, c, n, m):
msg = m.split(" ")
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):
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):
self.chandb.delete()
for i in self.channels:
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):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
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
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):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
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
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):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
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
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):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
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
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:
@ -214,7 +214,7 @@ commands = {
async def adminHandle(self, chan, source, msg):
msg = msg.split(" ")
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
print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0]))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg)))

View File

@ -6,7 +6,7 @@ modulename = "botlist"
@rawm("botlist")
async def botlist(s, c, n, m):
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):

View File

@ -31,17 +31,17 @@ async def bal(self):
async def send(self, c, n, m):
m = m.split(" ")
if len(m) < 2:
await self.message(c, "[\x036coin\x0f] invalid syntax")
await self.message(c, "invalid syntax")
return
try:
to = self.users[m.pop(0).lower()].account
except:
await self.message(
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 == "":
await self.message(c, "[\x036coin\x0f] they must authenticate with nickserv.")
await self.message(c, "they must authenticate with nickserv.")
return
amount = round(float(m.pop(0)), 2)
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))
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:
await self.message(
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:],
round(bals[m], 2),
@ -83,7 +83,7 @@ async def balance(self, c, n, m):
else:
await self.message(
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:],
round(bals[m], 2),
@ -91,7 +91,7 @@ async def balance(self, c, n, m):
),
)
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):
@ -101,7 +101,7 @@ async def richest(self, c, n, m):
await self.message(
c,
"[\x036coin\x0f] richest users: "
"richest users: "
+ ", ".join(
[
i[0][:1] + "\u200c" + i[0][1:] + ": " + str(round(i[1], 2))

View File

@ -5,7 +5,7 @@ import json, requests
@command("lookup")
async def lookup(self, c, n, m):
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
res = requests.get("https://callook.info/{}/json".format(m))
if res.status_code:
@ -13,7 +13,7 @@ async def lookup(self, c, n, m):
if js["status"] == "VALID":
await self.message(
c,
"[\x036ham\x0f] {}, name: {} grid: {}, expires: {}".format(
"{}, name: {} grid: {}, expires: {}".format(
js["current"]["operClass"],
js["name"],
js["location"]["gridsquare"],
@ -21,9 +21,9 @@ async def lookup(self, c, n, m):
),
)
return
await self.message(c, "[\x036ham\x0f] invalid callsign")
await self.message(c, "invalid callsign")
else:
await self.message(c, "[\x036ham\x0f] something went wrong...")
await self.message(c, "something went wrong...")
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)})]
)
except IndexError:
await self.message(c, "[\x036keep\x0f] No keeps found.")
await self.message(c, "No keeps found.")
return
await self.message(c, "[\x036keep\x0f] {}".format(keep))
await self.message(c, keep)
async def grabkeep(self, c, n, m):
@ -27,7 +27,7 @@ async def grabkeep(self, c, n, m):
if c in self.owolog:
backlog = [i for i in self.owolog[c] if m[0] == i[0]]
if len(backlog) < 1:
await self.message(c, "[\x036keep\x0f] nothing found to keep")
await self.message(c, "nothing found to keep")
return
try:
ms = backlog[0 - int(m[1])]
@ -35,23 +35,23 @@ async def grabkeep(self, c, n, m):
ms = backlog[-1]
m = "<{}> {}".format(ms[0], ms[1])
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
if c in self.owolog and len(self.owolog[c]) >= back:
ms = self.owolog[c][0 - back]
m = "<{}> {}".format(ms[0], ms[1])
else:
await self.message(
c, "[\x036keep\x0f] My backlog does not go back that far ;_;]"
c, "My backlog does not go back that far ;_;]"
)
return
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):
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):
@ -61,7 +61,7 @@ async def rmkeep(self, c, n, m):
):
co = m.strip().split(" ")
if len(co) < 2:
await self.message(c, "[\x036keep\x0f] wrong syntax")
await self.message(c, "wrong syntax")
return
crit = co.pop(0)
filt = " ".join(co)
@ -70,13 +70,13 @@ async def rmkeep(self, c, n, m):
elif crit == "quote" or crit == "q":
ou = self.keepdb.delete(keep={"like": filt})
else:
await self.message(c, "[\x036keep\x0f] invalid criterea")
await self.message(c, "invalid criterea")
if ou:
await self.message(c, "[\x036keep\x0f] removed some keep(s)")
await self.message(c, "removed some keep(s)")
else:
await self.message(c, "[\x036keep\x0f] did not remove any")
await self.message(c, "did not find any to remove")
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):

View File

@ -62,17 +62,17 @@ async def rpninp(self, chan, nick, msg):
elif msg == "r":
if chan in self.rpnprint:
await self.message(
chan, "[\x036rpn\x0f] {}".format(str(self.rpnhist[chan]))
chan, str(self.rpnhist[chan])
)
return
else:
return
except OverflowError:
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
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):
@ -88,10 +88,10 @@ async def rpntinp(self, chan, nick, msg):
async def rpntoggle(self, chan, nick, msg):
if chan in self.rpnprint:
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:
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):