diff --git a/bot.py b/bot.py index a91f75d..960c0e2 100755 --- a/bot.py +++ b/bot.py @@ -37,7 +37,7 @@ class Oven(pydle.Client): async def on_message(self, chan, source, msg): if source != self.nickname: if msg == '!botlist': - await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation') + await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation with llckthecheese') for i in self.raw: await self.raw[i](self, chan,source,msg) if msg[:len(self.prefix)] == self.prefix: diff --git a/modules/__pycache__/nlp.cpython-36.pyc b/modules/__pycache__/nlp.cpython-36.pyc new file mode 100644 index 0000000..cad3594 Binary files /dev/null and b/modules/__pycache__/nlp.cpython-36.pyc differ diff --git a/modules/nlp.py b/modules/nlp.py index fcf3262..4d0a691 100644 --- a/modules/nlp.py +++ b/modules/nlp.py @@ -2,11 +2,54 @@ import dataset import random +async def rec(self, m): + prew = self.db['prew'] + noch = self.db['noun'] + beg = self.db['beg'] + end = self.db['end'] + pre = '' + words = m.split(' ') + for w in words: + if pre == '': + beg.insert(dict(word=w)) + else: + prew.insert(dict(pre=pre, pro=w)) + pre = w + 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 genOut(self, noun): + prew = self.db['prew'] + beg = [ i['word'] for i in self.db['beg'].find() ] + end = [ i['word'] for i in self.db['end'].find() ] + iter=0 + out = [noun] + while out[0] not in beg and iter < 7: + out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out + iter += 1 + iter = 0 + while out[-1] not in end and iter < 7: + out.append(random.choice(list(prew.find(pre=out[-1])))['pro']) + iter += 1 + return out - - +async def filter(self, c, n, m): + if m[:5] == 'kim: ': + m = m[5:] + await rec(self, m) + words = m.split(' ') + await self.message(c, ' '.join(await genOut(self, await getNoun(self, words)))) async def init(self): self.db = dataset.connect('sqlite:///database.db') + self.raw['nlp'] = filter +