<commit_before>import json

from modules.base.command import Command
from cleverwrap import CleverWrap
import random


class CleverbotHandler(Command):
    def __init__(self, bot):
        super().__init__(bot)
        self.mention_handler = True
        self.allow_pm = False

        self.cbotcheck = False
        self.bot.sharedcfg['conversation'] = True
        key = self.bot.config['cleverbot_key'].strip()
        if key == '':
            self.bot.sharedcfg['cb_enabled'] = False
            self.log.warning('El valor "cleverbot_key" no se ha definido. La conversación será desactivada.')
            return

        self.cbot = CleverWrap(key)
        self.log.info('Conectando con Cleverbot API...')
        self.cbotcheck = self.cbot.say('test') is not None
        self.bot.sharedcfg['cb_enabled'] = self.cbotcheck
        if self.cbotcheck:
            self.log.info('CleverWrap iniciado correctamente.')
        else:
            self.log.warning('El valor "cleverbot_key" es inválido.')

    async def handle(self, message, cmd):
        if not self.bot.rx_mention.match(message.content) or not self.cbotcheck:
            return

        if not self.bot.sharedcfg['conversation']:
            self.cbot.say('l-lo siento sempai, no puedo hablar ahora uwu')

        msg = self.bot.rx_mention.sub('', message.content).strip()
        if msg == '':
            frase = random.choice(self.bot.config['frases'])
            reply = '{}\n\n*Si querías decirme algo, dílo de la siguiente forma: <@bot> <texto>*'.format(frase)
        else:
            await cmd.typing()
            try:
                reply = self.cbot.say(msg)
            except json.decoder.JSONDecodeError:
                reply = 'sorry, no puedo responderte ahora'

        await cmd.answer(reply)
<commit_msg>Registrar mensajes enviados a cleverbot<commit_after>import json

from modules.base.command import Command
from cleverwrap import CleverWrap
import random


class CleverbotHandler(Command):
    def __init__(self, bot):
        super().__init__(bot)
        self.mention_handler = True
        self.allow_pm = False

        self.cbotcheck = False
        self.bot.sharedcfg['conversation'] = True
        key = self.bot.config['cleverbot_key'].strip()
        if key == '':
            self.bot.sharedcfg['cb_enabled'] = False
            self.log.warning('El valor "cleverbot_key" no se ha definido. La conversación será desactivada.')
            return

        self.cbot = CleverWrap(key)
        self.log.info('Conectando con Cleverbot API...')
        self.cbotcheck = self.cbot.say('test') is not None
        self.bot.sharedcfg['cb_enabled'] = self.cbotcheck
        if self.cbotcheck:
            self.log.info('CleverWrap iniciado correctamente.')
        else:
            self.log.warning('El valor "cleverbot_key" es inválido.')

    async def handle(self, message, cmd):
        if not self.bot.rx_mention.match(message.content) or not self.cbotcheck:
            return

        if not self.bot.sharedcfg['conversation']:
            self.cbot.say('l-lo siento sempai, no puedo hablar ahora uwu')

        msg = self.bot.rx_mention.sub('', message.content).strip()
        if msg == '':
            frase = random.choice(self.bot.config['frases'])
            reply = '{}\n\n*Si querías decirme algo, dílo de la siguiente forma: <@bot> <texto>*'.format(frase)
        else:
            await cmd.typing()
            try:
                self.log.debug('Cleverbot <- "%s"', msg)
                reply = self.cbot.say(msg)
            except json.decoder.JSONDecodeError:
                reply = 'sorry, no puedo responderte ahora'

        await cmd.answer(reply)

{'fraction_non_alphanumeric': 0.11482993197278911, 'fraction_numerical': 0.0, 'mean_word_length': 2.2473498233215548, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6248621', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1113, 'n_words': 259}