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