#!/usr/bin/env python3

import discord
import asyncio
import sys

from chatterbot import ChatBot
chatbot = ChatBot(
    "José",
    storage_adapter='chatterbot.storage.JsonFileStorageAdapter',
    logic_adapters=[
        'chatterbot.logic.BestMatch'
    ],
    trainer='chatterbot.trainers.ChatterBotCorpusTrainer'
)

chatbot.train("chatterbot.corpus.portuguese.conversations")

sys.path.append("..")
import jauxiliar as jaux
import josecommon as jcommon
import joseerror as je

from random import SystemRandom
random = SystemRandom()

# 3 percent of all messages
ARTIF_CHATINESS = .03

class JoseArtif(jaux.Auxiliar):
    def __init__(self, cl):
        jaux.Auxiliar.__init__(self, cl)
        self.jose_mention = "<@%s>" % jcommon.JOSE_ID

    async def ext_load(self):
        return True, ''

    async def ext_unload(self):
        return True, ''

    async def e_on_message(self, message):
        # give up on anything related, use chatterbot
        if random.random() < ARTIF_CHATINESS or self.jose_mention in message.content:
            self.current = message
            await self.client.send_typing(message.channel)
            msg = message.content.replace(self.jose_mention, "")
            answer = chatbot.get_response(msg)
            await self.say(answer)

    async def c_command(self, message, args):
        pass

@@ -57,16 +57,28 @@
 port sys
+%0Aimport json
 %0A%0Afrom c
@@ -747,16 +747,41 @@
 .JOSE_ID
+%0A        self.answers = 0
 %0A%0A    as
@@ -1275,16 +1275,46 @@
 se(msg)%0A
+            self.answers += 1%0A
         
@@ -1362,14 +1362,17 @@
  c_c
-ommand
+hatstatus
 (sel
@@ -1402,9 +1402,290 @@
     
-pass
+with open('database.db', 'r') as f:%0A            dbjson = json.load(f)%0A        len_entries = len(dbjson)%0A        report_str = %22%22%22Status Report: %60%60%60%0AI made %25d answers in this session%0AI have %25d entries in my database%0A%60%60%60%22%22%22 %25 (self.answers, len_entries)%0A        await self.say(report_str)
 %0A

add chatstatus command