<commit_before>'use strict';

const DiscordCommand = require('../../../../bot/modules/DiscordCommand');

const models = require('../../../models');


class CommandRank extends DiscordCommand {
    constructor(bot) {
        super(bot, 'rank', ['rank']);
    }

    async onCommand(message) {
        const bot = this.getBot();
        const l = bot.getLocalizer();
        const discordId = message.author.id;

        try {
            const account = await models.BattleNetAccount.findOne({ discordId });
            if (!account) {
                return l.t('module.overwatch:rank.response-no-account');
            }
            const stats = await models.OverwatchStats.findOne({ accountName: account.accountName, platform: account.platform });
            if (!stats) {
                return l.t('module.overwatch:rank.response-not-available');
            }
            const regionStats = stats[stats.activeRegion];

            return l.t('module.overwatch:rank.response', {
                account_name: account.accountName, // eslint-disable-line camelcase
                rank: regionStats.rank,
                ranking: regionStats.ranking,
                region: stats.activeRegion
            });
        } catch (err) {
            return l.t('module.overwatch:rank.response-error', { error: err.message });
        }
    }
}

module.exports = CommandRank;
<commit_msg>Add proper region name for the Overwatch rank command<commit_after>'use strict';

const DiscordCommand = require('../../../../bot/modules/DiscordCommand');

const models = require('../../../models');


class CommandRank extends DiscordCommand {
    constructor(bot) {
        super(bot, 'rank', ['rank']);
    }

    async onCommand(message) {
        const bot = this.getBot();
        const l = bot.getLocalizer();
        const discordId = message.author.id;

        try {
            const account = await models.BattleNetAccount.findOne({ discordId });
            if (!account) {
                return l.t('module.overwatch:rank.response-no-account');
            }
            const stats = await models.OverwatchStats.findOne({ accountName: account.accountName, platform: account.platform });
            if (!stats) {
                return l.t('module.overwatch:rank.response-not-available');
            }
            const regionStats = stats[stats.activeRegion];

            return l.t('module.overwatch:rank.response', {
                account_name: account.accountName, // eslint-disable-line camelcase
                rank: regionStats.rank,
                ranking: regionStats.ranking,
                region: l.t(`module.overwatch:competitive-rank-checker.region-${stats.activeRegion}`)
            });
        } catch (err) {
            return l.t('module.overwatch:rank.response-error', { error: err.message });
        }
    }
}

module.exports = CommandRank;

{'fraction_non_alphanumeric': 0.13356521739130434, 'fraction_numerical': 0.0, 'mean_word_length': 2.082529474812433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7644976', 'n_tokens_mistral': 772, 'n_tokens_neox': 745, 'n_words': 152}