de Guus filter
This commit is contained in:
+21
-2
@@ -3,6 +3,7 @@ import discord
|
||||
from discord.ext import commands
|
||||
import numpy as np
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
class Chatbot(object):
|
||||
"""Een heuse chatbot. Under construction..."""
|
||||
@@ -12,6 +13,8 @@ class Chatbot(object):
|
||||
self.voice_states = {}
|
||||
self.END_OF_MESSAGE = "<EOM>"
|
||||
self.START_OF_MESSAGE = "<SOM>"
|
||||
self.pmLast = datetime(2018, 1, 1, 1, 1, 1)
|
||||
self.pmCount = 0
|
||||
try:
|
||||
np.load('markov_dict.npy')
|
||||
except FileNotFoundError:
|
||||
@@ -35,7 +38,10 @@ 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)
|
||||
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)
|
||||
elif message.channel.id == self.bot.hdChannels["belangrijk"]: #don't abuse the "belangrijk" channel
|
||||
pass
|
||||
@@ -55,6 +61,19 @@ class Chatbot(object):
|
||||
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:
|
||||
def makePairs(self, corpus):
|
||||
@@ -209,7 +228,7 @@ class Chatbot(object):
|
||||
@commands.command(pass_context=True, hidden=False)
|
||||
@asyncio.coroutine
|
||||
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.
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user