Skip to content

Add on: UNO shortcut command

Agustín San Román edited this page Feb 24, 2025 · 1 revision

This is a simple addon to add the uno command, a shortcut for the bot to use the 3 commands required to create and configure a UNO game.

Code

// Uno shortcut command
// Usage: .uno [player cap]

"use strict";

const DEFAULT_PLAYER_CAP = 30;

const DEFAULT_AUTO_START = 2; // Minutes

const DEFAULT_AUTO_DQ = 0.5; // Minutes

exports.setup = function (App) {
    return Tools('add-on').forApp(App).install({
        commandsOverwrite: true,
        commands: {
            "uno": function () {
                if (!this.can('tour', this.room)) return this.replyAccessDenied('tour');

                if (this.getRoomType(this.room) !== 'chat') {
                    return this.errorReply("This command is only available in chat rooms.");
                }

                let playerCap = DEFAULT_PLAYER_CAP;
                let autoStartMin = DEFAULT_AUTO_START;
                let autoDqMin = DEFAULT_AUTO_DQ;

                if (this.args[0]) {
                    playerCap = parseInt(this.args[0], 10);
                    if (isNaN(playerCap) || !isFinite(playerCap) || playerCap < 1) {
                        playerCap = DEFAULT_PLAYER_CAP;
                    }
                }

                const autoStartSec = Math.round(autoStartMin * 60);
                const autoDQSec = Math.round(autoDqMin * 60);

                this.reply([
                    "/uno create " + playerCap,
                    "/uno autostart " + autoStartSec,
                    "/uno timer " + autoDQSec
                ]);
            },
        },
    })
};

Clone this wiki locally