<commit_before>#!/usr/bin/env python
# Goshubot IRC Bot
# written by <NAME> <<EMAIL>>
# licensed under the BSD 2-clause license

from gbot.modules import Module


class list(Module):
    """Provides help and command listings to users."""
    core = True

    def __init__(self, bot):
        Module.__init__(self, bot)
        self.events = {
            'commands': {
                'list': [self.list, "[command] --- list all commands; if command is present, display info on that command instead~"],
                'help': [self.list, "[command] --- list all commands; if command is present, display info on that command instead~"],
            },
            'in': {
                'privmsg': [(0, self.privmsg)]
            }
        }

    def privmsg(self, event):
        if event.arguments[0].lower() in ['help', 'hello', 'hi']:
            response = 'Hello! I am a bot, to view the avaliable commands, please type {format}list'.format(format=self.bot.settings.store['command_prefix'])
            self.bot.irc.msg(event, response)

    def list(self, event, command, usercommand):
        bot_commands = {}

        for module in sorted(self.bot.modules.modules):
            module_commands = self.bot.modules.modules[module].commands
            for name in sorted(module_commands):
                if name == '*':
                    continue
                command = module_commands[name]

                if self.bot.accounts.access_level(self.bot.accounts.account(event.source, event.server)) >= command.view_level:
                    bot_commands[name] = command

        if usercommand.arguments:
            # single command info
            name = usercommand.arguments.split()[0].lower()
            if name in bot_commands:
                command = bot_commands[name]

                # fix help display for single help strings
                for help_string in command.description:
                    response = '*** Command:  {prefix}{cmd} {desc}'.format(prefix=self.bot.settings.store['command_prefix'],
                                                                           cmd=name,
                                                                           desc=help_string)
                    self.bot.irc.msg(event, response)

        else:
            # list commands
            output = ['*** Commands: ']
            i = 0
            limit = 256
            for name in sorted(bot_commands.keys()):
                if bot_commands[name].alias:
                    continue
                if (len(output[i]) + len(name)) > limit:
                    output.append('    ')
                    i += 1
                output[i] += name + ', '
            output[i] = output[i][:-2]  # remove last ', '

            output.append('Note: to display information on a specific command, use @i{prefix}list <command>@i. eg: @i{prefix}list 8ball'.format(prefix=self.bot.settings.store['command_prefix']))

            for line in output:
                self.bot.irc.msg(event, line)
<commit_msg>Allow  'help <command>  command to be prefixed with current command character<commit_after>#!/usr/bin/env python
# Goshubot IRC Bot
# written by <NAME> <<EMAIL>>
# licensed under the BSD 2-clause license

from gbot.modules import Module


class list(Module):
    """Provides help and command listings to users."""
    core = True

    def __init__(self, bot):
        Module.__init__(self, bot)
        self.events = {
            'commands': {
                'list': [self.list, "[command] --- list all commands; if command is present, display info on that command instead~"],
                'help': [self.list, "[command] --- list all commands; if command is present, display info on that command instead~"],
            },
            'in': {
                'privmsg': [(0, self.privmsg)]
            }
        }

    def privmsg(self, event):
        if event.arguments[0].lower() in ['help', 'hello', 'hi']:
            response = 'Hello! I am a bot, to view the avaliable commands, please type {prefix}list'.format(prefix=self.bot.settings.store['command_prefix'])
            self.bot.irc.msg(event, response)

    def list(self, event, command, usercommand):
        bot_commands = {}

        for module in sorted(self.bot.modules.modules):
            module_commands = self.bot.modules.modules[module].commands
            for name in sorted(module_commands):
                if name == '*':
                    continue
                command = module_commands[name]

                if self.bot.accounts.access_level(self.bot.accounts.account(event.source, event.server)) >= command.view_level:
                    bot_commands[name] = command

        if usercommand.arguments:
            # single command info
            name = usercommand.arguments.split()[0].lower()
            command_prefix = self.bot.settings.store['command_prefix']
            if name.startswith(command_prefix):
                name = name[len(command_prefix):]
            if name in bot_commands:
                command = bot_commands[name]

                # fix help display for single help strings
                for help_string in command.description:
                    response = '*** Command:  {prefix}{cmd} {desc}'.format(prefix=self.bot.settings.store['command_prefix'],
                                                                           cmd=name,
                                                                           desc=help_string)
                    self.bot.irc.msg(event, response)

        else:
            # list commands
            output = ['*** Commands: ']
            i = 0
            limit = 256
            for name in sorted(bot_commands.keys()):
                if bot_commands[name].alias:
                    continue
                if (len(output[i]) + len(name)) > limit:
                    output.append('    ')
                    i += 1
                output[i] += name + ', '
            output[i] = output[i][:-2]  # remove last ', '

            output.append('Note: to display information on a specific command, use @i{prefix}list <command>@i. eg: @i{prefix}list 8ball'.format(prefix=self.bot.settings.store['command_prefix']))

            for line in output:
                self.bot.irc.msg(event, line)

{'fraction_non_alphanumeric': 0.11442628154261228, 'fraction_numerical': 0.0034915092842405966, 'mean_word_length': 1.6714709622721493, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6837854', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1558, 'n_words': 428}