<commit_before>import discord
import time
from random import SystemRandom
random = SystemRandom()

import sys
import base64
import subprocess
import re
import importlib
import copy
import gc

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

jose_debug = jcommon.jose_debug

class JoseBot(jcommon.Extension):
    def __init__(self, _client):
        jcommon.Extension.__init__(self, _client)
        self.nick = 'jose-bot'
        self.modules = {}
        self.env = {
            'cooldowns': {},
            'stcmd': {},
        }
        self.start_time = time.time()
        self.command_lock = False
        self.dev_mode = False
        self.off_mode = False
        self.ev_empty()

    def ev_empty(self):
        self.event_tbl = {
            'on_message': [],
            'any_message': [],
            'server_join': [],
            'client_ready': [],
        }

    def ev_load(self, dflag=False):
        # register events
        count = 0
        for modname in self.modules:
            module = self.modules[modname]
            modinst = self.modules[modname]['inst']
            for method in module['handlers']:
                if method.startswith("e_"):
                    evname = method[method.find("_")+1:]

                    if dflag:
                        self.logger.info("Event handler %s@%s:%s", \
                            method, modname, evname)

                    # check if event exists
                    if evname in self.event_tbl:
                        handler = getattr(modinst, method, None)
                        if handler is None:
                            # ????
                            self.logger.error("Event handler %s@%s:%s doesn't... exist????", \
                                method, modname, evname)
                            sys.exit(0)

                        self.event_tbl[evname].append(handler)
                        count += 1
                    else:
                        self.logger.warning("Event %s@%s:%s doesn't exist in Event Table", \
                            method, modname, evname)

        self.logger.info("[ev_load] Loaded %d handlers" % count)

    async def unload_mod(self, modname):
        module = self.modules[modname]
        # if ext_unload exists
        if getattr(module['inst'], 'ext_unload', False):
            try:
                ok = await module['inst'].ext_unload()

                # first, we should, at least, remove the commands the module has
                # it will help a LOT on memory usage.
                instance_methods = (method for method in dir(instance)
                    if callable(getattr(instance, method)))

                for method in instance_methods:
                    if method.startswith('c_'):
                        # command, remove it
                        delattr(self, method)

                # delete stuff from the module table
                del instance_methods, self.modules[modname]

                # remove its events from the evt. table, if any
                if len(module['handlers']) > 0:<commit_msg>jose: create instance in unload_mod<commit_after>import discord
import time
from random import SystemRandom
random = SystemRandom()

import sys
import base64
import subprocess
import re
import importlib
import copy
import gc

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

jose_debug = jcommon.jose_debug

class JoseBot(jcommon.Extension):
    def __init__(self, _client):
        jcommon.Extension.__init__(self, _client)
        self.nick = 'jose-bot'
        self.modules = {}
        self.env = {
            'cooldowns': {},
            'stcmd': {},
        }
        self.start_time = time.time()
        self.command_lock = False
        self.dev_mode = False
        self.off_mode = False
        self.ev_empty()

    def ev_empty(self):
        self.event_tbl = {
            'on_message': [],
            'any_message': [],
            'server_join': [],
            'client_ready': [],
        }

    def ev_load(self, dflag=False):
        # register events
        count = 0
        for modname in self.modules:
            module = self.modules[modname]
            modinst = self.modules[modname]['inst']
            for method in module['handlers']:
                if method.startswith("e_"):
                    evname = method[method.find("_")+1:]

                    if dflag:
                        self.logger.info("Event handler %s@%s:%s", \
                            method, modname, evname)

                    # check if event exists
                    if evname in self.event_tbl:
                        handler = getattr(modinst, method, None)
                        if handler is None:
                            # ????
                            self.logger.error("Event handler %s@%s:%s doesn't... exist????", \
                                method, modname, evname)
                            sys.exit(0)

                        self.event_tbl[evname].append(handler)
                        count += 1
                    else:
                        self.logger.warning("Event %s@%s:%s doesn't exist in Event Table", \
                            method, modname, evname)

        self.logger.info("[ev_load] Loaded %d handlers" % count)

    async def unload_mod(self, modname):
        module = self.modules[modname]
        # if ext_unload exists
        if getattr(module['inst'], 'ext_unload', False):
            try:
                instance = module['inst']
                ok = await instance.ext_unload()

                # first, we should, at least, remove the commands the module has
                # it will help a LOT on memory usage.
                instance_methods = (method for method in dir(instance)
                    if callable(getattr(instance, method)))

                for method in instance_methods:
                    if method.startswith('c_'):
                        # command, remove it
                        delattr(self, method)

                # delete stuff from the module table
                del instance_methods, self.modules[modname]

                # remove its events from the evt. table, if any
                if len(module['handlers']) > 0:
{'fraction_non_alphanumeric': 0.09732824427480916, 'fraction_numerical': 0.0022264631043256997, 'mean_word_length': 1.4432789432789432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1485622', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1597, 'n_words': 437}