Friday, September 20, 2024 1:30:01 AM
> settings

Customize


Authenticate

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

        this.commandParams = {
            serverID: {
                regex: this.util.regex.serverID.base
            },
            target: {
                regex: this.util.regex.target.base
            },
            type: {
                regex: /money|respect|locker|heal|kill/
            },
            value: {
                regex: /-?\d+/,
                nullable: true
            }
        };

        this.information = {
            category: "server",
            params: "<server_id> <target_uid | @user> <type> <value>",
            help: "Modifies a player on a server.\nAvailable Types: `money`, `respect`, `locker`, `heal`, `kill`\nNote: For `money`, `respect`, and `locker`, negative values will remove, positive values will add. For `heal` and `kill`, value is not required and is ignored."
        };

        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 info = await this.db.getSteamUIDFromTag(this.params.target);
        if (!info.uid) {
            return this.ESMBot.send(this.message.channel, info.message);
        }
        if (["money", "respect", "locker"].includes(this.params.type) && this.params.value == null) {
            return this.ESMBot.send(this.message.channel, "Missing amount to add/remove");
        }
        this.send({
            serverID: this.params.serverID,
            command: "player",
            parameters: {
                function_name: "modifyPlayer",
                discord_tag: this.message.author.tag,
                target_uid: info.uid,
                type: this.params.type,
                value: this.params.value
            }
        });
    }

    async fromServer() {
        if (this.util.isEmpty(this.params)) return;

        let message = "";

        switch (this.params.type) {
            case "money":
            case "respect":
            case "locker":
                message = `you've modifed \`${this.info.parameters.target_uid}\`'s **${this.params.type}** by **${this.util.convertArmaNumber(this.params.modified_amount)}**. They used to have **${this.util.convertArmaNumber(this.params.previous_amount)}**, they now have **${this.util.convertArmaNumber(this.params.new_amount)}**.`;
                break;

            case "heal":
                let healMessages = [
                    "Heros never die!",
                    "The doctor is in",
                    "Ze healing is not rewarding as ze hurting"
                ];
                message = this.util.selectRandom(healMessages);
                break;

            case "kill":
                let killMessages = [
                    "Whoops... zat vas not medicine.",
                    "Side effects may include nausea, headaches... and death!",
                    "Snake? SNAAAAAAAAKE!!!",
                    `${this.params.name} has died of dysentery`
                ];
                message = this.util.selectRandom(killMessages);
                break;

            default:
                return;
        }

        this.ESMBot.send(this.info.channel, `${this.info.author.tag}, ${message}`);
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8