@ -19,7 +19,6 @@ from redbot.core.utils.predicates import MessagePredicate
from chatter . trainers import MovieTrainer , TwitterCorpusTrainer , UbuntuCorpusTrainer2
chatterbot_log = logging . getLogger ( " red.fox_v3.chatterbot " )
log = logging . getLogger ( " red.fox_v3.chatter " )
@ -30,12 +29,6 @@ def my_local_get_prefix(prefixes, content):
return None
class ENG_TRF :
ISO_639_1 = " en_core_web_trf "
ISO_639 = " eng "
ENGLISH_NAME = " English "
class ENG_LG :
ISO_639_1 = " en_core_web_lg "
ISO_639 = " eng "
@ -59,15 +52,12 @@ class Chatter(Cog):
This cog trains a chatbot that will talk like members of your Guild
"""
models = [ ENG_SM , ENG_MD , ENG_LG , ENG_TRF ]
algos = [ SpacySimilarity , JaccardSimilarity , LevenshteinDistance ]
def __init__ ( self , bot ) :
super ( ) . __init__ ( )
self . bot = bot
self . config = Config . get_conf ( self , identifier = 6710497116116101114 )
default_global = { " learning " : True , " model_number " : 0 , " algo_number " : 0 , " threshold " : 0.90 }
self . default_guild = {
default_global = { " learning " : True }
default_guild = {
" whitelist " : None ,
" days " : 1 ,
" convo_delta " : 15 ,
@ -80,16 +70,16 @@ class Chatter(Cog):
# TODO: Move training_model and similarity_algo to config
# TODO: Add an option to see current settings
self . tagger_language = ENG_ S M
self . tagger_language = ENG_ MD
self . similarity_algo = SpacySimilarity
self . similarity_threshold = 0.90
self . chatbot = None
self . chatbot = self . _create_chatbot ( )
# self.chatbot.set_trainer(ListTrainer)
# self.trainer = ListTrainer(self.chatbot)
self . config . register_global ( * * default_global )
self . config . register_guild ( * * self . default_guild )
self . config . register_guild ( * * default_guild )
self . loop = asyncio . get_event_loop ( )
@ -102,18 +92,6 @@ class Chatter(Cog):
""" Nothing to delete """
return
async def initialize ( self ) :
all_config = dict ( self . config . defaults [ " GLOBAL " ] )
all_config . update ( await self . config . all ( ) )
model_number = all_config [ " model_number " ]
algo_number = all_config [ " algo_number " ]
threshold = all_config [ " threshold " ]
self . tagger_language = self . models [ model_number ]
self . similarity_algo = self . algos [ algo_number ]
self . similarity_threshold = threshold
self . chatbot = self . _create_chatbot ( )
def _create_chatbot ( self ) :
return ChatBot (
@ -126,7 +104,7 @@ class Chatter(Cog):
logic_adapters = [ " chatterbot.logic.BestMatch " ] ,
maximum_similarity_threshold = self . similarity_threshold ,
tagger_language = self . tagger_language ,
logger = chatterbot_ log,
logger = log,
)
async def _get_conversation ( self , ctx , in_channels : List [ discord . TextChannel ] ) :
@ -350,12 +328,15 @@ class Chatter(Cog):
self , ctx : commands . Context , algo_number : int , threshold : float = None
) :
"""
Switch the active logic algorithm to one of the three . Default is Spacy
Switch the active logic algorithm to one of the three . Default after reload is Spacy
0 : Spacy
1 : Jaccard
2 : Levenshtein
"""
algos = [ SpacySimilarity , JaccardSimilarity , LevenshteinDistance ]
if algo_number < 0 or algo_number > 2 :
await ctx . send_help ( )
return
@ -368,11 +349,8 @@ class Chatter(Cog):
return
else :
self . similarity_threshold = threshold
await self . config . threshold . set ( self . similarity_threshold )
self . similarity_algo = self . algos [ algo_number ]
await self . config . algo_number . set ( algo_number )
self . similarity_algo = algos [ algo_number ]
async with ctx . typing ( ) :
self . chatbot = self . _create_chatbot ( )
@ -382,18 +360,20 @@ class Chatter(Cog):
@chatter.command ( name = " model " )
async def chatter_model ( self , ctx : commands . Context , model_number : int ) :
"""
Switch the active model to one of the three . Default is Small
Switch the active model to one of the three . Default after reload is Medium
0 : Small
1 : Medium ( Requires additional setup )
1 : Medium
2 : Large ( Requires additional setup )
3. Accurate ( Requires additional setup )
"""
if model_number < 0 or model_number > 3 :
models = [ ENG_SM , ENG_MD , ENG_LG ]
if model_number < 0 or model_number > 2 :
await ctx . send_help ( )
return
if model_number >= 0 :
if model_number == 2 :
await ctx . maybe_send_embed (
" Additional requirements needed. See guide before continuing. \n " " Continue? "
)
@ -406,8 +386,7 @@ class Chatter(Cog):
if not pred . result :
return
self . tagger_language = self . models [ model_number ]
await self . config . model_number . set ( model_number )
self . tagger_language = models [ model_number ]
async with ctx . typing ( ) :
self . chatbot = self . _create_chatbot ( )
@ -416,13 +395,7 @@ class Chatter(Cog):
)
@commands.is_owner ( )
@chatter.group ( name = " trainset " )
async def chatter_trainset ( self , ctx : commands . Context ) :
""" Commands for configuring training """
pass
@commands.is_owner ( )
@chatter_trainset.command ( name = " minutes " )
@chatter.command ( name = " minutes " )
async def minutes ( self , ctx : commands . Context , minutes : int ) :
"""
Sets the number of minutes the bot will consider a break in a conversation during training
@ -438,7 +411,7 @@ class Chatter(Cog):
await ctx . tick ( )
@commands.is_owner ( )
@chatter _trainset .command( name = " age " )
@chatter .command( name = " age " )
async def age ( self , ctx : commands . Context , days : int ) :
"""
Sets the number of days to look back
@ -657,7 +630,7 @@ class Chatter(Cog):
guild : discord . Guild = getattr ( message , " guild " , None )
if guild is None or await self . bot . cog_disabled_in_guild ( self , guild ) :
if await self . bot . cog_disabled_in_guild ( self , guild ) :
return
ctx : commands . Context = await self . bot . get_context ( message )
@ -732,9 +705,7 @@ class Chatter(Cog):
)
replying = None
if (
" reply " not in self . _guild_cache [ guild . id ] and self . default_guild [ " reply " ]
) or self . _guild_cache [ guild . id ] [ " reply " ] :
if self . _guild_cache [ guild . id ] [ " reply " ] :
if message != ctx . channel . last_message :
replying = message