<commit_before>const Command = require('./Command');

class CommandManager {
  constructor(client) {
    this.client = client;
    this.commands = {};
    this.pluginCommands = {};
    this.regexCmd = new RegExp(/^!(\S+)/);
    this.cachedHelpText = null;

    this.registerCommand(new Command(
      'help',
      'Display this help text',
      this.handleHelp.bind(this)
    ));

    this.client.on('message', this.handleMessage.bind(this));
  }

  registerCommand(command) {
    if (command.name in command) {
      throw new Error("Attempted to register duplicate command: " + command.name);
    }

    this.commands[command.name] = command;
  }

  registerPluginCommands(commands) {
    commands.forEach((command) => {
      this.registerCommand(command);
    });
  }

  handleHelp(message) {
    if (self.cachedHelpText != null) {
      return self.cachedHelpText;
    }

    const helpTexts = [];
    let cmd = null;

    for (const i in this.commands) {
      cmd = this.commands[i];
      helpTexts.push('!' + cmd.name + ' - ' + cmd.description);
    }

    self.cachedHelpText = "```" + helpTexts.join('\n') + "```";

    return self.cachedHelpText;
  }

  handleMessage(message) {
    if (message.author == this.client.user) {
      return;
    }

    const match = this.regexCmd.exec(message.content)

    // Check if message is a command
    if (match === null || !(match[1] in this.commands)) {
      return;
    }
<commit_msg>Fix js bug<commit_after>const Command = require('./Command');

class CommandManager {
  constructor(client) {
    this.client = client;
    this.commands = {};
    this.pluginCommands = {};
    this.regexCmd = new RegExp(/^!(\S+)/);
    this.cachedHelpText = null;

    this.registerCommand(new Command(
      'help',
      'Display this help text',
      this.handleHelp.bind(this)
    ));

    this.client.on('message', this.handleMessage.bind(this));
  }

  registerCommand(command) {
    if (command.name in command) {
      throw new Error("Attempted to register duplicate command: " + command.name);
    }

    this.commands[command.name] = command;
  }

  registerPluginCommands(commands) {
    commands.forEach((command) => {
      this.registerCommand(command);
    });
  }

  handleHelp(message) {
    if ( this.cachedHelpText != null) {
      return this.cachedHelpText;
    }

    const helpTexts = [];
    let cmd = null;

    for (const i in this.commands) {
      cmd = this.commands[i];
      helpTexts.push('!' + cmd.name + ' - ' + cmd.description);
    }

    this.cachedHelpText = "```" + helpTexts.join('\n') + "```";

    return this.cachedHelpText;
  }

  handleMessage(message) {
    if (message.author == this.client.user) {
      return;
    }

    const match = this.regexCmd.exec(message.content)

    // Check if message is a command
    if (match === null || !(match[1] in this.commands)) {
      return;
    }

{'fraction_non_alphanumeric': 0.15128383067314366, 'fraction_numerical': 0.0006939625260235947, 'mean_word_length': 2.686700767263427, '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': '3708381', 'n_tokens_mistral': 927, 'n_tokens_neox': 894, 'n_words': 180}