Friday, September 20, 2024 1:42:10 AM
> settings

Customize


Authenticate

> promote.js
const ESMCommand = require("../esm_command");
module.exports = class ESMCommand_Promote extends ESMCommand {
    constructor(bot) {
        super(bot);
        this.permissions = {
            requires_registration: true,
            requires_server: true
        };

        this.commandParams = {
            serverID: {
                regex: this.util.regex.serverID.base
            },
            territoryID: {
                regex: this.util.regex.territoryID.base
            },
            targetUID: {
                regex: this.util.regex.target.base
            }
        };

        this.information = {
            category: "territory",
            params: "<server_id> <territory_id> <target_uid | @user>",
            help: "Promotes a player to moderator in a territory. Player must be added to a territory first"
        };

        this.configuration = {
            allowedInTextChannels: {
                modifiable: true,
                default: false
            },
            cooldown: {
                modifiable: true,
                default: [2, "seconds"]
            },
            enabled: {
                modifiable: true,
                default: true
            }
        };
    }

    async fromDiscord() {
        if (this.util.regex.discordTag.base.test(this.params.targetUID)) {
            let discordUser = await this.ESMBot.getUser(this.params.targetUID);
            if (discordUser == null) {
                return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "USER_NOT_FOUND"));
            }
            let isRegistered = await this.db.isRegistered(discordUser.id);
            if (!isRegistered) {
                return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "USER_NOT_REGISTERED"));
            }
            this.params.targetUID = await this.db.getSteamUIDFromID(discordUser.id);
            if (this.params.targetUID == null) return
        }

        this.send({
            serverID: this.params.serverID,
            command: "promote",
            parameters: {
                function_name: "promotePlayer",
                territory_id: this.params.territoryID,
                target_uid: this.params.targetUID,
                uid: this.params.steamUID
            }
        });
    }

    async fromServer() {
        this.ESMBot.send(this.info.channel, `${this.info.author.tag}, \`${this.info.parameters.target_uid}\` has been promoted to moderator in territory \`${this.info.parameters.territory_id}\` on \`${this.serverID}\``);
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8