de Guus filter
This commit is contained in:
+22
-3
@@ -3,6 +3,7 @@ import discord
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import random
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
class Chatbot(object):
|
class Chatbot(object):
|
||||||
"""Een heuse chatbot. Under construction..."""
|
"""Een heuse chatbot. Under construction..."""
|
||||||
@@ -12,6 +13,8 @@ class Chatbot(object):
|
|||||||
self.voice_states = {}
|
self.voice_states = {}
|
||||||
self.END_OF_MESSAGE = "<EOM>"
|
self.END_OF_MESSAGE = "<EOM>"
|
||||||
self.START_OF_MESSAGE = "<SOM>"
|
self.START_OF_MESSAGE = "<SOM>"
|
||||||
|
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||||
|
self.pmCount = 0
|
||||||
try:
|
try:
|
||||||
np.load('markov_dict.npy')
|
np.load('markov_dict.npy')
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -35,7 +38,10 @@ 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)
|
if (self.isAllowedToLearnFromPm(message)): #avoid spam-learning
|
||||||
|
self.pmCount += 1
|
||||||
|
self.pmLast = datetime.now()
|
||||||
|
yield from self.learnFromMessagesInChannel(message.channel.id, 1)
|
||||||
yield from self.respondToMessage(message)
|
yield from self.respondToMessage(message)
|
||||||
elif message.channel.id == self.bot.hdChannels["belangrijk"]: #don't abuse the "belangrijk" channel
|
elif message.channel.id == self.bot.hdChannels["belangrijk"]: #don't abuse the "belangrijk" channel
|
||||||
pass
|
pass
|
||||||
@@ -54,7 +60,20 @@ class Chatbot(object):
|
|||||||
def __check(self, ctx):
|
def __check(self, ctx):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#The "Guus filter"
|
||||||
|
#Don't allow to learn from very large personal messages
|
||||||
|
#Only learn from 10 personal messages per hour at most
|
||||||
|
def isAllowedToLearnFromPm(self, message):
|
||||||
|
if len(message.content.strip()) > 150:
|
||||||
|
return False
|
||||||
|
diff = datetime.now() - self.pmLast
|
||||||
|
if diff.days > 0 or diff.seconds > 3600:
|
||||||
|
self.pmCount = 0
|
||||||
|
return True
|
||||||
|
if self.pmCount > 10:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
#Make word pairs:
|
#Make word pairs:
|
||||||
def makePairs(self, corpus):
|
def makePairs(self, corpus):
|
||||||
@@ -209,7 +228,7 @@ class Chatbot(object):
|
|||||||
@commands.command(pass_context=True, hidden=False)
|
@commands.command(pass_context=True, hidden=False)
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def reageer(self, ctx):
|
def reageer(self, ctx):
|
||||||
"""UNDER CONSTRUCTION. Laat Stroop ergens op reageren.
|
"""Laat Stroop ergens op reageren.
|
||||||
Stroop leert van onze gesprekken. Hij kan zich nu voordoen als een van ons. Soort van.
|
Stroop leert van onze gesprekken. Hij kan zich nu voordoen als een van ons. Soort van.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user