Random instead of first for more variety

Disable custom similarity threshold for now, until it's configurable
use filter to avoid looking at empty messages
pull/107/head
bobloy 5 years ago
parent 524b71cc83
commit c9e49a29e7

@ -5,7 +5,7 @@ from datetime import datetime, timedelta
import discord import discord
from chatterbot import ChatBot from chatterbot import ChatBot
from chatterbot.comparisons import JaccardSimilarity, LevenshteinDistance, SpacySimilarity from chatterbot.comparisons import JaccardSimilarity, LevenshteinDistance, SpacySimilarity
from chatterbot.response_selection import get_first_response from chatterbot.response_selection import get_random_response
from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer
from redbot.core import Config, commands from redbot.core import Config, commands
from redbot.core.commands import Cog from redbot.core.commands import Cog
@ -56,9 +56,9 @@ class Chatter(Cog):
storage_adapter="chatterbot.storage.SQLStorageAdapter", storage_adapter="chatterbot.storage.SQLStorageAdapter",
database_uri="sqlite:///" + str(data_path), database_uri="sqlite:///" + str(data_path),
statement_comparison_function=similarity_algorithm, statement_comparison_function=similarity_algorithm,
response_selection_method=get_first_response, response_selection_method=get_random_response,
logic_adapters=["chatterbot.logic.BestMatch"], logic_adapters=["chatterbot.logic.BestMatch"],
maximum_similarity_threshold=similarity_threshold, # maximum_similarity_threshold=similarity_threshold,
tagger_language=tagger_language, tagger_language=tagger_language,
) )
@ -72,6 +72,9 @@ class Chatter(Cog):
after = datetime.today() - timedelta(days=(await self.config.guild(ctx.guild).days())) after = datetime.today() - timedelta(days=(await self.config.guild(ctx.guild).days()))
convo_delta = timedelta(minutes=(await self.config.guild(ctx.guild).convo_delta())) convo_delta = timedelta(minutes=(await self.config.guild(ctx.guild).convo_delta()))
def predicate(message: discord.Message):
return message.clean_content
def new_conversation(msg, sent, out_in, delta): def new_conversation(msg, sent, out_in, delta):
# if sent is None: # if sent is None:
# return False # return False
@ -95,7 +98,9 @@ class Chatter(Cog):
try: try:
async for message in channel.history( async for message in channel.history(
limit=None, after=after limit=None, after=after, oldest_first=True
).filter(
predicate=predicate
): # type: discord.Message ): # type: discord.Message
# if message.author.bot: # Skip bot messages # if message.author.bot: # Skip bot messages
# continue # continue
@ -138,7 +143,6 @@ class Chatter(Cog):
for convo in data: for convo in data:
if len(convo) > 1: if len(convo) > 1:
trainer.train(convo) trainer.train(convo)
except: except:
return False return False
return True return True
@ -296,8 +300,9 @@ class Chatter(Cog):
ctx: commands.Context = await self.bot.get_context(message) ctx: commands.Context = await self.bot.get_context(message)
# if ctx.prefix is None: if ctx.prefix is not None:
# return return
########### ###########
# Thank you Cog-Creators # Thank you Cog-Creators
@ -305,6 +310,7 @@ class Chatter(Cog):
for p in prefixes: for p in prefixes:
if content.startswith(p): if content.startswith(p):
return p return p
return None
when_mentionables = commands.when_mentioned(self.bot, message) when_mentionables = commands.when_mentioned(self.bot, message)

Loading…
Cancel
Save