diff --git a/bot.py b/bot.py index 9a07f99..109b41b 100755 --- a/bot.py +++ b/bot.py @@ -94,6 +94,6 @@ class Oven(pydle.Client): if __name__ == "__main__": client = Oven('kim', realname='owens bot') client.admins = ['lickthecheese', 'ben', 'coffeeowl', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'khuxkm'] - client.prefix = '.' + client.prefix = 'kim: ' client.run('team.tilde.chat', tls=True, tls_verify=False) diff --git a/modules/__pycache__/admin.cpython-36.pyc b/modules/__pycache__/admin.cpython-36.pyc index c4531f5..0e1e097 100644 Binary files a/modules/__pycache__/admin.cpython-36.pyc and b/modules/__pycache__/admin.cpython-36.pyc differ diff --git a/modules/__pycache__/channels.cpython-36.pyc b/modules/__pycache__/channels.cpython-36.pyc index e35aafe..b03f2d2 100644 Binary files a/modules/__pycache__/channels.cpython-36.pyc and b/modules/__pycache__/channels.cpython-36.pyc differ diff --git a/modules/__pycache__/nlp.cpython-36.pyc b/modules/__pycache__/nlp.cpython-36.pyc index 8f37225..9a09023 100644 Binary files a/modules/__pycache__/nlp.cpython-36.pyc and b/modules/__pycache__/nlp.cpython-36.pyc differ diff --git a/modules/admin.py b/modules/admin.py index 039f93a..5586ad0 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -1,6 +1,5 @@ -import importlib, time - +import importlib, time, asyncio, pydle async def commit(self, chan, source, msg): await self.quit('{} told me to commit {}'.format(source,msg)) @@ -11,28 +10,43 @@ async def quit(self, chan, source, msg): async def reloadmods(self, chan, source, msg): - await self.message(chan, 'reloading modules...') + await self.message(chan, '[\x036admin\x0f] reloading modules...') + self.oldcmd = self.cmd self.cmd = {} self.raw = {} self.help = {} - for i in self.modules: - importlib.reload(self.modules[i]) - await self.modules[i].init(self) - await self.message(chan, 'done! did something break? if so you might need to restart') - + try: + for i in self.modules: + importlib.reload(self.modules[i]) + await self.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(self.modules))) + except: + await self.message(chan, '[\x036admin\x0f] reload failed... attempting to recover...') + self.cmd = self.oldcmd async def part(self, chan, source, msg): - await self.message(chan, 'bye {}'.format(msg)) + await self.message(chan, '[\x036admin\x0f] bye {}'.format(msg)) await self.part(msg) async def join(self, chan, source, msg): - await self.message(chan, 'joined {}'.format(msg)) + self.t = time.time()+1 + await self.message(chan, '[\x036admin\x0f] joined {}'.format(msg)) await self.join(msg) async def joins(self, chan, source, msg): - for i in self.joins: - await self.join(i) + await self.message(chan, '[\x036admin\x0f] I will drop commands for some seconds to ignore chanhistory...') + for i in self.chandb.all(): + self.t = time.time() + 2 + try: + await self.join(i['name']) + await asyncio.sleep(0.5) + print('joined {}'.format(i['name'])) + except pydle.client.AlreadyInChannel: + print('I am already in {}'.format(i['name'])) + await asyncio.sleep(2) + await self.message(chan, '[\x036admin\x0f] Sucess!') async def aexec(self, code): # Make an async function with the code and `exec` it @@ -47,17 +61,30 @@ async def aexec(self, code): async def ev(self, chan, source, msg): msg = msg.split(' ') - await aexec(self, ' '.join(msg)) - await self.message(chan, 'ok') + 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!') async def send(self, c, n, m): msg = m.split(' ') await self.message(msg.pop(0), ' '.join(msg)) - await self.message(c, 'ok') + await self.message(c, '[\x036admin\x0f] sent') async def shut(self, c, n, m): self.qtime[c] = time.time()+(60*10) - await self.message(c, 'Ok, il be back') + await self.message(c, '[\x036admin\x0f] 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') + + + commands = { 'quit': quit, @@ -68,24 +95,25 @@ commands = { 'eval': ev, 'send': send, 'joins': joins, - 'shut': shut + 'shut': shut, + 'schans': schans } async def adminHandle(self, chan, source, msg): if await self.is_admin(source): msg = msg.split(' ') if len(msg) < 1 or not msg[0] in commands: - await self.message(chan, 'you press the wrong button on the oven and it burns you') + await self.message(chan, '[\x036admin\x0f] Invalid command') return print('[ADMIN MODULE] {} told me to {}!!!'.format(source,msg[0])) await commands[msg.pop(0)](self, chan, source, ' '.join(msg)) else: - await self.message(chan, 'you try to open it, but the oven is locked') + await self.message(chan, '[\x036admin\x0f] You do not have permission to do this') async def init(self): + self.chandb = self.db['chan'] self.cmd['admin'] = adminHandle - self.joins = ["#chaos", "#lickthecheese", "#windowsloser", "#cminecraft", "#team", "#clubcraft", "#rscmakerspace", "#archlinux", "#one", "#starlanes", "#ipd", "#pinebox"] self.help['admin'] = ['admin - various bot owner commands (more for subcommands)', 'sub-commands of admin, for more info do help admin : quit reload commit part join joins eval send'] self.help['admin quit'] = ['admin quit - make the bot disconnect','no'] @@ -96,7 +124,7 @@ async def init(self): 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 - absolute power corrupts absolutely', 'lmao'] self.help['admin send'] = ['admin send - send a message', 'lmao'] - + self.help['admin schans'] = ['admin schans - save the commands to join',';p;'] diff --git a/modules/nlp.py b/modules/nlp.py index 0eef0b8..d13d0ce 100644 --- a/modules/nlp.py +++ b/modules/nlp.py @@ -21,12 +21,28 @@ async def rec(self, m): noch.insert(dict(word=w)) end.insert(dict(word=pre)) -async def getNoun(self, words): - nouns = [i['word'] for i in self.db['noun'].find()] - out = {} - for i in words: - out[i] = nouns.count(i) - return min(out, key=out.get) +async def getNoun(self, words, c): + if c in self.cstate: + oldnoun = self.cstate[c] + else: + oldnoun = None + nouns = [i['word'] for i in self.db['noun'].find()] + out = {} + for i in words: + out[i] = nouns.count(i) + noun = min(out, key=out.get) + + conversation = self.db['conver'] + if oldnoun != None: + print("adding", [oldnoun,noun]) + conversation.insert_ignore(dict(pre=oldnoun,pro=noun),['id']) + + nextnoun = [i['pro'] for i in conversation.find(pre=noun)] + print("nextnoun:",nextnoun) + if len(nextnoun) > 0: + noun = random.choice(nextnoun) + self.cstate[c] = noun + return noun async def genOut(self, noun): prew = self.db['prew'] @@ -72,7 +88,7 @@ async def go(self, c, n, m): words = m.split(' ') if words[0] == 'admin': return - await self.message(c, ' '.join(await genOut(self, await getNoun(self, words)))) + await self.message(c, ' '.join(await genOut(self, await getNoun(self, words, c)))) async def init(self): @@ -83,3 +99,4 @@ async def init(self): self.enmul = 25 self.raw['nlp'] = filter + self.cstate = {}