reformat with black

This commit is contained in:
xfnw 2022-01-26 21:26:57 -05:00
parent 847d5ae7e9
commit 7af2f8f675
6 changed files with 377 additions and 285 deletions

106
bot.py
View file

@ -10,80 +10,90 @@ from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM
from auth import username, password, channel from auth import username, password, channel
import shared import shared
def is_admin(func): def is_admin(func):
async def decorator(self,channel,nick,msg): async def decorator(self, channel, nick, msg):
if nick.lower() in self.users and self.users[nick.lower()].account in self.admins: if (
await func(self,channel,nick,msg) nick.lower() in self.users
and self.users[nick.lower()].account in self.admins
):
await func(self, channel, nick, msg)
else: else:
await message(self,'core',channel,'you do not have permission to do that') await message(
self, "core", channel, "you do not have permission to do that"
)
return decorator return decorator
#def is_chanop(func):
# def is_chanop(func):
def command(commandname): def command(commandname):
def decorator(func): def decorator(func):
shared.commands[commandname] = func shared.commands[commandname] = func
return func return func
return decorator return decorator
def listener(listenername): def listener(listenername):
def decorator(func): def decorator(func):
shared.listeners.append((listenername, func)) shared.listeners.append((listenername, func))
return func return func
return decorator return decorator
def rawm(rname): def rawm(rname):
def decorator(func): def decorator(func):
shared.rawm[rname] = func shared.rawm[rname] = func
return func return func
return decorator return decorator
async def message(self, channel, msg):
async def message(self,channel,msg):
modname = os.path.splittext(os.path.basename(inspect.stack()[1].filename))[0] modname = os.path.splittext(os.path.basename(inspect.stack()[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}"]))
class Server(BaseServer): class Server(BaseServer):
async def line_read(self, line: Line): async def line_read(self, line: Line):
if 'on_'+line.command.lower() in dir(self): if "on_" + line.command.lower() in dir(self):
asyncio.create_task(self.__getattribute__('on_'+line.command.lower())(line)) asyncio.create_task(
self.__getattribute__("on_" + line.command.lower())(line)
)
for listener in shared.listeners: for listener in shared.listeners:
if listener[0] == line.command: if listener[0] == line.command:
asyncio.create_task(listener[1](self,line)) asyncio.create_task(listener[1](self, line))
def line_preread(self, line: Line): def line_preread(self, line: Line):
print(f"{self.name} < {line.format()}") print(f"{self.name} < {line.format()}")
def line_presend(self, line: Line): def line_presend(self, line: Line):
print(f"{self.name} > {line.format()}") print(f"{self.name} > {line.format()}")
async def on_001(self, line): async def on_001(self, line):
asyncio.create_task(self.load_modules()) asyncio.create_task(self.load_modules())
async def load_modules(self): async def load_modules(self):
for i in [s for s in os.listdir('modules') if '.py' in s and '.swp' not in s]: for i in [s for s in os.listdir("modules") if ".py" in s and ".swp" not in s]:
i = i[:-3] i = i[:-3]
m = importlib.import_module('modules.' + i) m = importlib.import_module("modules." + i)
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 # depricated, to support old modules
async def message(self,channel,msg): async def message(self, channel, msg):
await self.send(build("PRIVMSG",[channel,msg])) await self.send(build("PRIVMSG", [channel, 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":
return return
channel = line.params[0] channel = line.params[0]
nick = line.source.split('!')[0] nick = line.source.split("!")[0]
msg = line.params[1] msg = line.params[1]
if nick == self.nickname: if nick == self.nickname:
@ -91,26 +101,28 @@ class Server(BaseServer):
if channel == self.nickname: if channel == self.nickname:
channel = nick channel = nick
await self.handle_rawm(channel,nick,msg) await self.handle_rawm(channel, nick, msg)
await self.handle_command(channel,nick,msg) await self.handle_command(channel, nick, msg)
async def handle_rawm(self,channel,nick,msg):
async def handle_rawm(self, channel, nick, msg):
for i in shared.rawm: for i in shared.rawm:
await shared.rawm[i](self,channel,nick,msg) await shared.rawm[i](self, channel, nick, msg)
async def handle_command(self,channel,nick,msg):
if msg[:len(shared.prefix)] == shared.prefix: async def handle_command(self, channel, nick, msg):
msg = msg[len(shared.prefix):] if msg[: len(shared.prefix)] == shared.prefix:
cmd = msg.split(' ')[0] msg = msg[len(shared.prefix) :]
msg = msg[len(cmd)+1:] cmd = msg.split(" ")[0]
msg = msg[len(cmd) + 1 :]
if len(cmd) < 1: if len(cmd) < 1:
return return
if cmd in shared.commands: if cmd in shared.commands:
await shared.commands[cmd](self,channel,nick,msg) await shared.commands[cmd](self, channel, nick, msg)
return return
results = [i for i in shared.commands if i.startswith(cmd)] results = [i for i in shared.commands if i.startswith(cmd)]
if len(results) == 1: if len(results) == 1:
await shared.commands[results[0]](self,channel,nick,msg) await shared.commands[results[0]](self, channel, nick, msg)
class Bot(BaseBot): class Bot(BaseBot):
@ -122,26 +134,24 @@ async def main():
bot = Bot() bot = Bot()
sasl_params = SASLUserPass(username, password) sasl_params = SASLUserPass(username, password)
params = ConnectionParams( params = ConnectionParams(
"min", "min",
host = "irc.libera.chat", host="irc.libera.chat",
port = 6697, port=6697,
tls = True, tls=True,
sasl = sasl_params, sasl=sasl_params,
autojoin = channel) autojoin=channel,
)
await bot.add_server("libera", params) await bot.add_server("libera", params)
params = ConnectionParams( params = ConnectionParams(
"min", "min", host="manonet.lumey.dev", port=6697, tls=True, autojoin=["#manonet"]
host = "manonet.lumey.dev", )
port = 6697,
tls = True,
autojoin = ['#manonet'])
await bot.add_server("manonet", params) await bot.add_server("manonet", params)
await bot.run() await bot.run()
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(main()) asyncio.run(main())

View file

@ -1,213 +1,260 @@
import importlib, time, asyncio, random import importlib, time, asyncio, random
from bot import * from bot import *
quitmessages = [ quitmessages = [
"time to die", "time to die",
'you can hide, but you can not run!', "you can hide, but you can not run!",
"you're next", "you're next",
'bye', "bye",
'the balun has been popped.', "the balun has been popped.",
] ]
async def commit(self, chan, source, msg): async def commit(self, chan, source, msg):
await self.quit('{} told me to commit {}'.format(source,msg)) await self.quit("{} told me to commit {}".format(source, msg))
async def quit(self, chan, source, msg): async def quit(self, chan, source, msg):
await self.send(build("QUIT",[random.choice(quitmessages)])) await self.send(build("QUIT", [random.choice(quitmessages)]))
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, "[\x036admin\x0f] reloading modules...")
shared.oldcmd = shared.commands shared.oldcmd = shared.commands
shared.commands = {} shared.commands = {}
shared.rawm = {} shared.rawm = {}
shared.listeners = [] shared.listeners = []
shared.help = {} shared.help = {}
try: try:
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, '[\x036admin\x0f] load {} sucess!'.format(i))
await self.message(chan, '[\x036admin\x0f] done! {} modules reloaded!'.format(len(shared.modules))) await self.message(
except: chan,
await self.message(chan, '[\x036admin\x0f] reload failed... attempting to recover...') "[\x036admin\x0f] done! {} modules reloaded!".format(len(shared.modules)),
shared.commands = shared.oldcmd )
except:
await self.message(
chan, "[\x036admin\x0f] reload failed... attempting to recover..."
)
shared.commands = shared.oldcmd
async def rawcmd(self, chan, source, msg): async def rawcmd(self, chan, source, msg):
await self.send_raw(msg) await self.send_raw(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, "[\x036admin\x0f] 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(chan, '[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...') await self.message(
chan,
"[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...",
)
async def aexec(self, code): async def aexec(self, code):
# Make an async function with the code and `exec` it # Make an async function with the code and `exec` it
exec( exec(f"async def __ex(self): " + "".join(f"\n {l}" for l in code.split("\n")))
f'async def __ex(self): ' +
''.join(f'\n {l}' for l in code.split('\n'))
)
# Get `__ex` from local variables, call it and return the result # Get `__ex` from local variables, call it and return the result
return await locals()['__ex'](self) return await locals()["__ex"](self)
async def ev(self, chan, source, msg): async def ev(self, chan, source, msg):
msg = msg.split(' ') msg = msg.split(" ")
try: try:
await self.message(chan, '[\x036admin\x0f] ok, output: {}'.format( await self.message(
str(await aexec(self, ' '.join(msg)))[:400] chan,
)) "[\x036admin\x0f] ok, output: {}".format(
except: str(await aexec(self, " ".join(msg)))[:400]
await self.message(chan, '[\x036admin\x0f] exception in eval!') ),
)
except:
await self.message(chan, "[\x036admin\x0f] 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, "[\x036admin\x0f] 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, "[\x036admin\x0f] 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, "[\x036admin\x0f] Ok")
async def addalias(self,c,n,m):
al = m.split(' ')[0] async def addalias(self, c, n, m):
m = m[len(al)+1:] # dont use the list since i want trailing spaces al = m.split(" ")[0]
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, "[\x036admin\x0f] 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, '[\x036admin\x0f] 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, "[\x036admin\x0f] 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, '[\x036admin\x0f] 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, "[\x036admin\x0f] 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, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
async def addtrigger(self,c,n,m):
al = m.split(' ')[0] async def addtrigger(self, c, n, m):
m = m[len(al)+1:] # dont use the list since i want trailing spaces al = m.split(" ")[0]
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, "[\x036admin\x0f] 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, '[\x036admin\x0f] added "{}" trigger for "{}"'.format(al, m))
class Ot:
class Ot():
def __init__(self, ms, al): def __init__(self, ms, al):
self.ms = str(ms) self.ms = str(ms)
self.al = str(al) self.al = str(al)
async def ot(alself,self,c,n,m):
async def ot(alself, self, c, n, m):
if alself.al in m and n != self.nickname: if alself.al in m and n != self.nickname:
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof'))) asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
shared.rawm.pop(alself.al) shared.rawm.pop(alself.al)
class Spook(): class Spook:
def __init__(self, ms, al): def __init__(self, ms, al):
self.ms = str(ms) self.ms = str(ms)
self.al = str(al) self.al = str(al)
async def spook(alself,self,c,n,m):
async def spook(alself, self, c, n, m):
if alself.al in m and n != self.nickname: if alself.al in m and n != self.nickname:
asyncio.create_task(self.message(c,alself.ms.format(m))) asyncio.create_task(self.message(c, alself.ms.format(m)))
shared.rawm.pop(alself.al) shared.rawm.pop(alself.al)
class Trigger(): class Trigger:
def __init__(self, ms, al): def __init__(self, ms, al):
self.ms = str(ms) self.ms = str(ms)
self.al = str(al) self.al = str(al)
async def trigger(alself,self,c,n,m):
async def trigger(alself, self, c, n, m):
if alself.al in m: if alself.al in m:
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof'))) asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
class Alias(): class Alias:
def __init__(self, ms): def __init__(self, ms):
self.ms = str(ms) self.ms = str(ms)
async def alias(alself,self,c,n,m):
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
async def alias(alself, self, c, n, m):
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
commands = { commands = {
'quit': quit, "quit": quit,
'reload': reloadmods, "reload": reloadmods,
'commit': commit, "commit": commit,
'raw': rawcmd, "raw": rawcmd,
'eval': ev, "eval": ev,
'send': send, "send": send,
'joins': joins, "joins": joins,
'shut': shut, "shut": shut,
'schans': schans, "schans": schans,
'addalias': addalias, "addalias": addalias,
'addtrigger': addtrigger, "addtrigger": addtrigger,
'addot': addot, "addot": addot,
'addspook': addspook, "addspook": addspook,
} }
@command('admin')
@command("admin")
@is_admin @is_admin
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, "[\x036admin\x0f] 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)))
async def init(self): async def init(self):
self.chandb = shared.db['chan'] 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;']
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;"]

View file

@ -1,9 +1,10 @@
from bot import * from bot import *
@listener('INVITE')
async def on_invite(self,line): @listener("INVITE")
self.send(build("JOIN",[line.params[1]])) async def on_invite(self, line):
self.send(build("JOIN", [line.params[1]]))
async def init(self): async def init(self):
pass pass

View file

@ -2,33 +2,46 @@ from bot import *
import dataset, random, time, re import dataset, random, time, re
def get(l,i):
try: def get(l, i):
if i <= len(l) and i >= 0: try:
return l[i] if i <= len(l) and i >= 0:
else: return l[i]
return '' else:
except IndexError: return ""
return '' except IndexError:
return ""
async def rec(self, m): async def rec(self, m):
prew = shared.db['prew'] prew = shared.db["prew"]
noch = shared.db['noun'] noch = shared.db["noun"]
beg = shared.db['beg'] beg = shared.db["beg"]
end = shared.db['end'] end = shared.db["end"]
words = m.split() words = m.split()
if words[0] == 'admin' or len(words) < 2: if words[0] == "admin" or len(words) < 2:
return return
beg.insert(dict(word=words[0])) beg.insert(dict(word=words[0]))
end.insert(dict(word=words[-1])) end.insert(dict(word=words[-1]))
for w in range(len(words)):
if w > 0:
prew.insert_ignore(
dict(
pre3=get(words, w - 3),
pre2=get(words, w - 2),
pre=get(words, w - 1),
pro=get(words, w),
pro2=get(words, w + 1),
pro3=get(words, w + 2),
),
["id"],
)
noch.insert(dict(word=w))
for w in range(len(words)):
if w > 0:
prew.insert_ignore(dict(pre3=get(words,w-3), pre2=get(words,w-2), pre=get(words,w-1), pro=get(words,w), pro2=get(words,w+1), pro3=get(words,w+2)),['id'])
noch.insert(dict(word=w))
async def getNoun(self, words, c): async def getNoun(self, words, c):
if c in shared.cstate: if c in shared.cstate:
@ -36,108 +49,133 @@ async def getNoun(self, words, c):
else: else:
oldnoun = None oldnoun = None
nouns = shared.db['noun'] nouns = shared.db["noun"]
out = {} out = {}
for i in words: for i in words:
out[i] = nouns.count(word=i) out[i] = nouns.count(word=i)
noun = min(out, key=out.get) noun = min(out, key=out.get)
conversation = shared.db['conver'] conversation = shared.db["conver"]
if oldnoun != None: if oldnoun != None:
print("adding", [oldnoun,noun]) print("adding", [oldnoun, noun])
conversation.insert_ignore(dict(pre=oldnoun,pro=noun),['id']) conversation.insert_ignore(dict(pre=oldnoun, pro=noun), ["id"])
nextnoun = [i['pro'] for i in conversation.find(pre=noun)] nextnoun = [i["pro"] for i in conversation.find(pre=noun)]
print("nextnoun:",nextnoun) print("nextnoun:", nextnoun)
if len(nextnoun) > 0: if len(nextnoun) > 0:
noun = random.choice(nextnoun) noun = random.choice(nextnoun)
shared.cstate[c] = noun shared.cstate[c] = noun
return noun return noun
async def genOut(self, noun): async def genOut(self, noun):
prew = shared.db['prew'] prew = shared.db["prew"]
beg = shared.db['beg'] beg = shared.db["beg"]
end = shared.db['end'] end = shared.db["end"]
nouns = shared.db['noun'] nouns = shared.db["noun"]
iter=0 iter = 0
coun=0 coun = 0
out = [noun] out = [noun]
while (beg.find_one(word=out[0]) is None or nouns.count(word=out[0])-1 > iter * shared.enmul) and iter < shared.maxiter: while (
try: beg.find_one(word=out[0]) is None
out = [ random.choice(list(prew.find(pro=out[0],pro2=out[1],pro3=out[2])))['pre'] ] + out or nouns.count(word=out[0]) - 1 > iter * shared.enmul
except IndexError: ) and iter < shared.maxiter:
try:
out = [ random.choice(list(prew.find(pro=out[0],pro2=out[1])))['pre'] ] + out
except IndexError:
try: try:
out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out out = [
random.choice(list(prew.find(pro=out[0], pro2=out[1], pro3=out[2])))[
"pre"
]
] + out
except IndexError: except IndexError:
iter += 69 try:
iter += 1 out = [
coun += 1 random.choice(list(prew.find(pro=out[0], pro2=out[1])))["pre"]
iter = 0 ] + out
while (end.find_one(word=out[-1]) is None or nouns.count(word=out[-1])-1 > iter * shared.enmul) and iter < shared.maxiter: except IndexError:
try: try:
out.append(random.choice(list(prew.find(pre3=out[-3],pre2=out[-2],pre=out[-1])))['pro']) out = [random.choice(list(prew.find(pro=out[0])))["pre"]] + out
except IndexError: except IndexError:
try: iter += 69
out.append(random.choice(list(prew.find(pre2=out[-2],pre=out[-1])))['pro']) iter += 1
except IndexError: coun += 1
iter = 0
while (
end.find_one(word=out[-1]) is None
or nouns.count(word=out[-1]) - 1 > iter * shared.enmul
) and iter < shared.maxiter:
try: try:
out.append(random.choice(list(prew.find(pre=out[-1])))['pro']) out.append(
random.choice(list(prew.find(pre3=out[-3], pre2=out[-2], pre=out[-1])))[
"pro"
]
)
except IndexError: except IndexError:
iter += 69 try:
iter += 1 out.append(
coun += 1 random.choice(list(prew.find(pre2=out[-2], pre=out[-1])))["pro"]
)
except IndexError:
try:
out.append(random.choice(list(prew.find(pre=out[-1])))["pro"])
except IndexError:
iter += 69
iter += 1
coun += 1
if coun <= 3: if coun <= 3:
shared.enmul -= 1 shared.enmul -= 1
elif coun >= shared.maxiter: elif coun >= shared.maxiter:
shared.enmul += 1 shared.enmul += 1
return out return out
async def filter(self, c, n, m): async def filter(self, c, n, m):
if c in shared.qtime and shared.qtime[c] > time.time(): if c in shared.qtime and shared.qtime[c] > time.time():
return return
if m[:len(shared.prefix)] == shared.prefix: if m[: len(shared.prefix)] == shared.prefix:
m = m[len(shared.prefix):] m = m[len(shared.prefix) :]
await go(self, c, n, m) await go(self, c, n, m)
elif m[:len(self.nickname)+1] == self.nickname+' ': elif m[: len(self.nickname) + 1] == self.nickname + " ":
m = m[len(self.nickname)+1:] m = m[len(self.nickname) + 1 :]
await go(self, c, n, m) await go(self, c, n, m)
elif '#' not in c and n != self.nickname: elif "#" not in c and n != self.nickname:
await go(self, c, n, m) await go(self, c, n, m)
else: else:
if len(m.split()) > 1: if len(m.split()) > 1:
if shared.learntime + shared.learndelay < time.time(): if shared.learntime + shared.learndelay < time.time():
await rec(self, m) await rec(self, m)
shared.learntime = time.time() shared.learntime = time.time()
async def go(self, c, n, m): async def go(self, c, n, m):
await rec(self, m) await rec(self, m)
words = re.sub(r'([\.,\?!])', r' \1', m).split() words = re.sub(r"([\.,\?!])", r" \1", m).split()
if words[0] == 'admin': if words[0] == "admin":
return return
msg = re.sub(r' ([\.,\?!])', r'\1', ' '.join(await genOut(self, await getNoun(self, words, c)))) msg = re.sub(
r" ([\.,\?!])",
r"\1",
" ".join(await genOut(self, await getNoun(self, words, c))),
)
if msg[-1] == "\x01" and msg[0] != "\x01": if msg[-1] == "\x01" and msg[0] != "\x01":
msg = msg[:-1] msg = msg[:-1]
await self.message(c, msg) await self.message(c, msg)
async def init(self): async def init(self):
shared.qtime = {}
shared.learntime = 0
# delay between grabbing random messages and passively shared.qtime = {}
# learning. shared.learntime = 0
shared.learndelay = 1
# sentance ending weight, lower means longer sentances,
# higher means shorter sentances. this will need to slowly
# get larger as the database grows
shared.enmul = 9
shared.maxiter = 14
shared.rawm['nlp'] = filter # delay between grabbing random messages and passively
shared.cstate = {} # learning.
shared.learndelay = 1
# sentance ending weight, lower means longer sentances,
# higher means shorter sentances. this will need to slowly
# get larger as the database grows
shared.enmul = 9
shared.maxiter = 14
shared.rawm["nlp"] = filter
shared.cstate = {}

View file

@ -1,14 +1,12 @@
import asyncio import asyncio
import bot import bot
@bot.command('test') @bot.command("test")
@bot.is_admin @bot.is_admin
async def testy(self,channel,nick,msg): async def testy(self, channel, nick, msg):
await bot.message(self,channel,'hi there') await bot.message(self, channel, "hi there")
async def init(self): async def init(self):
pass pass

View file

@ -1,12 +1,10 @@
import dataset import dataset
prefix = 'min: ' prefix = "min: "
modules = {} modules = {}
listeners = [] listeners = []
commands = {} commands = {}
rawm = {} rawm = {}
db = dataset.connect('sqlite:///database.db') db = dataset.connect("sqlite:///database.db")
qtime = {} qtime = {}