<commit_before>'use strict';

class Helpfile {
  constructor(bundle, name, options) {
    this.bundle = bundle;
    this.name = name;

    if (!options || !options.body) {
      throw new Error(`Help file [${name}] has no content`);
    }

    this.keywords = options.keywords || [name];
    this.command = options.command;
    this.channel = options.channel;
    this.related = options.related || [];
    this.body = options.body;
  }

  render(state) {
    let body = this.body;
    const name = this.name;

    const bar = "<yellow>---------------------------------------------------------------------------------</yellow>\r\n";

    const width = 80;
    let header = bar;
    // center name
    header += (new Array(width / 2 - Math.ceil(name.length / 2)).join(' '));
    header += '<bold><white>' + name + '</white></bold>\r\n';
    header += bar;

    if (this.command) {
      header += 'Syntax: ' + state.CommandManager.get(this.command).usage + '\r\n\r\n';
    } else if (this.channel) {
      // TODO: get channel usage
    }

    let footer = bar;
    if (this.related.length) {
      footer = "<yellow>------------------------------------RELATED--------------------------------------</yellow>\r\n";
      const related = this.related.join(', ');
      footer += (new Array(width / 2 - Math.ceil(related.length / 2)).join(' '));
      footer += related + '\r\n';
      footer += bar;
    }

    return header + this.body + footer;
  }
}

module.exports = Helpfile;<commit_msg>Helpfile refactor, channel usage impl & commenting (#127)<commit_after>'use strict';

class Helpfile {
  constructor(bundle, name, options) {
    this.bundle = bundle;
    this.name = name;

    if (!options || !options.body) {
      throw new Error(`Help file [${name}] has no content.`);
    }

    this.keywords = options.keywords || [name];
    this.command = options.command;
    this.channel = options.channel;
    this.related = options.related || [];
    this.body = options.body;
  }

  render(state) {
    let body = this.body;
    const name = this.name;

    const bar = "<yellow>---------------------------------------------------------------------------------</yellow>\r\n";
    const width = 80;
    const centerPadding = len => ' '.repeat(width / 2 - Math.ceil(len / 2));

    let header = bar;
    header += centerPadding(name.length); // Center name.
    header += `<bold><white>${name}</white></bold>\r\n`;
    header += bar;

    const formatUsageSyntax = usage => `Syntax: ${usage}\r\n\r\n`;
    if (this.command) {
      header += formatUsageSyntax(state.CommandManager.get(this.command).usage);
    } else if (this.channel) {
      header += formatUsageSyntax(state.ChannelManager.get(this.channel).showUsage());
    }

    let footer = bar;
    if (this.related.length) {
      footer = "<yellow>------------------------------------RELATED--------------------------------------</yellow>\r\n";
      const related = this.related.join(', ');
      footer += centerPadding(related.length); // Center the related topics.
      footer += related + '\r\n';
      footer += bar;
    }

    return header + this.body + footer;
  }
}

module.exports = Helpfile;
{'fraction_non_alphanumeric': 0.2506321112515803, 'fraction_numerical': 0.0041087231352718075, 'mean_word_length': 1.8877737226277371, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '4353391', 'n_tokens_mistral': 952, 'n_tokens_neox': 893, 'n_words': 213}