learn automatically
This commit is contained in:
+12
-2
@@ -35,14 +35,17 @@ class Chatbot(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if "DMChannel" in type(message.channel).__name__: #respond to messages in PM channels
|
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)
|
yield from self.respondToMessage(message)
|
||||||
elif message.channel.id == 139061614178598912: #don't abuse the "belangrijk" channel
|
elif message.channel.id == 139061614178598912: #don't abuse the "belangrijk" channel
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
a = random.randint(0,999)
|
a = random.randint(0,999)
|
||||||
if message.channel.id == 137218228953939968 and a < 40: #shitpost channel
|
if message.channel.id == 137218228953939968 and a < 40: #shitpost channel
|
||||||
|
yield from self.learnFromMessagesInChannel(message.channel.id, 10)
|
||||||
yield from self.respondToMessage(message)
|
yield from self.respondToMessage(message)
|
||||||
elif a < 10: #all other channels
|
elif a < 10: #all other channels
|
||||||
|
yield from self.learnFromMessagesInChannel(message.channel.id, 20)
|
||||||
yield from self.respondToMessage(message)
|
yield from self.respondToMessage(message)
|
||||||
|
|
||||||
#process commands:
|
#process commands:
|
||||||
@@ -146,6 +149,15 @@ class Chatbot(object):
|
|||||||
param nrOfMessages: use the x most recent messages
|
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)
|
channel=self.bot.get_channel(channelId)
|
||||||
#Open current chain:
|
#Open current chain:
|
||||||
wordDict = np.load('markov_dict.npy').item()
|
wordDict = np.load('markov_dict.npy').item()
|
||||||
@@ -193,8 +205,6 @@ class Chatbot(object):
|
|||||||
|
|
||||||
np.save("markov_dict.npy", wordDict)
|
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)
|
@commands.command(pass_context=True, hidden=False)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
|||||||
Reference in New Issue
Block a user