Bots Home
|
Create an App
MutliTimer
Author:
zerouser000
Description
Source Code
Launch Bot
Current Users
Created by:
Zerouser000
/** * MultiTimer Bot By ZeroUser000 */ 'use strict'; /* global cb */ const TIMER_LIMIT = Infinity; const CMD_GROUP = "timers"; const CMD_PREFIX = `/${CMD_GROUP}`; const ACTIVE_TIMERS = {}; const ROOM_DEST = "ROOM"; // Used to send const YES = "Yes"; const NO = "No"; cb.settings_choices = [ { name: 'AllowMods', type: "choice", choice1: YES, choice2: NO, defaultValue: YES, label: "Are mods allowed to manage timers" }, { name: 'AllowPublic', type: "choice", choice1: YES, choice2: NO, defaultValue: NO, label: "Are chat members allowed to set timers" }, { name: 'AllowFanclub', type: "choice", choice1: YES, choice2: NO, defaultValue: NO, label: "Are fanclub members allowed to set timers" }, { name: 'TimerLimit', type: "int", minValue: 1, maxValue: 9999, defaultValue: 9999, label: "Maximum number of timers allowed" }, { name: 'notifyUnauthorized', type: "choice", choice1: "Silent", choice2: "Notify", defaultValue: "Silent", label: "Silently fail or tell user if unauthorized" }, ]; // Auth check function isAllowed(user, is_mod, is_fanclub) { if (user === cb.room_slug) return true; else if (is_mod && cb.settings['AllowMods'] === YES) return true; else if (is_fanclub && cb.settings['AllowFanclub'] === YES) return true; return false; } // Callback handler for timers function timerCallback() { cb.chatNotice(`Time is up!`); cb.chatNotice(`this: ${JSON.stringify(this)}`); cb.chatNotice(`args: ${JSON.stringify(arguments)}`); } /** * Command namespace, everything in here is a callable command. */ const COMMANDS = { /** * Set a new timer * * @param {*} time * @param {*} sendTo */ set(user, time = 60, sendTo) { // /timers set 60 const id = cb.setTimeout(timerCallback, time * 1000); if(user) cb.sendNotice(`A new timer has been created with id ${id} (${time*1000} ms)`, user); }, /** * Cancel all timers */ clear(user, id) { }, /** * Cancel a timer * @param {*} name */ cancel(user, name) { const timer = ACTIVE_TIMERS.find(t => t.id = id); }, /** * */ help(user) { cb.sendNotice(` Commands are case sensitive set - Set a new timer, returns an id cancel id - Cancel a timer clear id - remove a timer help - Display this help `); } }; /** * Core of the timers mod, the command processor */ cb.onMessage(function (msg) { const { m, user, in_fanclub, is_mod } = msg; const [prefix, cmd="", ...args] = m.split(' '); if (prefix.toLowerCase() !== CMD_PREFIX) return msg; // If it's not a timers command we don't care. msg['X-Spam'] = true; // Hide the message from chat either way cb.sendNotice(`Timers command: [${prefix}] [${cmd}] [${args.length}]`, user); if (!isAllowed(user, is_mod, in_fanclub)) { if(cb.settings['notifyUnauthorized'] === 'Notify') cb.sendNotice(`You are not authorized to user the timers command`, user); return msg; } if (COMMANDS[cmd]) COMMANDS[cmd](user, ...args); else COMMANDS.help(user); return msg; });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.