Friday, September 20, 2024 1:39:29 AM
> settings

Customize


Authenticate

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

        this.commandParams = {
            serverID: {
                regex: this.util.regex.serverID.base
            }
        };

        this.information = {
            category: "server",
            params: "<server_id>",
            help: "Lists all territories for a server. This command can only be used in a text channel and is only available for a certain role."
        };

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

    async fromDiscord() {
        let communityID = await this.db.getCommunityID(this.message.guild.id);

        if (this.util.isEmpty(communityID)) {
            return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "FAILED_TO_FIND_COMMUNITY"));
        }

        let parsedID = this.util.getCommunityID(this.params.serverID);

        if (parsedID !== communityID) {
            return this.ESMBot.send(this.message.channel, this.ESMBot.errors.format(this.message.author, "UHH_UHH_UHH"));
        }

        this.send({
            command: "allterritories",
            parameters: {
                query: "list_territories_all"
            }
        });
    }

    async fromServer() {
        if (this.util.isEmpty(this.params)) {
            return this.ESMBot.send(this.info.channel, "I was unable to find any territories");
        }

        // Quick fix for only one territory
        if (!_.isArray(this.params)) {
            this.params = [this.params];
        }

        let message = "```|---------------------------------------------------------\n";
        for (let territory of this.params) {
            let territoryMessage = `| ${territory.territory_name} [${territory.id}] | ${territory.owner_name || "N/A"} (${territory.owner_uid})\n`;
            if ((message.length + territoryMessage.length) > 1500) {
                await this.ESMBot.send(this.info.channel, message + "|---------------------------------------------------------```");
                message = "```|---------------------------------------------------------\n";
            }
            message += territoryMessage;
        }
        this.ESMBot.send(this.info.channel, message + "|---------------------------------------------------------```");
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8