@ -3,6 +3,7 @@ import logging
import os
import pathlib
from datetime import datetime , timedelta
from typing import Literal
import discord
from chatterbot import ChatBot
@ -13,6 +14,7 @@ from redbot.core import Config, commands
from redbot . core . commands import Cog
from redbot . core . data_manager import cog_data_path
from redbot . core . utils . predicates import MessagePredicate
from redbot . core . utils import AsyncIter
log = logging . getLogger ( " red.fox_v3.chat " )
@ -65,6 +67,10 @@ class Chatter(Cog):
self . loop = asyncio . get_event_loop ( )
async def red_delete_data_for_user ( self , * * kwargs ) :
""" Nothing to delete """
return
def _create_chatbot ( self ) :
return ChatBot (
@ -107,7 +113,7 @@ class Chatter(Cog):
for channel in ctx . guild . text_channels :
if in_channel :
channel = in_channel
await ctx . send( " Gathering {} " . format ( channel . mention ) )
await ctx . maybe_ send_embe d( " Gathering {} " . format ( channel . mention ) )
user = None
i = 0
send_time = after - timedelta ( days = 100 ) # Makes the first message a new message
@ -188,7 +194,7 @@ class Chatter(Cog):
"""
if not confirm :
await ctx . send(
await ctx . maybe_ send_embe d(
" Warning, this command will erase all your training data and reset your configuration \n "
" If you want to proceed, run the command again as `[p]chatter cleardata True` "
)
@ -314,7 +320,7 @@ class Chatter(Cog):
Backup your training data to a json for later use
"""
await ctx . send( " Backing up data, this may take a while " )
await ctx . maybe_ send_embe d( " Backing up data, this may take a while " )
path : pathlib . Path = cog_data_path ( self )
@ -325,9 +331,9 @@ class Chatter(Cog):
)
if future :
await ctx . send( f " Backup successful! Look in { path } for your backup " )
await ctx . maybe_ send_embe d( f " Backup successful! Look in { path } for your backup " )
else :
await ctx . send( " Error occurred :( " )
await ctx . maybe_ send_embe d( " Error occurred :( " )
@chatter.command ( name = " trainubuntu " )
async def chatter_train_ubuntu ( self , ctx : commands . Context , confirmation : bool = False ) :
@ -359,9 +365,9 @@ class Chatter(Cog):
future = await self . loop . run_in_executor ( None , self . _train_english )
if future :
await ctx . send( " Training successful! " )
await ctx . maybe_ send_embe d( " Training successful! " )
else :
await ctx . send( " Error occurred :( " )
await ctx . maybe_ send_embe d( " Error occurred :( " )
@chatter.command ( )
async def train ( self , ctx : commands . Context , channel : discord . TextChannel ) :
@ -369,7 +375,7 @@ class Chatter(Cog):
Trains the bot based on language in this guild
"""
await ctx . send(
await ctx . maybe_ send_embe d(
" Warning: The cog may use significant RAM or CPU if trained on large data sets. \n "
" Additionally, large sets will use more disk space to save the trained data. \n \n "
" If you experience issues, clear your trained data and train again on a smaller scope. "
@ -379,10 +385,10 @@ class Chatter(Cog):
conversation = await self . _get_conversation ( ctx , channel )
if not conversation :
await ctx . send( " Failed to gather training data " )
await ctx . maybe_ send_embe d( " Failed to gather training data " )
return
await ctx . send(
await ctx . maybe_ send_embe d(
" Gather successful! Training begins now \n "
" (**This will take a long time, be patient. See console for progress**) "
)
@ -397,9 +403,9 @@ class Chatter(Cog):
pass
if future :
await ctx . send( " Training successful! " )
await ctx . maybe_ send_embe d( " Training successful! " )
else :
await ctx . send( " Error occurred :( " )
await ctx . maybe_ send_embe d( " Error occurred :( " )
@commands.Cog.listener ( )
async def on_message_without_command ( self , message : discord . Message ) :