<commit_before><commit_msg>Add a debug command for dumping useful info<commit_after>const db = require('../lib/database');
const Table = require('ascii-table');
const textHelpers = require('../lib/text_helpers');

module.exports = {
  bind: 'debug',
  administrative: true,
  handler: async function(message) {
    // channel configuration
    const channels = await db.pool.query('SELECT * FROM channels ORDER BY id');
    const channelsTable = new Table('Configured channels');
    channelsTable.setHeading('id', 'discord_id', 'name', 'temporary', 'temporary_index');
    channels.rows.forEach((row) =>
      channelsTable.addRow(row.id, row.discord_id, row.name, row.temporary ? 'TRUE' : 'FALSE', row.temporary_index));

    // general numeric statistics
    const generalStats = await db.pool.query('SELECT (SELECT COUNT(*) FROM game_sessions) AS session_count, ' +
      '(SELECT COUNT(*) FROM games) AS game_count, MAX(game_sessions.session_start) AS latest_session ' +
      'FROM game_sessions;');
    const statsTable = new Table('General statistics');
    const stats = generalStats.rows[0];
    statsTable.setHeading('Session count', 'Unique game count', 'Latest tracked session start');
    statsTable.addRow(stats.session_count, stats.game_count, stats.latest_session);

    // prepare reply
    let reply = channelsTable.toString();
    reply += '\n\n';
    reply += statsTable.toString();

    const messages = await textHelpers.paginateMessage(message, reply);
    messages.forEach((m) => m.delete({timeout: 10000}));
  },
  help: 'Display configuration and debug information.',
};

{'fraction_non_alphanumeric': 0.13829787234042554, 'fraction_numerical': 0.0037546933667083854, 'mean_word_length': 4.438775510204081, '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': '1846297', 'n_tokens_mistral': 463, 'n_tokens_neox': 450, 'n_words': 120}