init commit
This commit is contained in:
832
libs/phantombot/scripts/commands/customCommands.js
Normal file
832
libs/phantombot/scripts/commands/customCommands.js
Normal file
@@ -0,0 +1,832 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// Pre-build regular expressions.z
|
||||
var reCommandTag = new RegExp(/\(command\s([\w]+)\)/),
|
||||
customCommands = [],
|
||||
ScriptEventManager = Packages.tv.phantombot.script.ScriptEventManager,
|
||||
CommandEvent = Packages.tv.phantombot.event.command.CommandEvent;
|
||||
|
||||
/*
|
||||
* @function runCommand
|
||||
*
|
||||
* @param {string} username
|
||||
* @param {string} command
|
||||
* @param {string} args
|
||||
*/
|
||||
function runCommand(username, command, args, tags) {
|
||||
if (tags !== undefined) {
|
||||
ScriptEventManager.instance().onEvent(new CommandEvent(username, command, args, tags));
|
||||
} else {
|
||||
ScriptEventManager.instance().onEvent(new CommandEvent(username, command, args));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function returnCommandCost
|
||||
*
|
||||
* @export $
|
||||
* @param {string} sender
|
||||
* @param {string} command
|
||||
*/
|
||||
function returnCommandCost(sender, command, isMod) {
|
||||
sender = sender.toLowerCase();
|
||||
command = command.toLowerCase();
|
||||
|
||||
if ($.inidb.exists('pricecom', command) && parseInt($.inidb.get('pricecom', command)) > 0) {
|
||||
if ((((isMod && $.getIniDbBoolean('settings', 'pricecomMods', false) && !$.isBot(sender)) || !isMod))) {
|
||||
$.inidb.incr('points', sender, $.inidb.get('pricecom', command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function permCom
|
||||
*
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {string} command
|
||||
* @param {sub} subcommand
|
||||
* @returns 0 = good, 1 = command perm bad, 2 = subcommand perm bad
|
||||
*/
|
||||
function permCom(username, command, subcommand, tags) {
|
||||
var commandGroup, allowed;
|
||||
if (subcommand === '') {
|
||||
commandGroup = $.getCommandGroup(command);
|
||||
} else {
|
||||
commandGroup = $.getSubcommandGroup(command, subcommand);
|
||||
}
|
||||
|
||||
switch (commandGroup) {
|
||||
case 0:
|
||||
allowed = $.isCaster(username);
|
||||
break;
|
||||
case 1:
|
||||
allowed = $.isAdmin(username);
|
||||
break;
|
||||
case 2:
|
||||
allowed = $.isModv3(username, tags);
|
||||
break;
|
||||
case 3:
|
||||
allowed = $.isSubv3(username, tags) || $.isModv3(username, tags);
|
||||
break;
|
||||
case 4:
|
||||
allowed = $.isDonator(username) || $.isModv3(username, tags);
|
||||
break;
|
||||
case 5:
|
||||
allowed = $.isVIP(username, tags) || $.isModv3(username, tags);
|
||||
break;
|
||||
case 6:
|
||||
allowed = $.isReg(username) || $.isModv3(username, tags);
|
||||
break;
|
||||
default:
|
||||
allowed = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return allowed ? 0 : (subcommand === '' ? 1 : 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function priceCom
|
||||
*
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {string} command
|
||||
* @param {sub} subcommand
|
||||
* @param {bool} isMod
|
||||
* @returns 1 | 0 - Not a boolean
|
||||
*/
|
||||
function priceCom(username, command, subCommand, isMod) {
|
||||
if ((subCommand !== '' && $.inidb.exists('pricecom', command + ' ' + subCommand)) || $.inidb.exists('pricecom', command)) {
|
||||
if ((((isMod && $.getIniDbBoolean('settings', 'pricecomMods', false) && !$.isBot(username)) || !isMod)) && $.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
if ($.getUserPoints(username) < getCommandPrice(command, subCommand, '')) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function payCom
|
||||
*
|
||||
* @export $
|
||||
* @param {string} command
|
||||
* @returns 1 | 0 - Not a boolean
|
||||
*/
|
||||
function payCom(command) {
|
||||
return ($.inidb.exists('paycom', command) ? 0 : 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandPrice
|
||||
*
|
||||
* @export $
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @param {string} subCommandAction
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getCommandPrice(command, subCommand, subCommandAction) {
|
||||
command = command.toLowerCase();
|
||||
subCommand = subCommand.toLowerCase();
|
||||
subCommandAction = subCommandAction.toLowerCase();
|
||||
return parseInt($.inidb.exists('pricecom', command + ' ' + subCommand + ' ' + subCommandAction) ?
|
||||
$.inidb.get('pricecom', command + ' ' + subCommand + ' ' + subCommandAction) :
|
||||
$.inidb.exists('pricecom', command + ' ' + subCommand) ?
|
||||
$.inidb.get('pricecom', command + ' ' + subCommand) :
|
||||
$.inidb.exists('pricecom', command) ?
|
||||
$.inidb.get('pricecom', command) : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandPay
|
||||
*
|
||||
* @export $
|
||||
* @param {string} command
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getCommandPay(command) {
|
||||
return ($.inidb.exists('paycom', command) ? $.inidb.get('paycom', command) : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function addComRegisterCommands
|
||||
*/
|
||||
function addComRegisterCommands() {
|
||||
if ($.bot.isModuleEnabled('./commands/customCommands.js')) {
|
||||
var commands = $.inidb.GetKeyList('command', ''),
|
||||
i;
|
||||
for (i in commands) {
|
||||
if (!$.commandExists(commands[i])) {
|
||||
customCommands[commands[i]] = $.inidb.get('command', commands[i]);
|
||||
$.registerChatCommand('./commands/customCommands.js', commands[i], 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function addComRegisterAliases
|
||||
*/
|
||||
function addComRegisterAliases() {
|
||||
if ($.bot.isModuleEnabled('./commands/customCommands.js')) {
|
||||
var aliases = $.inidb.GetKeyList('aliases', ''),
|
||||
i;
|
||||
for (i in aliases) {
|
||||
if (!$.commandExists(aliases[i])) {
|
||||
$.registerChatCommand('./commands/customCommands.js', aliases[i], $.getIniDbNumber('permcom', aliases[i], 7));
|
||||
$.registerChatAlias(aliases[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
* @usestransformers global
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/*
|
||||
* This handles custom commands, no command path is needed.
|
||||
*/
|
||||
if (customCommands[command] !== undefined) {
|
||||
var tag = $.tags(event, customCommands[command], true);
|
||||
if (tag !== null) {
|
||||
$.say(tag);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath addcom [command] [command response] - Adds a custom command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('addcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
argsString = args.slice(1).join(' ');
|
||||
|
||||
if ($.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.error'));
|
||||
return;
|
||||
} else if ($.inidb.exists('disabledCommands', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.disabled'));
|
||||
return;
|
||||
} else if (argsString.indexOf('(command ') !== -1) {
|
||||
if (argsString.indexOf('(command ') !== 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.commandtag.notfirst'));
|
||||
return;
|
||||
} else {
|
||||
if (!$.commandExists(argsString.match(reCommandTag)[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.commandtag.invalid', argsString.match(reCommandTag)[1]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.add.success', action));
|
||||
$.logCustomCommand({
|
||||
'add.command': '!' + action,
|
||||
'add.response': argsString,
|
||||
'sender': sender,
|
||||
});
|
||||
$.registerChatCommand('./commands/customCommands.js', action);
|
||||
$.inidb.set('command', action, argsString);
|
||||
customCommands[action] = argsString;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath editcom [command] [command response] - Edits the current response of that command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('editcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.edit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
argsString = args.slice(1).join(' ');
|
||||
|
||||
if (!$.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.404', action));
|
||||
return;
|
||||
} else if ($.commandExists(action) && !$.inidb.exists('command', action)) {
|
||||
if ($.inidb.exists('aliases', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.edit.editcom.alias', $.inidb.get('aliases', action), argsString));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.edit.404'));
|
||||
}
|
||||
return;
|
||||
} else if ($.inidb.get('command', action).match(/\(adminonlyedit\)/) && !$.isAdmin(sender)) {
|
||||
if ($.getIniDbBoolean('settings', 'permComMsgEnabled', true)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.perm.404', $.getGroupNameById('1')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.edit.success', action));
|
||||
$.logCustomCommand({
|
||||
'edit.command': '!' + action,
|
||||
'edit.response': argsString,
|
||||
'sender': sender,
|
||||
});
|
||||
$.registerChatCommand('./commands/customCommands.js', action, 7);
|
||||
$.inidb.set('command', action, argsString);
|
||||
customCommands[action] = argsString;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tokencom [command] [token] - Stores a user/pass or API key to be replaced into a (customapi) tag. WARNING: This should be done from the bot console or web panel, if you run this from chat, anyone watching chat can copy your info!
|
||||
*/
|
||||
if (command.equalsIgnoreCase('tokencom')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.token.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
argsString = args.slice(1).join(' ');
|
||||
|
||||
var silent = false;
|
||||
if (action.startsWith('silent@')) {
|
||||
silent = true;
|
||||
action = action.substr(7);
|
||||
}
|
||||
|
||||
if (!$.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.404', action));
|
||||
return;
|
||||
} else if ($.inidb.get('command', action).match(/\(adminonlyedit\)/) && !$.isAdmin(sender)) {
|
||||
if ($.getIniDbBoolean('settings', 'permComMsgEnabled', true)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.perm.404', $.getGroupNameById('1')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.token.success', action));
|
||||
}
|
||||
|
||||
if (argsString.length === 0) {
|
||||
$.inidb.RemoveKey('commandtoken', '', action);
|
||||
} else {
|
||||
$.inidb.SetString('commandtoken', '', action, argsString);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath delcom [command] - Delete that custom command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delcom')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.delete.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.inidb.exists('command', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.404', action));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.delete.success', action));
|
||||
$.logCustomCommand({
|
||||
'delete.command': '!' + action,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.del('command', action);
|
||||
$.inidb.del('permcom', action);
|
||||
$.inidb.del('pricecom', action);
|
||||
$.inidb.del('aliases', action);
|
||||
$.inidb.del('commandtoken', action);
|
||||
$.unregisterChatCommand(action);
|
||||
delete customCommands[action];
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath aliascom [alias name] [existing command] - Create an alias to any command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('aliascom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = args.slice(1).join(' ').replace('!', '').toLowerCase();
|
||||
|
||||
if ($.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.error.exists'));
|
||||
return;
|
||||
} else if (!$.commandExists(subAction.split(' ')[0])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.error.target404'));
|
||||
return;
|
||||
} else if ($.inidb.exists('aliases', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.error', action));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.success', subAction, action));
|
||||
$.logCustomCommand({
|
||||
'alias.command': '!' + action,
|
||||
'alias.target': '!' + subAction,
|
||||
'sender': sender,
|
||||
});
|
||||
$.registerChatCommand('./commands/customCommands.js', action);
|
||||
$.inidb.set('aliases', action, subAction);
|
||||
$.registerChatAlias(action);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath delalias [alias] - Delete that alias
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delalias')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.delete.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.inidb.exists('aliases', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.delete.error.alias.404', action));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.alias.delete.success', action));
|
||||
$.logCustomCommand({
|
||||
'alias.delete.command': '!' + action,
|
||||
'sender': sender,
|
||||
});
|
||||
$.unregisterChatCommand(action);
|
||||
$.inidb.del('aliases', action);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath permcom [command] [groupId] - Set the permissions for any command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('permcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.perm.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
var group = 7;
|
||||
|
||||
if (args.length === 2) {
|
||||
group = args[1];
|
||||
|
||||
if (!$.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.perm.404', action));
|
||||
return;
|
||||
} else if (isNaN(parseInt(group))) {
|
||||
group = $.getGroupIdByName(group);
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.perm.success', action, $.getGroupNameById(group)));
|
||||
$.logCustomCommand({
|
||||
'set.perm.command': '!' + action,
|
||||
'set.perm.group': $.getGroupNameById(group),
|
||||
'sender': sender,
|
||||
});
|
||||
|
||||
var list = $.inidb.GetKeyList('aliases', ''),
|
||||
i;
|
||||
|
||||
for (i in list) {
|
||||
if (list[i].equalsIgnoreCase(action)) {
|
||||
$.inidb.set('permcom', $.inidb.get('aliases', list[i]), group);
|
||||
$.updateCommandGroup($.inidb.get('aliases', list[i]), group);
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.set('permcom', action, group);
|
||||
$.updateCommandGroup(action, group);
|
||||
} else {
|
||||
group = args[2];
|
||||
|
||||
if (!$.subCommandExists(action, subAction)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.perm.404', action + ' ' + subAction));
|
||||
return;
|
||||
} else if (isNaN(parseInt(group))) {
|
||||
group = $.getGroupIdByName(group);
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.perm.success', action + ' ' + subAction, $.getGroupNameById(group)));
|
||||
$.logCustomCommand({
|
||||
'set.perm.command': '!' + action + ' ' + subAction,
|
||||
'set.perm.group': $.getGroupNameById(group),
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('permcom', action + ' ' + subAction, group);
|
||||
$.updateSubcommandGroup(action, subAction, group);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath pricecom [command] [amount] - Set the amount of points a command should cost
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pricecom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.error.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length === 2) {
|
||||
if (isNaN(parseInt(subAction)) || parseInt(subAction) < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.error.invalid'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.success', action, subAction, $.pointNameMultiple));
|
||||
$.logCustomCommand({
|
||||
'set.price.command': '!' + action,
|
||||
'set.price.amount': subAction,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('pricecom', action, subAction);
|
||||
|
||||
var list = $.inidb.GetKeyList('aliases', ''),
|
||||
i;
|
||||
|
||||
for (i in list) {
|
||||
if (list[i].equalsIgnoreCase(action)) {
|
||||
$.inidb.set('pricecom', $.inidb.get('aliases', list[i]), parseInt(subAction));
|
||||
}
|
||||
if ($.inidb.get('aliases', list[i]).includes(action)) {
|
||||
$.inidb.set('pricecom', list[i], parseInt(subAction));
|
||||
}
|
||||
}
|
||||
} else if (args.length === 3) {
|
||||
if (isNaN(parseInt(args[2])) || parseInt(args[2]) < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.error.invalid'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.success', action + ' ' + subAction, args[2], $.pointNameMultiple));
|
||||
$.logCustomCommand({
|
||||
'set.price.command': '!' + action + ' ' + subAction,
|
||||
'set.price.amount': args[2],
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('pricecom', action + ' ' + subAction, args[2]);
|
||||
} else {
|
||||
if (args.length === 4) {
|
||||
if (isNaN(parseInt(args[3])) || parseInt(args[3]) < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.error.invalid'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.price.success', action + ' ' + subAction + ' ' + args[2], args[3], $.pointNameMultiple));
|
||||
$.logCustomCommand({
|
||||
'set.price.command': '!' + action + ' ' + subAction + ' ' + args[2],
|
||||
'set.price.amount': args[3],
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('pricecom', action + ' ' + subAction + ' ' + args[2], args[3]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath paycom [command] [amount] - Set the amount of points a command should reward a viewer
|
||||
*/
|
||||
if (command.equalsIgnoreCase('paycom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.pay.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.commandExists(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.pay.error.404'));
|
||||
return;
|
||||
} else if (isNaN(parseInt(subAction)) || parseInt(subAction) < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.pay.error.invalid'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.set.pay.success', action, subAction, $.pointNameMultiple));
|
||||
$.logCustomCommand({
|
||||
'set.pay.command': '!' + action,
|
||||
'set.pay.amount': subAction,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('paycom', action, subAction);
|
||||
|
||||
var list = $.inidb.GetKeyList('aliases', ''),
|
||||
i;
|
||||
|
||||
for (i in list) {
|
||||
if (list[i].equalsIgnoreCase(action)) {
|
||||
$.inidb.set('paycom', $.inidb.get('aliases', list[i]), subAction);
|
||||
}
|
||||
if ($.inidb.get('aliases', list[i]).includes(action)) {
|
||||
$.inidb.set('paycom', list[i], subAction);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath commands - Provides a list of all available custom commands.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('commands')) {
|
||||
var cmds = $.inidb.GetKeyList('command', ''),
|
||||
aliases = $.inidb.GetKeyList('aliases', ''),
|
||||
cmdList = [];
|
||||
|
||||
for (idx in cmds) {
|
||||
if (!$.inidb.exists('disabledCommands', cmds[idx])) {
|
||||
if (permCom(sender, cmds[idx], '') === 0) {
|
||||
cmdList.push('!' + cmds[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (idx in aliases) {
|
||||
var aliasCmd = $.inidb.get('aliases', aliases[idx]);
|
||||
|
||||
if (!$.inidb.exists('disabledCommands', aliasCmd)) {
|
||||
if (permCom(sender, aliasCmd, '') === 0) {
|
||||
cmdList.push('!' + aliases[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdList.length > 0) {
|
||||
$.paginateArray(cmdList, 'customcommands.cmds', ', ', true, sender);
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.404.no.commands'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botcommands - Will show you all of the bots commands
|
||||
*/
|
||||
if (command.equalsIgnoreCase('botcommands')) {
|
||||
var cmds = $.inidb.GetKeyList('permcom', ''),
|
||||
idx,
|
||||
totalPages,
|
||||
cmdList = [];
|
||||
|
||||
for (idx in cmds) {
|
||||
if (cmds[idx].indexOf(' ') !== -1) {
|
||||
continue;
|
||||
}
|
||||
if (permCom(sender, cmds[idx], '') === 0) {
|
||||
cmdList.push('!' + cmds[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
if (action === undefined) {
|
||||
totalPages = $.paginateArray(cmdList, 'customcommands.botcommands', ', ', true, sender, 1);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.botcommands.total', totalPages));
|
||||
return;
|
||||
} else if (!isNaN(action)) {
|
||||
totalPages = $.paginateArray(cmdList, 'customcommands.botcommands', ', ', true, sender, parseInt(action));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.botcommands.error'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath disablecom [command] - Disable a command from being used in chat
|
||||
*/
|
||||
if (command.equalsIgnoreCase('disablecom')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.disable.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.commandExists(action) || $.jsString(action) === 'disablecom' || $.jsString(action) === 'enablecom') {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.disable.404'));
|
||||
return;
|
||||
} else if ($.inidb.exists('disabledCommands', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.disable.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.disable.success', action));
|
||||
$.logCustomCommand({
|
||||
'disable.command': '!' + action,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.set('disabledCommands', action, true);
|
||||
$.tempUnRegisterChatCommand(action);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath enablecom [command] - Enable a command thats been disabled from being used in chat
|
||||
*/
|
||||
if (command.equalsIgnoreCase('enablecom')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.enable.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.inidb.exists('disabledCommands', action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.enable.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.enable.success', action));
|
||||
$.logCustomCommand({
|
||||
'enable.command': '!' + action,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.del('disabledCommands', action);
|
||||
$.registerChatCommand(($.inidb.exists('tempDisabledCommandScript', action) ? $.inidb.get('tempDisabledCommandScript', action) : './commands/customCommands.js'), action);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath resetcom [command] [count] - Resets the counter to zero, for a command that uses the (count) tag or optionally set to a specific value.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('resetcom')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.reset.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (args.length === 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.reset.success', action));
|
||||
$.logCustomCommand({
|
||||
'reset.command': '!' + action,
|
||||
'reset.count': 0,
|
||||
'sender': sender,
|
||||
});
|
||||
$.inidb.del('commandCount', action);
|
||||
} else {
|
||||
if (isNaN(subAction)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.reset.change.fail', subAction));
|
||||
} else {
|
||||
$.inidb.set('commandCount', action, subAction);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('customcommands.reset.change.success', action, subAction));
|
||||
$.logCustomCommand({
|
||||
'reset.command': '!' + action,
|
||||
'reset.count': subAction,
|
||||
'sender': sender,
|
||||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./commands/customCommands.js', 'addcom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'pricecom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'paycom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'aliascom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'delalias', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'delcom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'editcom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'tokencom', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'permcom', 1);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'commands', 7);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'disablecom', 1);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'enablecom', 1);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'botcommands', 2);
|
||||
$.registerChatCommand('./commands/customCommands.js', 'resetcom', 2);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function (event) {
|
||||
if (event.getScript().equalsIgnoreCase('./commands/customCommands.js')) {
|
||||
if (event.getArgs()[0] == 'remove') {
|
||||
if (customCommands[event.getArgs()[1].toLowerCase()] !== undefined) {
|
||||
delete customCommands[event.getArgs()[1].toLowerCase()];
|
||||
$.unregisterChatCommand(event.getArgs()[1].toLowerCase());
|
||||
$.coolDown.remove(event.getArgs()[1].toLowerCase());
|
||||
}
|
||||
} else if (event.getArgs()[0] == 'add') {
|
||||
customCommands[event.getArgs()[1].toLowerCase()] = event.getArgs()[2];
|
||||
$.registerChatCommand('./commands/customCommands.js', event.getArgs()[1].toLowerCase());
|
||||
if (event.getArgs()[3] != null && event.getArgs()[3].equalsIgnoreCase('cooldown')) {
|
||||
$.coolDown.add(event.getArgs()[1].toLowerCase(), parseInt(event.getArgs()[4]), event.getArgs()[5].equals('true'));
|
||||
}
|
||||
} else if (event.getArgs()[0] == 'edit') {
|
||||
customCommands[event.getArgs()[1].toLowerCase()] = event.getArgs()[2];
|
||||
if (event.getArgs()[3] != null && event.getArgs()[3].equalsIgnoreCase('cooldown')) {
|
||||
$.coolDown.add(event.getArgs()[1].toLowerCase(), parseInt(event.getArgs()[4]), event.getArgs()[5].equals('true'));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Export functions to API
|
||||
*/
|
||||
$.addComRegisterCommands = addComRegisterCommands;
|
||||
$.addComRegisterAliases = addComRegisterAliases;
|
||||
$.returnCommandCost = returnCommandCost;
|
||||
$.permCom = permCom;
|
||||
$.priceCom = priceCom;
|
||||
$.getCommandPrice = getCommandPrice;
|
||||
$.getCommandPay = getCommandPay;
|
||||
$.payCom = payCom;
|
||||
$.command = {
|
||||
run: runCommand
|
||||
};
|
||||
})();
|
||||
150
libs/phantombot/scripts/commands/deathctrCommand.js
Normal file
150
libs/phantombot/scripts/commands/deathctrCommand.js
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* deathCounter.js
|
||||
*
|
||||
* A death counter.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
/*
|
||||
* @function deathUpdateFile
|
||||
*
|
||||
* @param {String} game
|
||||
*/
|
||||
function deathUpdateFile(game) {
|
||||
var deathFile = './addons/deathctr/deathctr.txt',
|
||||
deathCounter = parseInt($.inidb.get('deaths', game));
|
||||
|
||||
if (!$.isDirectory('./addons/deathctr/')) {
|
||||
$.mkDir('./addons/deathctr');
|
||||
}
|
||||
if (isNaN(deathCounter)) {
|
||||
deathCounter = 0;
|
||||
}
|
||||
|
||||
$.writeToFile(deathCounter.toFixed(0), deathFile, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
game = ($.getGame($.channelName) != '' ? $.getGame($.channelName) : 'Some Game');
|
||||
|
||||
/*
|
||||
* @commandpath deathctr - Display the current number of deaths in game being played.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('deathctr')) {
|
||||
var deathCounter = parseInt($.inidb.get('deaths', game));
|
||||
var noDeathExists = isNaN(parseInt(deathCounter)) || parseInt(deathCounter) === 0 ? (deathCounter = 0, true) : (false);
|
||||
if (action === undefined) {
|
||||
if (noDeathExists) {
|
||||
$.say($.lang.get('deathcounter.none', $.ownerName, game));
|
||||
} else {
|
||||
$.say($.lang.get('deathcounter.counter', $.ownerName, game, deathCounter));
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* @commandpath deathctr reset - Reset the death counter for the game being played.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('reset')) {
|
||||
if (noDeathExists) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('deathcounter.reset-nil', game));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('deathcounter.reset', game, deathCounter));
|
||||
$.inidb.set('deaths', game, 0);
|
||||
$.deathUpdateFile(game);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath deathctr set [number] - Set the death counter for the game being played.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('set')) {
|
||||
if (isNaN(parseInt(args[1]))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('deathcounter.set-error'));
|
||||
return;
|
||||
} else {
|
||||
var setDeath = parseInt(args[1]);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('deathcounter.set-success', game, setDeath));
|
||||
$.inidb.set('deaths', game, setDeath);
|
||||
$.deathUpdateFile(game);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath deathctr incr - Add one to the death counter for the game being played.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add') || action.equalsIgnoreCase('incr') || action.equalsIgnoreCase('+')) {
|
||||
|
||||
$.say($.lang.get('deathcounter.add-success', $.ownerName, game, ($.inidb.exists('deaths', game) ? (parseInt($.inidb.get('deaths', game)) + 1) : 1)));
|
||||
$.inidb.incr('deaths', game, 1);
|
||||
$.deathUpdateFile(game);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath deathctr decr - Subtract one from the death counter for the game being played.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('sub') || action.equalsIgnoreCase('decr') || action.equalsIgnoreCase('-')) {
|
||||
if (isNaN(parseInt($.inidb.get('deaths', game))) || parseInt($.inidb.get('deaths', game)) === 0) {
|
||||
$.say($.lang.get('deathcounter.sub-zero', game));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.lang.get('deathcounter.sub-success', game, ($.inidb.exists('deaths', game) ? (parseInt($.inidb.get('deaths', game)) - 1) : 0)));
|
||||
$.inidb.decr('deaths', game, 1);
|
||||
$.deathUpdateFile(game);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/deathctrCommand.js', 'deathctr', 7);
|
||||
|
||||
$.registerChatSubcommand('deathctr', 'reset', 2);
|
||||
$.registerChatSubcommand('deathctr', 'set', 2);
|
||||
$.registerChatSubcommand('deathctr', 'add', 2);
|
||||
$.registerChatSubcommand('deathctr', 'incr', 2);
|
||||
$.registerChatSubcommand('deathctr', '+', 2);
|
||||
$.registerChatSubcommand('deathctr', 'sub', 2);
|
||||
$.registerChatSubcommand('deathctr', 'decr', 2);
|
||||
$.registerChatSubcommand('deathctr', '-', 2);
|
||||
|
||||
setInterval(function() {
|
||||
deathUpdateFile(($.getGame($.channelName) != '' ? $.getGame($.channelName) : 'Some Game'));
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
/*
|
||||
* Export functions to API
|
||||
*/
|
||||
$.deathUpdateFile = deathUpdateFile;
|
||||
})();
|
||||
182
libs/phantombot/scripts/commands/dualstreamCommand.js
Normal file
182
libs/phantombot/scripts/commands/dualstreamCommand.js
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var otherChannels = $.getSetIniDbString('dualStreamCommand', 'otherChannels', 'Channel-1 Channel-2'),
|
||||
timerToggle = $.getSetIniDbBoolean('dualStreamCommand', 'timerToggle', false),
|
||||
timerInterval = $.getSetIniDbNumber('dualStreamCommand', 'timerInterval', 20),
|
||||
reqMessages = $.getSetIniDbNumber('dualStreamCommand', 'reqMessages', 10),
|
||||
messageCount = 0,
|
||||
lastSent = 0;
|
||||
|
||||
/*
|
||||
* @function reloadMulti
|
||||
*/
|
||||
function reloadMulti() {
|
||||
otherChannels = $.getIniDbString('dualStreamCommand', 'otherChannels');
|
||||
timerToggle = $.getIniDbBoolean('dualStreamCommand', 'timerToggle');
|
||||
timerInterval = $.getIniDbNumber('dualStreamCommand', 'timerInterval');
|
||||
reqMessages = $.getIniDbNumber('dualStreamCommand', 'reqMessages');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
messageCount++;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
argsString = event.getArguments(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/*
|
||||
* @commandpath multi - Displays the current multi-link information of the usage
|
||||
*/
|
||||
if (command.equalsIgnoreCase('multi')) {
|
||||
if (action === undefined) {
|
||||
if (!otherChannels.equals('Channel-1 Channel-2')) {
|
||||
$.say($.lang.get('dualstreamcommand.link') + $.channelName + '/' + otherChannels.split(' ').join('/'));
|
||||
} else {
|
||||
if ($.isModv3(sender, event.getTags())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.usage'));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath multi set [channels] - Adds a space-delimited list of channels to the multi-link (local channel already added)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('set')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
otherChannels = args.slice(1).join('/').replace(/\/\//g, '/');
|
||||
|
||||
$.say($.lang.get('dualstreamcommand.link.set', $.channelName + '/' + otherChannels));
|
||||
$.inidb.set('dualStreamCommand', 'otherChannels', otherChannels);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath multi clear - Clears the multi-links and disables the timer
|
||||
*/
|
||||
if (action.equalsIgnoreCase('clear')) {
|
||||
otherChannels = 'Channel-1 Channel-2';
|
||||
timerToggle = false;
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.clear'));
|
||||
$.inidb.set('dualStreamCommand', 'timerToggle', timerToggle);
|
||||
$.inidb.del('dualStreamCommand', 'otherChannels');
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath multi timer [on / off] - Enable or disabled the multi-links timer
|
||||
*/
|
||||
if (action.equalsIgnoreCase('timer')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.timer.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
timerToggle = subAction.equalsIgnoreCase('on');
|
||||
$.say($.whisperPrefix(sender) + (timerToggle ? $.lang.get('dualstreamcommand.timer.enabled') : $.lang.get('dualstreamcommand.timer.disabled')));
|
||||
$.inidb.set('dualStreamCommand', 'timerToggle', timerToggle);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath multi timerinterval [time in minutes] - Set the interval for the multi-links timer
|
||||
*/
|
||||
if (action.equalsIgnoreCase('timerinterval')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.timerinterval.usage'));
|
||||
return;
|
||||
} else if (parseInt(subAction) < 5) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.timerinterval.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
timerInterval = parseInt(subAction);
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.timerinterval.set', timerInterval));
|
||||
$.inidb.set('dualStreamCommand', 'timerInterval', timerInterval);
|
||||
reloadMulti();
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath multi reqmessage [amount of messages] - Set the amount of message required before triggering the dual stream link
|
||||
*/
|
||||
if (action.equalsIgnoreCase('reqmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.req.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
reqMessages = parseInt(subAction);
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('dualstreamcommand.reqmessages.set', reqMessages));
|
||||
$.inidb.set('dualStreamCommand', 'reqMessages', reqMessages);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command, no command path needed here.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadmulti')) {
|
||||
reloadMulti();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/dualstreamCommand.js', 'multi', 7);
|
||||
$.registerChatCommand('./commands/dualstreamCommand.js', 'reloadmulti', 1);
|
||||
|
||||
$.registerChatSubcommand('multi', 'set', 2);
|
||||
$.registerChatSubcommand('multi', 'clear', 2);
|
||||
$.registerChatSubcommand('multi', 'timer', 2);
|
||||
$.registerChatSubcommand('multi', 'timerinterval', 1);
|
||||
$.registerChatSubcommand('multi', 'reqmessage', 1);
|
||||
|
||||
/*
|
||||
* interval timer.
|
||||
*/
|
||||
var interval = setInterval(function() {
|
||||
if (timerToggle && !otherChannels.equals('Channel-1 Channel-2')) {
|
||||
if ($.isOnline($.channelName) && messageCount >= reqMessages && $.systemTime() >= lastSent) {
|
||||
$.say($.lang.get('dualstreamcommand.link') + $.channelName + '/' + otherChannels.split(' ').join('/'));
|
||||
lastSent = ($.systemTime() + (timerInterval * 6e4));
|
||||
messageCount = 0;
|
||||
}
|
||||
}
|
||||
}, 10e3);
|
||||
});
|
||||
})();
|
||||
113
libs/phantombot/scripts/commands/highlightCommand.js
Normal file
113
libs/phantombot/scripts/commands/highlightCommand.js
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* highlightCommand.js
|
||||
*
|
||||
* Creates timestamps for highlights to revisit later to make creating highlights a bit
|
||||
* easier.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
sender = event.getSender(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
vodJsonStr,
|
||||
uptime,
|
||||
vodJsonObj,
|
||||
vodURL,
|
||||
twitchVODtime;
|
||||
|
||||
/*
|
||||
* @commandpath highlight [description] - Marks a highlight using the given description and with the current date stamp
|
||||
*/
|
||||
if (command.equalsIgnoreCase('highlight')) {
|
||||
if (!$.isOnline($.channelName)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('highlightcommand.highlight.offline'));
|
||||
return;
|
||||
} else if (args.length === 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('highlightcommand.highlight.usage', $.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : 'GMT'));
|
||||
return;
|
||||
}
|
||||
|
||||
vodJsonStr = $.twitch.GetChannelVODs($.channelName, 'current') + '';
|
||||
if (vodJsonStr.length === 0 || vodJsonStr === null) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.vod.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
uptime = $.getStreamUptimeSeconds($.channelName);
|
||||
twitchVODtime = $.makeTwitchVODTime(uptime);
|
||||
vodJsonObj = JSON.parse(vodJsonStr);
|
||||
vodURL = vodJsonObj.videos[0].url + twitchVODtime;
|
||||
|
||||
var streamUptimeMinutes = parseInt(uptime / 60),
|
||||
hours = parseInt(streamUptimeMinutes / 60),
|
||||
minutes = (parseInt(streamUptimeMinutes % 60) < 10 ? '0' + parseInt(streamUptimeMinutes % 60) : parseInt(streamUptimeMinutes % 60)),
|
||||
timestamp = hours + ':' + minutes,
|
||||
localDate = $.getCurLocalTimeString('dd-MM-yyyy hh:mm');
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('highlightcommand.highlight.success', timestamp));
|
||||
$.inidb.set('highlights', localDate, vodURL + ' : ' + args.join(' '));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath showhighlights - Get a list of current highlights
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gethighlights') || command.equalsIgnoreCase('showhighlights')) {
|
||||
if (!$.inidb.FileExists('highlights')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('highlightcommand.gethighlights.no-highlights'));
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = $.inidb.GetKeyList('highlights', ''),
|
||||
temp = [];
|
||||
|
||||
for (var i in keys) {
|
||||
temp.push('[' + keys[i] + ': ' + $.inidb.get('highlights', keys[i]) + '] ');
|
||||
}
|
||||
|
||||
$.paginateArray(temp, 'highlightcommand.highlights', ' ', true, sender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath clearhighlights - Clear the current highlights
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clearhighlights')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('highlightcommand.clearhighlights.success'));
|
||||
$.inidb.RemoveFile('highlights');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/highlightCommand.js', 'highlight', 2);
|
||||
$.registerChatCommand('./commands/highlightCommand.js', 'gethighlights', 2);
|
||||
$.registerChatCommand('./commands/highlightCommand.js', 'showhighlights', 2);
|
||||
$.registerChatCommand('./commands/highlightCommand.js', 'clearhighlights', 1);
|
||||
});
|
||||
})();
|
||||
74
libs/phantombot/scripts/commands/lastseenCommand.js
Normal file
74
libs/phantombot/scripts/commands/lastseenCommand.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* lastseenCommand.js
|
||||
*
|
||||
* This module stores the dates of when users have last seen in the channel.
|
||||
*/
|
||||
(function() {
|
||||
/*
|
||||
* @event ircChannelJoin
|
||||
*/
|
||||
$.bind('ircChannelJoin', function(event) {
|
||||
$.inidb.set('lastseen', event.getUser().toLowerCase(), $.systemTime());
|
||||
});
|
||||
|
||||
/*
|
||||
* @event ircChannelLeave
|
||||
*/
|
||||
$.bind('ircChannelLeave', function(event) {
|
||||
$.inidb.set('lastseen', event.getUser().toLowerCase(), $.systemTime());
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
target = args[0],
|
||||
date;
|
||||
|
||||
/*
|
||||
* @commandpath lastseen [username] - Find out when the given user was last seen in the channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('lastseen')) {
|
||||
if (target === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('lastseen.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
target = $.user.sanitize(target);
|
||||
|
||||
if ($.inidb.exists('lastseen', target)) {
|
||||
date = new Date(parseInt($.inidb.get('lastseen', target.toLowerCase())));
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('lastseen.response', $.username.resolve(target), date.toLocaleDateString(), date.toLocaleTimeString()));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('lastseen.404', $.username.resolve(target)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/lastseenCommand.js', 'lastseen', 7);
|
||||
});
|
||||
})();
|
||||
74
libs/phantombot/scripts/commands/nameConverter.js
Normal file
74
libs/phantombot/scripts/commands/nameConverter.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
|
||||
/**
|
||||
* @commandpath namechange [oldname] [newname] - Convert someones old Twitch username to his/her new Twitch name. The user will be able to keep their points, time, quotes, and more.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('namechange')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('namechange.default'));
|
||||
return;
|
||||
}
|
||||
|
||||
var tables = ['points', 'time', 'followed', 'subscribed', 'visited', 'group', 'panelchatuserstats', 'panelchatstats'],
|
||||
changed = 0,
|
||||
i;
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('namechange.updating', action, subAction));
|
||||
|
||||
// Update the default tables with that users new name if it's currently in any tables.
|
||||
for (i in tables) {
|
||||
if ($.inidb.exists(tables[i], action.toLowerCase()) == true) {
|
||||
$.inidb.set(tables[i], subAction.toLowerCase(), $.inidb.get(tables[i], action.toLowerCase()));
|
||||
$.inidb.del(tables[i], action.toLowerCase());
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the username in the quotes table.
|
||||
var keys = $.inidb.GetKeyList('quotes', ''),
|
||||
jsonArr;
|
||||
|
||||
for (i in keys) {
|
||||
if ($.inidb.get('quotes', keys[i]).toLowerCase().indexOf(action.toLowerCase()) > -1) {
|
||||
jsonArr = JSON.parse($.inidb.get('quotes', keys[i]));
|
||||
$.inidb.set('quotes', keys[i], JSON.stringify([String(subAction), String(jsonArr[1]), String(jsonArr[2]), String(jsonArr[3])]));
|
||||
}
|
||||
}
|
||||
|
||||
// Announce in chat once done.
|
||||
if (changed > 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('namechange.success', action, subAction, changed));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('namechange.notfound', action));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/nameConverter.js', 'namechange', 1);
|
||||
});
|
||||
})();
|
||||
132
libs/phantombot/scripts/commands/streamCommand.js
Normal file
132
libs/phantombot/scripts/commands/streamCommand.js
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* streamCommand.js
|
||||
*
|
||||
* This module offers commands to view/alter channel information like current game, title and status
|
||||
*/
|
||||
(function() {
|
||||
|
||||
/*
|
||||
* @function makeTwitchVODTime
|
||||
*
|
||||
* @param twitchUptime - Number of seconds stream has been up.
|
||||
* @return twitchVODTime
|
||||
*/
|
||||
function makeTwitchVODTime(twitchUptime) {
|
||||
return '?t=' + twitchUptime + 's';
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
vodJsonObj = {},
|
||||
twitchVODtime,
|
||||
vodJsonStr,
|
||||
uptime;
|
||||
|
||||
/*
|
||||
* @commandpath game - Give's you the current game and the playtime if the channel is online.
|
||||
* @commandpath title - Give's you the current title and the channel uptime if the channel is online.
|
||||
* @commandpath followage- Tells you how long you have been following the channel.
|
||||
* @commandpath playtime - Tells you how long the caster has been playing the current game for.
|
||||
* @commandpath uptime - Give's you the current stream uptime.
|
||||
* @commandpath age - Tells you how long you have been on Twitch for.
|
||||
* @commandpath setgame [game name] - Set your Twitch game title.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setgame')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.game.set.usage', $.getGame($.channelName)));
|
||||
return;
|
||||
}
|
||||
$.updateGame($.channelName, args.join(' '), sender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath settitle [stream title] - Set your Twitch stream title.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('settitle')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.title.set.usage', $.getStatus($.channelName)));
|
||||
return;
|
||||
}
|
||||
$.updateStatus($.channelName, args.join(' '), sender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath setcommunities [communities] - Set your Twitch communities.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setcommunities')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.communities.set.usage', $.twitchcache.getCommunities().join(', ').replace(/\s,/g, '')));
|
||||
return;
|
||||
}
|
||||
$.updateCommunity($.channelName, args.join('').replace(/\s/g, '').split(','), sender);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath vod - Displays stream uptime and current VOD or, if offline, the last VOD available.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('vod')) {
|
||||
if ($.isOnline($.channelName)) {
|
||||
vodJsonStr = $.twitch.GetChannelVODs($.channelName, 'current') + '';
|
||||
if (vodJsonStr.length === 0 || vodJsonStr === null) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.vod.404'));
|
||||
return;
|
||||
}
|
||||
uptime = $.getStreamUptime($.channelName);
|
||||
twitchVODtime = makeTwitchVODTime(uptime);
|
||||
vodJsonObj = JSON.parse(vodJsonStr);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.vod.online', uptime, vodJsonObj.videos[0].url + twitchVODtime));
|
||||
return;
|
||||
} else {
|
||||
vodJsonStr = $.twitch.GetChannelVODs($.channelName, 'archives') + '';
|
||||
if (vodJsonStr.length === 0 || vodJsonStr === null) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.vod.404'));
|
||||
return;
|
||||
}
|
||||
vodJsonObj = JSON.parse(vodJsonStr);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamcommand.vod.offline', vodJsonObj.videos[0].url, $.getTimeString(vodJsonObj.videos[0].length)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/streamCommand.js', 'setgame', 1);
|
||||
$.registerChatCommand('./commands/streamCommand.js', 'settitle', 1);
|
||||
$.registerChatCommand('./commands/streamCommand.js', 'setcommunities', 1);
|
||||
$.registerChatCommand('./commands/streamCommand.js', 'vod', 7);
|
||||
});
|
||||
|
||||
/*
|
||||
* Export Methods
|
||||
*/
|
||||
$.makeTwitchVODTime = makeTwitchVODTime;
|
||||
})();
|
||||
175
libs/phantombot/scripts/commands/topCommand.js
Normal file
175
libs/phantombot/scripts/commands/topCommand.js
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* topCommand.js
|
||||
*
|
||||
* Build and announce lists of top viewers (Highest points, highest time spent in the channel)
|
||||
*/
|
||||
(function() {
|
||||
var amountPoints = $.getSetIniDbNumber('settings', 'topListAmountPoints', 5),
|
||||
amountTime = $.getSetIniDbNumber('settings', 'topListAmountTime', 5);
|
||||
|
||||
/*
|
||||
* @function reloadTop
|
||||
*/
|
||||
function reloadTop() {
|
||||
amountPoints = $.getIniDbNumber('settings', 'topListAmountPoints');
|
||||
amountTime = $.getIniDbNumber('settings', 'topListAmountTime');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getTop5
|
||||
*
|
||||
* @param {string} iniName
|
||||
* @returns {Array}
|
||||
*/
|
||||
function getTop5(iniName) {
|
||||
var keys = $.inidb.GetKeysByNumberOrderValue(iniName, '', 'DESC', (iniName.equals('points') ? amountPoints + 2: amountTime + 2), 0),
|
||||
list = [],
|
||||
i,
|
||||
ctr = 0;
|
||||
|
||||
for (i in keys) {
|
||||
if (!$.isBot(keys[i]) && !$.isOwner(keys[i])) {
|
||||
if (ctr++ == (iniName.equals('points') ? amountPoints : amountTime)) {
|
||||
break;
|
||||
}
|
||||
list.push({
|
||||
username: keys[i],
|
||||
value: $.inidb.get(iniName, keys[i])
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
list.sort(function(a, b) {
|
||||
return (b.value - a.value);
|
||||
});
|
||||
|
||||
if (iniName.equals('points')) {
|
||||
return list.slice(0, amountPoints);
|
||||
} else {
|
||||
return list.slice(0, amountTime);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
sender = event.getSender(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath top - Display the top people with the most points
|
||||
*/
|
||||
if (command.equalsIgnoreCase('top')) {
|
||||
if (!$.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var temp = getTop5('points'),
|
||||
top = [],
|
||||
i;
|
||||
|
||||
for (i in temp) {
|
||||
top.push((parseInt(i) + 1) + '. ' + $.resolveRank(temp[i].username) + ' ' + $.getPointsString(temp[i].value));
|
||||
}
|
||||
|
||||
$.say($.lang.get('top5.default', amountPoints, $.pointNameMultiple, top.join(', ')));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath toptime - Display the top people with the most time
|
||||
*/
|
||||
if (command.equalsIgnoreCase('toptime')) {
|
||||
var temp = getTop5('time'),
|
||||
top = [],
|
||||
i;
|
||||
|
||||
for (i in temp) {
|
||||
top.push((parseInt(i) + 1) + '. ' + $.resolveRank(temp[i].username) + ' ' + $.getTimeString(temp[i].value, true));
|
||||
}
|
||||
|
||||
$.say($.lang.get('top5.default', amountTime, 'time', top.join(', ')));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath topamount - Set how many people who will show up in the !top points list
|
||||
*/
|
||||
if (command.equalsIgnoreCase('topamount')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.points.usage'));
|
||||
return;
|
||||
} else if (action > 15) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.max'));
|
||||
return;
|
||||
}
|
||||
|
||||
amountPoints = action;
|
||||
$.inidb.set('settings', 'topListAmountPoints', amountPoints);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.points.set', amountPoints));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath toptimeamount - Set how many people who will show up in the !toptime list
|
||||
*/
|
||||
if (command.equalsIgnoreCase('toptimeamount')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.time.usage'));
|
||||
return;
|
||||
} else if (action > 15) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.max'));
|
||||
return;
|
||||
}
|
||||
|
||||
amountTime = action;
|
||||
$.inidb.set('settings', 'topListAmountTime', amountTime);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.amount.time.set', amountTime));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath reloadtopbots - DEPRECATED. Use !reloadbots
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadtopbots')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('top5.reloadtopbots'));
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command, no command path needed.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadtop')) {
|
||||
reloadTop();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./commands/topCommand.js', 'top', 7);
|
||||
$.registerChatCommand('./commands/topCommand.js', 'toptime', 7);
|
||||
$.registerChatCommand('./commands/topCommand.js', 'topamount', 1);
|
||||
$.registerChatCommand('./commands/topCommand.js', 'toptimeamount', 1);
|
||||
$.registerChatCommand('./commands/topCommand.js', 'reloadtop', 1);
|
||||
$.registerChatCommand('./commands/topCommand.js', 'reloadtopbots', 1);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user