<commit_before>const Plugin = require("./../Plugin");
const Util = require("./../Util");

module.exports = class UserInfo extends Plugin {
    static get plugin() {
        return {
            name: "UserInfo",
            description: "Log usernames and user IDs",
            help: "Syntax: `/id user`",

            isProxy: true
        };
    }

    constructor(obj) {
        super(obj);

        if (!this.db)
            this.db = {};
        Util.nameResolver.setDb(this.db);
    }

    proxy(eventName, message) {
        // Discard inline messages
        if (!message.chat) return;

        if (message.from.username) {
            const username = message.from.username;
            const userId = message.from.id;
            this.log.debug(`Username ${username} mapped to ID ${userId}`);
            this.db[username] = userId;
        }

        // Register people who join or leave, too.
        if (message.new_chat_participant || message.left_chat_participant) {
            const source = message.new_chat_participant ?
                message.new_chat_participant :
                message.left_chat_participant;
            this.log.debug(`Username ${source.username} mapped to ID ${source.id}`);
            this.db[source.username] = source.id;
        }

        // Util.nameResolver.setDb(this.db);
        return Promise.resolve();
    }

    get commands() {
        return {
            id: ({message, args}) => {
                let username;
                if (args.length === 1)
                    username = args[0].replace("@", "");
                else if (message.reply_to_message) {
                    if (message.reply_to_message.new_chat_participant)
                        username = message.reply_to_message.new_chat_participant.username;
                    else if (message.reply_to_message.left_chat_participant)
                        username = message.reply_to_message.left_chat_participant.username;
                    else
                        username = message.reply_to_message.from.username;
                } else
                    return "Syntax: /id @username";

                if (!(username in Util.nameResolver.db))
                    return "I've never seen that user before.";

                const userId = Util.nameResolver.getUserIDFromUsername(username);
                const aliases = Util.nameResolver.getUsernamesFromUserID(userId);

                return `${username} - ${userId}

Known aliases: ${aliases.join(", ")}`;
            }<commit_msg>Add mod/admin tags to UserInfo<commit_after>const Plugin = require("./../Plugin");
const Util = require("./../Util");

module.exports = class UserInfo extends Plugin {
    static get plugin() {
        return {
            name: "UserInfo",
            description: "Log usernames and user IDs",
            help: "Syntax: `/id user`",

            isProxy: true
        };
    }

    constructor(obj) {
        super(obj);

        if (!this.db)
            this.db = {};
        Util.nameResolver.setDb(this.db);
        this.auth = obj.auth;
    }

    proxy(eventName, message) {
        // Discard inline messages
        if (!message.chat) return;

        if (message.from.username) {
            const username = message.from.username;
            const userId = message.from.id;
            this.log.debug(`Username ${username} mapped to ID ${userId}`);
            this.db[username] = userId;
        }

        // Register people who join or leave, too.
        if (message.new_chat_participant || message.left_chat_participant) {
            const source = message.new_chat_participant ?
                message.new_chat_participant :
                message.left_chat_participant;
            this.log.debug(`Username ${source.username} mapped to ID ${source.id}`);
            this.db[source.username] = source.id;
        }

        // Util.nameResolver.setDb(this.db);
        return Promise.resolve();
    }

    get commands() {
        return {
            id: ({message, args}) => {
                let username;
                if (args.length === 1)
                    username = args[0].replace("@", "");
                else if (message.reply_to_message) {
                    if (message.reply_to_message.new_chat_participant)
                        username = message.reply_to_message.new_chat_participant.username;
                    else if (message.reply_to_message.left_chat_participant)
                        username = message.reply_to_message.left_chat_participant.username;
                    else
                        username = message.reply_to_message.from.username;
                } else
                    return "Syntax: /id @username";

                if (!(username in Util.nameResolver.db))
                    return "I've never seen that user before.";

                const userId = Util.nameResolver.getUserIDFromUsername(username);
                const aliases = Util.nameResolver.getUsernamesFromUserID(userId);
                let tags = "";
                if (this.auth.isAdmin(message.from.id, message.chat.id))
                    tags += " [admin]";
                else if (this.auth.isMod(message.from.id, message.chat.id))
                    tags += " [mod]";

                return `${username} - ${userId}${tags}

Known aliases: ${aliases.join(", ")}`;
            }
{'fraction_non_alphanumeric': 0.1142963514519732, 'fraction_numerical': 0.0007446016381236039, 'mean_word_length': 1.6546442687747036, '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': '777660', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1396, 'n_words': 301}