<commit_before>import itertools

import smartbot
from smartbot.exceptions import *
from smartbot.formatting import *


class Plugin(smartbot.Plugin):
    names = ["help", "what?"]

    def on_command(self, msg, stdin, stdout, reply):
        plugin_name = None
        if len(msg["args"]) >= 2:
            plugin_name = msg["args"][1]
        else:
            plugin_name = stdin.read().strip()

        if plugin_name:
            try:
                plugin = self.bot.find_plugin(plugin_name)
                print(plugin.on_help(), file=stdout)
            except KeyError:
                raise StopCommand("{} does not exist.".format(plugin_name))
        else:
            plugin_names = ", ".join(sorted(itertools.chain.from_iterable(plugin.names for plugin in self.bot.plugins)))
            print("Help about:", plugin_names, file=stdout)

    def on_help(self):
        return "{} [{}]".format(
            self.bot.format("help", Style.bold),
            self.bot.format("plugin", Style.underline)
        )<commit_msg>Fix help plugin to cope with non-existent plugins<commit_after>import itertools

import smartbot
from smartbot.exceptions import *
from smartbot.formatting import *


class Plugin(smartbot.Plugin):
    names = ["help", "what?"]

    def on_command(self, msg, stdin, stdout, reply):
        plugin_name = None
        if len(msg["args"]) >= 2:
            plugin_name = msg["args"][1]
        else:
            plugin_name = stdin.read().strip()

        if plugin_name:
            plugin = self.bot.find_plugin(plugin_name)
            if plugin:
                print(plugin.on_help(), file=stdout)
            else:
                raise StopCommand("{} does not exist.".format(plugin_name))
        else:
            plugin_names = ", ".join(sorted(itertools.chain.from_iterable(plugin.names for plugin in self.bot.plugins)))
            print("Help about:", plugin_names, file=stdout)

    def on_help(self):
        return "{} [{}]".format(
            self.bot.format("help", Style.bold),
            self.bot.format("plugin", Style.underline)
        )
{'fraction_non_alphanumeric': 0.12756808408982323, 'fraction_numerical': 0.0019111323459149545, 'mean_word_length': 2.2872841444270016, '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': '5126005', 'n_tokens_mistral': 613, 'n_tokens_neox': 595, 'n_words': 135}