learn automatically

This commit is contained in:
JP
2018-07-24 20:53:26 +02:00
parent b74f29f216
commit e1e9644f93
+12 -2
View File
@@ -35,14 +35,17 @@ class Chatbot(object):
return
if "DMChannel" in type(message.channel).__name__: #respond to messages in PM channels
yield from self.learnFromMessagesInChannel(message.channel.id, 1)
yield from self.respondToMessage(message)
elif message.channel.id == 139061614178598912: #don't abuse the "belangrijk" channel
pass
else:
a = random.randint(0,999)
if message.channel.id == 137218228953939968 and a < 40: #shitpost channel
yield from self.learnFromMessagesInChannel(message.channel.id, 10)
yield from self.respondToMessage(message)
elif a < 10: #all other channels
yield from self.learnFromMessagesInChannel(message.channel.id, 20)
yield from self.respondToMessage(message)
#process commands:
@@ -145,7 +148,16 @@ class Chatbot(object):
param channelId: use this channel to train
param nrOfMessages: use the x most recent messages
"""
yield from self.learnFromMessagesInChannel(channelId, nrOfMessages)
yield from ctx.channel.send("Ik heb weer wat nieuwe woordjes geleerd. :slight_smile:")
#Learns from an x number of messages from a certain channel
@asyncio.coroutine
def learnFromMessagesInChannel(self, channelId, nrOfMessages):
channel=self.bot.get_channel(channelId)
#Open current chain:
wordDict = np.load('markov_dict.npy').item()
@@ -192,8 +204,6 @@ class Chatbot(object):
i += 1
np.save("markov_dict.npy", wordDict)
yield from ctx.channel.send("Ik heb weer wat nieuwe woordjes geleerd. :slight_smile:")
@commands.command(pass_context=True, hidden=False)