conversation flow

This commit is contained in:
xfnw 2020-07-12 12:21:53 +00:00
parent 7a336449dc
commit 4103f9fbdf
6 changed files with 74 additions and 29 deletions

2
bot.py
View file

@ -94,6 +94,6 @@ class Oven(pydle.Client):
if __name__ == "__main__": if __name__ == "__main__":
client = Oven('kim', realname='owens bot') client = Oven('kim', realname='owens bot')
client.admins = ['lickthecheese', 'ben', 'coffeeowl', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'khuxkm'] 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) client.run('team.tilde.chat', tls=True, tls_verify=False)

View file

@ -1,6 +1,5 @@
import importlib, time import importlib, time, asyncio, pydle
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))
@ -11,28 +10,43 @@ 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, 'reloading modules...') await self.message(chan, '[\x036admin\x0f] reloading modules...')
self.oldcmd = self.cmd
self.cmd = {} self.cmd = {}
self.raw = {} self.raw = {}
self.help = {} self.help = {}
try:
for i in self.modules: for i in self.modules:
importlib.reload(self.modules[i]) importlib.reload(self.modules[i])
await self.modules[i].init(self) await self.modules[i].init(self)
await self.message(chan, 'done! did something break? if so you might need to restart') #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): 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) await self.part(msg)
async def join(self, chan, source, 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) await self.join(msg)
async def joins(self, chan, source, msg): async def joins(self, chan, source, msg):
for i in self.joins: await self.message(chan, '[\x036admin\x0f] I will drop commands for some seconds to ignore chanhistory...')
await self.join(i) 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): 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
@ -47,17 +61,30 @@ async def aexec(self, code):
async def ev(self, chan, source, msg): async def ev(self, chan, source, msg):
msg = msg.split(' ') msg = msg.split(' ')
await aexec(self, ' '.join(msg)) try:
await self.message(chan, 'ok') 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): 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, 'ok') await self.message(c, '[\x036admin\x0f] sent')
async def shut(self, c, n, m): async def shut(self, c, n, m):
self.qtime[c] = time.time()+(60*10) 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 = { commands = {
'quit': quit, 'quit': quit,
@ -68,24 +95,25 @@ commands = {
'eval': ev, 'eval': ev,
'send': send, 'send': send,
'joins': joins, 'joins': joins,
'shut': shut 'shut': shut,
'schans': schans
} }
async def adminHandle(self, chan, source, msg): async def adminHandle(self, chan, source, msg):
if await self.is_admin(source): if await self.is_admin(source):
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, 'you press the wrong button on the oven and it burns you') 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]))
await commands[msg.pop(0)](self, chan, source, ' '.join(msg)) await commands[msg.pop(0)](self, chan, source, ' '.join(msg))
else: 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): async def init(self):
self.chandb = self.db['chan']
self.cmd['admin'] = adminHandle 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 <command>: quit reload commit part join joins eval send'] 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 quit'] = ['admin quit <message> - 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 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 eval'] = ['admin eval <command> - absolute power corrupts absolutely', 'lmao']
self.help['admin send'] = ['admin send <channel> <message> - send a message', '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

@ -21,12 +21,28 @@ async def rec(self, m):
noch.insert(dict(word=w)) noch.insert(dict(word=w))
end.insert(dict(word=pre)) end.insert(dict(word=pre))
async def getNoun(self, words): 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()] nouns = [i['word'] for i in self.db['noun'].find()]
out = {} out = {}
for i in words: for i in words:
out[i] = nouns.count(i) out[i] = nouns.count(i)
return min(out, key=out.get) 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): async def genOut(self, noun):
prew = self.db['prew'] prew = self.db['prew']
@ -72,7 +88,7 @@ async def go(self, c, n, m):
words = m.split(' ') words = m.split(' ')
if words[0] == 'admin': if words[0] == 'admin':
return 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): async def init(self):
@ -83,3 +99,4 @@ async def init(self):
self.enmul = 25 self.enmul = 25
self.raw['nlp'] = filter self.raw['nlp'] = filter
self.cstate = {}