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);
|
||||
});
|
||||
})();
|
||||
2052
libs/phantombot/scripts/core/chatModerator.js
Normal file
2052
libs/phantombot/scripts/core/chatModerator.js
Normal file
File diff suppressed because it is too large
Load Diff
358
libs/phantombot/scripts/core/commandCoolDown.js
Normal file
358
libs/phantombot/scripts/core/commandCoolDown.js
Normal file
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* commandCoolDown.js
|
||||
*
|
||||
* Manage cooldowns for commands
|
||||
*
|
||||
* To use the cooldown in other scipts use the $.coolDown API
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var defaultCooldownTime = $.getSetIniDbNumber('cooldownSettings', 'defaultCooldownTime', 5),
|
||||
modCooldown = $.getSetIniDbBoolean('cooldownSettings', 'modCooldown', false),
|
||||
defaultCooldowns = {},
|
||||
cooldowns = {};
|
||||
|
||||
$.raffleCommand = null;
|
||||
|
||||
/*
|
||||
* @class Cooldown
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function Cooldown(command, seconds, isGlobal) {
|
||||
this.isGlobal = isGlobal;
|
||||
this.command = command;
|
||||
this.seconds = seconds;
|
||||
this.cooldowns = [];
|
||||
this.time = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function loadCooldowns
|
||||
*/
|
||||
function loadCooldowns() {
|
||||
var commands = $.inidb.GetKeyList('cooldown', ''),
|
||||
json,
|
||||
i;
|
||||
|
||||
for (i in commands) {
|
||||
json = JSON.parse($.inidb.get('cooldown', commands[i]));
|
||||
|
||||
cooldowns[commands[i]] = new Cooldown(json.command, json.seconds, json.isGlobal.toString().equals('true'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function canIgnore
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {Boolean} isMod
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function canIgnore(username, isMod) {
|
||||
return (!modCooldown && isMod) || $.isAdmin(username);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function isSpecial
|
||||
*
|
||||
* @param {String} command
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function isSpecial(command) {
|
||||
return command == 'bet' ||
|
||||
command == 'tickets' ||
|
||||
command == 'bid' ||
|
||||
command == 'adventure' ||
|
||||
command == 'vote' ||
|
||||
command == 'joinqueue' ||
|
||||
command == $.raffleCommand;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function get
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {String} username
|
||||
* @param {Boolean} isMod
|
||||
* @return {Number}
|
||||
*/
|
||||
function get(command, username, isMod) {
|
||||
var cooldown = cooldowns[command];
|
||||
|
||||
if (isSpecial(command)) {
|
||||
if (command == 'adventure' && defaultCooldowns[command] !== undefined && defaultCooldowns[command] > $.systemTime()) {
|
||||
return defaultCooldowns[command];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (cooldown !== undefined && cooldown.seconds > 0) {
|
||||
if (cooldown.isGlobal) {
|
||||
if (cooldown.time > $.systemTime()) {
|
||||
return (canIgnore(username, isMod) ? 0 : cooldown.time);
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds, isMod);
|
||||
}
|
||||
} else {
|
||||
if (cooldown.cooldowns[username] !== undefined && cooldown.cooldowns[username] > $.systemTime()) {
|
||||
return (canIgnore(username, isMod) ? 0 : cooldown.cooldowns[username]);
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds, isMod, username);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (defaultCooldowns[command] !== undefined && defaultCooldowns[command] > $.systemTime()) {
|
||||
return (canIgnore(username, isMod) ? 0 : defaultCooldowns[command]);
|
||||
} else {
|
||||
return set(command, false, defaultCooldownTime, isMod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getSecs
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function getSecs(username, command, isMod) {
|
||||
var cooldown = cooldowns[command];
|
||||
|
||||
if (cooldown !== undefined && cooldown.seconds > 0) {
|
||||
if (cooldown.isGlobal) {
|
||||
if (cooldown.time > $.systemTime()) {
|
||||
return (cooldown.time - $.systemTime() > 1000 ? Math.ceil(((cooldown.time - $.systemTime()) / 1000)) : 1);
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds, isMod);
|
||||
}
|
||||
} else {
|
||||
if (cooldown.cooldowns[username] !== undefined && cooldown.cooldowns[username] > $.systemTime()) {
|
||||
return (cooldown.cooldowns[username] - $.systemTime() > 1000 ? Math.ceil(((cooldown.cooldowns[username] - $.systemTime()) / 1000)) : 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (defaultCooldowns[command] !== undefined && defaultCooldowns[command] > $.systemTime()) {
|
||||
return (defaultCooldowns[command] - $.systemTime() > 1000 ? Math.ceil(((defaultCooldowns[command] - $.systemTime()) / 1000)) : 1);
|
||||
} else {
|
||||
return set(command, false, defaultCooldownTime, isMod);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function set
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Boolean} hasCooldown
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isMod
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function set(command, hasCooldown, seconds, isMod, username) {
|
||||
seconds = (seconds > 0 ? ((parseInt(seconds) * 1e3) + $.systemTime()) : 0);
|
||||
|
||||
if (hasCooldown) {
|
||||
if (username === undefined) {
|
||||
cooldowns[command].time = seconds;
|
||||
} else {
|
||||
cooldowns[command].cooldowns[username] = seconds;
|
||||
}
|
||||
} else {
|
||||
defaultCooldowns[command] = seconds;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function add
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function add(command, seconds, isGlobal) {
|
||||
// Make sure we have the right type.
|
||||
if (typeof seconds !== 'number') {
|
||||
seconds = (parseInt(seconds + ''));
|
||||
}
|
||||
|
||||
if (cooldowns[command] === undefined) {
|
||||
cooldowns[command] = new Cooldown(command, seconds, isGlobal);
|
||||
$.inidb.set('cooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
} else {
|
||||
cooldowns[command].isGlobal = isGlobal;
|
||||
cooldowns[command].seconds = seconds;
|
||||
$.inidb.set('cooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function remove
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function remove(command) {
|
||||
$.inidb.del('cooldown', command);
|
||||
if (cooldowns[command] !== undefined) {
|
||||
delete cooldowns[command];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function clear
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function clear(command) {
|
||||
if (cooldowns[command] !== undefined) {
|
||||
cooldowns[command].time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
/*
|
||||
* @commandpath coolcom [command] [seconds] [type (global / user)] - Sets a cooldown for a command, default is global. Using -1 for the seconds removes the cooldown.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('coolcom')) {
|
||||
if (action === undefined || isNaN(parseInt(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.coolcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = (actionArgs !== undefined && actionArgs == 'user' ? false : true);
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = parseInt(subAction);
|
||||
|
||||
if (subAction > -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.coolcom.set', action, subAction));
|
||||
add(action, subAction, actionArgs);
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.coolcom.remove', action));
|
||||
remove(action);
|
||||
}
|
||||
clear(command);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('cooldown')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.cooldown.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath cooldown togglemoderators - Toggles if moderators ignore command cooldowns.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglemoderators')) {
|
||||
modCooldown = !modCooldown;
|
||||
$.setIniDbBoolean('cooldownSettings', 'modCooldown', modCooldown);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.set.togglemodcooldown', (modCooldown ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath cooldown setdefault [seconds] - Sets a default global cooldown for commands without a cooldown.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setdefault')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.default.usage'));
|
||||
return;
|
||||
} else if (parseInt(subAction) < 5) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.coolcom.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
defaultCooldownTime = parseInt(subAction);
|
||||
$.setIniDbNumber('cooldownSettings', 'defaultCooldownTime', defaultCooldownTime);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cooldown.default.set', defaultCooldownTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/commandCoolDown.js', 'coolcom', 1);
|
||||
|
||||
$.registerChatCommand('./core/commandCoolDown.js', 'cooldown', 1);
|
||||
$.registerChatSubcommand('cooldown', 'togglemoderators', 1);
|
||||
$.registerChatSubcommand('cooldown', 'setdefault', 1);
|
||||
loadCooldowns();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./core/commandCoolDown.js')) {
|
||||
if (event.getArgs()[0] == 'add') {
|
||||
add(event.getArgs()[1], event.getArgs()[2], event.getArgs()[3].equals('true'));
|
||||
} else if (event.getArgs()[0] == 'update') {
|
||||
defaultCooldownTime = $.getIniDbNumber('cooldownSettings', 'defaultCooldownTime', 5);
|
||||
modCooldown = $.getIniDbBoolean('cooldownSettings', 'modCooldown', false);
|
||||
} else {
|
||||
remove(event.getArgs()[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Export to the $. API */
|
||||
$.coolDown = {
|
||||
remove: remove,
|
||||
clear: clear,
|
||||
get: get,
|
||||
set: set,
|
||||
add: add,
|
||||
getSecs: getSecs
|
||||
};
|
||||
})();
|
||||
114
libs/phantombot/scripts/core/commandPause.js
Normal file
114
libs/phantombot/scripts/core/commandPause.js
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* commandPause.js
|
||||
*
|
||||
* Pause using ANY command
|
||||
*/
|
||||
(function() {
|
||||
var isActive = $.getSetIniDbBoolean('commandPause', 'commandsPaused', false),
|
||||
defaultTime = $.getSetIniDbNumber('commandPause', 'defaultTime', 300),
|
||||
timerId = -1;
|
||||
|
||||
/**
|
||||
* @function pause
|
||||
* @export $.commandPause
|
||||
* @param {Number} [seconds]
|
||||
*/
|
||||
function pause(seconds) {
|
||||
seconds = (seconds ? seconds : defaultTime);
|
||||
if (isActive) {
|
||||
clearTimeout(timerId);
|
||||
} else {
|
||||
$.setIniDbBoolean('commandPause', 'commandsPaused', true);
|
||||
isActive = true;
|
||||
}
|
||||
timerId = setTimeout(function() {
|
||||
unPause();
|
||||
}, seconds * 1e3);
|
||||
$.say($.lang.get('commandpause.initiated', $.getTimeString(seconds)));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function isPaused
|
||||
* @export $.commandPause
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isPaused() {
|
||||
return isActive;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function clear
|
||||
* @export $.commandPause
|
||||
*/
|
||||
function unPause() {
|
||||
if (timerId > -1) {
|
||||
clearTimeout(timerId);
|
||||
$.setIniDbBoolean('commandPause', 'commandsPaused', false);
|
||||
isActive = false;
|
||||
timerId = -1;
|
||||
$.say($.lang.get('commandpause.ended'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @event event
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @commandpath pausecommands [seconds] - Pause all command usage for the given amount of time. If [seconds] is not present, uses a default value
|
||||
* @commandpath pausecommands clear - Unpause commands
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pausecommands')) {
|
||||
if (args[0] != undefined || args[0] != null) {
|
||||
if (args[0] == 'clear') {
|
||||
unPause();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNaN(parseInt(args[0]))) {
|
||||
pause(parseInt(args[0]));
|
||||
} else {
|
||||
pause();
|
||||
}
|
||||
} else {
|
||||
$.say($.lang.get('pausecommands.usage'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if ($.bot.isModuleEnabled('./core/commandPause.js')) {
|
||||
$.registerChatCommand('./core/commandPause.js', 'pausecommands', 2);
|
||||
}
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.commandPause = {
|
||||
pause: pause,
|
||||
isPaused: isPaused,
|
||||
unPause: unPause,
|
||||
};
|
||||
})();
|
||||
358
libs/phantombot/scripts/core/commandRegister.js
Normal file
358
libs/phantombot/scripts/core/commandRegister.js
Normal file
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* commandRegister.js
|
||||
*
|
||||
* Register and keep track of commands.
|
||||
*
|
||||
* NOTE: You will have to register ANY command you implement!
|
||||
* The commandEvent will not get fired to your module if the registry does not know about it!
|
||||
*/
|
||||
(function() {
|
||||
var commands = {},
|
||||
aliases = {};
|
||||
|
||||
/*
|
||||
* @function registerChatCommand
|
||||
*
|
||||
* @param {String} script
|
||||
* @param {String} command
|
||||
* @param {String} groupId
|
||||
*/
|
||||
function registerChatCommand(script, command, groupId) {
|
||||
// If groupId is undefined set it to 7 (viewer).
|
||||
groupId = (groupId === undefined ? 7 : groupId);
|
||||
|
||||
if (commandExists(command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// This is for the panel commands.
|
||||
if (groupId == 30) {
|
||||
if ($.inidb.exists('permcom', command)) {
|
||||
$.inidb.del('permcom', command);
|
||||
}
|
||||
commands[command] = {
|
||||
groupId: groupId,
|
||||
script: script,
|
||||
subcommands: {}
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle disabled commands.
|
||||
if ($.inidb.exists('disabledCommands', command)) {
|
||||
$.inidb.set('tempDisabledCommandScript', command, script);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get and set the command permission.
|
||||
groupId = $.getSetIniDbNumber('permcom', command, groupId);
|
||||
|
||||
commands[command] = {
|
||||
groupId: groupId,
|
||||
script: script,
|
||||
subcommands: {}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* @function registerChatSubcommand
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
* @param {String} groupId
|
||||
*/
|
||||
function registerChatSubcommand(command, subcommand, groupId) {
|
||||
// If groupId is undefined set it to 7 (viewer).
|
||||
groupId = (groupId === undefined ? 7 : groupId);
|
||||
|
||||
if (!commandExists(command) || subCommandExists(command, subcommand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get and set the command permission.
|
||||
groupId = $.getSetIniDbNumber('permcom', (command + ' ' + subcommand), groupId);
|
||||
|
||||
commands[command].subcommands[subcommand] = {
|
||||
groupId: groupId
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function registerChatAlias
|
||||
*
|
||||
* @param {String} alias
|
||||
*/
|
||||
function registerChatAlias(alias) {
|
||||
if (!aliasExists(alias)) {
|
||||
aliases[alias] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function unregisterChatCommand
|
||||
*
|
||||
* @param {String} command
|
||||
*/
|
||||
function unregisterChatCommand(command) {
|
||||
if (commandExists(command)) {
|
||||
delete commands[command];
|
||||
delete aliases[command];
|
||||
}
|
||||
|
||||
$.inidb.del('permcom', command);
|
||||
$.inidb.del('pricecom', command);
|
||||
$.inidb.del('cooldown', command);
|
||||
$.inidb.del('paycom', command);
|
||||
$.inidb.del('disabledCommands', command);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function tempUnRegisterChatCommand
|
||||
*
|
||||
* @param {String} command
|
||||
*/
|
||||
function tempUnRegisterChatCommand(command) {
|
||||
$.inidb.set('tempDisabledCommandScript', command, commands[command].script);
|
||||
if (commandExists(command)) {
|
||||
delete commands[command];
|
||||
delete aliases[command];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function unregisterChatSubcommand
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
*/
|
||||
function unregisterChatSubcommand(command, subcommand) {
|
||||
if (subCommandExists(command, subcommand)) {
|
||||
delete commands[command].subcommands[subcommand];
|
||||
}
|
||||
|
||||
$.inidb.del('permcom', command + ' ' + subcommand);
|
||||
$.inidb.del('pricecom', command + ' ' + subcommand);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandScript
|
||||
*
|
||||
* @param {String} command
|
||||
* @return {String}
|
||||
*/
|
||||
function getCommandScript(command) {
|
||||
if (commands[command] === undefined) {
|
||||
return "Undefined";
|
||||
}
|
||||
|
||||
return commands[command].script;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function commandExists
|
||||
*
|
||||
* @param {String} command
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function commandExists(command) {
|
||||
return (commands[command] !== undefined);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function aliasExists
|
||||
*
|
||||
* @param {String} command
|
||||
*/
|
||||
function aliasExists(alias) {
|
||||
return (aliases[alias] !== undefined);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function subCommandExists
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function subCommandExists(command, subcommand) {
|
||||
if (commandExists(command)) {
|
||||
return (commands[command].subcommands[subcommand] !== undefined);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandGroup
|
||||
*
|
||||
* @param {String} command
|
||||
* @return {Number}
|
||||
*/
|
||||
function getCommandGroup(command) {
|
||||
if (commandExists(command)) {
|
||||
return commands[command].groupId;
|
||||
}
|
||||
return 7;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandGroupName
|
||||
*
|
||||
* @param {String} command
|
||||
* @return {String}
|
||||
*/
|
||||
function getCommandGroupName(command) {
|
||||
var group = '';
|
||||
|
||||
if (commandExists(command)) {
|
||||
if (commands[command].groupId == 0) {
|
||||
group = 'Caster';
|
||||
} else if (commands[command].groupId == 1) {
|
||||
group = 'Administrator';
|
||||
} else if (commands[command].groupId == 2) {
|
||||
group = 'Moderator';
|
||||
} else if (commands[command].groupId == 3) {
|
||||
group = 'Subscriber';
|
||||
} else if (commands[command].groupId == 4) {
|
||||
group = 'Donator';
|
||||
} else if (commands[command].groupId == 5) {
|
||||
group = 'VIP';
|
||||
} else if (commands[command].groupId == 6) {
|
||||
group = 'Regular';
|
||||
} else if (commands[command].groupId == 7) {
|
||||
group = 'Viewer';
|
||||
}
|
||||
return group;
|
||||
}
|
||||
return 'Viewer';
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getSubcommandGroup
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
* @return {Number}
|
||||
*/
|
||||
function getSubcommandGroup(command, subcommand) {
|
||||
if (commandExists(command)) {
|
||||
if (subCommandExists(command, subcommand)) {
|
||||
return commands[command].subcommands[subcommand].groupId;
|
||||
}
|
||||
return getCommandGroup(command);
|
||||
}
|
||||
return 7;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getSubCommandGroupName
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
* @return {String}
|
||||
*/
|
||||
function getSubCommandGroupName(command, subcommand) {
|
||||
var group = '';
|
||||
|
||||
if (subCommandExists(command, subcommand)) {
|
||||
if (commands[command].subcommands[subcommand].groupId == 0) {
|
||||
group = 'Caster';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 1) {
|
||||
group = 'Administrator';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 2) {
|
||||
group = 'Moderator';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 3) {
|
||||
group = 'Subscriber';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 4) {
|
||||
group = 'Donator';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 5) {
|
||||
group = 'VIP';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 6) {
|
||||
group = 'Regular';
|
||||
} else if (commands[command].subcommands[subcommand].groupId == 7) {
|
||||
group = 'Viewer';
|
||||
}
|
||||
return group;
|
||||
}
|
||||
return 'Viewer';
|
||||
}
|
||||
|
||||
/*
|
||||
* @function updateCommandGroup
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Number} groupId
|
||||
*/
|
||||
function updateCommandGroup(command, groupId) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].groupId = groupId;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function updateSubcommandGroup
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String} subcommand
|
||||
* @param {Number} groupId
|
||||
*/
|
||||
function updateSubcommandGroup(command, subcommand, groupId) {
|
||||
if (subCommandExists(command, subcommand)) {
|
||||
commands[command].subcommands[subcommand].groupId = groupId;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getSubCommandFromArguments
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {String[]} args
|
||||
*/
|
||||
function getSubCommandFromArguments(command, args) {
|
||||
if (!commandExists(command) || args[0] === undefined) {
|
||||
return '';
|
||||
} else {
|
||||
var subCommand = args[0].toLowerCase();
|
||||
|
||||
if (subCommandExists(command, subCommand)) {
|
||||
return subCommand;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/** Export functions to API */
|
||||
$.registerChatCommand = registerChatCommand;
|
||||
$.registerChatSubcommand = registerChatSubcommand;
|
||||
$.unregisterChatCommand = unregisterChatCommand;
|
||||
$.unregisterChatSubcommand = unregisterChatSubcommand;
|
||||
$.commandExists = commandExists;
|
||||
$.subCommandExists = subCommandExists;
|
||||
$.getCommandGroup = getCommandGroup;
|
||||
$.getCommandGroupName = getCommandGroupName;
|
||||
$.getSubcommandGroup = getSubcommandGroup;
|
||||
$.getSubCommandGroupName = getSubCommandGroupName;
|
||||
$.updateCommandGroup = updateCommandGroup;
|
||||
$.updateSubcommandGroup = updateSubcommandGroup;
|
||||
$.getCommandScript = getCommandScript;
|
||||
$.aliasExists = aliasExists;
|
||||
$.registerChatAlias = registerChatAlias;
|
||||
$.tempUnRegisterChatCommand = tempUnRegisterChatCommand;
|
||||
$.getSubCommandFromArguments = getSubCommandFromArguments;
|
||||
})();
|
||||
1702
libs/phantombot/scripts/core/commandTags.js
Normal file
1702
libs/phantombot/scripts/core/commandTags.js
Normal file
File diff suppressed because it is too large
Load Diff
345
libs/phantombot/scripts/core/fileSystem.js
Normal file
345
libs/phantombot/scripts/core/fileSystem.js
Normal file
@@ -0,0 +1,345 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* fileSystem.js
|
||||
*
|
||||
* Export general file management to th $ API
|
||||
*/
|
||||
(function() {
|
||||
var JFile = java.io.File,
|
||||
JFileInputStream = java.io.FileInputStream,
|
||||
JFileOutputStream = java.io.FileOutputStream,
|
||||
Paths = Packages.java.nio.file.Paths,
|
||||
executionPath = Packages.tv.phantombot.PhantomBot.GetExecutionPath(),
|
||||
fileHandles = [],
|
||||
validPaths = [
|
||||
'./addons',
|
||||
'./config/audio-hooks',
|
||||
'./config/gif-alerts',
|
||||
'./logs',
|
||||
'./scripts'
|
||||
];
|
||||
|
||||
/**
|
||||
* @function readFile
|
||||
* @export $
|
||||
* @param {string} path
|
||||
* @returns {Array}
|
||||
*/
|
||||
function readFile(path) {
|
||||
var lines = [];
|
||||
|
||||
if (!fileExists(path)) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked readFile() target outside of validPaths:' + path);
|
||||
return lines;
|
||||
}
|
||||
|
||||
try {
|
||||
var fis = new JFileInputStream(path),
|
||||
scan = new java.util.Scanner(fis);
|
||||
for (var i = 0; scan.hasNextLine(); ++i) {
|
||||
lines[i] = scan.nextLine();
|
||||
}
|
||||
fis.close();
|
||||
} catch (e) {
|
||||
$.log.error('Failed to open \'' + path + '\': ' + e);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function mkDir
|
||||
* @export $
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function mkDir(path) {
|
||||
if (invalidLocation(path)){
|
||||
$.consoleLn('Blocked mkDir() target outside of validPaths:' + path);
|
||||
return false;
|
||||
}
|
||||
|
||||
var dir = new JFile(path);
|
||||
return dir.mkdir();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function moveFile
|
||||
* @export $
|
||||
* @param {string} file
|
||||
* @param {string} path
|
||||
*/
|
||||
function moveFile(file, path) {
|
||||
var fileO = new JFile(file),
|
||||
pathO = new JFile(path);
|
||||
|
||||
if (invalidLocation(file) || invalidLocation(path)) {
|
||||
$.consoleLn('Blocked moveFile() source or target outside of validPaths:' + file + ' to ' + path);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((fileO != null && pathO != null) || (file != "" && path != "")) {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.moveFileToDirectory(fileO, pathO, true);
|
||||
} catch (ex) {
|
||||
$.log.error("moveFile(" + file + ", " + path + ") failed: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function saveArray
|
||||
* @export $
|
||||
* @param {Array} array
|
||||
* @param {string} path
|
||||
* @param {boolean} append
|
||||
*/
|
||||
function saveArray(array, path, append) {
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked saveArray() target outside of validPaths:' + path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var fos = new JFileOutputStream(path, append),
|
||||
ps = new java.io.PrintStream(fos),
|
||||
l = array.length;
|
||||
for (var i = 0; i < l; ++i) {
|
||||
ps.println(array[i]);
|
||||
}
|
||||
fos.close();
|
||||
} catch (e) {
|
||||
$.log.error('Failed to write to \'' + path + '\': ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function closeOpenFiles
|
||||
*/
|
||||
function closeOpenFiles() {
|
||||
var dateFormat = new java.text.SimpleDateFormat('MM-dd-yyyy'),
|
||||
date = dateFormat.format(new java.util.Date());
|
||||
|
||||
for (var key in fileHandles) {
|
||||
if (!fileHandles[key].startDate.equals(date)) {
|
||||
fileHandles[key].fos.close();
|
||||
delete fileHandles[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function writeToFile
|
||||
* @export $
|
||||
* @param {string} line
|
||||
* @param {string} path
|
||||
* @param {boolean} append
|
||||
*/
|
||||
function writeToFile(line, path, append) {
|
||||
var dateFormat = new java.text.SimpleDateFormat('MM-dd-yyyy'),
|
||||
date = dateFormat.format(new java.util.Date()),
|
||||
fos,
|
||||
ps;
|
||||
|
||||
if (invalidLocation(path)){
|
||||
$.consoleLn('Blocked writeToFile() target outside of validPaths:' + path);
|
||||
return;
|
||||
}
|
||||
|
||||
closeOpenFiles();
|
||||
|
||||
if (fileHandles[path] !== undefined && append) {
|
||||
fos = fileHandles[path].fos;
|
||||
ps = fileHandles[path].ps;
|
||||
} else {
|
||||
fos = new JFileOutputStream(path, append);
|
||||
ps = new java.io.PrintStream(fos);
|
||||
fileHandles[path] = {
|
||||
fos: fos,
|
||||
ps: ps,
|
||||
startDate: date
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
ps.println(line);
|
||||
fos.flush();
|
||||
} catch (e) {
|
||||
$.log.error('Failed to write to \'' + path + '\': ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function touchFile
|
||||
* @export $
|
||||
* @param {string} path
|
||||
*/
|
||||
function touchFile(path) {
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked touchFile() target outside of validPaths:' + path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var fos = new JFileOutputStream(path, true);
|
||||
fos.close();
|
||||
} catch (e) {
|
||||
$.log.error('Failed to touch \'' + path + '\': ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function deleteFile
|
||||
* @export $
|
||||
* @param {string} path
|
||||
* @param {boolean} now
|
||||
*/
|
||||
function deleteFile(path, now) {
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked deleteFile() target outside of validPaths:' + path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var f = new JFile(path);
|
||||
if (now) {
|
||||
f['delete']();
|
||||
} else {
|
||||
f.deleteOnExit();
|
||||
}
|
||||
} catch (e) {
|
||||
$.log.error('Failed to delete \'' + path + '\': ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function fileExists
|
||||
* @export $
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function fileExists(path) {
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked fileExists() target outside of validPaths:' + path);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var f = new JFile(path);
|
||||
return f.exists();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function findFiles
|
||||
* @export $
|
||||
* @param {string} directory
|
||||
* @param {string} pattern
|
||||
* @returns {Array}
|
||||
*/
|
||||
function findFiles(directory, pattern) {
|
||||
if (invalidLocation(directory)) {
|
||||
$.consoleLn('Blocked findFiles() target outside of validPaths:' + directory);
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
var f = new JFile(directory),
|
||||
ret = [];
|
||||
if (f.isDirectory()) {
|
||||
var files = f.list();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
if (files[i].indexOf(pattern) != -1) {
|
||||
ret.push(files[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} catch (e) {
|
||||
$.log.error('Failed to search in \'' + directory + '\': ' + e);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isDirectory
|
||||
* @export $
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isDirectory(path) {
|
||||
if (invalidLocation(path)) {
|
||||
$.consoleLn('Blocked isDirectory() target outside of validPaths:' + path);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var f = new JFile(path);
|
||||
return f.isDirectory();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function findSize
|
||||
* @export $
|
||||
* @param {string} file
|
||||
* @returns {Number}
|
||||
*/
|
||||
function findSize(file) {
|
||||
if (invalidLocation(file)) {
|
||||
$.consoleLn('Blocked findSize() target outside of validPaths:' + file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
var fileO = new JFile(file);
|
||||
return fileO.length();
|
||||
}
|
||||
|
||||
function invalidLocation(path) {
|
||||
var p = Paths.get(path);
|
||||
|
||||
for (var x in validPaths) {
|
||||
if (p.toAbsolutePath().startsWith(Paths.get(executionPath, validPaths[x]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Export functions to API */
|
||||
$.deleteFile = deleteFile;
|
||||
$.fileExists = fileExists;
|
||||
$.findFiles = findFiles;
|
||||
$.findSize = findSize;
|
||||
$.isDirectory = isDirectory;
|
||||
$.mkDir = mkDir;
|
||||
$.moveFile = moveFile;
|
||||
$.readFile = readFile;
|
||||
$.saveArray = saveArray;
|
||||
$.touchFile = touchFile;
|
||||
$.writeToFile = writeToFile;
|
||||
})();
|
||||
180
libs/phantombot/scripts/core/gameMessages.js
Normal file
180
libs/phantombot/scripts/core/gameMessages.js
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* gameMessages.js
|
||||
*
|
||||
* An API for predefined game result messages
|
||||
* Use the $.gameMessages API
|
||||
*/
|
||||
(function() {
|
||||
var lastRandom = -1,
|
||||
winMessageCount = {
|
||||
roll: 0,
|
||||
gamble: 0,
|
||||
slot: 0
|
||||
},
|
||||
lostMessagesCount = {
|
||||
roll: 0,
|
||||
gamble: 0,
|
||||
slot: 0
|
||||
};
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
var i;
|
||||
|
||||
// Load up messages for the roll command.
|
||||
for (i = 1; $.lang.exists('roll.win.' + i); i++) {
|
||||
winMessageCount.roll++;
|
||||
}
|
||||
|
||||
// Load up messages for the roll command.
|
||||
for (i = 1; $.lang.exists('roll.lost.' + i); i++) {
|
||||
lostMessagesCount.roll++;
|
||||
}
|
||||
|
||||
// Load up messages for the slot command.
|
||||
for (i = 1; $.lang.exists('slot.win.' + i); i++) {
|
||||
winMessageCount.slot++;
|
||||
}
|
||||
|
||||
// Load up messages for the slot command.
|
||||
for (i = 1; $.lang.exists('slot.lost.' + i); i++) {
|
||||
lostMessagesCount.slot++;
|
||||
}
|
||||
|
||||
// Load up messages for the gamble command.
|
||||
for (i = 1; $.lang.exists('gamble.win.' + i); i++) {
|
||||
winMessageCount.gamble++;
|
||||
}
|
||||
|
||||
// Load up messages for the gamble command.
|
||||
for (i = 1; $.lang.exists('gamble.lost.' + i); i++) {
|
||||
lostMessagesCount.gamble++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getWin
|
||||
*
|
||||
* @export $.gameMessages
|
||||
* @param {string} username
|
||||
* @param {string} game
|
||||
* @returns {string}
|
||||
*/
|
||||
function getWin(username, game) {
|
||||
var rand;
|
||||
|
||||
switch (game) {
|
||||
case 'roll':
|
||||
if (winMessageCount.roll === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, winMessageCount.roll);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.win.' + rand, $.resolveRank(username));
|
||||
case 'gamble':
|
||||
if (winMessageCount.gamble === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, winMessageCount.gamble);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.win.' + rand, $.resolveRank(username));
|
||||
case 'slot':
|
||||
if (winMessageCount.slot === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, winMessageCount.slot);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.win.' + rand, $.resolveRank(username));
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLose
|
||||
* @export $.gameMessages
|
||||
* @param {string} username
|
||||
* @returns {string}
|
||||
*/
|
||||
function getLose(username, game) {
|
||||
var rand;
|
||||
|
||||
switch (game) {
|
||||
case 'roll':
|
||||
if (lostMessagesCount.roll === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, lostMessagesCount.roll);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.lost.' + rand, $.resolveRank(username));
|
||||
case 'gamble':
|
||||
if (lostMessagesCount.gamble === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, lostMessagesCount.gamble);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.lost.' + rand, $.resolveRank(username));
|
||||
case 'slot':
|
||||
if (lostMessagesCount.slot === 0) {
|
||||
return '';
|
||||
} else {
|
||||
do {
|
||||
rand = $.randRange(1, lostMessagesCount.slot);
|
||||
} while (rand == lastRandom);
|
||||
}
|
||||
lastRandom = rand;
|
||||
return $.lang.get(game + '.lost.' + rand, $.resolveRank(username));
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if ($.bot.isModuleEnabled('./core/gameMessages.js')) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.gameMessages = {
|
||||
getWin: getWin,
|
||||
getLose: getLose
|
||||
};
|
||||
})();
|
||||
377
libs/phantombot/scripts/core/initCommands.js
Normal file
377
libs/phantombot/scripts/core/initCommands.js
Normal file
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
* 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 bot = $.botName.toLowerCase();
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase(bot)) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.usage', bot));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName disconnect - Removes the bot from your channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disconnect')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.disconnect', 'irc-ws.chat.twitch.tv'));
|
||||
|
||||
setTimeout(function() {
|
||||
java.lang.System.exit(0);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName moderate - Forces the bot to detect its moderator status.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('moderate')) {
|
||||
$.session.getModerationStatus();
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName setconnectmessage [message] - Sets a message that will be said once the bot joins the channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setconnectmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg.usage', bot));
|
||||
return;
|
||||
}
|
||||
|
||||
var message = args.slice(1).join(' ');
|
||||
|
||||
$.setIniDbString('settings', 'connectedMsg', message);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName removeconnectmessage - Removes the message said when the bot joins the channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('removeconnectmessage')) {
|
||||
$.inidb.del('settings', 'connectedMsg');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.connected.msg.removed'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName togglepricecommods - Toggles if moderators and higher pay for commands.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglepricecommods')) {
|
||||
var toggle = !$.getIniDbBoolean('settings', 'pricecomMods', false);
|
||||
|
||||
$.setIniDbBoolean('settings', 'pricecomMods', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.on.pay') : $.lang.get('init.mod.toggle.off.pay')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName togglepermcommessage - Toggles if the no permission message is said in the chat.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglepermcommessage')) {
|
||||
var toggle = !$.getIniDbBoolean('settings', 'permComMsgEnabled', false);
|
||||
|
||||
$.setIniDbBoolean('settings', 'permComMsgEnabled', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.perm.msg.on') : $.lang.get('init.mod.toggle.perm.msg.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName togglepricecommessage - Toggles if the cost message is said in the chat.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglepricecommessage')) {
|
||||
var toggle = !$.getIniDbBoolean('settings', 'priceComMsgEnabled', false);
|
||||
|
||||
$.setIniDbBoolean('settings', 'priceComMsgEnabled', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.mod.toggle.price.msg.on') : $.lang.get('init.mod.toggle.price.msg.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath botName togglecooldownmessage - Toggles if the cooldown message is said in the chat.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglecooldownmessage')) {
|
||||
var toggle = !$.getIniDbBoolean('settings', 'coolDownMsgEnabled', false);
|
||||
|
||||
$.setIniDbBoolean('settings', 'coolDownMsgEnabled', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('init.toggle.cooldown.msg.on') : $.lang.get('init.toggle.cooldown.msg.off')));
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('module')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath module delete [path] - Removes a module from the modules list. This does not remove the module itself.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('delete')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.usage'));
|
||||
return;
|
||||
} else if ($.getIniDbString('modules', subAction, undefined) === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.404', subAction));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('modules', subAction);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.delete.success', subAction));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath module list - Gives a list of all the modules with their current status.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('list')) {
|
||||
var keys = Object.keys($.bot.modules),
|
||||
modules = $.bot.modules,
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (modules[keys[i]].scriptName.indexOf('./core') !== -1 || modules[keys[i]].scriptName.indexOf('./lang') !== -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
temp.push(modules[keys[i]].scriptName + (modules[keys[i]].isEnabled ? ' (' + $.lang.get('common.enabled') + ')' : ' (' + $.lang.get('common.disabled') + ')'));
|
||||
}
|
||||
|
||||
var totalPages = $.paginateArray(temp, 'init.module.list', ', ', true, sender, (isNaN(parseInt(subAction)) ? 1 : parseInt(subAction)));
|
||||
|
||||
if (totalPages > 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.list.total', totalPages));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath module status [module path] - Retrieve the current status (enabled/disabled) of the given module
|
||||
*/
|
||||
if (action.equalsIgnoreCase('status')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.status'));
|
||||
return;
|
||||
}
|
||||
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
if (module.isEnabled) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.check.enabled', module.getModuleName()));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.check.disabled', module.getModuleName()));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath module enable [module path] - Enable a module using the path and name of the module
|
||||
*/
|
||||
if (action.equalsIgnoreCase('enable')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.enable'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, true);
|
||||
$.bot.loadScript(module.scriptName);
|
||||
$.bot.modules[module.scriptName].isEnabled = true;
|
||||
|
||||
var hookIndex = $.bot.getHookIndex($.bot.modules[module.scriptName].scriptName, 'initReady');
|
||||
|
||||
try {
|
||||
if (hookIndex !== -1) {
|
||||
$.bot.getHook(module.scriptName, 'initReady').handler();
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.enabled', module.getModuleName()));
|
||||
} catch (ex) {
|
||||
$.log.error('Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex);
|
||||
$.consoleLn("Sending stack trace to error log...");
|
||||
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath module disable [module path] - Disable a module using the path and name of the module
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disable')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.usage.disable'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
$.bot.modules[module.scriptName].isEnabled = false;
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.disabled', module.getModuleName()));
|
||||
|
||||
if (module.scriptName.equalsIgnoreCase('./systems/pointSystem.js')) {
|
||||
var modules = ['./games/adventureSystem.js', './games/roll.js', './games/slotMachine.js', './systems/ticketraffleSystem.js', './systems/raffleSystem.js', './games/gambling.js'],
|
||||
i;
|
||||
|
||||
for (i in modules) {
|
||||
module = $.bot.getModule(modules[i]);
|
||||
|
||||
$.bot.modules[modules[i]].isEnabled = false;
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.auto-disabled'));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('init.module.404'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('enablesilent')) {
|
||||
if (subAction === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, true);
|
||||
$.bot.loadScript(module.scriptName);
|
||||
$.bot.modules[module.scriptName].isEnabled = true;
|
||||
|
||||
var hookIndex = $.bot.getHookIndex(module.scriptName, 'initReady');
|
||||
|
||||
try {
|
||||
if (hookIndex !== -1) {
|
||||
$.bot.getHook(module.scriptName, 'initReady').handler();
|
||||
}
|
||||
} catch (ex) {
|
||||
$.log.error('Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex);
|
||||
$.consoleLn("Sending stack trace to error log...");
|
||||
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disablesilent')) {
|
||||
if (subAction === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.indexOf('./core') !== -1 || subAction.indexOf('./lang') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
$.bot.modules[module.scriptName].isEnabled = false;
|
||||
|
||||
if (module.scriptName.equalsIgnoreCase('./systems/pointSystem.js')) {
|
||||
var modules = ['./games/adventureSystem.js', './games/roll.js', './games/slotMachine.js', './systems/ticketraffleSystem.js', './systems/raffleSystem.js', './games/gambling.js'],
|
||||
i;
|
||||
|
||||
for (i in modules) {
|
||||
module = $.bot.getModule(modules[i]);
|
||||
|
||||
$.bot.modules[module.scriptName].isEnabled = false;
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reconnect')) {
|
||||
if ($.isBot(sender)) {
|
||||
$.session.reconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Panel command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('disconnect')) {
|
||||
if ($.isBot(sender)) {
|
||||
java.lang.System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath echo [message] - Send a message as the bot.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('chat') || command.equalsIgnoreCase('echo')) {
|
||||
if (argsString.length() > 0) {
|
||||
$.say(argsString);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/initCommands.js', 'chat', 1);
|
||||
$.registerChatCommand('./core/initCommands.js', 'module', 1);
|
||||
$.registerChatCommand('./core/initCommands.js', 'echo', 1);
|
||||
$.registerChatCommand('./core/initCommands.js', 'reconnect', 1);
|
||||
$.registerChatCommand('./core/initCommands.js', 'disconnect', 1);
|
||||
$.registerChatCommand('./core/initCommands.js', bot, 2);
|
||||
$.registerChatSubcommand(bot, 'disconnect', 1);
|
||||
$.registerChatSubcommand(bot, 'reconnect', 1);
|
||||
$.registerChatSubcommand(bot, 'moderate', 2);
|
||||
|
||||
// Say the connected message.
|
||||
if ($.inidb.exists('settings', 'connectedMsg')) {
|
||||
$.say($.inidb.get('settings', 'connectedMsg'));
|
||||
}
|
||||
});
|
||||
})();
|
||||
110
libs/phantombot/scripts/core/jsTimers.js
Normal file
110
libs/phantombot/scripts/core/jsTimers.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* jsTimers.js
|
||||
*
|
||||
* A general javascript module to replace Rhino's crappy timer functions
|
||||
*/
|
||||
|
||||
var setTimeout,
|
||||
clearTimeout,
|
||||
setInterval,
|
||||
clearInterval;
|
||||
|
||||
(function() {
|
||||
var counter = 1,
|
||||
registry = {};
|
||||
|
||||
/**
|
||||
* @function setTimeout
|
||||
* @param {Function} fn
|
||||
* @param {Number} delay
|
||||
* @param {String} name
|
||||
|
||||
* @returns {Number}
|
||||
*/
|
||||
setTimeout = function(fn, delay, name) {
|
||||
var id = counter++,
|
||||
timer;
|
||||
|
||||
if (name !== undefined) {
|
||||
timer = new java.util.Timer(name);
|
||||
} else {
|
||||
timer = new java.util.Timer();
|
||||
}
|
||||
|
||||
registry[id] = new JavaAdapter(java.util.TimerTask, {
|
||||
run: fn
|
||||
});
|
||||
timer.schedule(registry[id], delay);
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function setInterval
|
||||
* @param {Function} fn
|
||||
* @param {Number} interval
|
||||
* @param {String} name
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
setInterval = function(fn, interval, name) {
|
||||
var id = counter++,
|
||||
timer;
|
||||
|
||||
if (name !== undefined) {
|
||||
timer = new java.util.Timer(name);
|
||||
} else {
|
||||
timer = new java.util.Timer();
|
||||
}
|
||||
|
||||
registry[id] = new JavaAdapter(java.util.TimerTask, {
|
||||
run: fn
|
||||
});
|
||||
timer.schedule(registry[id], interval, interval);
|
||||
|
||||
return id;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function clearTimeout
|
||||
* @param {Number} id
|
||||
*/
|
||||
clearTimeout = function(id) {
|
||||
if (id == undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (registry[id] != undefined) {
|
||||
try {
|
||||
registry[id].cancel();
|
||||
} catch (ex) {
|
||||
// Cannot cancel since timer is already over.
|
||||
// Ignore this.
|
||||
}
|
||||
}
|
||||
|
||||
delete registry[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {clearTimeout}
|
||||
*/
|
||||
clearInterval = clearTimeout;
|
||||
})();
|
||||
134
libs/phantombot/scripts/core/keywordCoolDown.js
Normal file
134
libs/phantombot/scripts/core/keywordCoolDown.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* keywordCoolDown.js
|
||||
*
|
||||
* Manage cooldowns for keywords
|
||||
*
|
||||
* To use the cooldown in other scipts use the $.coolDownKeywords API
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var modCooldown = $.getIniDbBoolean('cooldownSettings', 'modCooldown', false),
|
||||
cooldown = [];
|
||||
|
||||
/**
|
||||
* @function permCheck
|
||||
* @param username
|
||||
* @return boolean
|
||||
*/
|
||||
function permCheck(username) {
|
||||
return (!modCooldown && $.isMod(username)) || $.isAdmin(username);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getCooldown
|
||||
* @param keyword
|
||||
* @return number
|
||||
*/
|
||||
function getCooldown(keyword) {
|
||||
if ($.inidb.exists('coolkey', keyword.toLowerCase())) {
|
||||
return parseInt($.inidb.get('coolkey', keyword.toLowerCase()));
|
||||
} else if ($.inidb.exists('coolkey', keyword)) { // ignore case
|
||||
return parseInt($.inidb.get('coolkey', keyword));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function set
|
||||
* @export $.coolDownKeywords
|
||||
* @param keyword
|
||||
* @param time
|
||||
* @param username
|
||||
*/
|
||||
function set(keyword, hasCooldown, time, username) {
|
||||
if (time == null || time == 0 || time == 1 || isNaN(time)) {
|
||||
return;
|
||||
}
|
||||
|
||||
time = ((time * 1000) + $.systemTime());
|
||||
keyword = keyword.toLowerCase();
|
||||
|
||||
cooldown.push({
|
||||
keyword: keyword,
|
||||
time: time
|
||||
});
|
||||
$.consoleDebug('Pushed keyword ' + keyword + ' to cooldown.');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function get
|
||||
* @export $.coolDownKeywords
|
||||
* @param keyword
|
||||
* @param username
|
||||
* @return number
|
||||
*/
|
||||
function get(keyword, username) {
|
||||
var hasCooldown = $.inidb.exists('coolkey', keyword.toLowerCase()) || $.inidb.exists('coolkey', keyword), // ignore case.
|
||||
i;
|
||||
|
||||
if (!hasCooldown)
|
||||
return 0;
|
||||
|
||||
for (i in cooldown) {
|
||||
if (cooldown[i].keyword.equalsIgnoreCase(keyword)) {
|
||||
if ((cooldown[i].time - $.systemTime()) > 0) {
|
||||
if (permCheck(username)) return 0;
|
||||
return parseInt(cooldown[i].time - $.systemTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set(keyword, hasCooldown, getCooldown(keyword));
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function clear
|
||||
* @export $.coolDownKeywords
|
||||
* @param keyword
|
||||
*/
|
||||
function clear(keyword) {
|
||||
var i;
|
||||
for (i in cooldown) {
|
||||
if (cooldown[i].keyword.equalsIgnoreCase(keyword)) {
|
||||
cooldown.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function clearAll
|
||||
*/
|
||||
function clearAll() {
|
||||
var i;
|
||||
for (i in cooldown) {
|
||||
cooldown.splice(i, 1);
|
||||
}
|
||||
};
|
||||
|
||||
/** EXPORT TO $. API*/
|
||||
$.coolDownKeywords = {
|
||||
set: set,
|
||||
get: get,
|
||||
clear: clear,
|
||||
};
|
||||
})();
|
||||
198
libs/phantombot/scripts/core/lang.js
Normal file
198
libs/phantombot/scripts/core/lang.js
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* lang.js
|
||||
*
|
||||
* Provide a language API
|
||||
* Use the $.lang API
|
||||
*
|
||||
* NOTE: Reading from/writing to the lang data directly is not possbile anymore!
|
||||
* Use the register(), exists() and get() functions!
|
||||
*/
|
||||
(function() {
|
||||
var data = [],
|
||||
curLang = ($.inidb.exists('settings', 'lang') ? $.inidb.get('settings', 'lang') : 'english');
|
||||
|
||||
/**
|
||||
* @function load
|
||||
*/
|
||||
function load(force) {
|
||||
$.bot.loadScriptRecursive('./lang/english', true, (force ? force : false));
|
||||
if (curLang != 'english') {
|
||||
$.bot.loadScriptRecursive('./lang/' + curLang, true, (force ? force : false));
|
||||
}
|
||||
|
||||
if ($.isDirectory('./scripts/lang/custom')) {
|
||||
$.bot.loadScriptRecursive('./lang/custom', true, (force ? force : false));
|
||||
}
|
||||
|
||||
// Set "response_@chat" to true if it hasn't been set yet, so the bot isn't muted when using a fresh install
|
||||
if (!$.inidb.exists('settings', 'response_@chat')) {
|
||||
$.setIniDbBoolean('settings', 'response_@chat', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function register
|
||||
* @export $.lang
|
||||
* @param {string} key
|
||||
* @param {string} string
|
||||
*/
|
||||
function register(key, string) {
|
||||
if (key && string) {
|
||||
data[key.toLowerCase()] = string;
|
||||
}
|
||||
if (key && string.length === 0) {
|
||||
data[key.toLowerCase()] = '<<EMPTY_PLACEHOLDER>>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function get
|
||||
* @export $.lang
|
||||
* @param {string} key
|
||||
* @returns {string}
|
||||
*/
|
||||
function get(key) {
|
||||
var string = data[key.toLowerCase()],
|
||||
i;
|
||||
|
||||
if (string === undefined) {
|
||||
$.log.warn('Lang string for key "' + key + '" was not found.');
|
||||
return '';
|
||||
}
|
||||
|
||||
if (string == '<<EMPTY_PLACEHOLDER>>') {
|
||||
return '';
|
||||
}
|
||||
|
||||
for (i = 1; i < arguments.length; i++) {
|
||||
while (string.indexOf("$" + i) >= 0) {
|
||||
string = string.replace("$" + i, arguments[i]);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function paramCount
|
||||
* @export $.lang
|
||||
* @param {string} key
|
||||
* @returns {Number}
|
||||
*/
|
||||
function paramCount(key) {
|
||||
var string = data[key.toLowerCase()],
|
||||
i,
|
||||
ctr = 0;
|
||||
|
||||
if (!string) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 1; i < 99; i++) {
|
||||
if (string.indexOf("$" + i) >= 0) {
|
||||
ctr++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ctr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function exists
|
||||
* @export $.lang
|
||||
* @param {string} key
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function exists(key) {
|
||||
return (data[key.toLowerCase()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
inversedState;
|
||||
|
||||
/**
|
||||
* @commandpath lang [language name] - Get or optionally set the current language (use folder name from "./lang" directory);
|
||||
*/
|
||||
if (command.equalsIgnoreCase('lang')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + get('lang.curlang', curLang));
|
||||
} else {
|
||||
action = action.toLowerCase();
|
||||
if (!$.fileExists('./scripts/lang/' + action + '/main.js')) {
|
||||
$.say($.whisperPrefix(sender) + get('lang.lang.404'));
|
||||
} else {
|
||||
$.inidb.set('settings', 'lang', action);
|
||||
curLang = action;
|
||||
load(true);
|
||||
$.say($.whisperPrefix(sender) + get('lang.lang.changed', action));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath mute - Toggle muting the bot in the chat
|
||||
*/
|
||||
if (command.equalsIgnoreCase('mute')) {
|
||||
inversedState = !$.getIniDbBoolean('settings', 'response_@chat');
|
||||
|
||||
$.setIniDbBoolean('settings', 'response_@chat', inversedState);
|
||||
$.reloadMisc();
|
||||
$.say($.whisperPrefix(sender) + (inversedState ? get('lang.response.enabled') : get('lang.response.disabled')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath toggleme - Toggle prepending chat output with "/me".
|
||||
*/
|
||||
if (command.equalsIgnoreCase('toggleme')) {
|
||||
inversedState = !$.getIniDbBoolean('settings', 'response_action');
|
||||
|
||||
$.setIniDbBoolean('settings', 'response_action', inversedState);
|
||||
$.reloadMisc();
|
||||
$.say($.whisperPrefix(sender) + (inversedState ? get('lang.response.action.enabled') : get('lang.response.action.disabled')));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/lang.js', 'lang', 1);
|
||||
$.registerChatCommand('./core/lang.js', 'mute', 1);
|
||||
$.registerChatCommand('./core/lang.js', 'toggleme', 1);
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.lang = {
|
||||
exists: exists,
|
||||
get: get,
|
||||
register: register,
|
||||
paramCount: paramCount
|
||||
};
|
||||
|
||||
// Run the load function to enable modules, loaded after lang.js, to access the language strings immediatly
|
||||
load();
|
||||
})();
|
||||
404
libs/phantombot/scripts/core/logging.js
Normal file
404
libs/phantombot/scripts/core/logging.js
Normal file
@@ -0,0 +1,404 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* logging.js
|
||||
*
|
||||
* Provide and API for logging events and errors
|
||||
* Use the $ API for log functions
|
||||
* Use the $.logging API for getting log-like date and time strings
|
||||
*/
|
||||
(function() {
|
||||
var logDays = $.getSetIniDbNumber('settings', 'log_rotate_days', 30),
|
||||
logs = {
|
||||
file: $.getSetIniDbBoolean('settings', 'log.file', true),
|
||||
event: $.getSetIniDbBoolean('settings', 'log.event', true),
|
||||
error: $.getSetIniDbBoolean('settings', 'log.error', true)
|
||||
},
|
||||
cmdLogEnabled = $.getSetIniDbBoolean('discordSettings', 'customCommandLogs', false),
|
||||
cmdDiscordLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./core/logging.js')) {
|
||||
cmdLogEnabled = $.getSetIniDbBoolean('discordSettings', 'customCommandLogs', false);
|
||||
cmdDiscordLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* function reloadLogs()
|
||||
*/
|
||||
function reloadLogs() {
|
||||
$.getIniDbNumber('settings', 'log_rotate_days');
|
||||
logs.file = $.getIniDbBoolean('settings', 'log.file');
|
||||
logs.event = $.getIniDbBoolean('settings', 'log.event');
|
||||
logs.error = $.getIniDbBoolean('settings', 'log.error');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getLogDateString
|
||||
*
|
||||
* @export $.logging
|
||||
* @param {Number} timeStamp
|
||||
* @return {String}
|
||||
*/
|
||||
function getLogDateString(timeStamp) {
|
||||
var now = (timeStamp ? new Date(timeStamp) : new Date()),
|
||||
pad = function(i) {
|
||||
return (i < 10 ? '0' + i : i);
|
||||
};
|
||||
|
||||
return pad(now.getDate()) + '-' + pad(now.getMonth() + 1) + '-' + now.getFullYear();
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getLogTimeString
|
||||
*
|
||||
* @export $.logging
|
||||
* @param {Number} timeStamp
|
||||
* @return {String}
|
||||
*/
|
||||
function getLogTimeString(timeStamp) {
|
||||
if (timeStamp) {
|
||||
return (new Date(timeStamp)).toLocaleTimeString('en-GB').replace(' ', '_');
|
||||
} else {
|
||||
return (new Date()).toTimeString();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getLogEntryTimeDateString
|
||||
*
|
||||
* @export $.logging
|
||||
* @return {String}
|
||||
*/
|
||||
function getLogEntryTimeDateString() {
|
||||
var dateFormat = new java.text.SimpleDateFormat("MM-dd-yyyy @ HH:mm:ss.SSS z");
|
||||
|
||||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone(($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : 'GMT')));
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logCustomCommand
|
||||
*
|
||||
* @param {object} info
|
||||
*/
|
||||
function logCustomCommand(info) {
|
||||
var lines = Object.keys(info).map(function(key) {
|
||||
return '**' + $.lang.get('discord.customcommandlogs.' + key) + '**: ' + info[key];
|
||||
});
|
||||
$.log.file('customCommands', lines.join('\r\n'));
|
||||
if (!$.hasDiscordToken && cmdLogEnabled && cmdDiscordLogChannel) {
|
||||
$.discordAPI.sendMessageEmbed(cmdDiscordLogChannel, 'blue', lines.join('\r\n\r\n'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logfile
|
||||
*
|
||||
* @export $
|
||||
* @param {String} filePrefix
|
||||
* @param {String} message
|
||||
* @param {String} sender
|
||||
*/
|
||||
function logfile(filePrefix, message, sender) {
|
||||
if (logs.file === false || message.indexOf('.mods') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory('./logs/' + filePrefix + '/')) {
|
||||
if (!$.isDirectory('./logs/')) {
|
||||
$.mkDir('./logs');
|
||||
}
|
||||
$.mkDir('./logs/' + filePrefix);
|
||||
}
|
||||
|
||||
$.writeToFile('[' + getLogEntryTimeDateString() + '] ' + message, './logs/' + filePrefix + '/' + getLogDateString() + '.txt', true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logEvent
|
||||
*
|
||||
* @export $
|
||||
* @param {string} message
|
||||
*/
|
||||
function logEvent(message) {
|
||||
if (logs.event === false || message.indexOf('specialuser') !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory('./logs/events')) {
|
||||
if (!$.isDirectory('./logs/')) {
|
||||
$.mkDir('./logs');
|
||||
}
|
||||
$.mkDir('./logs/event');
|
||||
}
|
||||
|
||||
try {
|
||||
throw new Error('eventlog');
|
||||
} catch (e) {
|
||||
sourceFile = e.stack.split('\n')[1].split('@')[1];
|
||||
}
|
||||
|
||||
$.writeToFile('[' + getLogEntryTimeDateString() + '] [' + sourceFile.trim() + '] ' + message, './logs/event/' + getLogDateString() + '.txt', true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logError
|
||||
*
|
||||
* @export $
|
||||
* @param {String} message
|
||||
*/
|
||||
function logError(message) {
|
||||
if (logs.error === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory('./logs/error/')) {
|
||||
if (!$.isDirectory('./logs/')) {
|
||||
$.mkDir('./logs');
|
||||
}
|
||||
$.mkDir('./logs/error');
|
||||
}
|
||||
|
||||
try {
|
||||
throw new Error('errorlog');
|
||||
} catch (e) {
|
||||
sourceFile = e.stack.split('\n')[1].split('@')[1];
|
||||
}
|
||||
|
||||
$.writeToFile('[' + getLogEntryTimeDateString() + '] [' + sourceFile.trim() + '] ' + message, './logs/error/' + getLogDateString() + '.txt', true);
|
||||
Packages.com.gmt2001.Console.err.printlnRhino(java.util.Objects.toString('[' + sourceFile.trim() + '] ' + message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logWarning
|
||||
*
|
||||
* @export $
|
||||
* @param {String} message
|
||||
*/
|
||||
function logWarning(message) {
|
||||
if (logs.error === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory('./logs/warning/')) {
|
||||
if (!$.isDirectory('./logs/')) {
|
||||
$.mkDir('./logs');
|
||||
}
|
||||
$.mkDir('./logs/warning');
|
||||
}
|
||||
|
||||
try {
|
||||
throw new Error('warninglog');
|
||||
} catch (e) {
|
||||
sourceFile = e.stack.split('\n')[1].split('@')[1];
|
||||
}
|
||||
|
||||
$.writeToFile('[' + getLogEntryTimeDateString() + '] [' + sourceFile.trim() + '] ' + message, './logs/warning/' + getLogDateString() + '.txt', true);
|
||||
Packages.com.gmt2001.Console.warn.printlnRhino(java.util.Objects.toString(message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function logRotate
|
||||
*/
|
||||
function logRotate() {
|
||||
var logFiles,
|
||||
idx,
|
||||
logFileDate,
|
||||
logDirs = ['chat', 'chatModerator', 'core', 'core-debug', 'core-error', 'error', 'event', 'patternDetector', 'pointSystem', 'private-messages'],
|
||||
logDirIdx,
|
||||
datefmt = new java.text.SimpleDateFormat('dd-MM-yyyy'),
|
||||
date,
|
||||
rotateDays = $.getIniDbNumber('settings', 'log_rotate_days') * 24 * 60 * 6e4,
|
||||
checkDate = $.systemTime() - rotateDays;
|
||||
|
||||
if (rotateDays === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.log.event('Starting Log Rotation');
|
||||
for (logDirIdx = 0; logDirIdx < logDirs.length; logDirIdx++) {
|
||||
logFiles = $.findFiles('./logs/' + logDirs[logDirIdx], 'txt');
|
||||
for (idx = 0; idx < logFiles.length; idx++) {
|
||||
logFileDate = logFiles[idx].match(/(\d{2}-\d{2}-\d{4})/)[1];
|
||||
date = datefmt.parse(logFileDate);
|
||||
if (date.getTime() < checkDate) {
|
||||
$.log.event('Log Rotate: Deleted ./logs/' + logDirs[logDirIdx] + '/' + logFiles[idx]);
|
||||
$.deleteFile('./logs/' + logDirs[logDirIdx] + '/' + logFiles[idx], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
$.log.event('Finished Log Rotation');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
logfile('chat', '' + event.getSender() + ': ' + event.getMessage());
|
||||
});
|
||||
|
||||
/*
|
||||
* @event ircPrivateMessage
|
||||
*/
|
||||
$.bind('ircPrivateMessage', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
message = event.getMessage().toLowerCase();
|
||||
|
||||
if (message.startsWith('specialuser')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.indexOf('the moderators if this room') === -1) {
|
||||
logfile('private-messages', '' + sender + ': ' + message);
|
||||
}
|
||||
|
||||
if (sender.equalsIgnoreCase('jtv')) {
|
||||
if (message.equalsIgnoreCase('clearchat')) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.clearchat'));
|
||||
} else if (message.indexOf('clearchat') !== -1) {
|
||||
logEvent($.lang.get('console.received.purgetimeoutban', message.substring(10)));
|
||||
} else if (message.indexOf('now in slow mode') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.slowmode.start', message.substring(message.indexOf('every') + 6)));
|
||||
} else if (message.indexOf('no longer in slow mode') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.slowmode.end'));
|
||||
} else if (message.indexOf('now in subscribers-only') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.subscriberonly.start'));
|
||||
} else if (message.indexOf('no longer in subscribers-only') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.subscriberonly.end'));
|
||||
} else if (message.indexOf('now in r9k') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.r9k.start'));
|
||||
} else if (message.indexOf('no longer in r9k') !== -1) {
|
||||
logfile('private-messages', '' + $.lang.get('console.received.r9k.end'));
|
||||
} else if (message.indexOf('hosting') !== -1) {
|
||||
var target = String(message).replace(/now hosting /ig, '').replace(/\./ig, '');
|
||||
|
||||
if (target.equalsIgnoreCase('-')) {
|
||||
$.bot.channelIsHosting = null;
|
||||
logfile('private-messages', '' + $.lang.get('console.received.host.end'));
|
||||
} else {
|
||||
$.bot.channelIsHosting = target;
|
||||
logfile('private-messages', '' + $.lang.get('console.received.host.start', target));
|
||||
}
|
||||
} else {
|
||||
logfile('private-messages', '' + sender + ': ' + message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
sender = event.getSender(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('log')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('logging.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath log rotatedays [days] - Display or set number of days to rotate the logs. 0 to disable log rotation.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rotatedays')) {
|
||||
if (args[1] === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('logging.rotatedays.usage', $.getIniDbNumber('settings', 'log_rotate_days')));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('logging.rotatedays.usage', $.getIniDbNumber('settings', 'log_rotate_days')));
|
||||
return;
|
||||
}
|
||||
if (parseInt(args[1]) === 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('logging.rotatedays.success.off'));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('logging.rotatedays.success', args[1]));
|
||||
}
|
||||
$.inidb.set('settings', 'log_rotate_days', args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath log files - Toggle the logging of files
|
||||
*/
|
||||
if (action.equalsIgnoreCase('files')) {
|
||||
logs.file = !logs.file;
|
||||
$.setIniDbBoolean('settings', 'log.file', logs.file);
|
||||
$.say($.whisperPrefix(sender) + (logs.file ? $.lang.get('logging.enabled.files') : $.lang.get('logging.disabled.files')));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath log events - Toggle the logging of events
|
||||
*/
|
||||
if (action.equalsIgnoreCase('events')) {
|
||||
logs.event = !logs.event;
|
||||
$.setIniDbBoolean('settings', 'log.event', logs.event);
|
||||
$.say($.whisperPrefix(sender) + (logs.event ? $.lang.get('logging.enabled.event') : $.lang.get('logging.disabled.event')));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath log errors - Toggle the logging of errors
|
||||
*/
|
||||
if (action.equalsIgnoreCase('errors')) {
|
||||
logs.error = !logs.error;
|
||||
$.setIniDbBoolean('settings', 'log.error', logs.error);
|
||||
$.say($.whisperPrefix(sender) + (logs.error ? $.lang.get('logging.enabled.error') : $.lang.get('logging.disabled.error')));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var interval = setInterval(function() {
|
||||
logRotate();
|
||||
}, 24 * 60 * 6e4, 'scripts::core::logging.js');
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/logging.js', 'log', 1);
|
||||
|
||||
logRotate();
|
||||
});
|
||||
|
||||
/* Export functions to API */
|
||||
$.logging = {
|
||||
getLogEntryTimeDateString: getLogEntryTimeDateString,
|
||||
getLogDateString: getLogDateString,
|
||||
getLogTimeString: getLogTimeString
|
||||
};
|
||||
|
||||
$.log = {
|
||||
file: logfile,
|
||||
event: logEvent,
|
||||
error: logError,
|
||||
warn: logWarning
|
||||
};
|
||||
|
||||
$.reloadLogs = reloadLogs;
|
||||
$.logCustomCommand = logCustomCommand;
|
||||
})();
|
||||
821
libs/phantombot/scripts/core/misc.js
Normal file
821
libs/phantombot/scripts/core/misc.js
Normal file
@@ -0,0 +1,821 @@
|
||||
/*
|
||||
* 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 currentHostTarget = '',
|
||||
respond = getSetIniDbBoolean('settings', 'response_@chat', true),
|
||||
action = getSetIniDbBoolean('settings', 'response_action', false),
|
||||
secureRandom = new java.security.SecureRandom(),
|
||||
reg = new RegExp(/^@\w+,\s?$/),
|
||||
timeout = 0;
|
||||
|
||||
/*
|
||||
* @function reloadMisc
|
||||
*/
|
||||
function reloadMisc() {
|
||||
respond = getIniDbBoolean('settings', 'response_@chat');
|
||||
action = getIniDbBoolean('settings', 'response_action');
|
||||
}
|
||||
|
||||
/**
|
||||
** This function sometimes does not work. So only use it for stuff that people dont use much
|
||||
* @function hasKey
|
||||
* @export $.list
|
||||
* @param {Array} list
|
||||
* @param {*} value
|
||||
* @param {Number} [subIndex]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasKey(list, value, subIndex) {
|
||||
var i;
|
||||
|
||||
if (subIndex > -1) {
|
||||
for (i in list) {
|
||||
if (list[i][subIndex].equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i in list) {
|
||||
if (list[i].equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getMessageWrites
|
||||
*/
|
||||
function getMessageWrites() {
|
||||
return parseInt($.session.getWrites());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isKnown
|
||||
* @export $.user
|
||||
* @param {string} username
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isKnown(username) {
|
||||
return $.inidb.exists('visited', username.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function sanitize
|
||||
* @export $.user
|
||||
* @param {string} username
|
||||
* @returns {string}
|
||||
*/
|
||||
function sanitize(username) {
|
||||
return (username == null ? username : String(username).replace(/\W/g, '').toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isFollower
|
||||
* @export $.user
|
||||
* @param {string} username
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isFollower(username) {
|
||||
var userFollowsCheck;
|
||||
|
||||
if ($.inidb.exists('followed', username.toLowerCase())) {
|
||||
return true;
|
||||
} else {
|
||||
userFollowsCheck = $.twitch.GetUserFollowsChannel(username.toLowerCase(), $.channelName.toLowerCase());
|
||||
if (userFollowsCheck.getInt('_http') == 200) {
|
||||
$.inidb.set('followed', username.toLowerCase(), true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCurrentHostTarget
|
||||
* @export $
|
||||
* @returns {string}
|
||||
*/
|
||||
function getCurrentHostTarget() {
|
||||
return currentHostTarget.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function strlen
|
||||
* @export $
|
||||
* @param {string} str
|
||||
* @returns {Number}
|
||||
*/
|
||||
function strlen(str) {
|
||||
if (str == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((typeof str.length) instanceof java.lang.String) {
|
||||
if ((typeof str.length).equalsIgnoreCase('number')) {
|
||||
return str.length;
|
||||
} else {
|
||||
return str.length;
|
||||
}
|
||||
} else {
|
||||
if ((typeof str.length) == 'number') {
|
||||
return str.length;
|
||||
} else {
|
||||
return str.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function equalsIgnoreCase(str1, str2) {
|
||||
try {
|
||||
return str1.equalsIgnoreCase(str2);
|
||||
} catch (e) {
|
||||
try {
|
||||
return str1.toLowerCase() == str2.toLowerCase();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function say
|
||||
* @export $
|
||||
* @param {string} message
|
||||
*/
|
||||
function say(message) {
|
||||
if (reg.test(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (respond && !action) {
|
||||
$.session.say(message);
|
||||
} else {
|
||||
if (respond && action) {
|
||||
// If the message is a Twitch command, remove the /me.
|
||||
if (message.startsWith('.') || message.startsWith('/')) {
|
||||
$.session.say(message);
|
||||
} else {
|
||||
$.session.say('/me ' + message);
|
||||
}
|
||||
}
|
||||
if (!respond) {
|
||||
$.consoleLn('[MUTED] ' + message);
|
||||
$.log.file('chat', '[MUTED] ' + $.botName.toLowerCase() + ': ' + message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
$.log.file('chat', '' + $.botName.toLowerCase() + ': ' + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function say
|
||||
* @export $
|
||||
* @param {string} message
|
||||
* @param {boolean} run
|
||||
*/
|
||||
function sayWithTimeout(message, run) {
|
||||
if (((timeout + 10000) > systemTime()) || !run) {
|
||||
return;
|
||||
}
|
||||
|
||||
timeout = systemTime();
|
||||
|
||||
say(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function systemTime
|
||||
* @export $
|
||||
* @returns {Number}
|
||||
*/
|
||||
function systemTime() {
|
||||
return parseInt(java.lang.System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function systemTimeNano
|
||||
* @export $
|
||||
* @returns {Number}
|
||||
*/
|
||||
function systemTimeNano() {
|
||||
return parseInt(java.lang.System.nanoTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function rand
|
||||
* @export $
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
function rand(max) {
|
||||
if (max == 0) {
|
||||
return max;
|
||||
}
|
||||
return (Math.abs(secureRandom.nextInt()) % max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function randRange
|
||||
* @export $
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
function randRange(min, max) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
return parseInt(rand(max - min + 1) + min);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function randElement
|
||||
* @export $
|
||||
* @param {Array} array
|
||||
* @returns {*}
|
||||
*/
|
||||
function randElement(array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array[randRange(0, array.length - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function arrayShuffle
|
||||
* @param {Array} array
|
||||
* @returns {Array}
|
||||
*/
|
||||
function arrayShuffle(array) {
|
||||
for (var i = array.length - 1; i > 0; i--) {
|
||||
var j = Math.floor(Math.random() * (i + 1));
|
||||
var temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function randInterval
|
||||
* @export $
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
function randInterval(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function trueRandRange
|
||||
* @export $
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
function trueRandRange(min, max) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
|
||||
try {
|
||||
var HttpRequest = Packages.com.gmt2001.HttpRequest,
|
||||
HashMap = Packages.java.util.HashMap,
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
json = new JSONObject('{}'),
|
||||
parameters = new JSONObject('{}'),
|
||||
header = new HashMap(1),
|
||||
id = rand(65535),
|
||||
request;
|
||||
|
||||
header.put('Content-Type', 'application/json-rpc');
|
||||
|
||||
parameters
|
||||
.put('apiKey', '0d710311-5840-45dd-be83-82904de87c5d')
|
||||
.put('n', 1)
|
||||
.put('min', min)
|
||||
.put('max', max)
|
||||
.put('replacement', true)
|
||||
.put('base', 10);
|
||||
|
||||
json
|
||||
.put('jsonrpc', '2.0')
|
||||
.put('method', 'generateIntegers')
|
||||
.put('params', parameters)
|
||||
.put('id', id);
|
||||
|
||||
request = HttpRequest.getData(
|
||||
HttpRequest.RequestType.GET,
|
||||
'https://api.random.org/json-rpc/1/invoke',
|
||||
json.toString(),
|
||||
header
|
||||
);
|
||||
|
||||
if (request.success) {
|
||||
var data = new JSONObject(request.content)
|
||||
.getJSONObject('result')
|
||||
.getJSONObject('random')
|
||||
.getJSONArray('data');
|
||||
|
||||
if (data.length() > 0) {
|
||||
return data.getInt(0);
|
||||
}
|
||||
} else {
|
||||
if (request.httpCode == 0) {
|
||||
$.log.error('Failed to use random.org: ' + request.exception);
|
||||
} else {
|
||||
$.log.error('Failed to use random.org: HTTP' + request.httpCode + ' ' + request.content);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
$.log.error('Failed to use random.org: ' + error);
|
||||
}
|
||||
|
||||
return randRange(min, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function trueRandElement
|
||||
* @exprtto $
|
||||
* @param {Array} array
|
||||
* @returns {*}
|
||||
*/
|
||||
function trueRandElement(array) {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
return array[trueRand(array.length - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function trueRand
|
||||
* @export $
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
function trueRand(max) {
|
||||
return trueRandRange(0, max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function outOfRange
|
||||
* @export $
|
||||
* @param {Number} number
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function outOfRange(number, min, max) {
|
||||
return (number < min || number > max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getOrdinal
|
||||
* @export $
|
||||
* @param {Number} number
|
||||
* @returns {string}
|
||||
*/
|
||||
function getOrdinal(number) {
|
||||
var s = ["th", "st", "nd", "rd"],
|
||||
v = number % 100;
|
||||
return (number + (s[(v - 20) % 10] || s[v] || s[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getPercentage
|
||||
* @export $
|
||||
* @param {Number} current
|
||||
* @param {Number} total
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getPercentage(current, total) {
|
||||
return Math.ceil((current / total) * 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getIniDbBoolean
|
||||
* @export $
|
||||
* @param {string} fileName
|
||||
* @param {string|Number} key
|
||||
* @param {boolean} [defaultValue]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function getIniDbBoolean(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return ($.inidb.get(fileName, key) == 'true');
|
||||
} else {
|
||||
return (defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getSetIniDbBoolean
|
||||
* @export $
|
||||
* @param {string} fileName
|
||||
* @param {string|Number} key
|
||||
* @param {boolean} [defaultValue]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function getSetIniDbBoolean(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return ($.inidb.get(fileName, key) == 'true');
|
||||
} else {
|
||||
$.inidb.set(fileName, key, defaultValue.toString());
|
||||
return (defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @function setIniDbBoolean
|
||||
* @export $
|
||||
* @param {string} fileName
|
||||
* @param {string|Number} key
|
||||
* @param {boolean} state
|
||||
*/
|
||||
function setIniDbBoolean(fileName, key, state) {
|
||||
$.inidb.set(fileName, key, state.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getIniDbString
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
*/
|
||||
function getIniDbString(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return ($.inidb.get(fileName, key) + '');
|
||||
} else {
|
||||
return (defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getSetIniDbString
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
*/
|
||||
function getSetIniDbString(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return ($.inidb.get(fileName, key) + '');
|
||||
} else {
|
||||
$.inidb.set(fileName, key, defaultValue);
|
||||
return (defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setIniDbString
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
*/
|
||||
function setIniDbString(fileName, key, value) {
|
||||
$.inidb.set(fileName, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getIniDbNumber
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function getIniDbNumber(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return parseInt($.inidb.get(fileName, key));
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getSetIniDbNumber
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function getSetIniDbNumber(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return parseInt($.inidb.get(fileName, key));
|
||||
} else {
|
||||
$.inidb.set(fileName, key, defaultValue.toString());
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setIniDbNumber
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function setIniDbNumber(fileName, key, value) {
|
||||
$.inidb.set(fileName, key, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getIniDbFloat
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function getIniDbFloat(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return parseFloat($.inidb.get(fileName, key));
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getSetIniDbFloat
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function getSetIniDbFloat(fileName, key, defaultValue) {
|
||||
if ($.inidb.exists(fileName, key) == true) {
|
||||
return parseFloat($.inidb.get(fileName, key));
|
||||
} else {
|
||||
$.inidb.set(fileName, key, defaultValue.toString());
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setIniDbFloat
|
||||
* @export $
|
||||
* @param {string}
|
||||
* @param {string}
|
||||
* @param {number}
|
||||
*/
|
||||
function setIniDbFloat(fileName, key, value) {
|
||||
$.inidb.set(fileName, key, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function paginateArray
|
||||
* @export $
|
||||
* @param {Array} Input array of data to paginate
|
||||
* @param {String} Key in the $.lang system
|
||||
* @param {String} Seperator to use between items
|
||||
* @param {boolean} Use $.whisperPrefix(sender) ?
|
||||
* @param {String} Value of sender for $.whisperPrefix
|
||||
* @param {Number} Page to display, 0 for ALL
|
||||
* @return {Number} Total number of pages.
|
||||
*
|
||||
*/
|
||||
function paginateArray(array, langKey, sep, whisper, sender, display_page) {
|
||||
var idx,
|
||||
output = '',
|
||||
maxlen,
|
||||
hasNoLang = langKey.startsWith('NULL'),
|
||||
pageCount = 0;
|
||||
|
||||
if (display_page === undefined) {
|
||||
display_page = 0;
|
||||
}
|
||||
|
||||
maxlen = 440 - (hasNoLang ? langKey.length : $.lang.get(langKey).length);
|
||||
langKey = langKey.replace('NULL', '');
|
||||
for (idx in array) {
|
||||
output += array[idx];
|
||||
if (output.length >= maxlen) {
|
||||
pageCount++;
|
||||
if (display_page === 0 || display_page === pageCount) {
|
||||
if (output.length > 0) {
|
||||
if (whisper) {
|
||||
$.say($.whisperPrefix(sender) + (hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
} else {
|
||||
$.say((hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
}
|
||||
}
|
||||
}
|
||||
output = '';
|
||||
} else {
|
||||
if (idx < array.length - 1) {
|
||||
output += sep;
|
||||
}
|
||||
}
|
||||
}
|
||||
pageCount++;
|
||||
if (output.length > 0) {
|
||||
if (display_page === 0 || display_page === pageCount) {
|
||||
if (whisper) {
|
||||
$.say($.whisperPrefix(sender) + (hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
} else {
|
||||
$.say((hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function paginateArrayDiscord
|
||||
* @export $
|
||||
* @param {Array} Input array of data to paginate
|
||||
* @param {String} Key in the $.lang system
|
||||
* @param {String} Seperator to use between items
|
||||
* @param {String} Value of sender for $.whisperPrefix
|
||||
* @param {Number} Page to display, 0 for ALL
|
||||
* @return {Number} Total number of pages.
|
||||
*
|
||||
*/
|
||||
function paginateArrayDiscord(array, langKey, sep, channel, sender, display_page) {
|
||||
var idx,
|
||||
output = '',
|
||||
maxlen,
|
||||
hasNoLang = langKey.startsWith('NULL'),
|
||||
pageCount = 0;
|
||||
|
||||
if (display_page === undefined) {
|
||||
display_page = 0;
|
||||
}
|
||||
|
||||
maxlen = 1400 - (hasNoLang ? langKey.length : $.lang.get(langKey).length);
|
||||
langKey = langKey.replace('NULL', '');
|
||||
for (idx in array) {
|
||||
output += array[idx];
|
||||
if (output.length >= maxlen) {
|
||||
pageCount++;
|
||||
if (output.length > 0) {
|
||||
if (display_page === 0 || display_page === pageCount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(sender) + ' ' + (hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
}
|
||||
}
|
||||
output = '';
|
||||
} else {
|
||||
if (idx < array.length - 1) {
|
||||
output += sep;
|
||||
}
|
||||
}
|
||||
}
|
||||
pageCount++;
|
||||
if (output.length > 0) {
|
||||
if (display_page === 0 || display_page === pageCount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(sender) + ' ' + (hasNoLang ? (langKey + output) : $.lang.get(langKey, output)));
|
||||
}
|
||||
}
|
||||
return pageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from: https://jsperf.com/replace-vs-split-join-vs-replaceall/95s
|
||||
*
|
||||
* Implementation of string.replaceAll
|
||||
*
|
||||
* @function replace
|
||||
* @export $
|
||||
* @param {string}
|
||||
*/
|
||||
function replace(str, from, to) {
|
||||
var idx, parts = [], l = from.length, prev = 0;
|
||||
for (; ~(idx = str.indexOf(from, prev)); ) {
|
||||
parts.push(str.slice(prev, idx), to);
|
||||
prev = idx + l;
|
||||
}
|
||||
parts.push(str.slice(prev));
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from: https://github.com/tc39/proposal-string-matchall
|
||||
*
|
||||
* Implementation of string.matchAll
|
||||
*
|
||||
* @function matchAll
|
||||
* @export $
|
||||
* @param {type} str
|
||||
* @param {type} regex
|
||||
* @returns {Array}
|
||||
*/
|
||||
function matchAll(str, regex) {
|
||||
regex.lastIndex = 0;
|
||||
var matches = [];
|
||||
str.replace(regex, function () {
|
||||
var match = Array.prototype.slice.call(arguments, 0, -2);
|
||||
match.input = arguments[arguments.length - 1];
|
||||
match.index = arguments[arguments.length - 2];
|
||||
matches.push(match);
|
||||
});
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
function match(str, regex) {
|
||||
regex.lastIndex = 0;
|
||||
return str.match(regex);
|
||||
}
|
||||
|
||||
function test(str, regex) {
|
||||
regex.lastIndex = 0;
|
||||
return regex.test(str);
|
||||
}
|
||||
|
||||
function regexExec(str, regex) {
|
||||
regex.lastIndex = 0;
|
||||
return regex.exec(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function userPrefix
|
||||
* @export $
|
||||
* @param {username}
|
||||
*/
|
||||
function userPrefix(username, comma) {
|
||||
if (!comma) {
|
||||
return '@' + $.username.resolve(username) + ' ';
|
||||
}
|
||||
return '@' + $.username.resolve(username) + ', ';
|
||||
}
|
||||
|
||||
function javaString(str) {
|
||||
return new Packages.java.lang.String(str);
|
||||
}
|
||||
|
||||
function jsString(str) {
|
||||
return String(str + '');
|
||||
}
|
||||
|
||||
/** Export functions to API */
|
||||
$.user = {
|
||||
isKnown: isKnown,
|
||||
isFollower: isFollower,
|
||||
sanitize: sanitize
|
||||
};
|
||||
|
||||
$.arrayShuffle = arrayShuffle;
|
||||
$.getCurrentHostTarget = getCurrentHostTarget;
|
||||
$.getIniDbBoolean = getIniDbBoolean;
|
||||
$.getIniDbString = getIniDbString;
|
||||
$.getIniDbNumber = getIniDbNumber;
|
||||
$.getIniDbFloat = getIniDbFloat;
|
||||
$.getSetIniDbBoolean = getSetIniDbBoolean;
|
||||
$.getSetIniDbString = getSetIniDbString;
|
||||
$.getSetIniDbNumber = getSetIniDbNumber;
|
||||
$.getSetIniDbFloat = getSetIniDbFloat;
|
||||
$.setIniDbBoolean = setIniDbBoolean;
|
||||
$.setIniDbString = setIniDbString;
|
||||
$.setIniDbNumber = setIniDbNumber;
|
||||
$.setIniDbFloat = setIniDbFloat;
|
||||
$.getOrdinal = getOrdinal;
|
||||
$.getPercentage = getPercentage;
|
||||
$.outOfRange = outOfRange;
|
||||
$.rand = rand;
|
||||
$.randElement = randElement;
|
||||
$.randInterval = randInterval;
|
||||
$.randRange = randRange;
|
||||
$.say = say;
|
||||
$.strlen = strlen;
|
||||
$.systemTime = systemTime;
|
||||
$.trueRand = trueRand;
|
||||
$.trueRandElement = trueRandElement;
|
||||
$.trueRandRange = trueRandRange;
|
||||
$.paginateArray = paginateArray;
|
||||
$.replace = replace;
|
||||
$.matchAll = matchAll;
|
||||
$.match = match;
|
||||
$.test = test;
|
||||
$.regexExec = regexExec;
|
||||
$.userPrefix = userPrefix;
|
||||
$.reloadMisc = reloadMisc;
|
||||
$.hasKey = hasKey;
|
||||
$.systemTimeNano = systemTimeNano;
|
||||
$.getMessageWrites = getMessageWrites;
|
||||
$.sayWithTimeout = sayWithTimeout;
|
||||
$.paginateArrayDiscord = paginateArrayDiscord;
|
||||
$.equalsIgnoreCase = equalsIgnoreCase;
|
||||
$.javaString = javaString;
|
||||
$.jsString = jsString;
|
||||
})();
|
||||
537
libs/phantombot/scripts/core/panelCommands.js
Normal file
537
libs/phantombot/scripts/core/panelCommands.js
Normal file
@@ -0,0 +1,537 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This script is used to reload variables from scripts when you edit stuff on the panel. Only the bot can use these, and you can't disable them
|
||||
*/
|
||||
|
||||
(function() {
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
|
||||
/* reloads the betting vars */
|
||||
if (command.equalsIgnoreCase('reloadbet')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadBet();
|
||||
}
|
||||
|
||||
/** Adds or removes a user from the moderator cache */
|
||||
if (command.equalsIgnoreCase('permissionsetuser')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
if (parseInt(args[1]) <= 2) {
|
||||
$.addModeratorToCache(action.toLowerCase());
|
||||
} else {
|
||||
$.removeModeratorFromCache(action.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('reloadmisc')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.reloadMisc();
|
||||
$.reloadWhispers();
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the tipeeestream vars.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('tipeeestreamreload')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadTipeeeStream();
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the streamelements vars.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('streamelementsreload')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadStreamElements();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets permissions on a command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('permcomsilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
var group = args[1];
|
||||
|
||||
if (isNaN(parseInt(group))) {
|
||||
group = $.getGroupIdByName(group);
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
var subcommand = args[1],
|
||||
group = args[2];
|
||||
if (isNaN(parseInt(group))) {
|
||||
group = $.getGroupIdByName(group);
|
||||
}
|
||||
|
||||
$.inidb.set('permcom', action + ' ' + subcommand, group);
|
||||
$.updateSubcommandGroup(action, subcommand, group);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the command variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadcommand')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.addComRegisterAliases();
|
||||
$.addComRegisterCommands();
|
||||
if (action) {
|
||||
$.unregisterChatCommand(action);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers a command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('registerpanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.registerChatCommand(($.inidb.exists('tempDisabledCommandScript', args[0].toLowerCase()) ? $.inidb.get('tempDisabledCommandScript', args[0].toLowerCase()) : './commands/customCommands.js'), args[0].toLowerCase());
|
||||
$.inidb.del('tempDisabledCommandScript', args[0].toLowerCase());
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* unregtisters a command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('unregisterpanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.tempUnRegisterChatCommand(args[0].toLowerCase());
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the moderation variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadmod')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadModeration();
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('reloadkill')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadKill();
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('reloadraid')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadRaid();
|
||||
}
|
||||
|
||||
/* reloads the clip vars */
|
||||
if (command.equalsIgnoreCase('reloadclip')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadClips();
|
||||
}
|
||||
|
||||
/*
|
||||
* Clears the highlight
|
||||
*/
|
||||
if (command.equalsIgnoreCase("clearhighlightspanel")) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.inidb.RemoveFile("highlights");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* makes a highlight
|
||||
*/
|
||||
if (command.equalsIgnoreCase('highlightpanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
if (!$.isOnline($.channelName)) {
|
||||
return;
|
||||
}
|
||||
var streamUptimeMinutes = parseInt($.getStreamUptimeSeconds($.channelName) / 60);
|
||||
var hours = parseInt(streamUptimeMinutes / 60);
|
||||
var minutes = parseInt(streamUptimeMinutes % 60);
|
||||
if (minutes < 10) {
|
||||
minutes = "0" + minutes;
|
||||
}
|
||||
timestamp = hours + ":" + minutes;
|
||||
localDate = $.getCurLocalTimeString("'['dd-MM-yyyy']'");
|
||||
$.inidb.set('highlights', timestamp, localDate + ' ' + args.splice(0).join(' '));
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the title on stream
|
||||
*/
|
||||
if (command.equalsIgnoreCase('settitlesilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
var argsString = args.splice(0).join(' ');
|
||||
$.updateStatus($.channelName, argsString, sender, true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the game on stream
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setgamesilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
var argsString = args.splice(0).join(' ');
|
||||
$.updateGame($.channelName, argsString, sender, true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the community on stream
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setcommunitysilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
var argsString = args.join(' ').split(', ');
|
||||
$.updateCommunity($.channelName, argsString, sender, true);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the adventure variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadadventure')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadAdventure();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the gambling variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadgamble')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadGamble();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the roll variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('loadprizesroll')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.loadPrizes();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the roulette variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadroulette')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadRoulette();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the slot variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('loadprizes')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.loadPrizesSlot();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the bits variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadbits')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadBits();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the donation variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('donationpanelupdate')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.donationpanelupdate();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the follow variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('followerpanelupdate')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.updateFollowConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the host variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadhost')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.updateHost();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the subscriber variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('subscriberpanelupdate')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.updateSubscribeConfig();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the greeting variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('greetingspanelupdate')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.greetingspanelupdate();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the notice variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadnotice')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadNoticeSettings();
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the points variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadpoints')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.updateSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets a points bonus
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pointsbonuspanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.setTempBonus(action, args[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gives points to everyone in the channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pointsallpanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
for (var i in $.users) {
|
||||
$.inidb.incr('points', $.users[i].toLowerCase(), parseInt(action));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Takes points from everyone in the channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pointstakeallpanel')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
for (var i in $.users) {
|
||||
if ($.getUserPoints($.users[i].toLowerCase()) > parseInt(action)) {
|
||||
$.inidb.decr('points', $.users[i].toLowerCase(), parseInt(action));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the raffle variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadraffle')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadRaffle();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the rank variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('rankreloadtable')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.loadRanksTimeTable();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the ticket raffle variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadtraffle')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadTRaffle();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the time variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('updatetimesettings')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.updateTimeSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reloads the log variables.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('reloadlogs')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
$.reloadLogs();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
$.bind('initReady', function() {
|
||||
/* 10 second delay here because I don't want these commands to be registered first. */
|
||||
setTimeout(function() {
|
||||
$.registerChatCommand('./core/panelCommands.js', 'permissionsetuser', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadcommand', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'permcomsilent', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'registerpanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'unregisterpanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadmod', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'clearhighlightspanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'highlightpanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'settitlesilent', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'setgamesilent', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadadventure', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadgamble', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'loadprizesroll', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadroulette', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'loadprizes', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadbits', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'donationpanelupdate', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'followerpanelupdate', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadhost', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'subscriberpanelupdate', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'greetingspanelupdate', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadnotice', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadpoints', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'pointsallpanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'pointsbonuspanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'pointstakeallpanel', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadraffle', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'rankreloadtable', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadtraffle', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'updatetimesettings', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadlogs', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadbet', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'tipeeestreamreload', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'streamelementsreload', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'setcommunitysilent', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadclip', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadkill', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadraid', 30);
|
||||
$.registerChatCommand('./core/panelCommands.js', 'reloadmisc', 30);
|
||||
}, 10000);
|
||||
});
|
||||
})();
|
||||
231
libs/phantombot/scripts/core/panelHandler.js
Normal file
231
libs/phantombot/scripts/core/panelHandler.js
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
// Only tracks data for now.
|
||||
(function() {
|
||||
/*
|
||||
* @function addObjectToArray
|
||||
*
|
||||
* @param {String} table
|
||||
* @param {String} key
|
||||
* @param {String} type
|
||||
* @param {Object} object
|
||||
*/
|
||||
function addObjectToArray(table, key, type, object) {
|
||||
var array = ($.inidb.exists(table, key) ? JSON.parse($.inidb.get(table, key)) : []);
|
||||
|
||||
// Make sure it is an array.
|
||||
if (object.type === undefined) {
|
||||
object.type = type;
|
||||
}
|
||||
|
||||
// Add the object to the array.
|
||||
array.push(object);
|
||||
|
||||
// Only keep 50 objects in the array.
|
||||
if (array.length > 50) {
|
||||
// Sort for newer events
|
||||
array.sort(function(a, b) {
|
||||
return b.date - a.date;
|
||||
});
|
||||
|
||||
// Remove old events.
|
||||
array = array.slice(0, 50);
|
||||
}
|
||||
|
||||
// Save it.
|
||||
saveObject(table, key, array);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function saveObject
|
||||
*
|
||||
* @param {String} table
|
||||
* @param {String} key
|
||||
* @param {Object} object
|
||||
*/
|
||||
function saveObject(table, key, object) {
|
||||
$.inidb.set(table, key, JSON.stringify(object, function(key, value) {
|
||||
try {
|
||||
if (value.getClass() !== null) {
|
||||
switch (value) {
|
||||
case value instanceof java.lang.Number:
|
||||
return parseInt(value);
|
||||
case value instanceof java.lang.Boolean:
|
||||
return value.booleanValue();
|
||||
default:
|
||||
return (value + '');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
return value;
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getFormatedUptime
|
||||
*/
|
||||
function getFormatedUptime() {
|
||||
var streamUptimeMinutes = parseInt($.getStreamUptimeSeconds($.channelName) / 60),
|
||||
hours = parseInt(streamUptimeMinutes / 60),
|
||||
minutes = (parseInt(streamUptimeMinutes % 60) < 10 ? '0' + parseInt(streamUptimeMinutes % 60) : parseInt(streamUptimeMinutes % 60)),
|
||||
timestamp = hours + ':' + minutes;
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function updateStreamData
|
||||
*/
|
||||
function updateStreamData() {
|
||||
saveObject('panelData', 'stream', {
|
||||
'communities': $.twitchcache.getCommunities().join(','),
|
||||
'views' : $.twitchcache.getViews() + '',
|
||||
'followers' : $.getFollows($.channelName),
|
||||
'viewers' : $.getViewers($.channelName),
|
||||
'title' : $.getStatus($.channelName),
|
||||
'isLive' : $.isOnline($.channelName),
|
||||
'game' : $.getGame($.channelName),
|
||||
'uptime' : getFormatedUptime(),
|
||||
'chatters' : $.users.length,
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function() {
|
||||
updateStreamData();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchOffline
|
||||
*/
|
||||
$.bind('twitchOffline', function() {
|
||||
updateStreamData();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchFollow
|
||||
*/
|
||||
$.bind('twitchFollow', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Follower', {
|
||||
'username': event.getFollower(),
|
||||
'date' : $.systemTime()
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event bits
|
||||
*/
|
||||
$.bind('twitchBits', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Bits', {
|
||||
'username': event.getUsername(),
|
||||
'amount' : event.getBits(),
|
||||
'date' : $.systemTime()
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchAutoHosted
|
||||
*/
|
||||
$.bind('twitchAutoHosted', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Auto-Host', {
|
||||
'username': event.getHoster(),
|
||||
'viewers' : event.getUsers(),
|
||||
'date' : $.systemTime(),
|
||||
'isAuto' : true
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchHosted
|
||||
*/
|
||||
$.bind('twitchHosted', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Host', {
|
||||
'username': event.getHoster(),
|
||||
'viewers' : event.getUsers(),
|
||||
'date' : $.systemTime(),
|
||||
'isAuto' : false
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriber
|
||||
*/
|
||||
$.bind('twitchSubscriber', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Subscriber', {
|
||||
'username': event.getSubscriber(),
|
||||
'date' : $.systemTime(),
|
||||
'isReSub' : false,
|
||||
'months' : 0
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchPrimeSubscriber
|
||||
*/
|
||||
$.bind('twitchPrimeSubscriber', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Prime Subscriber', {
|
||||
'username': event.getSubscriber(),
|
||||
'date' : $.systemTime(),
|
||||
'isReSub' : false,
|
||||
'months' : 0
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchReSubscriber
|
||||
*/
|
||||
$.bind('twitchReSubscriber', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'ReSubscriber', {
|
||||
'username': event.getReSubscriber(),
|
||||
'months' : event.getMonths(),
|
||||
'date' : $.systemTime(),
|
||||
'isReSub' : true
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchSubscriptionGift', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Gifted Subscription', {
|
||||
'recipient': event.getRecipient(),
|
||||
'username' : event.getUsername(),
|
||||
'months' : event.getMonths(),
|
||||
'date' : $.systemTime(),
|
||||
'isReSub' : (parseInt(event.getMonths()) > 1)
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchRaid
|
||||
*/
|
||||
$.bind('twitchRaid', function(event) {
|
||||
addObjectToArray('panelData', 'data', 'Raid', {
|
||||
'username' : event.getUsername(),
|
||||
'viewers' : event.getViewers(),
|
||||
'date' : $.systemTime()
|
||||
});
|
||||
});
|
||||
|
||||
// Interval that updates stream data.
|
||||
setInterval(updateStreamData, 2e4);
|
||||
})();
|
||||
210
libs/phantombot/scripts/core/patternDetector.js
Normal file
210
libs/phantombot/scripts/core/patternDetector.js
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* patterDetector.js
|
||||
*
|
||||
* Export an API for checking chat messages for links, email addresses, excessive character sequenses etc.
|
||||
* Use the $.patternDetector API
|
||||
*/
|
||||
(function() {
|
||||
var patterns = {
|
||||
link: new RegExp('((?:(http|https|rtsp):\\/\\/(?:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\\'\\(\\)' + '\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-z0-9\\$\\-\\_' + '\\.\\+\\!\\*\\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?' + '((?:(?:[a-z0-9][a-z0-9\\-]{0,64}\\.)+' + '(?:' + '(?:aero|a[cdefgilmnoqrstuwxz])' + '|(?:biz|bike|bot|b[abdefghijmnorstvwyz])' + '|(?:com|c[acdfghiklmnoruvxyz])' + '|d[ejkmoz]' + '|(?:edu|e[cegrstu])' + '|(?:fyi|f[ijkmor])' + '|(?:gov|g[abdefghilmnpqrstuwy])' + '|(?:how|h[kmnrtu])' + '|(?:info|i[delmnoqrst])' + '|(?:jobs|j[emop])' + '|k[eghimnrwyz]' + '|l[abcikrstuvy]' + '|(?:mil|mobi|moe|m[acdeghklmnopqrstuvwxyz])' + '|(?:name|net|n[acefgilopruz])' + '|(?:org|om)' + '|(?:pro|p[aefghklmnrstwy])' + '|qa' + '|(?:r[eouw])' + '|(?:s[abcdeghijklmnortuvyz])' + '|(?:t[cdfghjklmnoprtvwz])' + '|u[agkmsyz]' + '|(?:vote|v[ceginu])' + '|(?:xxx)' + '|(?:watch|w[fs])' + '|y[etu]' + '|z[amw]))' + '|(?:(?:25[0-5]|2[0-4]' + '[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]' + '|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]' + '[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}' + '|[1-9][0-9]|[0-9])))' + '(?:\\:\\d{1,5})?)' + '(\\/(?:(?:[a-z0-9\\;\\/\\?\\:\\@\\&\\=\\#\\~' + '\\-\\.\\+\\!\\*\\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?' + '(?:\\b|$)' + '|(\\.[a-z]+\\/|magnet:\/\/|mailto:\/\/|ed2k:\/\/|irc:\/\/|ircs:\/\/|skype:\/\/|ymsgr:\/\/|xfire:\/\/|steam:\/\/|aim:\/\/|spotify:\/\/)', 'ig'),
|
||||
emotes: new RegExp('([0-9][0-9]-[0-9][0-9])|([0-9]-[0-9])', 'g'),
|
||||
repeatedSeq: /(.)(\1+)/ig,
|
||||
nonAlphaSeq: /([^a-z0-9 ])(\1+)/ig,
|
||||
nonAlphaCount: /([^a-z0-9 ])/ig,
|
||||
capsCount: /([A-Z])/g,
|
||||
meCheck: /^\/me/,
|
||||
fakePurge: new RegExp(/^<message \w+>|^<\w+ deleted>/i)
|
||||
};
|
||||
|
||||
/**
|
||||
* @function hasLinks
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasLinks(event) {
|
||||
return $.test(event.getMessage(), patterns.link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLinks
|
||||
* @export $.patternDetector
|
||||
* @param {String} message
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function getLinks(message) {
|
||||
// turn Java String into JavaScript string
|
||||
// https://github.com/mozilla/rhino/issues/638
|
||||
message = message + '';
|
||||
return $.match(message, patterns.link);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function logLastLink
|
||||
* @export $.patternDetector
|
||||
*/
|
||||
function logLastLink(event) {
|
||||
$.log.file('patternDetector', 'Matched link on message from ' + event.getSender() + ': ' + $.regexExec(event.getMessage(), patterns.link)[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLongestRepeatedSequence
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {number}
|
||||
*/
|
||||
function getLongestRepeatedSequence(event) {
|
||||
var sequences = $.match(event.getMessage(), patterns.repeatedSeq);
|
||||
|
||||
return (sequences === null ? 0 : sequences.sort(function(a, b) {
|
||||
return b.length - a.length;
|
||||
})[0].length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLongestNonLetterSequence
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {number}
|
||||
*/
|
||||
function getLongestNonLetterSequence(event) {
|
||||
var message = (event.getMessage() + ''),
|
||||
sequences = $.match(message, patterns.nonAlphaSeq);
|
||||
|
||||
return (sequences === null ? 0 : sequences.sort(function(a, b) {
|
||||
return b.length - a.length;
|
||||
})[0].length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getNumberOfNonLetters
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {number}
|
||||
*/
|
||||
function getNumberOfNonLetters(event) {
|
||||
var sequences = $.match(event.getMessage(), patterns.nonAlphaCount);
|
||||
|
||||
return (sequences === null ? 0 : sequences.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmotesCount
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {number}
|
||||
* @info this gets the emote count from the ircv3 tags and the emotes cache if enabled.
|
||||
*/
|
||||
function getEmotesCount(event) {
|
||||
var emotes = event.getTags().get('emotes'),
|
||||
matched = $.match(emotes, patterns.emotes),
|
||||
extraEmotes = $.emotesHandler.getEmotesMatchCount(event.getMessage());
|
||||
|
||||
return (matched === null ? extraEmotes : (matched.length + extraEmotes));
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getMessageWithoutEmotes
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {string}
|
||||
*/
|
||||
function getMessageWithoutEmotes(event, message) {
|
||||
var emotes = event.getTags().get('emotes'),
|
||||
str = message,
|
||||
i;
|
||||
|
||||
if (emotes.length() > 0) {
|
||||
emotes = emotes.replaceAll('[0-9]+:', '').split('/');
|
||||
for (i in emotes) {
|
||||
str = str.replace(getWordAt(message, parseInt(emotes[i].split('-')[0])), '');
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getWordAt
|
||||
*
|
||||
* @param {String} str
|
||||
* @param {Number} pos
|
||||
* @return {String}
|
||||
*/
|
||||
function getWordAt(str, pos) {
|
||||
str = String(str);
|
||||
pos = pos >>> 0;
|
||||
|
||||
var left = str.slice(0, pos + 2).search(/\S+$/),
|
||||
right = str.slice(pos).search(/\s/);
|
||||
|
||||
if (right < 0) {
|
||||
return str.slice(left);
|
||||
}
|
||||
|
||||
return str.slice(left, right + pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getNumberOfCaps
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {number}
|
||||
*/
|
||||
function getNumberOfCaps(event) {
|
||||
var sequences = $.match(getMessageWithoutEmotes(event, event.getMessage()), patterns.capsCount);
|
||||
|
||||
return (sequences === null ? 0 : sequences.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getColoredMessage
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function getColoredMessage(event) {
|
||||
return event.getMessage().indexOf('/me') === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getFakePurge
|
||||
* @export $.patternDetector
|
||||
* @param {Object} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function getFakePurge(event) {
|
||||
return $.test(String(event.getMessage()).replace(patterns.meCheck, ''), patterns.fakePurge);
|
||||
}
|
||||
|
||||
/** Export functions to API */
|
||||
$.patternDetector = {
|
||||
hasLinks: hasLinks,
|
||||
getLinks: getLinks,
|
||||
getLongestRepeatedSequence: getLongestRepeatedSequence,
|
||||
getLongestNonLetterSequence: getLongestNonLetterSequence,
|
||||
getNumberOfNonLetters: getNumberOfNonLetters,
|
||||
getEmotesCount: getEmotesCount,
|
||||
getMessageWithoutEmotes: getMessageWithoutEmotes,
|
||||
getNumberOfCaps: getNumberOfCaps,
|
||||
logLastLink: logLastLink,
|
||||
getColoredMessage: getColoredMessage,
|
||||
getFakePurge: getFakePurge
|
||||
};
|
||||
})();
|
||||
1147
libs/phantombot/scripts/core/permissions.js
Normal file
1147
libs/phantombot/scripts/core/permissions.js
Normal file
File diff suppressed because it is too large
Load Diff
531
libs/phantombot/scripts/core/streamInfo.js
Normal file
531
libs/phantombot/scripts/core/streamInfo.js
Normal file
@@ -0,0 +1,531 @@
|
||||
/*
|
||||
* 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 currentGame = null;
|
||||
var count = 1;
|
||||
var gamesPlayed;
|
||||
|
||||
/**
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function(event) {
|
||||
if (($.systemTime() - $.inidb.get('panelstats', 'playTimeReset')) >= (480 * 6e4)) {
|
||||
var uptime = getStreamUptimeSeconds($.channelName);
|
||||
$.inidb.set('panelstats', 'gameCount', 1);
|
||||
count = $.inidb.get('panelstats', 'gameCount');
|
||||
$.inidb.del('streamInfo', 'gamesPlayed');
|
||||
$.inidb.set('panelstats', 'playTimeStart', $.systemTime());
|
||||
$.inidb.set('panelstats', 'playTimeReset', $.systemTime());
|
||||
$.inidb.set('streamInfo', 'gamesPlayed', (count + ': ' + $.twitchcache.getGameTitle() + ' - ' + (uptime / 3600 < 10 ? '0' : '') + Math.floor(uptime / 3600) + ':' + ((uptime % 3600) / 60 < 10 ? '0' : '') + Math.floor((uptime % 3600) / 60) + '='));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchOffline
|
||||
*/
|
||||
$.bind('twitchOffline', function(event) {
|
||||
if (($.systemTime() - $.inidb.get('panelstats', 'playTimeReset')) >= (480 * 6e4)) {
|
||||
$.inidb.set('panelstats', 'playTimeStart', 0);
|
||||
$.inidb.set('panelstats', 'playTimeReset', 0);
|
||||
$.inidb.set('panelstats', 'gameCount', 1);
|
||||
$.inidb.del('streamInfo', 'gamesPlayed');
|
||||
}
|
||||
$.inidb.set('streamInfo', 'downtime', String($.systemTime()));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchGameChange
|
||||
*/
|
||||
$.bind('twitchGameChange', function(event) {
|
||||
var uptime = getStreamUptimeSeconds($.channelName);
|
||||
|
||||
if ($.isOnline($.channelName)) {
|
||||
$.inidb.set('panelstats', 'playTimeStart', $.systemTime());
|
||||
if ($.inidb.exists('streamInfo', 'gamesPlayed')) {
|
||||
$.inidb.incr('panelstats', 'gameCount', 1);
|
||||
count = $.inidb.get('panelstats', 'gameCount');
|
||||
gamesPlayed = $.inidb.get('streamInfo', 'gamesPlayed');
|
||||
gamesPlayed += (count + ': ' + $.twitchcache.getGameTitle() + ' - ' + (uptime / 3600 < 10 ? '0' : '') + Math.floor(uptime / 3600) + ':' + ((uptime % 3600) / 60 < 10 ? '0' : '') + Math.floor((uptime % 3600) / 60) + '=');
|
||||
$.inidb.set('streamInfo', 'gamesPlayed', gamesPlayed);
|
||||
} else {
|
||||
count = $.inidb.get('panelstats', 'gameCount');
|
||||
$.inidb.set('streamInfo', 'gamesPlayed', (count + ': ' + $.twitchcache.getGameTitle() + ' - ' + (uptime / 3600 < 10 ? '0' : '') + Math.floor(uptime / 3600) + ':' + ((uptime % 3600) / 60 < 10 ? '0' : '') + Math.floor((uptime % 3600) / 60) + '='));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @function getGamesPlayed()
|
||||
* @export $
|
||||
* @return string
|
||||
*/
|
||||
function getGamesPlayed() {
|
||||
if ($.inidb.exists('streamInfo', 'gamesPlayed')) {
|
||||
var games = $.inidb.get('streamInfo', 'gamesPlayed'),
|
||||
string = games.split('=').join(', ');
|
||||
|
||||
return string;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getPlayTime()
|
||||
* @export $
|
||||
*/
|
||||
function getPlayTime() {
|
||||
var playTime = parseInt($.inidb.get('panelstats', 'playTimeStart')),
|
||||
time;
|
||||
|
||||
if (playTime) {
|
||||
time = ($.systemTime() - playTime);
|
||||
return $.getTimeStringMinutes(time / 1000);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isOnline
|
||||
* @export $
|
||||
* @param {string} channelName
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isOnline(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
return $.twitchcache.isStreamOnlineString().equals('true');
|
||||
} else {
|
||||
return !$.twitch.GetStream(channelName).isNull('stream');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getStatus
|
||||
* @export $
|
||||
* @param {string} channelName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStatus(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
return ($.twitchcache.getStreamStatus() + '');
|
||||
} else {
|
||||
var channelData = $.twitch.GetChannel(channelName);
|
||||
|
||||
if (!channelData.isNull('status') && channelData.getInt('_http') == 200) {
|
||||
return channelData.getString('status');
|
||||
} else if (channelData.isNull('status') && channelData.getInt('_http') == 200) {
|
||||
return $.lang.get('common.twitch.no.status');
|
||||
}
|
||||
$.log.error('Failed to get the current status: ' + channelData.getString('message'));
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getGame
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getGame(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
return ($.twitchcache.getGameTitle() + '');
|
||||
} else {
|
||||
var channelData = $.twitch.GetChannel(channelName);
|
||||
|
||||
if (!channelData.isNull('game') && channelData.getInt('_http') == 200) {
|
||||
return channelData.getString("game");
|
||||
} else if (channelData.isNull('game') && channelData.getInt('_http') == 200) {
|
||||
return $.lang.get('common.twitch.no.game');
|
||||
}
|
||||
|
||||
if (!channelData.isNull('message')) {
|
||||
$.log.error('Failed to get the current game: ' + channelData.getString('message'));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLogo
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {Url}
|
||||
*/
|
||||
function getLogo(channelName) {
|
||||
var channel = $.twitch.GetChannel(channelName);
|
||||
|
||||
if (!channel.isNull('logo') && channel.getInt('_http') == 200) {
|
||||
return channel.getString('logo');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getStreamUptimeSeconds
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {number}
|
||||
*/
|
||||
function getStreamUptimeSeconds(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
return $.twitchcache.getStreamUptimeSeconds();
|
||||
} else {
|
||||
var stream = $.twitch.GetStream(channelName),
|
||||
now = new Date(),
|
||||
createdAtDate,
|
||||
time;
|
||||
|
||||
if (stream.isNull('stream')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
createdAtDate = new Date(stream.getJSONObject('stream').getString('created_at'));
|
||||
if (createdAtDate) {
|
||||
time = (now - createdAtDate);
|
||||
return Math.floor(time / 1000);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getStreamUptime
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStreamUptime(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
var uptime = $.twitchcache.getStreamUptimeSeconds();
|
||||
|
||||
if (uptime === 0) {
|
||||
$.consoleLn("Fallback uptime");
|
||||
var stream = $.twitch.GetStream(channelName),
|
||||
now = new Date(),
|
||||
createdAtDate,
|
||||
time;
|
||||
|
||||
if (stream.isNull('stream')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
createdAtDate = new Date(stream.getJSONObject('stream').getString('created_at'));
|
||||
time = (now - createdAtDate);
|
||||
return $.getTimeString(time / 1000);
|
||||
}
|
||||
return $.getTimeString(uptime);
|
||||
} else {
|
||||
var stream = $.twitch.GetStream(channelName),
|
||||
now = new Date(),
|
||||
createdAtDate,
|
||||
time;
|
||||
|
||||
if (stream.isNull('stream')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
createdAtDate = new Date(stream.getJSONObject('stream').getString('created_at'));
|
||||
if (createdAtDate) {
|
||||
time = now - createdAtDate;
|
||||
return $.getTimeString(time / 1000);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getStreamDownTime
|
||||
* @export $
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStreamDownTime() {
|
||||
var now = $.systemTime(),
|
||||
down = $.inidb.get('streamInfo', 'downtime'),
|
||||
time;
|
||||
|
||||
if (down > 0) {
|
||||
time = (now - down);
|
||||
return $.getTimeString(time / 1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getStreamStartedAt
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {string}
|
||||
*/
|
||||
function getStreamStartedAt(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
if ($.twitchcache.getStreamOnlineString === 'false') {
|
||||
return 'Stream is offline';
|
||||
}
|
||||
createdAtDate = new Date($.twitchcache.getStreamCreatedAt() + '');
|
||||
return $.dateToString(createdAtDate);
|
||||
} else {
|
||||
var stream = $.twitch.GetStream(channelName),
|
||||
createdAtDate;
|
||||
|
||||
if (stream.isNull('stream')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
createdAtDate = new Date(stream.getJSONObject('stream').getString('created_at'));
|
||||
return $.dateToString(createdAtDate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getViewers
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getViewers(channelName) {
|
||||
if ($.twitchCacheReady.equals('true') && channelName.equalsIgnoreCase($.channelName)) {
|
||||
return $.twitchcache.getViewerCount();
|
||||
} else {
|
||||
var stream = $.twitch.GetStream(channelName);
|
||||
|
||||
if (!stream.isNull('stream') && stream.getInt('_http') == 200) {
|
||||
return stream.getJSONObject('stream').getInt('viewers');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getFollows
|
||||
* @export $
|
||||
* @param channelName
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getFollows(channelName) {
|
||||
var channel = $.twitch.GetChannel(channelName);
|
||||
|
||||
if (!channel.isNull('followers') && channel.getInt('_http') == 200) {
|
||||
return channel.getInt('followers');
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getFollowDate
|
||||
* @export $
|
||||
* @param username
|
||||
* @param channelName
|
||||
*/
|
||||
function getFollowDate(sender, username, channelName) {
|
||||
username = $.user.sanitize(username);
|
||||
channelName = $.user.sanitize(channelName);
|
||||
|
||||
var user = $.twitch.GetUserFollowsChannel(username, channelName);
|
||||
|
||||
if (user.getInt('_http') === 404) {
|
||||
return $.lang.get('followhandler.follow.age.datefmt.404');
|
||||
}
|
||||
|
||||
var date = new Date(user.getString('created_at')),
|
||||
dateFormat = new java.text.SimpleDateFormat($.lang.get('followhandler.follow.age.datefmt')),
|
||||
dateFinal = dateFormat.format(date);
|
||||
|
||||
return dateFinal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getFollowAge
|
||||
* @export $
|
||||
* @param username
|
||||
* @param channelName
|
||||
*/
|
||||
function getFollowAge(sender, username, channelName) {
|
||||
username = $.user.sanitize(username);
|
||||
channelName = $.user.sanitize(channelName);
|
||||
|
||||
var user = $.twitch.GetUserFollowsChannel(username, channelName);
|
||||
|
||||
if (user.getInt('_http') === 404) {
|
||||
$.say($.lang.get('followhandler.follow.age.err.404', $.userPrefix(sender, true), username, channelName));
|
||||
return;
|
||||
}
|
||||
|
||||
var date = new Date(user.getString('created_at')),
|
||||
dateFormat = new java.text.SimpleDateFormat("MMMM dd', 'yyyy"),
|
||||
dateFinal = dateFormat.format(date),
|
||||
days = Math.floor((($.systemTime() - date.getTime()) / 1000) / 86400);
|
||||
|
||||
if (days > 0) {
|
||||
$.say($.lang.get('followhandler.follow.age.time.days', $.userPrefix(sender, true), username, channelName, dateFinal, days));
|
||||
} else {
|
||||
$.say($.lang.get('followhandler.follow.age.time', $.userPrefix(sender, true), username, channelName, dateFinal));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getChannelAge
|
||||
* @export $
|
||||
* @param event
|
||||
*/
|
||||
function getChannelAge(event) {
|
||||
var channelData = $.twitch.GetChannel((!event.getArgs()[0] ? event.getSender() : $.user.sanitize(event.getArgs()[0])));
|
||||
|
||||
if (channelData.getInt('_http') === 404) {
|
||||
$.say($.userPrefix(event.getSender(), true) + $.lang.get('channel.age.user.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
var date = new Date(channelData.getString('created_at')),
|
||||
dateFormat = new java.text.SimpleDateFormat("MMMM dd', 'yyyy"),
|
||||
dateFinal = dateFormat.format(date),
|
||||
days = Math.floor((Math.abs((date.getTime() - $.systemTime()) / 1000)) / 86400);
|
||||
|
||||
if (days > 0) {
|
||||
$.say($.lang.get('common.get.age.days', $.userPrefix(event.getSender(), true), (!event.getArgs()[0] ? event.getSender() : $.user.sanitize(event.getArgs()[0])), dateFinal, days));
|
||||
} else {
|
||||
$.say($.lang.get('common.get.age', $.userPrefix(event.getSender(), true), (!event.getArgs()[0] ? event.getSender() : $.user.sanitize(event.getArgs()[0])), dateFinal));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getSubscriberCount
|
||||
* @export $
|
||||
* @return {number} count
|
||||
*/
|
||||
function getSubscriberCount() {
|
||||
var jsonObject = $.twitch.GetChannelSubscriptions($.channelName.toLowerCase(), 100, 0, true);
|
||||
|
||||
if (jsonObject.getInt('_http') !== 200) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return jsonObject.getInt('_total') - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function updateGame
|
||||
* @export $
|
||||
* @param {string} channelName
|
||||
* @param {string} game
|
||||
* @param {string} sender
|
||||
* @param {boolean} silent
|
||||
*/
|
||||
function updateGame(channelName, game, sender, silent) {
|
||||
var http = $.twitch.UpdateChannel(channelName, '', game);
|
||||
|
||||
if (http.getBoolean('_success')) {
|
||||
if (http.getInt('_http') == 200) {
|
||||
if (!silent) {
|
||||
$.say($.lang.get('common.game.change', http.getString('game')));
|
||||
}
|
||||
|
||||
$.twitchcache.setGameTitle(http.getString('game'));
|
||||
$.inidb.set('streamInfo', 'game', http.getString('game'));
|
||||
$.log.event($.username.resolve(sender) + ' changed the current game to ' + http.getString('game'));
|
||||
if ($.bot.isModuleEnabled('./commands/deathctrCommand.js')) {
|
||||
$.deathUpdateFile(game);
|
||||
}
|
||||
} else {
|
||||
$.log.error('Failed to change the game. The Twitch API might be having issues.');
|
||||
$.log.error(http.getString('message'));
|
||||
}
|
||||
} else {
|
||||
$.log.error('Failed to change the game. Make sure you have your api oauth code set. https://phantombot.github.io/PhantomBot/oauth/');
|
||||
$.log.error(http.getString('_exception') + ' ' + http.getString('_exceptionMessage'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function updateStatus
|
||||
* @export $
|
||||
* @param {string} channelName
|
||||
* @param {string} status
|
||||
* @param {string} sender
|
||||
* @param {boolean} silent
|
||||
*/
|
||||
function updateStatus(channelName, status, sender, silent) {
|
||||
var http = $.twitch.UpdateChannel(channelName, status, '');
|
||||
|
||||
if (http.getBoolean('_success')) {
|
||||
if (http.getInt('_http') == 200) {
|
||||
if (!silent) {
|
||||
$.say($.lang.get('common.title.change', http.getString('status')));
|
||||
}
|
||||
$.twitchcache.setStreamStatus(http.getString('status'));
|
||||
$.inidb.set('streamInfo', 'title', http.getString('status'));
|
||||
$.log.event(sender + ' changed the current status to ' + http.getString('status'));
|
||||
} else {
|
||||
$.log.error('Failed to change the status. The Twitch API might be having issues.');
|
||||
$.log.error(http.getString('message'));
|
||||
}
|
||||
} else {
|
||||
$.log.error('Failed to change the status. Make sure you have your api oauth code set. https://phantombot.github.io/PhantomBot/oauth/');
|
||||
$.log.error(http.getString('_exception') + ' ' + http.getString('_exceptionMessage'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function updateStatus
|
||||
* @export $
|
||||
* @param {string} channelName
|
||||
* @param {string} communities
|
||||
* @param {string} sender
|
||||
* @param {boolean} silent
|
||||
*/
|
||||
function updateCommunity(channelName, communities, sender, silent) {
|
||||
var http = $.twitch.UpdateCommunities(channelName, communities);
|
||||
|
||||
if (http.getBoolean('_success') && http.getInt('_http') == 204) {
|
||||
if (!silent) {
|
||||
$.say($.lang.get('common.communities.change'));
|
||||
}
|
||||
$.twitchcache.setCommunities(communities);
|
||||
$.inidb.set('streamInfo', 'communities', communities.join(', '));
|
||||
} else {
|
||||
$.log.error('Failed to change the status. Make sure you have your api oauth code set. https://phantombot.github.io/PhantomBot/oauth/');
|
||||
$.log.error(http.getString('_exception') + ' ' + http.getString('_exceptionMessage'));
|
||||
}
|
||||
}
|
||||
|
||||
/** Export functions to API */
|
||||
$.getPlayTime = getPlayTime;
|
||||
$.getFollows = getFollows;
|
||||
$.getGame = getGame;
|
||||
$.getLogo = getLogo;
|
||||
$.getStatus = getStatus;
|
||||
$.getStreamStartedAt = getStreamStartedAt;
|
||||
$.getStreamUptime = getStreamUptime;
|
||||
$.getStreamUptimeSeconds = getStreamUptimeSeconds;
|
||||
$.getViewers = getViewers;
|
||||
$.isOnline = isOnline;
|
||||
$.updateGame = updateGame;
|
||||
$.updateStatus = updateStatus;
|
||||
$.updateCommunity = updateCommunity;
|
||||
$.getFollowAge = getFollowAge;
|
||||
$.getFollowDate = getFollowDate;
|
||||
$.getChannelAge = getChannelAge;
|
||||
$.getStreamDownTime = getStreamDownTime;
|
||||
$.getGamesPlayed = getGamesPlayed;
|
||||
$.getSubscriberCount = getSubscriberCount;
|
||||
})();
|
||||
548
libs/phantombot/scripts/core/timeSystem.js
Normal file
548
libs/phantombot/scripts/core/timeSystem.js
Normal file
@@ -0,0 +1,548 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* timeSystem.js
|
||||
*
|
||||
* Keep track of users in the channel and log their time in the channel
|
||||
* Exports various time formatting functions
|
||||
* Use the $ API
|
||||
*/
|
||||
(function() {
|
||||
var levelWithTime = $.getSetIniDbBoolean('timeSettings', 'timeLevel', false),
|
||||
timeLevelWarning = $.getSetIniDbBoolean('timeSettings', 'timeLevelWarning', true),
|
||||
keepTimeWhenOffline = $.getSetIniDbBoolean('timeSettings', 'keepTimeWhenOffline', true),
|
||||
hoursForLevelUp = $.getSetIniDbNumber('timeSettings', 'timePromoteHours', 50),
|
||||
regularsGroupId = 6,
|
||||
interval,
|
||||
inter;
|
||||
|
||||
/**
|
||||
* @function updateTimeSettings
|
||||
*/
|
||||
function updateTimeSettings() {
|
||||
levelWithTime = $.getIniDbBoolean('timeSettings', 'timeLevel');
|
||||
keepTimeWhenOffline = $.getIniDbBoolean('timeSettings', 'keepTimeWhenOffline');
|
||||
hoursForLevelUp = $.getIniDbNumber('timeSettings', 'timePromoteHours');
|
||||
timeLevelWarning = $.getIniDbBoolean('timeSettings', 'timeLevelWarning');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCurLocalTimeString
|
||||
* @export $
|
||||
* @param {String} timeformat
|
||||
* @returns {String}
|
||||
*
|
||||
* timeformat = java.text.SimpleDateFormat allowed formats:
|
||||
* Letter Date or Time Component Presentation Examples
|
||||
* G Era designator Text AD
|
||||
* y Year Year 1996; 96
|
||||
* M Month in year Month July; Jul; 07
|
||||
* w Week in year Number 27
|
||||
* W Week in month Number 2
|
||||
* D Day in year Number 189
|
||||
* d Day in month Number 9
|
||||
* F Day of week in month Number 2
|
||||
* E Day in week Text Tuesday; Tue
|
||||
* a AM/PM marker Text PM
|
||||
* H Hour in day (0-23) Number 0
|
||||
* k Hour in day (1-24) Number 24
|
||||
* K Hour in am/pm (0-11) Number 0
|
||||
* h Hour in am/pm (1-12) Number 12
|
||||
* m Minute in hour Number 30
|
||||
* s Second in minute Number 55
|
||||
* S Millisecond Number 978
|
||||
* z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
|
||||
* Z Time zone RFC 822 time zone -0800
|
||||
*
|
||||
* Note that fixed strings must be encapsulated with quotes. For example, the below inserts a comma
|
||||
* and paranthesis into the returned time string:
|
||||
*
|
||||
* getCurLocalTimeString("MMMM dd', 'yyyy hh:mm:ss zzz '('Z')'");
|
||||
*/
|
||||
function getCurLocalTimeString(format) {
|
||||
var dateFormat = new java.text.SimpleDateFormat(format);
|
||||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone(($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : "GMT")));
|
||||
return dateFormat.format(new java.util.Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLocalTimeString
|
||||
* @export $
|
||||
* @param {String} timeformat
|
||||
* @param {Number} utc_seconds
|
||||
* @return {String}
|
||||
*/
|
||||
function getLocalTimeString(format, utc_secs) {
|
||||
var dateFormat = new java.text.SimpleDateFormat(format);
|
||||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone(($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : "GMT")));
|
||||
return dateFormat.format(new java.util.Date(utc_secs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCurrentLocalTimeString
|
||||
* @export $
|
||||
* @param {String} timeformat
|
||||
* @param {String} timeZone
|
||||
* @return {String}
|
||||
*/
|
||||
function getCurrentLocalTimeString(format, timeZone) {
|
||||
var dateFormat = new java.text.SimpleDateFormat(format);
|
||||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone(timeZone));
|
||||
return dateFormat.format(new java.util.Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getLocalTime
|
||||
* @export $
|
||||
* @param {String} timeformat
|
||||
* @param {String} timeZone
|
||||
* @return {String}
|
||||
*/
|
||||
function getLocalTime() {
|
||||
var dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone(($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : "GMT")));
|
||||
return dateFormat.format(new java.util.Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function dateToString
|
||||
* @export $
|
||||
* @param {Date} date
|
||||
* @param {boolean} [timeOnly]
|
||||
* @returns {string}
|
||||
*/
|
||||
function dateToString(date, timeOnly) {
|
||||
var year = date.getFullYear(),
|
||||
month = date.getMonth() + 1,
|
||||
day = date.getDate(),
|
||||
hours = date.getHours(),
|
||||
minutes = date.getMinutes();
|
||||
|
||||
if (timeOnly) {
|
||||
return hours + ':' + minutes;
|
||||
} else {
|
||||
return day + '-' + month + '-' + year + ' @ ' + hours + ':' + minutes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getTimeString
|
||||
* @export $
|
||||
* @param {Number} time
|
||||
* @param {boolean} [hoursOnly]
|
||||
* @returns {string}
|
||||
*/
|
||||
function getTimeString(time, hoursOnly) {
|
||||
var floor = Math.floor,
|
||||
months = (time / 2628000);
|
||||
days = ((months % 1) * 30.42),
|
||||
hours = ((days % 1) * 24),
|
||||
minutes = ((hours % 1) * 60),
|
||||
seconds = ((minutes % 1) * 60);
|
||||
|
||||
if (hoursOnly) {
|
||||
return floor(time / 3600) + $.lang.get('common.hours3');
|
||||
} else {
|
||||
var timeStringParts = [],
|
||||
timeString = '';
|
||||
|
||||
// Append months if greater than one.
|
||||
if (months >= 1) {
|
||||
timeStringParts.push(floor(months) + ' ' + (months < 2 ? $.lang.get('common.time.month') : $.lang.get('common.time.months')));
|
||||
}
|
||||
|
||||
// Append days if greater than one.
|
||||
if (days >= 1) {
|
||||
timeStringParts.push(floor(days) + ' ' + (days < 2 ? $.lang.get('common.time.day') : $.lang.get('common.time.days')));
|
||||
}
|
||||
|
||||
// Append hours if greater than one.
|
||||
if (hours >= 1) {
|
||||
timeStringParts.push(floor(hours) + ' ' + (hours < 2 ? $.lang.get('common.time.hour') : $.lang.get('common.time.hours')));
|
||||
}
|
||||
|
||||
// Append minutes if greater than one.
|
||||
if (minutes >= 1) {
|
||||
timeStringParts.push(floor(minutes) + ' ' + (minutes < 2 ? $.lang.get('common.time.minute') : $.lang.get('common.time.minutes')));
|
||||
}
|
||||
|
||||
// Append seconds if greater than one.
|
||||
if (seconds >= 1) {
|
||||
timeStringParts.push(floor(seconds) + ' ' + (seconds < 2 ? $.lang.get('common.time.second') : $.lang.get('common.time.seconds')));
|
||||
}
|
||||
|
||||
// If the array is empty, return 0 seconds.
|
||||
if (timeStringParts.length === 0) {
|
||||
return ('0 ' + $.lang.get('common.time.seconds'));
|
||||
}
|
||||
|
||||
// Join the array to make a string.
|
||||
timeString = timeStringParts.join(', ');
|
||||
|
||||
// Replace last comma with ", and".
|
||||
if (timeString.indexOf(',') !== -1) {
|
||||
timeString = (timeString.substr(0, timeString.lastIndexOf(',')) + $.lang.get('common.time.and') + timeString.substr(timeString.lastIndexOf(',') + 2));
|
||||
}
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCountString
|
||||
* @export $
|
||||
* @param {Number} time
|
||||
* @param {boolean} [countUp]
|
||||
* @returns {string}
|
||||
*/
|
||||
function getCountString(time, countUp) {
|
||||
var floor = Math.floor,
|
||||
months = (time / 2628000);
|
||||
days = ((months % 1) * 30.42),
|
||||
hours = ((days % 1) * 24),
|
||||
minutes = ((hours % 1) * 60),
|
||||
seconds = ((minutes % 1) * 60);
|
||||
|
||||
var timeStringParts = [],
|
||||
timeString = '';
|
||||
|
||||
// Append months if greater than one.
|
||||
if (months >= 1) {
|
||||
timeStringParts.push(floor(months) + ' ' + (months < 2 ? $.lang.get('common.time.month') : $.lang.get('common.time.months')));
|
||||
}
|
||||
|
||||
// Append days if greater than one.
|
||||
if (days >= 1) {
|
||||
timeStringParts.push(floor(days) + ' ' + (days < 2 ? $.lang.get('common.time.day') : $.lang.get('common.time.days')));
|
||||
}
|
||||
|
||||
// Append hours if greater than one.
|
||||
if (hours >= 1) {
|
||||
timeStringParts.push(floor(hours) + ' ' + (hours < 2 ? $.lang.get('common.time.hour') : $.lang.get('common.time.hours')));
|
||||
}
|
||||
|
||||
// Append minutes if greater than one.
|
||||
if (minutes >= 1) {
|
||||
timeStringParts.push(floor(minutes) + ' ' + (minutes < 2 ? $.lang.get('common.time.minute') : $.lang.get('common.time.minutes')));
|
||||
}
|
||||
|
||||
// Append seconds if greater than one.
|
||||
if (seconds >= 1) {
|
||||
timeStringParts.push(floor(seconds) + ' ' + (seconds < 2 ? $.lang.get('common.time.second') : $.lang.get('common.time.seconds')));
|
||||
}
|
||||
|
||||
// If the array is empty, return 0 seconds.
|
||||
if (timeStringParts.length === 0) {
|
||||
if (countUp) {
|
||||
return ($.lang.get('common.time.nostart'));
|
||||
} else {
|
||||
return ($.lang.get('common.time.expired'));
|
||||
}
|
||||
}
|
||||
|
||||
// Join the array to make a string.
|
||||
timeString = timeStringParts.join(', ');
|
||||
|
||||
// Replace last comma with ", and".
|
||||
if (timeString.indexOf(',') !== -1) {
|
||||
timeString = (timeString.substr(0, timeString.lastIndexOf(',')) + $.lang.get('common.time.and') + timeString.substr(timeString.lastIndexOf(',') + 2));
|
||||
}
|
||||
return timeString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getTimeStringMinutes
|
||||
* @export $
|
||||
* @param {Number} time
|
||||
* @param {boolean} [hoursOnly]
|
||||
* @returns {string}
|
||||
*/
|
||||
function getTimeStringMinutes(time) {
|
||||
var floor = Math.floor,
|
||||
cHours = time / 3600,
|
||||
cMins = cHours % 1 * 60;
|
||||
|
||||
if (cHours == 0 || cHours < 1) {
|
||||
return (floor(~~cMins) + $.lang.get('common.minutes2'));
|
||||
} else {
|
||||
return (floor(cHours) + $.lang.get('common.hours2') + floor(~~cMins) + $.lang.get('common.minutes2'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserTime
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @returns {number}
|
||||
*/
|
||||
function getUserTime(username) {
|
||||
return ($.inidb.exists('time', username.toLowerCase()) ? $.inidb.get('time', username.toLowerCase()) : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserTimeString
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @returns {string}
|
||||
*/
|
||||
function getUserTimeString(username) {
|
||||
var floor = Math.floor,
|
||||
time = $.getUserTime(username.toLowerCase()),
|
||||
cHours = time / 3600,
|
||||
cMins = cHours % 1 * 60;
|
||||
|
||||
if (floor(cHours) > 0) {
|
||||
return ($.lang.get('user.time.string.hours', floor(cHours), floor(~~cMins)));
|
||||
} else {
|
||||
return ($.lang.get('user.time.string.minutes', floor(~~cMins)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
username = $.username.resolve(sender),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subject,
|
||||
timeArg;
|
||||
|
||||
/**
|
||||
* @commandpath time - Announce amount of time spent in channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('time')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get("timesystem.get.self", $.resolveRank(sender), getUserTimeString(sender)));
|
||||
} else if (action && $.inidb.exists('time', action.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get("timesystem.get.other", $.username.resolve(action), getUserTimeString(action)));
|
||||
} else {
|
||||
subject = args[1];
|
||||
timeArg = parseInt(args[2]);
|
||||
|
||||
/**
|
||||
* @commandpath time add [user] [seconds] - Add seconds to a user's logged time (for correction purposes)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
|
||||
if (!subject || isNaN(timeArg)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subject = $.user.sanitize(subject);
|
||||
|
||||
if (timeArg < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.add.error.negative'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.user.isKnown(subject)) {
|
||||
$.inidb.incr('time', subject, timeArg);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.add.success', getTimeString(timeArg), $.username.resolve(subject), getUserTimeString(subject)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', $.username.resolve(subject)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath time take [user] [seconds] - Take seconds from a user's logged time
|
||||
*/
|
||||
if (action.equalsIgnoreCase('take')) {
|
||||
if (!subject || isNaN(timeArg)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.take.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subject = $.user.sanitize(subject);
|
||||
if (!$.user.isKnown(subject)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', subject));
|
||||
}
|
||||
|
||||
if (timeArg > $.getUserTime(subject)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.take.error.toomuch', subject));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.decr('time', subject, timeArg);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.take.success', $.getTimeString(timeArg), $.username.resolve(subject), getUserTimeString(subject)))
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('set')) {
|
||||
if (!subject || isNaN(timeArg)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.settime.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeArg < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.settime.error.negative'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
subject = $.user.sanitize(subject);
|
||||
if ($.user.isKnown(subject)) {
|
||||
$.inidb.set('time', subject, timeArg);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.settime.success', $.username.resolve(subject), $.getUserTimeString(subject)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', subject));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath time promotehours [hours] - Set the amount of hours a user has to be logged to automatically become a regular
|
||||
*/
|
||||
if (action.equalsIgnoreCase('promotehours')) {
|
||||
if (isNaN(subject)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.promotehours.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subject < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.promotehours.error.negative', $.getGroupNameById(regularsGroupId)));
|
||||
return;
|
||||
}
|
||||
|
||||
hoursForLevelUp = parseInt(subject);
|
||||
$.inidb.set('timeSettings', 'timePromoteHours', hoursForLevelUp);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.promotehours.success', $.getGroupNameById(regularsGroupId), hoursForLevelUp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath time autolevel - Auto levels a user to regular after hitting 50 hours.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autolevel')) {
|
||||
levelWithTime = !levelWithTime;
|
||||
$.setIniDbBoolean('timeSettings', 'timeLevel', levelWithTime);
|
||||
$.say($.whisperPrefix(sender) + (levelWithTime ? $.lang.get('timesystem.autolevel.enabled', $.getGroupNameById(regularsGroupId), hoursForLevelUp) : $.lang.get('timesystem.autolevel.disabled', $.getGroupNameById(regularsGroupId), hoursForLevelUp)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath time autolevelnotification - Toggles if a chat announcement is made when a user is promoted to a regular.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autolevelnotification')) {
|
||||
timeLevelWarning = !timeLevelWarning;
|
||||
$.setIniDbBoolean('timeSettings', 'timeLevelWarning', timeLevelWarning);
|
||||
$.say($.whisperPrefix(sender) + (timeLevelWarning ? $.lang.get('timesystem.autolevel.chat.enabled') : $.lang.get('timesystem.autolevel.chat.disabled')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath time offlinetime - Toggle logging a user's time when the channel is offline
|
||||
*/
|
||||
if (action.equalsIgnoreCase('offlinetime')) {
|
||||
keepTimeWhenOffline = !keepTimeWhenOffline;
|
||||
$.setIniDbBoolean('timeSettings', 'keepTimeWhenOffline', keepTimeWhenOffline);
|
||||
$.say($.whisperPrefix(sender) + (keepTimeWhenOffline ? $.lang.get('timesystem.offlinetime.enabled') : $.lang.get('timesystem.offlinetime.disabled')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath streamertime - Announce the caster's local time
|
||||
*/
|
||||
if (command.equalsIgnoreCase('streamertime')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.streamertime', getCurLocalTimeString("MMMM dd', 'yyyy hh:mm:ss a zzz '('Z')'"), $.username.resolve($.ownerName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath timezone [timezone name] - Show configured timezone or optionally set the timezone. See List: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
||||
*/
|
||||
if (command.equalsIgnoreCase('timezone')) {
|
||||
var tzData;
|
||||
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.timezone.usage', ($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : "GMT")));
|
||||
return;
|
||||
}
|
||||
|
||||
tzData = java.util.TimeZone.getTimeZone(action);
|
||||
if (tzData.getID().equals("GMT") && !action.equals("GMT")) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.timezone.invalid', action));
|
||||
return;
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('timesystem.set.timezone.success', tzData.getID(), tzData.observesDaylightTime()));
|
||||
$.inidb.set('settings', 'timezone', tzData.getID());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Set an interval for increasing all current users logged time
|
||||
interval = setInterval(function() {
|
||||
var username,
|
||||
i;
|
||||
|
||||
if ($.isOnline($.channelName) || keepTimeWhenOffline) {
|
||||
$.inidb.IncreaseBatchString('time', '', $.users, '60');
|
||||
}
|
||||
}, 6e4, 'scripts::systems::timeSystem.js#1');
|
||||
|
||||
// Interval for auto level to regular
|
||||
inter = setInterval(function() {
|
||||
var username,
|
||||
i;
|
||||
|
||||
if (levelWithTime) {
|
||||
for (i in $.users) {
|
||||
username = $.users[i].toLowerCase();
|
||||
if (!$.isMod(username) && !$.isAdmin(username) && !$.isSub(username) && !$.isVIP(username) && $.inidb.exists('time', username) && Math.floor(parseInt($.inidb.get('time', username)) / 3600) >= hoursForLevelUp && parseInt($.getUserGroupId(username)) > regularsGroupId) {
|
||||
if (!$.hasModList(username)) { // Added a second check here to be 100% sure the user is not a mod.
|
||||
$.setUserGroupById(username, regularsGroupId);
|
||||
if (timeLevelWarning) {
|
||||
$.say($.lang.get(
|
||||
'timesystem.autolevel.promoted',
|
||||
$.username.resolve(username),
|
||||
$.getGroupNameById(regularsGroupId).toLowerCase(),
|
||||
hoursForLevelUp
|
||||
)); //No whisper mode needed here.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 9e5, 'scripts::systems::timeSystem.js#2');
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/timeSystem.js', 'streamertime');
|
||||
$.registerChatCommand('./core/timeSystem.js', 'timezone', 1);
|
||||
$.registerChatCommand('./core/timeSystem.js', 'time');
|
||||
|
||||
$.registerChatSubcommand('time', 'add', 1);
|
||||
$.registerChatSubcommand('time', 'take', 1);
|
||||
$.registerChatSubcommand('time', 'set', 1);
|
||||
$.registerChatSubcommand('time', 'autolevel', 1);
|
||||
$.registerChatSubcommand('time', 'promotehours', 1);
|
||||
$.registerChatSubcommand('time', 'autolevelnotification', 1);
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.dateToString = dateToString;
|
||||
$.getTimeString = getTimeString;
|
||||
$.getCountString = getCountString;
|
||||
$.getUserTime = getUserTime;
|
||||
$.getUserTimeString = getUserTimeString;
|
||||
$.getCurLocalTimeString = getCurLocalTimeString;
|
||||
$.getLocalTimeString = getLocalTimeString;
|
||||
$.getTimeStringMinutes = getTimeStringMinutes;
|
||||
$.updateTimeSettings = updateTimeSettings;
|
||||
$.getCurrentLocalTimeString = getCurrentLocalTimeString;
|
||||
$.getLocalTime = getLocalTime;
|
||||
})();
|
||||
980
libs/phantombot/scripts/core/updates.js
Normal file
980
libs/phantombot/scripts/core/updates.js
Normal file
@@ -0,0 +1,980 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* updater.js
|
||||
*
|
||||
* Update PhantomBot database
|
||||
*
|
||||
* This module will be executed before loading any of the other scripts even the core!
|
||||
* Add a new wrapped function if you want to apply updates for a new version
|
||||
*/
|
||||
|
||||
/**
|
||||
* PhantomBot v2.0
|
||||
*/
|
||||
(function() {
|
||||
var modules,
|
||||
versions,
|
||||
sounds,
|
||||
i;
|
||||
|
||||
/** New setup */
|
||||
if ($.changed == true && $.changed != null && $.changed != undefined && !$.inidb.exists('updates', 'installedNewBot') && $.inidb.get('updates', 'installedNewBot') != 'true') {
|
||||
$.consoleLn('');
|
||||
$.consoleLn('Initializing PhantomBot version ' + $.version + ' for the first time...');
|
||||
|
||||
modules = [
|
||||
'./commands/topCommand.js',
|
||||
'./commands/highlightCommand.js',
|
||||
'./commands/deathctrCommand.js',
|
||||
'./commands/dualstreamCommand.js',
|
||||
'./games/8ball.js',
|
||||
'./games/adventureSystem.js',
|
||||
'./games/killCommand.js',
|
||||
'./games/random.js',
|
||||
'./games/roll.js',
|
||||
'./games/roulette.js',
|
||||
'./games/slotMachine.js',
|
||||
'./games/gambling.js',
|
||||
'./handlers/followHandler.js',
|
||||
'./handlers/hostHandler.js',
|
||||
'./handlers/subscribeHandler.js',
|
||||
'./handlers/donationHandler.js',
|
||||
'./handlers/wordCounter.js',
|
||||
'./handlers/gameWispHandler.js',
|
||||
'./handlers/keywordHandler.js',
|
||||
'./handlers/twitterHandler.js',
|
||||
'./handlers/tipeeeStreamHandler.js',
|
||||
'./systems/cleanupSystem.js',
|
||||
'./systems/greetingSystem.js',
|
||||
'./systems/pointSystem.js',
|
||||
'./systems/noticeSystem.js',
|
||||
'./systems/pollSystem.js',
|
||||
'./systems/quoteSystem.js',
|
||||
'./systems/raffleSystem.js',
|
||||
'./systems/ticketraffleSystem.js',
|
||||
'./systems/raidSystem.js',
|
||||
'./systems/youtubePlayer.js',
|
||||
'./systems/ranksSystem.js',
|
||||
'./systems/auctionSystem.js',
|
||||
'./systems/audioPanelSystem.js',
|
||||
'./systems/queueSystem.js',
|
||||
'./systems/bettingSystem.js',
|
||||
'./commands/nameConverter.js',
|
||||
'./handlers/clipHandler.js',
|
||||
'./handlers/dataServiceHandler.js',
|
||||
'./handlers/gameScanHandler.js',
|
||||
'./discord/handlers/bitsHandler.js',
|
||||
'./discord/handlers/followHandler.js',
|
||||
'./discord/handlers/subscribeHandler.js',
|
||||
'./discord/handlers/tipeeeStreamHandler.js',
|
||||
'./discord/handlers/streamlabsHandler.js',
|
||||
'./discord/handlers/hostHandler.js',
|
||||
'./discord/handlers/twitterHandler.js',
|
||||
'./discord/handlers/keywordHandler.js',
|
||||
'./discord/handlers/streamHandler.js',
|
||||
'./discord/systems/greetingsSystem.js',
|
||||
'./discord/commands/customCommands.js',
|
||||
'./discord/games/8ball.js',
|
||||
'./discord/games/kill.js',
|
||||
'./discord/games/random.js',
|
||||
'./discord/games/roulette.js',
|
||||
'./discord/games/gambling.js',
|
||||
'./discord/games/roll.js',
|
||||
'./discord/games/slotMachine.js',
|
||||
'./discord/systems/pointSystem.js'
|
||||
];
|
||||
|
||||
$.consoleLn('Disabling default modules...');
|
||||
for (i in modules) {
|
||||
$.inidb.set('modules', modules[i], 'false');
|
||||
}
|
||||
|
||||
$.consoleLn('Adding default custom commands...');
|
||||
$.inidb.set('command', 'uptime', '(pointtouser) (channelname) has been online for (uptime)');
|
||||
$.inidb.set('command', 'followage', '(followage)');
|
||||
$.inidb.set('command', 'playtime', '(pointtouser) (channelname) has been playing (game) for (playtime)');
|
||||
$.inidb.set('command', 'title', '(pointtouser) (titleinfo)');
|
||||
$.inidb.set('command', 'game', '(pointtouser) (gameinfo)');
|
||||
$.inidb.set('command', 'age', '(age)');
|
||||
|
||||
$.consoleLn('Installing old updates...');
|
||||
versions = ['installedv2', 'installedv2.0.5', 'installedv2.0.6', 'installedv2.0.7', 'installedv2.0.7.2',
|
||||
'installedv2.0.8', 'installedv2.0.9', 'installedv2.1.0', 'installedv2.1.1', 'installedv2.2.1', 'installedv2.3s',
|
||||
'installedv2.3.3ss', 'installedv2.3.5ss', 'installedv2.3.5.1', 'installedv2.3.5.2', 'installedv2.3.5.3', 'installedv2.3.6',
|
||||
'installedv2.3.6ss', 'installedv2.3.6b', 'installedv2.3.7', 'installedv2.3.7b', 'installedv2.3.9', 'installedv2.3.9.1', 'installedv2.3.9.1b',
|
||||
'installedv2.4.0', 'installedv2.4.1'
|
||||
];
|
||||
for (i in versions) {
|
||||
$.inidb.set('updates', versions[i], 'true');
|
||||
}
|
||||
|
||||
sounds = "";
|
||||
modules = "";
|
||||
versions = "";
|
||||
$.changed = false;
|
||||
$.inidb.set('updates', 'installedNewBot', 'true');
|
||||
$.consoleLn('Initializing complete!');
|
||||
$.consoleLn('');
|
||||
}
|
||||
|
||||
/** Version 2.0 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2') || $.inidb.get('updates', 'installedv2') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0 updates...');
|
||||
var tableNamesList = $.inidb.GetFileList(),
|
||||
commandsBackup,
|
||||
timeBackup,
|
||||
pointsBackup,
|
||||
defaultDisabledModules = [
|
||||
'./games/8ball.js',
|
||||
'./games/adventureSystem.js',
|
||||
'./games/killCommand.js',
|
||||
'./commands/topCommand.js',
|
||||
'./games/random.js',
|
||||
'./games/roll.js',
|
||||
'./games/roulette.js',
|
||||
'./games/slotMachine.js',
|
||||
'./handlers/followHandler.js',
|
||||
'./handlers/hostHandler.js',
|
||||
'./handlers/subscribeHandler.js',
|
||||
'./handlers/donationHandler.js',
|
||||
'./systems/cleanupSystem.js',
|
||||
'./systems/greetingSystem.js',
|
||||
'./systems/pointSystem.js',
|
||||
'./systems/noticeSystem.js',
|
||||
'./systems/pollSystem.js',
|
||||
'./systems/quoteSystem.js',
|
||||
'./systems/raffleSystem.js',
|
||||
'./systems/ticketraffleSystem.js',
|
||||
'./systems/raidSystem.js',
|
||||
'./systems/youtubePlayer.js',
|
||||
'./systems/audioPanelSystem.js'
|
||||
];
|
||||
|
||||
if ($.inidb.FileExists('points') || $.inidb.FileExists('command') || $.inidb.FileExists('time')) {
|
||||
$.consoleLn('Backing up commands...');
|
||||
commandsBackup = getTableContents('command');
|
||||
|
||||
$.consoleLn('Backing up times...');
|
||||
timeBackup = getTableContents('time');
|
||||
|
||||
$.consoleLn('Backing up points...');
|
||||
pointsBackup = getTableContents('points');
|
||||
|
||||
$.consoleLn('Backup completed.');
|
||||
$.consoleLn('Deleting old files...');
|
||||
for (i in tableNamesList) {
|
||||
$.inidb.RemoveFile(tableNamesList[i]);
|
||||
}
|
||||
|
||||
$.consoleLn('Restoring commands...');
|
||||
restoreTableContents('command', commandsBackup);
|
||||
|
||||
$.consoleLn('Restoring times...');
|
||||
restoreTableContents('time', timeBackup);
|
||||
|
||||
$.consoleLn('Restoring points...');
|
||||
restoreTableContents('points', pointsBackup);
|
||||
}
|
||||
|
||||
$.consoleLn('Disabling default modules...');
|
||||
for (i in defaultDisabledModules) {
|
||||
$.inidb.set('modules', defaultDisabledModules[i], 'false');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot v2.0 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.0.5 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.5') || $.inidb.get('updates', 'installedv2.0.5') != 'true') {
|
||||
var newDefaultDisabledModules = [
|
||||
'./systems/betSystem.js',
|
||||
'./handlers/wordCounter.js',
|
||||
'./systems/ranksSystem.js',
|
||||
'./systems/auctionSystem.js',
|
||||
'./commands/highlightCommand.js'
|
||||
]; //ADD NEW MODULES IN 2.0.5 TO BE DISABLED PLEASE.
|
||||
|
||||
$.consoleLn('Starting PhantomBot version 2.0.5 updates...');
|
||||
|
||||
$.consoleLn('Disabling new default modules...');
|
||||
for (i in newDefaultDisabledModules) {
|
||||
$.inidb.set('modules', newDefaultDisabledModules[i], 'false');
|
||||
}
|
||||
|
||||
$.consoleLn('Removing commandCooldown table...');
|
||||
$.inidb.RemoveFile('commandCooldown');
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.5 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.5', 'true');
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.6') || $.inidb.get('updates', 'installedv2.0.6') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0.6 updates...');
|
||||
|
||||
|
||||
if ($.inidb.exists('chatModerator', 'capsLimit')) {
|
||||
$.inidb.del('chatModerator', 'capsLimit');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.6 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.6', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.0.7 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.7') || $.inidb.get('updates', 'installedv2.0.7') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0.7 updates...');
|
||||
|
||||
var newDefaultDisabledModules = [
|
||||
'./handlers/gameWispHandler.js',
|
||||
'./commands/deathctrCommand.js',
|
||||
]; //ADD NEW MODULES IN 2.0.7 TO BE DISABLED PLEASE.
|
||||
|
||||
$.consoleLn('Disabling new default modules...');
|
||||
for (i in newDefaultDisabledModules) {
|
||||
$.inidb.set('modules', newDefaultDisabledModules[i], 'false');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('chatModerator', 'regularsToggle')) {
|
||||
if ($.inidb.get('chatModerator', 'regularsToggle').equalsIgnoreCase('true')) {
|
||||
$.inidb.set('chatModerator', 'regularsModerateLinks', false);
|
||||
$.inidb.del('chatModerator', 'regularsToggle');
|
||||
} else if ($.inidb.get('chatModerator', 'regularsToggle').equalsIgnoreCase('false')) {
|
||||
$.inidb.set('chatModerator', 'regularsModerateLinks', true);
|
||||
$.inidb.del('chatModerator', 'regularsToggle');
|
||||
}
|
||||
}
|
||||
|
||||
if ($.inidb.exists('chatModerator', 'subscribersToggle')) {
|
||||
if ($.inidb.get('chatModerator', 'subscribersToggle').equalsIgnoreCase('true')) {
|
||||
$.inidb.set('chatModerator', 'subscribersModerateLinks', false);
|
||||
$.inidb.del('chatModerator', 'subscribersToggle');
|
||||
} else if ($.inidb.get('chatModerator', 'subscribersToggle').equalsIgnoreCase('false')) {
|
||||
$.inidb.set('chatModerator', 'subscribersModerateLinks', true);
|
||||
$.inidb.del('chatModerator', 'subscribersToggle');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete uptime command if it exits because I added this as a default command.
|
||||
*/
|
||||
if ($.inidb.exists('command', 'uptime')) {
|
||||
$.inidb.del('command', 'uptime');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.7 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.7', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.0.7.2 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.7.2') || $.inidb.get('updates', 'installedv2.0.7.2') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0.7.2 updates...');
|
||||
|
||||
if ($.inidb.exists('chatModerator', 'longMessageMessage')) {
|
||||
if ($.inidb.get('chatModerator', 'longMessageMessage').equalsIgnoreCase('false')) {
|
||||
$.inidb.del('chatModerator', 'longMessageMessage');
|
||||
}
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.7.2 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.7.2', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.0.8 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.8') || $.inidb.get('updates', 'installedv2.0.8') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0.8 updates...');
|
||||
|
||||
var newDefaultDisabledModules = [
|
||||
'./handlers/twitterHandler.js',
|
||||
'./systems/audioPanelSystem.js',
|
||||
'./systems/queueSystem.js'
|
||||
]; //ADD NEW MODULES IN 2.0.8 TO BE DISABLED PLEASE.
|
||||
|
||||
$.consoleLn('Disabling new default modules...');
|
||||
for (i in newDefaultDisabledModules) {
|
||||
$.inidb.set('modules', newDefaultDisabledModules[i], 'false');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.8 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.8', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.0.9 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.0.9') || $.inidb.get('updates', 'installedv2.0.9') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.0.9 updates...');
|
||||
|
||||
$.consoleLn('Deleting old emotes cache...');
|
||||
$.inidb.del('emotescache', 'emotes');
|
||||
|
||||
$.consoleLn('PhantomBot v2.0.9 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.0.9', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.1/2.0.10 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.1.0') || $.inidb.get('updates', 'installedv2.1.0') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot version 2.1 updates...');
|
||||
|
||||
$.consoleLn('Aliasing !permission to !group...');
|
||||
$.inidb.set('aliases', 'group', 'permission');
|
||||
|
||||
$.consoleLn('Aliasing !permissionpoints to !grouppoints...');
|
||||
$.inidb.set('aliases', 'grouppoints', 'permissionpoints');
|
||||
|
||||
$.consoleLn('Aliasing !permissions to !groups...');
|
||||
$.inidb.set('aliases', 'groups', 'permissions');
|
||||
|
||||
$.consoleLn('Disabling new modules...');
|
||||
$.inidb.set('modules', './games/gambling.js', 'false');
|
||||
|
||||
$.consoleLn('Setting up the new Twitter post delay...');
|
||||
$.inidb.set('twitter', 'postdelay_update', 180);
|
||||
|
||||
$.consoleLn('PhantomBot v2.1 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.1.0', 'true');
|
||||
$.inidb.set('updates', 'installedNewBot', 'true'); //If bot login is deleted after updates were installed we don't want to reset the modules.
|
||||
}
|
||||
|
||||
/** Version 2.2 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.1.1') || $.inidb.get('updates', 'installedv2.1.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot v2.2 updates...');
|
||||
|
||||
$.consoleLn('PhantomBot v2.2 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.1.1', 'true');
|
||||
}
|
||||
|
||||
/** Version 2.3 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3s') || $.inidb.get('updates', 'installedv2.3s') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot v2.3 updates...');
|
||||
|
||||
$.consoleLn('Disabling new modules...');
|
||||
$.inidb.set('modules', './handlers/bitsHandler.js', 'false');
|
||||
|
||||
$.consoleLn('Setting up new default custom commands...');
|
||||
if (!$.inidb.exists('command', 'uptime')) {
|
||||
$.inidb.set('command', 'uptime', '(pointtouser) (channelname) has been online for (uptime)');
|
||||
}
|
||||
if (!$.inidb.exists('command', 'followage')) {
|
||||
$.inidb.set('command', 'followage', '(followage)');
|
||||
}
|
||||
if (!$.inidb.exists('command', 'playtime')) {
|
||||
$.inidb.set('command', 'playtime', '(pointtouser) (channelname) has been playing (game) for (playtime)');
|
||||
}
|
||||
if (!$.inidb.exists('command', 'title')) {
|
||||
$.inidb.set('command', 'title', '(pointtouser) (titleinfo)');
|
||||
}
|
||||
if (!$.inidb.exists('command', 'game')) {
|
||||
$.inidb.set('command', 'game', '(pointtouser) (gameinfo)');
|
||||
}
|
||||
if (!$.inidb.exists('command', 'age')) {
|
||||
$.inidb.set('command', 'age', '(age)');
|
||||
}
|
||||
if ($.inidb.exists('permcom', 'game set')) {
|
||||
$.inidb.set('permcom', 'setgame', $.inidb.get('permcom', 'game set'));
|
||||
}
|
||||
if ($.inidb.exists('permcom', 'title set')) {
|
||||
$.inidb.set('permcom', 'settitle', $.inidb.get('permcom', 'title set'));
|
||||
}
|
||||
|
||||
$.inidb.del('permcom', 'game set');
|
||||
$.inidb.del('permcom', 'title set');
|
||||
|
||||
$.consoleLn('Setting up new toggles...');
|
||||
$.inidb.set('adventureSettings', 'warningMessage', true);
|
||||
$.inidb.set('adventureSettings', 'enterMessage', true);
|
||||
|
||||
$.consoleLn('PhantomBot v2.3 updates completed!');
|
||||
$.inidb.set('updates', 'installedv2.3s', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.3s updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.3ss') || $.inidb.get('updates', 'installedv2.3.3ss') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.3 updates...');
|
||||
|
||||
$.consoleLn('Deleting the old emotes cache.');
|
||||
$.inidb.RemoveFile('emotecache');
|
||||
|
||||
$.consoleLn('Updating raffle settings...');
|
||||
if ($.inidb.exists('settings', 'raffleMSGToggle')) {
|
||||
$.inidb.set('raffleSettings', 'raffleMSGToggle', $.inidb.get('settings', 'raffleMSGToggle'));
|
||||
$.inidb.del('settings', 'raffleMSGToggle');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('settings', 'noRepickSame')) {
|
||||
$.inidb.set('raffleSettings', 'noRepickSame', $.inidb.get('settings', 'noRepickSame'));
|
||||
$.inidb.del('settings', 'noRepickSame');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('settings', 'raffleMessage')) {
|
||||
$.inidb.set('raffleSettings', 'raffleMessage', $.inidb.get('settings', 'raffleMessage'));
|
||||
$.inidb.del('settings', 'raffleMessage');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('settings', 'raffleMessageInterval')) {
|
||||
$.inidb.set('raffleSettings', 'raffleMessageInterval', $.inidb.get('settings', 'raffleMessageInterval'));
|
||||
$.inidb.del('settings', 'raffleMessageInterval');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('command', 'uptime') && $.inidb.get('command', 'uptime').equalsIgnoreCase('(@sender) (channelname) has been online for (uptime)')) {
|
||||
$.inidb.set('command', 'uptime', '(pointtouser) (channelname) has been online for (uptime)');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('command', 'playtime') && $.inidb.get('command', 'playtime').equalsIgnoreCase('(@sender) (channelname) has been playing (game) for (playtime)')) {
|
||||
$.inidb.set('command', 'playtime', '(pointtouser) (channelname) has been playing (game) for (playtime)');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('command', 'title') && $.inidb.get('command', 'title').equalsIgnoreCase('(@sender) (titleinfo)')) {
|
||||
$.inidb.set('command', 'title', '(pointtouser) (titleinfo)');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('command', 'game') && $.inidb.get('command', 'game').equalsIgnoreCase('(@sender) (gameinfo)')) {
|
||||
$.inidb.set('command', 'game', '(pointtouser) (gameinfo)');
|
||||
}
|
||||
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.3 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.3ss', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.5 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.5ss') || $.inidb.get('updates', 'installedv2.3.5ss') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.5 updates...');
|
||||
|
||||
$.inidb.set('chatModerator', 'moderationLogs', 'false');
|
||||
$.inidb.set('modules', './systems/bettingSystem.js', 'false');
|
||||
$.inidb.del('modules', './systems/betSystem.js');
|
||||
|
||||
$.consoleLn('Removing old discord settings...');
|
||||
$.inidb.RemoveFile('discordSettings');
|
||||
$.inidb.RemoveFile('discordKeywords');
|
||||
$.inidb.RemoveFile('discordCommands');
|
||||
$.inidb.RemoveFile('discordCooldown');
|
||||
$.inidb.del('modules', './handlers/discordHandler.js');
|
||||
|
||||
$.consoleLn('Disabling new modules.');
|
||||
$.inidb.set('modules', './handlers/tipeeeStreamHandler.js', 'false');
|
||||
|
||||
$.consoleLn('Reloading blacklist and whitelist...');
|
||||
var keys = $.inidb.GetKeyList('blackList', ''),
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
$.inidb.set('blackList', $.inidb.get('blackList', keys[i]), 'true');
|
||||
$.inidb.del('blackList', keys[i]);
|
||||
}
|
||||
|
||||
keys = $.inidb.GetKeyList('whiteList', '');
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
$.inidb.set('whiteList', $.inidb.get('whiteList', keys[i]), 'true');
|
||||
$.inidb.del('whiteList', keys[i]);
|
||||
}
|
||||
|
||||
$.consoleLn('Updating host settings...');
|
||||
$.inidb.set('settings', 'hostToggle', true);
|
||||
|
||||
$.consoleLn('Disabling default discord modules.');
|
||||
modules = [
|
||||
'./discord/handlers/bitsHandler.js',
|
||||
'./discord/handlers/followHandler.js',
|
||||
'./discord/handlers/subscribeHandler.js',
|
||||
'./discord/handlers/streamlabsHandler.js',
|
||||
'./discord/handlers/tipeeeStreamHandler.js',
|
||||
'./discord/handlers/hostHandler.js',
|
||||
'./discord/handlers/twitterHandler.js',
|
||||
'./discord/handlers/keywordHandler.js',
|
||||
'./discord/handlers/streamHandler.js',
|
||||
'./discord/handlers/gamewispHandler.js',
|
||||
'./discord/systems/greetingsSystem.js',
|
||||
'./discord/commands/customCommands.js',
|
||||
'./discord/games/8ball.js',
|
||||
'./discord/games/kill.js',
|
||||
'./discord/games/random.js',
|
||||
'./discord/games/roulette.js'
|
||||
];
|
||||
for (i in modules) {
|
||||
$.inidb.set('modules', modules[i], 'false');
|
||||
}
|
||||
|
||||
$.inidb.set('permcom', 'permission', '1');
|
||||
if ($.inidb.exists('permcom', 'group')) {
|
||||
$.inidb.set('permcom', 'group', '1');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.5 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.5ss', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.5.1 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.5.1') || $.inidb.get('updates', 'installedv2.3.5.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.5.1 updates...');
|
||||
|
||||
if ($.inidb.exists('aliases', 'points')) {
|
||||
$.inidb.del('aliases', 'points');
|
||||
}
|
||||
|
||||
if ($.inidb.exists('aliases', 'point')) {
|
||||
$.inidb.del('aliases', 'point');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.5.1 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.5.1', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.5.2 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.5.2') || $.inidb.get('updates', 'installedv2.3.5.2') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.5.2 updates...');
|
||||
|
||||
$.consoleLn('Reloading quotes... Please do not turn off your bot.');
|
||||
var keys = $.inidb.GetKeyList('quotes', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
var quote = $.inidb.get('quotes', keys[i]);
|
||||
if (quote != null) {
|
||||
temp.push(quote);
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('quotes');
|
||||
|
||||
|
||||
for (i in temp) {
|
||||
$.inidb.set('quotes', i, temp[i]);
|
||||
}
|
||||
|
||||
$.inidb.SaveAll(true);
|
||||
|
||||
$.inidb.del('modules', './handlers/discordHandler.js');
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.5.2 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.5.2', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.5.3 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.5.3') || $.inidb.get('updates', 'installedv2.3.5.3') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.5.3 updates...');
|
||||
|
||||
if (!$.inidb.exists('settings', 'followDelay') || ($.inidb.exists('settings', 'followDelay') && parseInt($.inidb.get('settings', 'followDelay')) < 5)) {
|
||||
$.inidb.set('settings', 'followDelay', 5);
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.5.3 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.5.3', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.6 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.6') || $.inidb.get('updates', 'installedv2.3.6') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.6 updates...');
|
||||
|
||||
$.consoleLn('Disabling default discord modules.');
|
||||
$.inidb.set('modules', './discord/games/roll.js', 'false');
|
||||
$.inidb.set('modules', './discord/games/slotMachine.js', 'false');
|
||||
$.inidb.set('modules', './discord/games/gambling.js', 'false');
|
||||
$.inidb.set('modules', './discord/systems/pointSystem.js', 'false');
|
||||
|
||||
$.inidb.set('permcom', $.botName.toLowerCase(), '2');
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.6 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.6', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.6s updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.6ss') || $.inidb.get('updates', 'installedv2.3.6ss') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.6s updates...');
|
||||
|
||||
$.inidb.del('cooldown', 'globalCooldownTime');
|
||||
$.inidb.del('cooldown', 'modCooldown');
|
||||
$.inidb.del('cooldown', 'perUserCooldown');
|
||||
$.inidb.del('cooldown', 'globalCooldown');
|
||||
$.inidb.del('discordCooldown', 'globalCooldown');
|
||||
$.inidb.del('discordCooldown', 'globalCooldownTime');
|
||||
|
||||
var keys = $.inidb.GetKeyList('cooldown', ''),
|
||||
seconds,
|
||||
i;
|
||||
|
||||
$.consoleLn('Updating cooldowns...');
|
||||
for (i in keys) {
|
||||
seconds = $.inidb.get('cooldown', keys[i]);
|
||||
$.inidb.set('cooldown', keys[i], JSON.stringify({
|
||||
command: String(keys[i]),
|
||||
seconds: String(seconds),
|
||||
isGlobal: 'true'
|
||||
}));
|
||||
}
|
||||
|
||||
$.consoleLn('Updating Discord cooldowns...');
|
||||
for (i in keys) {
|
||||
seconds = $.inidb.get('discordCooldown', keys[i]);
|
||||
$.inidb.set('discordCooldown', keys[i], JSON.stringify({
|
||||
command: String(keys[i]),
|
||||
seconds: String(seconds),
|
||||
isGlobal: 'true'
|
||||
}));
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.6s completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.6ss', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.6b updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.6b') || $.inidb.get('updates', 'installedv2.3.6b') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.6b updates...');
|
||||
|
||||
$.consoleLn('Fixing uppercase usernames in tables.');
|
||||
|
||||
var keys = $.inidb.GetKeyList('points', ''),
|
||||
i;
|
||||
|
||||
|
||||
for (i in keys) {
|
||||
if (keys[i].match(/[A-Z]/)) {
|
||||
if ($.inidb.get('points', keys[i]) == null) {
|
||||
$.inidb.del('points', null);
|
||||
continue;
|
||||
}
|
||||
$.inidb.incr('points', keys[i].toLowerCase(), parseInt($.inidb.get('points', keys[i])));
|
||||
$.inidb.del('points', keys[i]);
|
||||
$.consoleLn('[points] ' + keys[i] + ' -> ' + keys[i].toLowerCase() + '::' + $.inidb.get('points', keys[i].toLowerCase()));
|
||||
} else if (keys[i].match(/[^a-zA-Z0-9_]/)) {
|
||||
$.inidb.del('points', keys[i]);
|
||||
$.consoleLn('[points] [remove] ' + keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
keys = $.inidb.GetKeyList('group', '');
|
||||
|
||||
for (i in keys) {
|
||||
if (keys[i].match(/[A-Z]/)) {
|
||||
$.inidb.set('group', keys[i].toLowerCase(), $.inidb.get('group', keys[i]));
|
||||
$.inidb.del('group', keys[i]);
|
||||
$.consoleLn('[permission] ' + keys[i] + ' -> ' + keys[i].toLowerCase() + '::' + $.inidb.get('group', keys[i].toLowerCase()));
|
||||
} else if (keys[i].match(/[^a-zA-Z0-9_]/)) {
|
||||
$.inidb.del('group', keys[i]);
|
||||
$.consoleLn('[permission] [remove] ' + keys[i]);
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.SaveAll(true);
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.6b completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.6b', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.7 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.7b') || $.inidb.get('updates', 'installedv2.3.7b') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.7 updates...');
|
||||
|
||||
var keys = $.inidb.GetKeyList('blackList', ''),
|
||||
timeout = $.getIniDbNumber('chatModerator', 'blacklistTimeoutTime', 600),
|
||||
message = $.getIniDbString('chatModerator', 'blacklistMessage', 'you were timed out for using a blacklisted phrase.'),
|
||||
messageB = $.getIniDbString('chatModerator', 'silentBlacklistMessage', 'Using a blacklisted word. (Automated by ' + $.botName + ')'),
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
if ($.getIniDbNumber('chatModerator', 'msgCooldownSecs', 45) == 45) {
|
||||
$.inidb.set('chatModerator', 'msgCooldownSecs', 30);
|
||||
}
|
||||
|
||||
$.consoleLn('Updating blacklist...');
|
||||
for (i in keys) {
|
||||
obj = {
|
||||
id: String(i),
|
||||
timeout: String(timeout),
|
||||
isRegex: keys[i].startsWith('regex:'),
|
||||
phrase: String(keys[i]),
|
||||
isSilent: false,
|
||||
excludeRegulars: false,
|
||||
excludeSubscribers: false,
|
||||
message: String(message),
|
||||
banReason: String(messageB)
|
||||
};
|
||||
$.inidb.set('blackList', keys[i], JSON.stringify(obj));
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.7 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.7b', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.9 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.9') || $.inidb.get('updates', 'installedv2.3.9') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.9 updates...');
|
||||
|
||||
$.consoleLn('Removing old discord handler...');
|
||||
$.inidb.del('modules', './handlers/discordHandler.js');
|
||||
|
||||
$.consoleLn('Removing old emotes cache...');
|
||||
$.inidb.RemoveFile('emotecache');
|
||||
|
||||
$.inidb.set('modules', './discord/handlers/streamElementsHandler.js', 'false');
|
||||
$.inidb.set('modules', './handlers/streamElementsHandler.js', 'false');
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.9 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.9', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.9.1 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.9.1') || $.inidb.get('updates', 'installedv2.3.9.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.9.1 updates...');
|
||||
|
||||
$.consoleLn('Updating old variables...');
|
||||
|
||||
if ($.inidb.FileExists('discordSettings')) {
|
||||
$.inidb.set('discordSettings', 'gameMessage', '(name) just changed game on Twitch!');
|
||||
$.inidb.set('discordSettings', 'onlineMessage', '(name) just went online on Twitch!');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.9.1 completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.9.1', 'true');
|
||||
}
|
||||
|
||||
/* version 2.3.9.1b updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.3.9.1b') || $.inidb.get('updates', 'installedv2.3.9.1b') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.3.9.1b updates...');
|
||||
|
||||
if ($.inidb.FileExists('discordStreamStats')) {
|
||||
$.consoleLn('Removing old Discord stats...');
|
||||
$.inidb.RemoveFile('discordStreamStats');
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.3.9.1b completed!');
|
||||
$.inidb.set('updates', 'installedv2.3.9.1b', 'true');
|
||||
}
|
||||
|
||||
/* version 2.4.0 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.4.0') || $.inidb.get('updates', 'installedv2.4.0') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.4.0 updates...');
|
||||
|
||||
if ($.getIniDbNumber('cooldownSettings', 'defaultCooldownTime', 5) < 5) {
|
||||
$.inidb.set('cooldownSettings', 'defaultCooldownTime', 5);
|
||||
}
|
||||
|
||||
$.consoleLn('Updating keywords...');
|
||||
var keys = $.inidb.GetKeyList('keywords', ''),
|
||||
keywords = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
keywords.push({
|
||||
key: keys[i],
|
||||
res: $.inidb.get('keywords', keys[i])
|
||||
});
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('keywords');
|
||||
|
||||
for (i in keywords) {
|
||||
try {
|
||||
new RegExp('\\b' + keywords[i].key + '\\b');
|
||||
|
||||
$.inidb.set('keywords', 'regex:\\b' + keywords[i].key + '\\b', JSON.stringify({
|
||||
keyword: 'regex:\\b' + keywords[i].key + '\\b',
|
||||
response: keywords[i].res + '',
|
||||
isRegex: true
|
||||
}));
|
||||
$.inidb.set('coolkey', 'regex:\\b' + keywords[i].key + '\\b', $.getIniDbNumber('coolkey', keywords[i].key, 5));
|
||||
$.inidb.del('coolkey', keywords[i].key);
|
||||
} catch (e) {
|
||||
$.inidb.set('keywords', keywords[i].key, JSON.stringify({
|
||||
keyword: keywords[i].key,
|
||||
response: keywords[i].res + '',
|
||||
isRegex: false
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 2.4.0 completed!');
|
||||
$.inidb.set('updates', 'installedv2.4.0', 'true');
|
||||
}
|
||||
|
||||
/* version 2.4.1 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.4.1') || $.inidb.get('updates', 'installedv2.4.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.4.1 updates...');
|
||||
|
||||
$.inidb.del('modules', './systems/raidSystem.js');
|
||||
|
||||
// Remove old raids for the new format.
|
||||
$.inidb.RemoveFile('outgoing_raids');
|
||||
|
||||
$.consoleLn('PhantomBot update 2.4.1 completed!');
|
||||
$.inidb.set('updates', 'installedv2.4.1', 'true');
|
||||
}
|
||||
|
||||
/* version 2.4.2.1 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv2.4.2.1') || $.inidb.get('updates', 'installedv2.4.2.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 2.4.2.1 updates...');
|
||||
|
||||
$.inidb.del('modules', './discord/handlers/gamewispHandler.js');
|
||||
$.inidb.del('modules', './handlers/gameWispHandler.js');
|
||||
|
||||
$.consoleLn('PhantomBot update 2.4.2.1 completed!');
|
||||
$.inidb.set('updates', 'installedv2.4.2.1', 'true');
|
||||
}
|
||||
|
||||
/* version 3.0.1 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv3.0.1') || $.inidb.get('updates', 'installedv3.0.1') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 3.0.1 updates...');
|
||||
|
||||
if (!$.hasDiscordToken) {
|
||||
while (!$.inidb.exists('discordPermsObj', 'obj')) {
|
||||
try {
|
||||
java.lang.Thread.sleep(1000);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to run update as Discord is not yet connected, please restart PhantomBot...');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var discordCommandPermissions = $.inidb.GetKeyList('discordPermcom', '');
|
||||
var everyoneRoleID = 0;
|
||||
var discordRoles = $.discordAPI.getGuildRoles();
|
||||
|
||||
for (var i = 0; i < discordRoles.size(); i++) {
|
||||
if (discordRoles.get(i).getName().equalsIgnoreCase('@everyone')) {
|
||||
everyoneRoleID = discordRoles.get(i).getId().asString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < discordCommandPermissions.length; i++) {
|
||||
var permission = $.inidb.get('discordPermcom', discordCommandPermissions[i]);
|
||||
var permissionsObj = {
|
||||
'roles': [], // Array of string IDs.
|
||||
'permissions': [] // Array of objects.
|
||||
};
|
||||
|
||||
if ((permission + '').equals('0')) {
|
||||
permissionsObj.roles.push(everyoneRoleID + '');
|
||||
}
|
||||
|
||||
permissionsObj.permissions.push({
|
||||
'name': 'Administrator',
|
||||
'selected': ((permission + '').equals('1') + '')
|
||||
});
|
||||
|
||||
$.inidb.set('discordPermcom', discordCommandPermissions[i], JSON.stringify(permissionsObj));
|
||||
}
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 3.0.1 completed!');
|
||||
$.inidb.set('updates', 'installedv3.0.1', 'true');
|
||||
}
|
||||
|
||||
/* version 3.3.0 updates */
|
||||
if (!$.inidb.exists('updates', 'installedv3.3.0') || $.inidb.get('updates', 'installedv3.3.0') != 'true') {
|
||||
$.consoleLn('Starting PhantomBot update 3.3.0 updates...');
|
||||
|
||||
$.consoleLn('Updating keywords...');
|
||||
var keys = $.inidb.GetKeyList('keywords', ''),
|
||||
newKeywords = [],
|
||||
key,
|
||||
json,
|
||||
i,
|
||||
strippedKeys = {};
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
key = keys[i];
|
||||
json = JSON.parse($.inidb.get('keywords', key));
|
||||
if (json.isRegex) {
|
||||
json.isCaseSensitive = true;
|
||||
key = key.replace('regex:', '');
|
||||
json.keyword = json.keyword.replace('regex:', '');
|
||||
} else {
|
||||
json.isCaseSensitive = false;
|
||||
}
|
||||
if (strippedKeys.hasOwnProperty(key)) {
|
||||
throw 'Could not update keywords list. The keyword "' + key +
|
||||
'" exists both as regex and as plain keyword. ' +
|
||||
"Please resolve the conflict and restart phantombot.";
|
||||
}
|
||||
strippedKeys[key] = true;
|
||||
newKeywords.push({
|
||||
key: key,
|
||||
json: json
|
||||
});
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('keywords');
|
||||
|
||||
for (i = 0; i < newKeywords.length; i++) {
|
||||
$.inidb.set('keywords', newKeywords[i].key, JSON.stringify(newKeywords[i].json));
|
||||
}
|
||||
|
||||
$.consoleLn('PhantomBot update 3.3.0 completed!');
|
||||
$.inidb.set('updates', 'installedv3.3.0', 'true');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getTableContents
|
||||
* @param {string} tableName
|
||||
* @returns {Array}
|
||||
*/
|
||||
function getTableContents(tableName) {
|
||||
var contents = [],
|
||||
keyList = $.inidb.GetKeyList(tableName, ''),
|
||||
temp,
|
||||
i;
|
||||
|
||||
for (i in keyList) {
|
||||
|
||||
// Handle Exceptions per table
|
||||
switch (tableName) {
|
||||
// Ignore rows with less than 600 seconds (10 minutes)
|
||||
case 'time':
|
||||
temp = parseInt($.inidb.get(tableName, keyList[i]));
|
||||
if (temp >= 600) {
|
||||
contents[keyList[i]] = $.inidb.get(tableName, keyList[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
// Ignore rows with less than 10 points
|
||||
case 'points':
|
||||
temp = parseInt($.inidb.get(tableName, keyList[i]));
|
||||
if (temp >= 10) {
|
||||
contents[keyList[i]] = $.inidb.get(tableName, keyList[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
// Put the rows in by default
|
||||
default:
|
||||
contents[keyList[i]] = $.inidb.get(tableName, keyList[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setTableContents
|
||||
* @param {string} tableName
|
||||
* @param {Array} contents
|
||||
*/
|
||||
function restoreTableContents(tableName, contents) {
|
||||
var i;
|
||||
|
||||
|
||||
for (i in contents) {
|
||||
$.inidb.set(tableName, i, contents[i]);
|
||||
}
|
||||
|
||||
$.inidb.SaveAll(true);
|
||||
}
|
||||
})();
|
||||
134
libs/phantombot/scripts/core/whisper.js
Normal file
134
libs/phantombot/scripts/core/whisper.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 whisperMode = $.getSetIniDbBoolean('settings', 'whisperMode', false),
|
||||
ScriptEventManager = Packages.tv.phantombot.script.ScriptEventManager,
|
||||
CommandEvent = Packages.tv.phantombot.event.command.CommandEvent;
|
||||
|
||||
/**
|
||||
* @function reloadWhispers
|
||||
*/
|
||||
function reloadWhispers() {
|
||||
whisperMode = $.getIniDbBoolean('settings', 'whisperMode');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function hasKey
|
||||
*
|
||||
* @param {array} list
|
||||
* @param {string} value
|
||||
* @param {int} subIndex
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasKey(list, value, subIndex) {
|
||||
var i;
|
||||
|
||||
for (i in list) {
|
||||
if (list[i][subIndex].equalsIgnoreCase(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function whisperPrefix
|
||||
*
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {boolean} force
|
||||
* @returns {string}
|
||||
*/
|
||||
function whisperPrefix(username, force) {
|
||||
if (username.toLowerCase() == $.botName.toLowerCase()) {
|
||||
return '';
|
||||
}
|
||||
if (whisperMode || force) {
|
||||
return '/w ' + username + ' ';
|
||||
}
|
||||
return '@' + $.username.resolve(username) + ', ';
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getBotWhisperMode
|
||||
*
|
||||
* @export $
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function getBotWhisperMode() {
|
||||
return whisperMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @event ircPrivateMessage
|
||||
*/
|
||||
$.bind('ircPrivateMessage', function(event) {
|
||||
var sender = event.getSender(),
|
||||
message = event.getMessage(),
|
||||
arguments = '',
|
||||
split,
|
||||
command;
|
||||
|
||||
if (sender.equalsIgnoreCase('jtv') || sender.equalsIgnoreCase('twitchnotify')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.startsWith('!') && $.isMod(sender) && $.userExists(sender)) {
|
||||
message = message.substring(1);
|
||||
if (message.includes(' ')) {
|
||||
split = message.indexOf(' ');
|
||||
command = message.substring(0, split).toLowerCase();
|
||||
arguments = message.substring(split + 1);
|
||||
} else {
|
||||
command = message;
|
||||
}
|
||||
|
||||
ScriptEventManager.instance().onEvent(new CommandEvent(sender, command, arguments));
|
||||
$.log.file('whispers', '' + sender + ': ' + message);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @commandpath togglewhispermode - Toggle whisper mode
|
||||
*/
|
||||
if (command.equalsIgnoreCase('togglewhispermode')) {
|
||||
whisperMode = !whisperMode;
|
||||
$.setIniDbBoolean('settings', 'whisperMode', whisperMode);
|
||||
$.say(whisperPrefix(sender) + (whisperMode ? $.lang.get('whisper.whispers.enabled') : $.lang.get('whisper.whispers.disabled')));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./core/whisper.js', 'togglewhispermode', 1);
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.whisperPrefix = whisperPrefix;
|
||||
$.getBotWhisperMode = getBotWhisperMode;
|
||||
$.reloadWhispers = reloadWhispers;
|
||||
})();
|
||||
1
libs/phantombot/scripts/custom/README.txt
Normal file
1
libs/phantombot/scripts/custom/README.txt
Normal file
@@ -0,0 +1 @@
|
||||
Place custom scripts in this directory.
|
||||
615
libs/phantombot/scripts/discord/commands/customCommands.js
Normal file
615
libs/phantombot/scripts/discord/commands/customCommands.js
Normal file
@@ -0,0 +1,615 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle custom commands for discord.
|
||||
*/
|
||||
(function() {
|
||||
var reCustomAPI = new RegExp(/\(customapi\s([\w\W:\/\$\=\?\&]+)\)/),
|
||||
reCustomAPIJson = new RegExp(/\(customapijson ([\w\.:\/\$=\?\&]+)\s([\w\W]+)\)/),
|
||||
reCustomArg = new RegExp(/\(([1-9])=([a-zA-Z1-9\)\(]+)\)/),
|
||||
reCustomToUserArg = new RegExp(/\(touser=([a-zA-Z1-9]+)\)/),
|
||||
reCustomAPITextTag = new RegExp(/{([\w\W]+)}/);
|
||||
|
||||
/**
|
||||
* @function getCustomAPIValue
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} url
|
||||
* @return {object}
|
||||
*/
|
||||
function getCustomAPIValue(url) {
|
||||
var HttpResponse = Packages.com.gmt2001.HttpResponse,
|
||||
HttpRequest = Packages.com.gmt2001.HttpRequest,
|
||||
HashMap = Packages.java.util.HashMap,
|
||||
responseData = HttpRequest.getData(HttpRequest.RequestType.GET, url, '', new HashMap());
|
||||
|
||||
return responseData.content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function tags
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {object} event
|
||||
* @param {string} s
|
||||
* @return {string}
|
||||
*/
|
||||
function tags(event, s) {
|
||||
if (s.match(reCustomArg)) {
|
||||
s = $.replace(s, s.match(reCustomArg)[0], (event.getArgs()[parseInt(s.match(reCustomArg)[1]) - 1] === undefined ? s.match(reCustomArg)[2] : $.discord.resolve.global(event.getArgs()[parseInt(s.match(reCustomArg)[1]) - 1])));
|
||||
}
|
||||
|
||||
if (s.match(/\(1\)/g)) {
|
||||
for (var i = 1; i < 10; i++) {
|
||||
if (s.includes('(' + i + ')')) {
|
||||
s = $.replace(s, '(' + i + ')', (event.getArgs()[i - 1] !== undefined ? event.getArgs()[i - 1] : ''));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(reCustomToUserArg)) {
|
||||
s = $.replace(s, s.match(reCustomToUserArg)[0], (event.getArgs()[0] ? $.discord.username.resolve(event.getArgs().join(' ')) : s.match(reCustomToUserArg)[1]));
|
||||
}
|
||||
|
||||
if (s.match(/\(sender\)/)) {
|
||||
s = $.replace(s, '(sender)', event.getUsername());
|
||||
}
|
||||
|
||||
if (s.match(/\(@sender\)/)) {
|
||||
s = $.replace(s, '(@sender)', event.getMention());
|
||||
}
|
||||
|
||||
if (s.match(/\(touser\)/)) {
|
||||
s = $.replace(s, '(touser)', (event.getArgs()[0] ? $.discord.username.resolve(event.getArgs().join(' ')) : event.getMention()));
|
||||
}
|
||||
|
||||
if (s.match(/\(random\)/)) {
|
||||
s = $.replace(s, '(random)', $.discord.username.random());
|
||||
}
|
||||
|
||||
if (s.match(/\(#\)/)) {
|
||||
s = $.replace(s, '(#)', $.randRange(1, 100).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(# (\d+),(\d+)\)/g)) {
|
||||
var mat = s.match(/\(# (\d+),(\d+)\)/);
|
||||
s = $.replace(s, mat[0], $.randRange(parseInt(mat[1]), parseInt(mat[2])).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(status\)/)) {
|
||||
s = $.replace(s, '(status)', $.getStatus($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(game\)/)) {
|
||||
s = $.replace(s, '(game)', $.getGame($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(uptime\)/)) {
|
||||
s = $.replace(s, '(uptime)', $.getStreamUptime($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(echo\)/)) {
|
||||
s = $.replace(s, '(echo)', (event.getArgs()[0] ? event.getArguments() : ''));
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', $.getViewers($.channelName).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(follows\)/g)) {
|
||||
s = $.replace(s, '(follows)', $.getFollows($.channelName).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(readfile/)) {
|
||||
if (s.search(/\((readfile ([^)]+)\))/g) >= 0) {
|
||||
s = $.replace(s, '(' + RegExp.$1, $.readFile('./addons/' + $.replace(RegExp.$2, '..', ''))[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(readfilerand/)) {
|
||||
if (s.search(/\((readfilerand ([^)]+)\))/g) >= 0) {
|
||||
var results = $.readFile('./addons/' + RegExp.$2);
|
||||
s = $.replace(s, '(' + RegExp.$1, $.randElement(results));
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(count\)/g)) {
|
||||
$.inidb.incr('discordCommandCount', event.getCommand(), 1);
|
||||
s = $.replace(s, '(count)', $.inidb.get('discordCommandCount', event.getCommand()));
|
||||
}
|
||||
|
||||
if (s.match(/\(writefile ([\w\W^,]+), ([\w^,]+), ([\w\W^,]+)\)/)) {
|
||||
var file = s.match(/\(writefile (.+), (.+), (.+)\)/)[1],
|
||||
append = (s.match(/\(writefile (.+), (.+), (.+)\)/)[2] == 'true' ? true : false),
|
||||
string = s.match(/\(writefile (.+), (.+), (.+)\)/)[3];
|
||||
$.writeToFile(string, './addons/' + $.replace(file, '..', ''), append);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s.match(/\(lasttip\)/g)) {
|
||||
s = $.replace(s, '(lasttip)', ($.inidb.exists('donations', 'last_donation_message') ? $.inidb.get('donations', 'last_donation_message') : 'No donations found.'));
|
||||
}
|
||||
|
||||
if (s.match(/\(encodeurl ([\w\W]+)\)/)) {
|
||||
var m = s.match(/\(encodeurl ([\w\W]+)\)/);
|
||||
s = $.replace(s, m[0], encodeURI(m[1]));
|
||||
}
|
||||
|
||||
if (s.match(reCustomAPIJson) || s.match(reCustomAPI)) {
|
||||
s = api(event, s);
|
||||
}
|
||||
|
||||
if (s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)/)) {
|
||||
$.discord.setRole(s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[2], s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[1]);
|
||||
|
||||
s = $.replace(s, s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[0], '');
|
||||
if (s.length === 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function api
|
||||
*
|
||||
* @param {object} event
|
||||
* @param {string} message
|
||||
* @return {string}
|
||||
*/
|
||||
function api(event, message) {
|
||||
var JSONObject = Packages.org.json.JSONObject,
|
||||
JSONArray = Packages.org.json.JSONArray,
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
origCustomAPIResponse = '',
|
||||
customAPIReturnString = '',
|
||||
message = message + '',
|
||||
customAPIResponse = '',
|
||||
customJSONStringTag = '',
|
||||
commandToExec = 0,
|
||||
jsonObject,
|
||||
regExCheck,
|
||||
jsonItems,
|
||||
jsonCheckList;
|
||||
|
||||
// Get the URL for a customapi, if applicable, and process $1 - $9. See below about that.
|
||||
if ((regExCheck = message.match(reCustomAPI))) {
|
||||
if (regExCheck[1].indexOf('$1') != -1) {
|
||||
for (var i = 1; i <= 9; i++) {
|
||||
if (regExCheck[1].indexOf('$' + i) != -1) {
|
||||
if (!args[i - 1]) {
|
||||
return $.lang.get('customcommands.customapi.404', command);
|
||||
}
|
||||
regExCheck[1] = regExCheck[1].replace('$' + i, args[i - 1]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
customAPIReturnString = getCustomAPIValue(regExCheck[1]);
|
||||
}
|
||||
|
||||
// Design Note. As of this comment, this parser only supports parsing out of objects, it does not
|
||||
// support parsing of arrays, especially walking arrays. If that needs to be done, please write
|
||||
// a custom JavaScript. We limit $1 - $9 as well; 10 or more arguments being passed by users to an
|
||||
// API seems like overkill. Even 9 does, to be honest.
|
||||
if ((regExCheck = message.match(reCustomAPIJson))) {
|
||||
if (regExCheck[1].indexOf('$1') != -1) {
|
||||
for (var i = 1; i <= 9; i++) {
|
||||
if (regExCheck[1].indexOf('$' + i) != -1) {
|
||||
if (!args[i - 1]) {
|
||||
return $.lang.get('customcommands.customapi.404', command);
|
||||
}
|
||||
regExCheck[1] = regExCheck[1].replace('$' + i, args[i - 1]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
origCustomAPIResponse = getCustomAPIValue(regExCheck[1]);
|
||||
jsonItems = regExCheck[2].split(' ');
|
||||
for (var j = 0; j < jsonItems.length; j++) {
|
||||
if (jsonItems[j].startsWith('{') && jsonItems[j].endsWith('}')) {
|
||||
customAPIReturnString += " " + jsonItems[j].match(reCustomAPITextTag)[1];
|
||||
} else if (jsonItems[j].startsWith('{') && !jsonItems[j].endsWith('}')) {
|
||||
customJSONStringTag = '';
|
||||
while (!jsonItems[j].endsWith('}')) {
|
||||
customJSONStringTag += jsonItems[j++] + " ";
|
||||
}
|
||||
customJSONStringTag += jsonItems[j];
|
||||
customAPIReturnString += " " + customJSONStringTag.match(reCustomAPITextTag)[1];
|
||||
} else {
|
||||
jsonCheckList = jsonItems[j].split('.');
|
||||
if (jsonCheckList.length == 1) {
|
||||
try {
|
||||
customAPIResponse = new JSONObject(origCustomAPIResponse).get(jsonCheckList[0]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
customAPIReturnString += " " + customAPIResponse;
|
||||
} else {
|
||||
for (var i = 0; i < jsonCheckList.length - 1; i++) {
|
||||
if (i == 0) {
|
||||
try {
|
||||
jsonObject = new JSONObject(origCustomAPIResponse).get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
} else if (!isNaN(jsonCheckList[i + 1])) {
|
||||
try {
|
||||
jsonObject = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
jsonObject = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
customAPIResponse = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
customAPIReturnString += " " + customAPIResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return message.replace(reCustomAPI, customAPIReturnString).replace(reCustomAPIJson, customAPIReturnString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function permCom
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {int}
|
||||
*/
|
||||
function permCom(command, subCommand) {
|
||||
if (subCommand === '') {
|
||||
return $.discord.getCommandPermission(command);
|
||||
} else {
|
||||
return $.discord.getSubCommandPermission(command, subCommand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadCustomCommands
|
||||
*
|
||||
* @export $.discord
|
||||
*/
|
||||
function loadCustomCommands() {
|
||||
if ($.bot.isModuleEnabled('./discord/commands/customCommands.js')) {
|
||||
var keys = $.inidb.GetKeyList('discordCommands', ''),
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', keys[i], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* Checks for custom commands, no command path needed here.
|
||||
*/
|
||||
if ($.inidb.exists('discordCommands', command)) {
|
||||
var tag = tags(event, $.inidb.get('discordCommands', command));
|
||||
if (tag !== null) {
|
||||
$.discord.say(channel, tag);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath addcom [command] [response] - Adds a custom command to be used in your Discord server.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('addcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if ($.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordCommands', action, args.slice(1).join(' '));
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', action, 0);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath editcom [command] [response] - Edits an existing command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('editcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordCommands', action, args.slice(1).join(' '));
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', action, 0);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath delcom [command] - Deletes a custom command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delcom')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('discordCommands', action);
|
||||
$.discord.unregisterCommand(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath channelcom [command] [channel / --global / --list] - Makes a command only work in that channel, separate the channels with commas (no spaces) for multiple, use --global as the channel to make the command global again.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('channelcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('--global') || subAction.equalsIgnoreCase('-g')) {
|
||||
$.inidb.del('discordChannelcom', action);
|
||||
$.discord.updateCommandChannel(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.global', action));
|
||||
return;
|
||||
} else if (subAction.equalsIgnoreCase('--list') || subAction.equalsIgnoreCase('-l')) {
|
||||
var keys = ($.inidb.exists('discordChannelcom', action) ? $.inidb.get('discordChannelcom', action).split(',') : []),
|
||||
key = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
key.push('#' + keys[i]);
|
||||
}
|
||||
|
||||
if (key.length !== 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + key.join(', '));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.404'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = subAction.split(','),
|
||||
key = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
key.push($.discord.sanitizeChannelName(keys[i]));
|
||||
}
|
||||
|
||||
$.inidb.set('discordChannelcom', action, key.join(','));
|
||||
$.discord.updateCommandChannel(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.success', action, subAction.replace(',', ', ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath pricecom [command] [amount] - Sets a cost for that command, users must of their Twitch accounts linked for this to work.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pricecom')) {
|
||||
if (action === undefined || (subAction === undefined || isNaN(parseInt(subAction)))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.pricecom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordPricecom', action, subAction);
|
||||
$.discord.setCommandCost(action, subAction);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.pricecom.success', action, $.getPointsString(subAction)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath aliascom [alias] [command] - Alias a command to another command, this only works with commands that have a single command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('aliascom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.aliascom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = subAction.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(subAction)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordAliascom', subAction, action);
|
||||
$.discord.setCommandAlias(subAction, action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.aliascom.success', action, subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath delalias [alias] - Removes the alias of that command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delalias')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delalias.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.aliasExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.alias.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = $.inidb.GetKeyList('discordAliascom', ''),
|
||||
i;
|
||||
for (i in keys) {
|
||||
if ($.inidb.get('discordAliascom', keys[i]).equalsIgnoreCase(action)) {
|
||||
$.inidb.del('discordAliascom', keys[i]);
|
||||
$.discord.removeAlias(keys[i], '');
|
||||
}
|
||||
}
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delalias.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath commands - Shows all of the custom commands you created.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('commands')) {
|
||||
var keys = $.inidb.GetKeyList('discordCommands', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('!' + keys[i]);
|
||||
}
|
||||
|
||||
$.paginateArrayDiscord(temp, 'discord.customcommands.commands', ', ', channel, mention);
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath botcommands - Gives you a list of commands that you are allowed to use.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('botcommands')) {
|
||||
var keys = $.inidb.GetKeyList('discordPermcom', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
if (keys[i].indexOf(' ') === -1) {
|
||||
temp.push('!' + keys[i]);
|
||||
}
|
||||
}
|
||||
$.paginateArrayDiscord(temp, 'discord.customcommands.bot.commands', ', ', channel, mention);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'addcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'delcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'editcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'coolcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'channelcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'pricecom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'aliascom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'delalias', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'commands', 0);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'botcommands', 1);
|
||||
|
||||
loadCustomCommands();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/commands/customCommands.js')) {
|
||||
if (event.getArguments().length() === 0) {
|
||||
if (!$.discord.commandExists(event.getArgs()[0])) {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', event.getArgs()[0], event.getArgs()[1]);
|
||||
} else {
|
||||
$.discord.setCommandPermission(event.getArgs()[0], event.getArgs()[1]);
|
||||
$.discord.setCommandCost(event.getArgs()[0], (event.getArgs()[4].length() === 0 ? '' : event.getArgs()[4]));
|
||||
if (event.getArgs()[3].length() === 0) {
|
||||
$.discord.removeAlias(event.getArgs()[0], $.inidb.get('discordAliascom', event.getArgs()[0]));
|
||||
} else {
|
||||
$.discord.setCommandAlias(event.getArgs()[0], (event.getArgs()[3].length() === 0 ? '' : event.getArgs()[3]));
|
||||
}
|
||||
|
||||
if (event.getArgs()[2].length() === 0) {
|
||||
$.inidb.del('discordChannelcom', event.getArgs()[0]);
|
||||
} else {
|
||||
$.inidb.set('discordChannelcom', event.getArgs()[0], String(event.getArgs()[2]).replace(/#/g, '').toLowerCase());
|
||||
}
|
||||
|
||||
$.discord.updateCommandChannel(event.getArgs()[0]);
|
||||
}
|
||||
} else {
|
||||
$.discord.unregisterCommand(event.getArgs()[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.loadCustomCommands = loadCustomCommands;
|
||||
$.discord.tags = tags;
|
||||
$.discord.permCom = permCom;
|
||||
})();
|
||||
161
libs/phantombot/scripts/discord/core/accountLink.js
Normal file
161
libs/phantombot/scripts/discord/core/accountLink.js
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles linking of a Discord account to a Twitch account.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var accounts = {},
|
||||
interval;
|
||||
|
||||
/**
|
||||
* @function resolveTwitchName
|
||||
* @function discordToTwitch
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} userId (snowflake)
|
||||
* @return {string or null}
|
||||
*/
|
||||
function resolveTwitchName(userId) {
|
||||
return ($.inidb.exists('discordToTwitch', userId) ? $.inidb.get('discordToTwitch', userId) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
user = event.getDiscordUser(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath account - Checks the current account linking status of the sender.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('account')) {
|
||||
var userId = event.getSenderId(),
|
||||
islinked = $.inidb.exists('discordToTwitch', userId);
|
||||
|
||||
if (action === undefined) {
|
||||
if (islinked) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.link', $.inidb.get('discordToTwitch', userId)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath account link - Starts the process of linking an account. Completing this will overwrite existing links
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('link')) {
|
||||
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+',
|
||||
text = '',
|
||||
i;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
text += code.charAt(Math.floor(Math.random() * code.length));
|
||||
}
|
||||
|
||||
accounts[userId] = {
|
||||
userObj: user,
|
||||
time: $.systemTime(),
|
||||
code: text
|
||||
};
|
||||
|
||||
if (islinked) {
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link.relink', $.channelName, text));
|
||||
} else {
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link', $.channelName, text));
|
||||
}
|
||||
/**
|
||||
* @discordcommandpath account remove - Removes account links from the sender.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('remove')) {
|
||||
$.inidb.del('discordToTwitch', userId);
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link.remove'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath account link [code] - Completes an account link for Discord.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('account')) {
|
||||
if (action !== undefined && action.equalsIgnoreCase('link')) {
|
||||
var code = args[1];
|
||||
if (code === undefined || code.length() < 10) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('discord.accountlink.link.fail'));
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = Object.keys(accounts),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (accounts[keys[i]].code == code && (accounts[keys[i]].time + 6e5) > $.systemTime()) {
|
||||
$.inidb.set('discordToTwitch', keys[i], sender.toLowerCase());
|
||||
|
||||
$.discordAPI.sendPrivateMessage(accounts[keys[i]].userObj, $.lang.get('discord.accountlink.link.success', sender.toLowerCase()));
|
||||
delete accounts[keys[i]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('discord.accountlink.link.fail'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/accountLink.js', 'account', 0);
|
||||
$.discord.registerSubCommand('accountlink', 'link', 0);
|
||||
$.discord.registerSubCommand('accountlink', 'remove', 0);
|
||||
// This is used to verify your account from Twitch. Do not remove it.
|
||||
$.registerChatCommand('./discord/core/accountLink.js', 'account', 7);
|
||||
|
||||
|
||||
// Interval to clear our old codes that have not yet been registered.
|
||||
interval = setInterval(function() {
|
||||
var keys = Object.keys(accounts),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if ((accounts[keys[i]].time + 6e5) < $.systemTime()) {
|
||||
delete accounts[keys[i]];
|
||||
}
|
||||
}
|
||||
}, 6e4, 'scripts::discord::core::accountLink.js');
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.resolveTwitchName = resolveTwitchName;
|
||||
})();
|
||||
259
libs/phantombot/scripts/discord/core/commandCooldown.js
Normal file
259
libs/phantombot/scripts/discord/core/commandCooldown.js
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* this module is made to handle command cooldowns for discord.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var defaultCooldownTime = $.getSetIniDbNumber('discordCooldownSettings', 'defaultCooldownTime', 5),
|
||||
defaultCooldowns = [],
|
||||
cooldowns = [];
|
||||
|
||||
/*
|
||||
* @class Cooldown
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function Cooldown(command, seconds, isGlobal) {
|
||||
this.isGlobal = isGlobal;
|
||||
this.command = command;
|
||||
this.seconds = seconds;
|
||||
this.cooldowns = [];
|
||||
this.time = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function loadCooldowns
|
||||
*/
|
||||
function loadCooldowns() {
|
||||
var commands = $.inidb.GetKeyList('discordCooldown', ''),
|
||||
json,
|
||||
i;
|
||||
|
||||
for (i in commands) {
|
||||
json = JSON.parse($.inidb.get('discordCooldown', commands[i]));
|
||||
|
||||
cooldowns[commands[i]] = new Cooldown(json.command, json.seconds, (json.isGlobal == true));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function get
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function get(command, username) {
|
||||
var cooldown = cooldowns[command];
|
||||
|
||||
if (cooldown !== undefined) {
|
||||
if (cooldown.isGlobal) {
|
||||
if (cooldown.time > $.systemTime()) {
|
||||
return cooldown.time;
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds);
|
||||
}
|
||||
} else {
|
||||
if (cooldown.cooldowns[username] !== undefined && cooldown.cooldowns[username] > $.systemTime()) {
|
||||
return cooldown.cooldowns[username];
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds, username);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (defaultCooldowns[command] !== undefined && defaultCooldowns[command] > $.systemTime()) {
|
||||
return defaultCooldowns[command];
|
||||
} else {
|
||||
return set(command, false, defaultCooldownTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function set
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Boolean} hasCooldown
|
||||
* @param {Number} seconds
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function set(command, hasCooldown, seconds, username) {
|
||||
seconds = ((parseInt(seconds) * 1e3) + $.systemTime());
|
||||
|
||||
if (hasCooldown) {
|
||||
if (username === undefined) {
|
||||
cooldowns[command].time = seconds;
|
||||
} else {
|
||||
cooldowns[command].cooldowns[username] = seconds;
|
||||
}
|
||||
} else {
|
||||
defaultCooldowns[command] = seconds;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function add
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function add(command, seconds, isGlobal) {
|
||||
if (cooldowns[command] === undefined) {
|
||||
cooldowns[command] = new Cooldown(command, seconds, isGlobal);
|
||||
$.inidb.set('discordCooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
} else {
|
||||
cooldowns[command].isGlobal = isGlobal;
|
||||
cooldowns[command].seconds = seconds;
|
||||
$.inidb.set('discordCooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function remove
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function remove(command) {
|
||||
$.inidb.del('discordCooldown', command);
|
||||
if (cooldowns[command] !== undefined) {
|
||||
delete cooldowns[command];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function clear
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function clear(command) {
|
||||
if (cooldowns[command] !== undefined) {
|
||||
cooldowns[command].time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
/*
|
||||
* @commandpath coolcom [command] [seconds] [type (global / user)] - Sets a cooldown for a command, default is global. Using -1 for the seconds removes the cooldown.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('coolcom')) {
|
||||
if (action === undefined || isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = (actionArgs !== undefined && actionArgs == 'user' ? false : true);
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = parseInt(subAction);
|
||||
|
||||
if (subAction > -1) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.set', action, subAction));
|
||||
add(action, subAction, actionArgs);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.remove', action));
|
||||
remove(action);
|
||||
}
|
||||
clear(command);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('cooldown')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.cooldown.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath cooldown setdefault [seconds] - Sets a default global cooldown for commands without a cooldown.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setdefault')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.default.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
defaultCooldownTime = parseInt(subAction);
|
||||
$.setIniDbNumber('discordCooldownSettings', 'defaultCooldownTime', defaultCooldownTime);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.default.set', defaultCooldownTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/commandCoolDown.js', 'coolcom', 1);
|
||||
|
||||
$.discord.registerCommand('./discord/core/commandCoolDown.js', 'cooldown', 1);
|
||||
$.discord.registerSubCommand('cooldown', 'setdefault', 1);
|
||||
loadCooldowns();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/core/commandCoolDown.js')) {
|
||||
if (event.getArgs()[0] == 'add') {
|
||||
add(event.getArgs()[1], event.getArgs()[2], event.getArgs()[3].equals('true'));
|
||||
} else {
|
||||
remove(event.getArgs()[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Export to the $. API */
|
||||
$.discord.cooldown = {
|
||||
remove: remove,
|
||||
clear: clear,
|
||||
get: get,
|
||||
set: set,
|
||||
add: add
|
||||
};
|
||||
})();
|
||||
432
libs/phantombot/scripts/discord/core/misc.js
Normal file
432
libs/phantombot/scripts/discord/core/misc.js
Normal file
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles the main things for the Discord modules. This is like the core if you would like to call it that.
|
||||
*
|
||||
* Command permissions for the registerCommand function:
|
||||
* - 1 means only administrators can access the command.
|
||||
* - 0 means everyone can access the command.
|
||||
*
|
||||
* Guidelines for merging thing on our repo for this module:
|
||||
* - Please try not to call the $.discordAPI function out of this script, move all the main functions here and export the function to the $.discord API.
|
||||
* - To register command to our command list please add a comment starting with @discordcommandpath before the command info.
|
||||
* - Make sure to comment on every function what their name is and the parameters they require and if they return something.
|
||||
*/
|
||||
(function() {
|
||||
var embedReg = new RegExp(/\(embed\s([\s\d\w]+),\s([\w\W]+)\)/),
|
||||
fileRegMsg = new RegExp(/\(file\s([\w\W]+),\s?([\r\n\w\W]*)\)/),
|
||||
fileReg = new RegExp(/\(file\s([\w\W]+)\)/),
|
||||
messageDeleteArray = [];
|
||||
|
||||
/**
|
||||
* @function userPrefix
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} username
|
||||
* @return {String}
|
||||
*/
|
||||
function userPrefix(username) {
|
||||
return (username + ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isConnected
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isConnected() {
|
||||
return $.discordAPI.isLoggedIn() &&
|
||||
$.discordAPI.checkConnectionStatus() == Packages.tv.phantombot.discord.DiscordAPI.ConnectionState.CONNECTED
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserMention
|
||||
*
|
||||
* @export $.discord.username
|
||||
* @param {string} username
|
||||
* @return {string}
|
||||
*/
|
||||
function getUserMention(username) {
|
||||
return ($.discordAPI.getUser(username) != null ? $.discordAPI.getUser(username).getMention() : username);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserMentionOrChannel
|
||||
*
|
||||
* @export $.discord.resolve
|
||||
* @param {string} argument
|
||||
* @return {string}
|
||||
*/
|
||||
function getUserMentionOrChannel(argument) {
|
||||
if ($.discordAPI.getUser(username) != null) {
|
||||
return $.discordAPI.getUser(argument).getMention();
|
||||
} else if ($.discordAPI.getChannel(argument) != null) {
|
||||
return $.discordAPI.getChannel(argument).getMention();
|
||||
} else {
|
||||
return argument;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getRandomUser
|
||||
*
|
||||
* @export $.discord.username
|
||||
* @return {string}
|
||||
*/
|
||||
function getRandomUser() {
|
||||
return ($.discordAPI.getUsers().get($.randRange(0, $.discordAPI.getUsers().size() - 1)).getMention()());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function say
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} channel
|
||||
* @param {string} message
|
||||
*/
|
||||
function say(channel, message) {
|
||||
if (embedReg.test(message)) {
|
||||
return $.discordAPI.sendMessageEmbed(channel, message.match(embedReg)[1], message.match(embedReg)[2]);
|
||||
} else if (fileRegMsg.test(message)) {
|
||||
return $.discordAPI.sendFile(channel, message.match(fileRegMsg)[2], message.match(fileRegMsg)[1]);
|
||||
} else if (fileReg.test(message)) {
|
||||
return $.discordAPI.sendFile(channel, message.match(fileReg)[1]);
|
||||
} else {
|
||||
return $.discordAPI.sendMessage(channel, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setGame
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} game
|
||||
*/
|
||||
function setGame(game) {
|
||||
$.discordAPI.setGame(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setGame
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} game
|
||||
* @param {string} url
|
||||
*/
|
||||
function setStream(game, url) {
|
||||
$.discordAPI.setStream(game, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function removeGame
|
||||
*
|
||||
* @export $.discord
|
||||
*/
|
||||
function removeGame() {
|
||||
$.discordAPI.removeGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setRole
|
||||
*
|
||||
* @param {string} role
|
||||
* @param {string} username
|
||||
* @export $.discord
|
||||
*/
|
||||
function setRole(role, username) {
|
||||
return $.discordAPI.addRole(role, username);
|
||||
}
|
||||
|
||||
function sanitizeChannelName(channel) {
|
||||
channel = channel.trim();
|
||||
|
||||
if (channel.substr(0, 1) === '<') {
|
||||
channel = channel.substr(1);
|
||||
}
|
||||
|
||||
if (channel.substr(0, 1) === '#') {
|
||||
channel = channel.substr(1);
|
||||
}
|
||||
|
||||
if (channel.substr(channel.length - 1, 1) === '>') {
|
||||
channel = channel.substr(0, channel.length - 1);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function handleDeleteReaction
|
||||
*
|
||||
* @param {object} user
|
||||
* @param {object} message
|
||||
* @param {object} commandMessage
|
||||
* @export $.discord
|
||||
*/
|
||||
function handleDeleteReaction(user, message, commandMessage) {
|
||||
var xEmoji = Packages.discord4j.core.object.reaction.ReactionEmoji.unicode('❌');
|
||||
message.addReaction(xEmoji);
|
||||
|
||||
messageDeleteArray[message.getId().asString()] = {
|
||||
lastMessage: message,
|
||||
lastCommandMessage: commandMessage,
|
||||
lastUser: user,
|
||||
timeout: setTimeout(function() {
|
||||
messageDeleteArray[message.getId().asString()].lastMessage.delete().subscribe();
|
||||
messageDeleteArray[message.getId().asString()].lastCommandMessage.delete().subscribe();
|
||||
delete messageDeleteArray[message.getId().asString()];
|
||||
}, 3e4)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @discordcommandpath module enable [path] - Enables any modules in the bot, it should only be used to enable discord modules though.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('module')) {
|
||||
if (action === undefined || (subAction === undefined && !action.equalsIgnoreCase('list'))) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('enable')) {
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, true);
|
||||
$.bot.loadScript(module.scriptName);
|
||||
$.bot.modules[module.scriptName].isEnabled = true;
|
||||
|
||||
var hookIndex = $.bot.getHookIndex(module.scriptName, 'initReady');
|
||||
|
||||
try {
|
||||
if (hookIndex !== -1) {
|
||||
$.bot.getHook(module.scriptName, 'initReady').handler();
|
||||
}
|
||||
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.enabled', module.getModuleName()));
|
||||
} catch (ex) {
|
||||
$.log.error('[DISCORD] Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex.message);
|
||||
$.consoleLn("Sending stack trace to error log...");
|
||||
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
|
||||
}
|
||||
} else {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.404', subAction));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath module disable [path] - Disables any modules in the bot, it should only be used to enable discord modules though.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disable')) {
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
$.bot.modules[module.scriptName].isEnabled = false;
|
||||
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.disabled', module.getModuleName()));
|
||||
} else {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.404', subAction));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath module list - Lists all of the discord modules.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('list')) {
|
||||
var keys = Object.keys($.bot.modules),
|
||||
modules = $.bot.modules,
|
||||
list = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (!modules[keys[i]].scriptName.startsWith('./discord/core/') && modules[keys[i]].scriptName.startsWith('./discord/')) {
|
||||
list.push(modules[keys[i]].scriptName + ' [' + (modules[keys[i]].isEnabled === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled')) + ']');
|
||||
}
|
||||
}
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.list', list.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath setgame [game name] - Sets the bot game.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setgame')) {
|
||||
if (action === undefined) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
setGame(args.join(' '));
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.set', args.join(' ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath setstream [twitch url] [game name] - Sets the bot game and marks it as streaming.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setstream')) {
|
||||
if (action === undefined) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.stream.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
setStream(args.slice(1).join(' '), action);
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.stream.set', action, args.slice(1).join(' ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath removegame - Removes the bot's game and streaming status if set.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('removegame')) {
|
||||
removeGame();
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.removed'));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleCreated
|
||||
*/
|
||||
$.bind('discordRoleCreated', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
|
||||
permObj.roles.push({
|
||||
'name': event.getDiscordRole().getName() + '',
|
||||
'_id': event.getRoleID() + '',
|
||||
'selected': 'false'
|
||||
});
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleUpdated
|
||||
*/
|
||||
$.bind('discordRoleUpdated', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
|
||||
for (var i = 0; i < permObj.roles.length; i++) {
|
||||
if (permObj.roles[i]._id.equals(event.getRoleID() + '')) {
|
||||
permObj.roles[i].name = event.getDiscordRole().getName() + '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleDeleted
|
||||
*/
|
||||
$.bind('discordRoleDeleted', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
var commands = $.inidb.GetKeyList('discordPermcom', '');
|
||||
|
||||
for (var i = 0; i < permObj.roles.length; i++) {
|
||||
if (permObj.roles[i]._id.equals(event.getRoleID() + '')) {
|
||||
permObj.roles.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
var perms = JSON.parse($.inidb.get('discordPermcom', commands[i]));
|
||||
|
||||
if (perms.roles.indexOf((event.getRoleID() + '')) > -1) {
|
||||
perms.roles.splice(perms.roles.indexOf((event.getRoleID() + '')), 1);
|
||||
$.discord.setCommandPermission(commands[i], perms);
|
||||
$.inidb.set('discordPermcom', commands[i], JSON.stringify(perms));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordMessageReaction
|
||||
*/
|
||||
$.bind('discordMessageReaction', function (event) {
|
||||
var reactionEvent = event.getEvent(),
|
||||
reactionUser = event.getSenderId();
|
||||
|
||||
if (event.getReactionEmoji().asUnicodeEmoji().equals(Packages.discord4j.core.object.reaction.ReactionEmoji.unicode('❌'))) {
|
||||
var messageID = reactionEvent.getMessage().block().getId().asString(),
|
||||
messageInArray = messageDeleteArray[messageID];
|
||||
if (messageInArray !== undefined) {
|
||||
if (messageInArray.lastUser.getId().asString().equals(reactionUser) &&
|
||||
messageInArray.lastMessage.getId().asString().equals(messageID)) {
|
||||
reactionEvent.getMessage().block().delete().subscribe();
|
||||
messageInArray.lastCommandMessage.delete().subscribe();
|
||||
clearTimeout(messageInArray.timeout);
|
||||
delete messageDeleteArray[messageID];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'module', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'setgame', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'setstream', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'removegame', 1);
|
||||
$.discord.registerSubCommand('module', 'list', 1);
|
||||
$.discord.registerSubCommand('module', 'enable', 1);
|
||||
$.discord.registerSubCommand('module', 'disable', 1);
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
/* There are the same functions twice in here - that's normal and wanted. */
|
||||
$.discord = {
|
||||
isConnected: isConnected,
|
||||
getUserMention: getUserMention,
|
||||
userMention: getUserMention,
|
||||
removeGame: removeGame,
|
||||
userPrefix: userPrefix,
|
||||
setStream: setStream,
|
||||
setGame: setGame,
|
||||
setRole: setRole,
|
||||
say: say,
|
||||
handleDeleteReaction: handleDeleteReaction,
|
||||
sanitizeChannelName: sanitizeChannelName,
|
||||
resolve: {
|
||||
global: getUserMentionOrChannel,
|
||||
getUserMentionOrChannel: getUserMentionOrChannel
|
||||
},
|
||||
username: {
|
||||
resolve: getUserMention,
|
||||
random: getRandomUser,
|
||||
getUserMention: getUserMention,
|
||||
getRandomUser: getRandomUser
|
||||
}
|
||||
};
|
||||
})();
|
||||
722
libs/phantombot/scripts/discord/core/moderation.js
Normal file
722
libs/phantombot/scripts/discord/core/moderation.js
Normal file
@@ -0,0 +1,722 @@
|
||||
/*
|
||||
* 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 blacklist = [],
|
||||
whitelist = [],
|
||||
permitList = {},
|
||||
timeout = {},
|
||||
spam = {},
|
||||
lastMessage = 0,
|
||||
|
||||
linkToggle = $.getSetIniDbBoolean('discordSettings', 'linkToggle', false),
|
||||
linkPermit = $.getSetIniDbNumber('discordSettings', 'linkPermit', 60),
|
||||
|
||||
capsToggle = $.getSetIniDbBoolean('discordSettings', 'capToggle', false),
|
||||
capsLimitPercent = $.getSetIniDbNumber('discordSettings', 'capsLimitPercent', 50),
|
||||
capsTriggerLength = $.getSetIniDbNumber('discordSettings', 'capsTriggerLength', 15),
|
||||
|
||||
longMessageToggle = $.getSetIniDbBoolean('discordSettings', 'longMessageToggle', false),
|
||||
longMessageLimit = $.getSetIniDbNumber('discordSettings', 'longMessageLimit', 600),
|
||||
|
||||
spamToggle = $.getSetIniDbBoolean('discordSettings', 'spamToggle', false),
|
||||
spamLimit = $.getSetIniDbNumber('discordSettings', 'spamLimit', 5),
|
||||
|
||||
modLogs = $.getSetIniDbBoolean('discordSettings', 'modLogs', false),
|
||||
modLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
|
||||
/**
|
||||
* @function reload
|
||||
*/
|
||||
function reload() {
|
||||
linkToggle = $.getSetIniDbBoolean('discordSettings', 'linkToggle', false),
|
||||
linkPermit = $.getSetIniDbNumber('discordSettings', 'linkPermit', 60);
|
||||
capsToggle = $.getSetIniDbBoolean('discordSettings', 'capToggle', false);
|
||||
capsLimitPercent = $.getSetIniDbNumber('discordSettings', 'capsLimitPercent', 50);
|
||||
capsTriggerLength = $.getSetIniDbNumber('discordSettings', 'capsTriggerLength', 15);
|
||||
longMessageToggle = $.getSetIniDbBoolean('discordSettings', 'longMessageToggle', false);
|
||||
longMessageLimit = $.getSetIniDbNumber('discordSettings', 'longMessageLimit', 600);
|
||||
spamToggle = $.getSetIniDbBoolean('discordSettings', 'spamToggle', false);
|
||||
spamLimit = $.getSetIniDbNumber('discordSettings', 'spamLimit', 5);
|
||||
modLogs = $.getSetIniDbBoolean('discordSettings', 'modLogs', false);
|
||||
modLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadBlackList
|
||||
*/
|
||||
function loadBlackList() {
|
||||
var keys = $.inidb.GetKeyList('discordBlacklist', ''),
|
||||
i;
|
||||
|
||||
blacklist = [];
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
blacklist.push(keys[i].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadWhitelist
|
||||
*/
|
||||
function loadWhitelist() {
|
||||
var keys = $.inidb.GetKeyList('discordWhitelist', ''),
|
||||
i;
|
||||
|
||||
whitelist = []
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
whitelist.push(keys[i].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function hasPermit
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function hasPermit(username) {
|
||||
if (permitList[username] !== undefined && (permitList[username] + linkPermit) >= $.systemTime()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} message
|
||||
*/
|
||||
function isWhiteList(username, message) {
|
||||
for (var i in whitelist) {
|
||||
if (message.includes(whitelist[i]) || username == whitelist[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hasBlackList
|
||||
*
|
||||
* @param {String} message
|
||||
*/
|
||||
function hasBlackList(message) {
|
||||
for (var i in blacklist) {
|
||||
if (message.includes(blacklist[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function username
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function bulkDelete(username, channel) {
|
||||
$.discordAPI.bulkDeleteMessages(channel, spam[username].messages);
|
||||
delete spam[username];
|
||||
}
|
||||
|
||||
/**
|
||||
* function timeoutUser
|
||||
*
|
||||
* @param {Object} message
|
||||
*/
|
||||
function timeoutUser(message) {
|
||||
$.discordAPI.deleteMessage(message);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedDelete
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedDelete(username, creator, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Deleted_message_of:**'] = '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'blue', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedTimeout
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} reason
|
||||
* @param {String} time
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedTimeout(username, creator, reason, time, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Timeout_placed_on:**'] = '[' + username + '](https://www.twitch.tv/popout/' + $.channelName + '/viewercard/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Reason:**'] = reason;
|
||||
obj['**Time:**'] = time + ' seconds.';
|
||||
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'yellow', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedBanned
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} reason
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedBanned(username, creator, reason, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Ban_placed_on:**'] = '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Reason:**'] = reason;
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'red', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @event PubSubModerationDelete
|
||||
*/
|
||||
$.bind('PubSubModerationDelete', function (event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedDelete(username, creator, message);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationTimeout
|
||||
*/
|
||||
$.bind('PubSubModerationTimeout', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage(),
|
||||
reason = event.getReason(),
|
||||
time = parseInt(event.getTime());
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedTimeout(username, creator, reason, time, message);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationUnTimeout
|
||||
*/
|
||||
$.bind('PubSubModerationUnTimeout', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'green', '**Timeout removed from:** ' + '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')' + ' \r\n\r\n **Creator:** ' + creator);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationUnBan
|
||||
*/
|
||||
$.bind('PubSubModerationUnBan', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'green', '**Ban removed from:** ' + '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')' + ' \r\n\r\n **Creator:** ' + creator);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationBan
|
||||
*/
|
||||
$.bind('PubSubModerationBan', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage(),
|
||||
reason = event.getReason();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedBanned(username, creator, reason, message);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelMessage
|
||||
*/
|
||||
$.bind('discordChannelMessage', function(event) {
|
||||
var sender = event.getSenderId(),
|
||||
channel = event.getDiscordChannel(),
|
||||
message = event.getMessage().toLowerCase(),
|
||||
messageLength = message.length();
|
||||
|
||||
if (event.isAdmin() == false && !hasPermit(sender) && !isWhiteList(sender, message)) {
|
||||
if (linkToggle && $.discord.pattern.hasLink(message)) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (longMessageToggle && messageLength > longMessageLimit) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (capsToggle && messageLength > capsTriggerLength && (($.discord.pattern.getCapsCount(event.getMessage()) / messageLength) * 100) > capsLimitPercent) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (spamToggle) {
|
||||
if (spam[sender] !== undefined) {
|
||||
if (spam[sender].time + 5000 > $.systemTime() && (spam[sender].total + 1) <= spamLimit) {
|
||||
spam[sender].total++; spam[sender].messages.push(event.getDiscordMessage());
|
||||
} else if (spam[sender].time + 5000 < $.systemTime() && (spam[sender].total + 1) <= spamLimit) {
|
||||
spam[sender] = { total: 1, time: $.systemTime(), messages: [event.getDiscordMessage()] };
|
||||
} else {
|
||||
spam[sender].messages.push(event.getDiscordMessage());
|
||||
bulkDelete(sender, channel);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
spam[sender] = { total: 1, time: $.systemTime(), messages: [event.getDiscordMessage()] };
|
||||
}
|
||||
}
|
||||
|
||||
if (hasBlackList(message)) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastMessage = $.systemTime();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
if (command.equalsIgnoreCase('moderation')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('links')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation links toggle - Toggles the link filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
linkToggle = !linkToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'linkToggle', linkToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.toggle', (linkToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation links permittime [seconds] - Sets the amount a time a permit lasts for.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('permittime')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.permit.time.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
linkPermit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'linkPermit', linkPermit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.permit.time.set', linkPermit));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('caps')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps toggle - Toggle the caps filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
capsToggle = !capsToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'capsToggle', capsToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.toggle', (capsToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps triggerlength [characters] - Sets the amount of characters needed a message before checking for caps.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('triggerlength')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.trigger.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
capsTriggerLength = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'capsTriggerLength', capsTriggerLength);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.trigger.set', capsTriggerLength));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps limitpercent [percent] - Sets the amount in percent of caps are allowed in a message.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limitpercent')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
capsLimitPercent = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'capsLimitPercent', capsLimitPercent);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.limit.set', capsLimitPercent));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('longmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation longmessage toggle - Toggles the long message filter
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
longMessageToggle = !longMessageToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'longMessageToggle', longMessageToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.toggle', (longMessageToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation longmessage limit [characters] - Sets the amount of characters allowed in a message.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limit')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
longMessageLimit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'longMessageLimit', longMessageLimit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.limit.set', longMessageLimit));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('spam')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation spam toggle - Toggles the spam filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
spamToggle = !spamToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'spamToggle', spamToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.toggle', (spamToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation limit [messages] - Sets the amount of messages users are allowed to send in 5 seconds.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limit')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
spamLimit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'spamLimit', spamLimit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.limit.set', spamLimit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (action.equalsIgnoreCase('blacklist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist add [phrase] - Adds a word or phrase to the blacklist which will be deleted if said in any channel.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('discordBlacklist', actionArgs, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.add.success'));
|
||||
loadBlackList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist remove [phrase] - Removes a word or phrase to the blacklist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('discordBlacklist', args.splice(2).join(' ').toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('discordBlacklist', actionArgs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.success'));
|
||||
loadBlackList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist list - Gives you a list of everything in the blacklist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('list')) {
|
||||
var keys = $.inidb.GetKeyList('discordBlacklist', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('#' + i + ': ' + keys[i]);
|
||||
}
|
||||
|
||||
if (temp.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.list.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.list', temp.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('whitelist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist add [phrase or username#discriminator] - Adds a phrase, word or username that will not get checked by the moderation system.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('discordWhitelist', actionArgs, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.add.success'));
|
||||
loadWhitelist();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist add [phrase or username#discriminator] - Removes that phrase, word or username from the whitelist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('discordWhitelist', args.splice(2).join(' ').toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('discordWhitelist', actionArgs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.success'));
|
||||
loadWhitelist();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist list - Gives you a list of everything in the whitelist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('list')) {
|
||||
var keys = $.inidb.GetKeyList('discordWhitelist', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('#' + i + ': ' + keys[i]);
|
||||
}
|
||||
|
||||
if (temp.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.list.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.list', temp.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation cleanup [channel] [amount] - Will delete that amount of messages for that channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('cleanup')) {
|
||||
var resolvedChannel = null;
|
||||
if (subAction === undefined || (actionArgs == undefined || isNaN(parseInt(actionArgs)))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.usage'));
|
||||
return;
|
||||
} else if (parseInt(actionArgs) > 10000 || parseInt(actionArgs) < 2) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.err.amount'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.match(/<#\d+>/)) {
|
||||
resolvedChannel = $.discordAPI.getChannelByID(subAction.match(/<#(\d+)>/)[1]);
|
||||
}
|
||||
if (resolvedChannel == null) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.err.unknownchannel', subAction));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.bulkDelete(resolvedChannel, parseInt(actionArgs));
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.done', actionArgs));
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('logs')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.toggle.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation logs toggle - Will toggle if Twitch moderation logs are to be said in Discord. Requires a bot restart.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
modLogs = !modLogs;
|
||||
$.setIniDbBoolean('discordSettings', 'modLogs', modLogs);
|
||||
$.setIniDbBoolean('chatModerator', 'moderationLogs', modLogs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.toggle', (modLogs ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation logs channel [channel name] - Will make Twitch moderator action be announced in that channel.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('channel')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
modLogChannel = $.discord.sanitizeChannelName(args.splice(2).join(' '));
|
||||
$.setIniDbString('discordSettings', 'modLogChannel', modLogChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.channel.set', args.splice(2).join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/core/moderation.js')) {
|
||||
reload();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if ($.bot.isModuleEnabled('./discord/core/moderation.js')) {
|
||||
$.discord.registerCommand('./discord/core/moderation.js', 'moderation', 1);
|
||||
$.discord.registerSubCommand('moderation', 'links', 1);
|
||||
$.discord.registerSubCommand('moderation', 'caps', 1);
|
||||
$.discord.registerSubCommand('moderation', 'longmessage', 1);
|
||||
$.discord.registerSubCommand('moderation', 'spam', 1);
|
||||
$.discord.registerSubCommand('moderation', 'blacklist', 1);
|
||||
$.discord.registerSubCommand('moderation', 'whitelist', 1);
|
||||
$.discord.registerSubCommand('moderation', 'cleanup', 1);
|
||||
$.discord.registerSubCommand('moderation', 'logs', 1);
|
||||
|
||||
loadWhitelist();
|
||||
loadBlackList();
|
||||
setInterval(function() {
|
||||
if (spam.length !== 0 && lastMessage - $.systemTime() <= 0) {
|
||||
spam = {};
|
||||
if (permitList.length !== 0) {
|
||||
permitList = {};
|
||||
}
|
||||
}
|
||||
}, 6e4, 'scripts::discord::core::moderation');
|
||||
}
|
||||
});
|
||||
})();
|
||||
57
libs/phantombot/scripts/discord/core/patternDetector.js
Normal file
57
libs/phantombot/scripts/discord/core/patternDetector.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 link = new RegExp('((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\\'\\(\\)' + '\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-z0-9\\$\\-\\_' + '\\.\\+\\!\\*\\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?' + '((?:(?:[a-z0-9][a-z0-9\\-]{0,64}\\.)+' + '(?:' + '(?:aero|arpa|app|a[cdefgilmnoqrstuwxz])' + '|(?:biz|bar|best|bingo|bot|b[abdefghijmnorstvwyz])' + '|(?:cat|com|coop|cash|chat|codes|cool|c[acdfghiklmnoruvxyz])' + '|d[ejkmoz]' + '|(?:edu|e[cegrstu])' + '|(?:fyi|f[ijkmor])' + '|(?:gov|g[abdefghilmnpqrstuwy])' + '|(?:how|h[kmnrtu])' + '|(?:info|int|i[delmnoqrst])' + '|(?:jobs|j[emop])' + '|k[eghimnrwyz]' + '|l[abcikrstuvy]' + '|(?:mil|mobi|moe|m[acdeghklmnopqrstuvwxyz])' + '|(?:name|net|n[acefgilopruz])' + '|(?:org|om)' + '|(?:pro|p[aefghklmnrstwy])' + '|qa' + '|(?:rodeo|rocks|r[eouw])' + '|(?:stream|support|sale|s[abcdeghijklmnortuvyz])' + '|(?:tel|travel|top|t[cdfghjklmnoprtvwz])' + '|u[agkmsyz]' + '|(?:vote|video|v[aceginu])' + '|(?:xxx)' + '|(?:watch|w[fs])' + '|y[etu]' + '|z[amw]))' + '|(?:(?:25[0-5]|2[0-4]' + '[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]' + '|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]' + '[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}' + '|[1-9][0-9]|[0-9])))' + '(?:\\:\\d{1,5})?)' + '(\\/(?:(?:[a-z0-9\\;\\/\\?\\:\\@\\&\\=\\#\\~' + '\\-\\.\\+\\!\\*\\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?' + '(?:\\b|$)' + '|(\\.[a-z]+\\/|magnet:\/\/|mailto:\/\/|ed2k:\/\/|irc:\/\/|ircs:\/\/|skype:\/\/|ymsgr:\/\/|xfire:\/\/|steam:\/\/|aim:\/\/|spotify:\/\/)', 'i'),
|
||||
caps = /([A-Z])/g,
|
||||
lastLink = '';
|
||||
|
||||
/**
|
||||
* @function hasLink
|
||||
*
|
||||
* @export $.discord.pattern
|
||||
* @param {String} message
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasLink(message) {
|
||||
try {
|
||||
lastLink = link.exec(message)[0];
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCapsCount
|
||||
*
|
||||
* @export $.discord.pattern
|
||||
* @param {String} message
|
||||
* @return {Number}
|
||||
*/
|
||||
function getCapsCount(message) {
|
||||
var sequences = message.match(caps);
|
||||
|
||||
return (sequences === null ? 0 : sequences.length);
|
||||
}
|
||||
|
||||
/* Export to the $. API. */
|
||||
$.discord.pattern = {
|
||||
getCapsCount: getCapsCount,
|
||||
hasLink: hasLink
|
||||
};
|
||||
})();
|
||||
355
libs/phantombot/scripts/discord/core/registerCommand.js
Normal file
355
libs/phantombot/scripts/discord/core/registerCommand.js
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This script is made to register discord commands.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var commands = {},
|
||||
aliases = {};
|
||||
|
||||
/**
|
||||
* @function commandExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {boolean}
|
||||
*/
|
||||
function commandExists(command) {
|
||||
return (commands[command] !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function aliasExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {boolean}
|
||||
*/
|
||||
function aliasExists(command) {
|
||||
return (aliases[command] !== undefined && aliases[command] !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function subCommandExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {boolean}
|
||||
*/
|
||||
function subCommandExists(command, subCommand) {
|
||||
return (commands[command] !== undefined && commands[command].subCommand[subCommand] !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {JSON} permission
|
||||
*/
|
||||
function setCommandPermission(command, permission) {
|
||||
if (command.includes(' ')) {
|
||||
if (subCommandExists(command.split(' ')[0], command.split(' ')[1])) {
|
||||
commands[command.split(' ')[0]].subCommand[command.split(' ')[1]].permission = getJSONCommandPermission(command, permission);
|
||||
}
|
||||
} else {
|
||||
if (commandExists(command)) {
|
||||
commands[command].permission = getJSONCommandPermission(command, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @info Gets the json for the command permission
|
||||
*/
|
||||
function getJSONCommandPermission(commandStr, permission) {
|
||||
// Already JSON return.
|
||||
if (permission.toString().startsWith('{')) {
|
||||
return permission;
|
||||
}
|
||||
|
||||
// The script sometimes load before discord, so add this.
|
||||
while (!$.inidb.exists('discordPermsObj', 'obj')) {
|
||||
try {
|
||||
java.lang.Thread.sleep(1000);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to set permission on Discord command as Discord is not connected. Please restart PhantomBot.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Build a new json object for the permissions of this command.
|
||||
var everyoneRoleID = 0;
|
||||
var discordRoles = $.discordAPI.getGuildRoles();
|
||||
var permissionsObj = {
|
||||
'roles': [],
|
||||
'permissions': []
|
||||
};
|
||||
|
||||
for (var i = 0; i < discordRoles.size(); i++) {
|
||||
if (discordRoles.get(i).getName().equalsIgnoreCase('@everyone')) {
|
||||
everyoneRoleID = discordRoles.get(i).getId().asString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((permission + '').equals('0')) {
|
||||
permissionsObj.roles.push(everyoneRoleID + '');
|
||||
}
|
||||
|
||||
permissionsObj.permissions.push({
|
||||
'name': 'Administrator',
|
||||
'selected': ((permission + '').equals('1') + '')
|
||||
});
|
||||
|
||||
return JSON.stringify(permissionsObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandCost
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {int} cost
|
||||
*/
|
||||
function setCommandCost(command, cost) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].cost = parseInt(cost);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} alias
|
||||
*/
|
||||
function setCommandAlias(command, alias) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].alias = alias.toLowerCase();
|
||||
aliases[commands[command].alias] = command.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function removeAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} alias
|
||||
*/
|
||||
function removeAlias(command, alias) {
|
||||
if (commandExists(command)) {
|
||||
delete aliases[commands[command].alias];
|
||||
commands[command].alias = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandCost
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {int}
|
||||
*/
|
||||
function getCommandCost(command) {
|
||||
if (commandExists(command)) {
|
||||
return commands[command].cost;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {int}
|
||||
*/
|
||||
function getCommandPermission(command) {
|
||||
if (commandExists(command)) {
|
||||
return JSON.parse(commands[command].permission);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {int}
|
||||
*/
|
||||
function getSubCommandPermission(command, subCommand) {
|
||||
if (commandExists(command) && subCommandExists(command, subCommand)) {
|
||||
return JSON.parse(commands[command].subCommand[subCommand].permission);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function updateCommandChannel(command) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].channels = ($.inidb.exists('discordChannelcom', command) ? $.inidb.get('discordChannelcom', command) : '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandChannelAllowed
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} channelName
|
||||
* @param {string} channelId
|
||||
* @return {string}
|
||||
*/
|
||||
function getCommandChannelAllowed(command, channelName, channelId) {
|
||||
if (commandExists(command) && commands[command].channels !== '') {
|
||||
var channels = commands[command].channels;
|
||||
var found = channels.indexOf(channelName + ',') === 0 || channels.indexOf(',' + channelName + ',') >= 0
|
||||
|| (channels.indexOf(channelName) === channels.lastIndexOf(',') + 1 && channels.endsWith(channelName))
|
||||
|| channels.indexOf(channelId + ',') === 0 || channels.indexOf(',' + channelId + ',') >= 0
|
||||
|| (channels.indexOf(channelId) === channels.lastIndexOf(',') + 1 && channels.endsWith(channelId));
|
||||
return found;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {string}
|
||||
*/
|
||||
function getCommandAlias(command) {
|
||||
if (aliasExists(command)) {
|
||||
return aliases[command];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @function registerCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} scriptFile
|
||||
* @param {string} command
|
||||
* @param {int} permission
|
||||
*/
|
||||
function registerCommand(scriptFile, command, permission) {
|
||||
if (!commandExists(command)) {
|
||||
if ($.inidb.exists('discordPermcom', command)) {
|
||||
permission = $.getIniDbString('discordPermcom', command);
|
||||
} else {
|
||||
permission = $.getSetIniDbString('discordPermcom', command, getJSONCommandPermission(command, permission));
|
||||
}
|
||||
|
||||
commands[command] = {
|
||||
permission: getJSONCommandPermission(command, permission),
|
||||
cost: ($.inidb.exists('discordPricecom', command) ? $.inidb.get('discordPricecom', command) : 0),
|
||||
alias: ($.inidb.exists('discordAliascom', command) ? $.inidb.get('discordAliascom', command) : ''),
|
||||
channels: ($.inidb.exists('discordChannelcom', command) ? $.inidb.get('discordChannelcom', command) : ''),
|
||||
scriptFile: scriptFile,
|
||||
subCommand: {}
|
||||
};
|
||||
|
||||
|
||||
if (commands[command].alias !== '') {
|
||||
aliases[commands[command].alias] = command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function registerSubCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @param {int} permission
|
||||
*/
|
||||
function registerSubCommand(command, subCommand, permission) {
|
||||
if (commandExists(command) && !subCommandExists(command, subCommand)) {
|
||||
if ($.inidb.exists('discordPermcom', command)) {
|
||||
permission = $.getIniDbString('discordPermcom', command);
|
||||
} else {
|
||||
permission = $.getSetIniDbString('discordPermcom', command, getJSONCommandPermission(command, permission));
|
||||
}
|
||||
|
||||
commands[command].subCommand[subCommand] = {
|
||||
permission: getJSONCommandPermission((command + ' ' + subCommand), permission)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function unregisterSubCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
*/
|
||||
function unregisterSubCommand(command, subCommand) {
|
||||
if (commandExists(command) && subCommandExists(command, subCommand)) {
|
||||
delete commands[command].subCommand[subCommand];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function unregisterCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
*/
|
||||
function unregisterCommand(command) {
|
||||
if (commandExists(command)) {
|
||||
if (commands[command].alias !== '') {
|
||||
delete aliases[commands[command].alias];
|
||||
}
|
||||
delete commands[command];
|
||||
}
|
||||
}
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.commands = commands;
|
||||
$.discord.commandExists = commandExists;
|
||||
$.discord.subCommandExists = subCommandExists;
|
||||
$.discord.getCommandPermission = getCommandPermission;
|
||||
$.discord.getSubCommandPermission = getSubCommandPermission;
|
||||
$.discord.registerCommand = registerCommand;
|
||||
$.discord.registerSubCommand = registerSubCommand;
|
||||
$.discord.unregisterCommand = unregisterCommand;
|
||||
$.discord.unregisterSubCommand = unregisterSubCommand;
|
||||
$.discord.setCommandPermission = setCommandPermission;
|
||||
$.discord.getCommandChannelAllowed = getCommandChannelAllowed;
|
||||
$.discord.updateCommandChannel = updateCommandChannel;
|
||||
$.discord.setCommandCost = setCommandCost;
|
||||
$.discord.getCommandCost = getCommandCost;
|
||||
$.discord.getCommandAlias = getCommandAlias;
|
||||
$.discord.setCommandAlias = setCommandAlias;
|
||||
$.discord.aliasExists = aliasExists;
|
||||
$.discord.removeAlias = removeAlias;
|
||||
})();
|
||||
303
libs/phantombot/scripts/discord/core/roleManager.js
Normal file
303
libs/phantombot/scripts/discord/core/roleManager.js
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* 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 autoSetPermissions = $.getSetIniDbBoolean('discordSettings', 'autoSetPermissions', false),
|
||||
autoSetRanks = $.getSetIniDbBoolean('discordSettings', 'autoSetRanks', false);
|
||||
|
||||
/*
|
||||
* updateRoleManager
|
||||
*/
|
||||
function updateRoleManager() {
|
||||
autoSetPermissions = $.getIniDbBoolean('discordSettings', 'autoSetPermissions');
|
||||
autoSetRanks = $.getIniDbBoolean('discordSettings', 'autoSetRanks');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function roleUpdateCheck
|
||||
*/
|
||||
function roleUpdateCheck() {
|
||||
if ($.discord.isConnected()) {
|
||||
var users = $.inidb.GetKeyList('discordToTwitch', ''),
|
||||
i;
|
||||
|
||||
// If both options are disabled, stop here.
|
||||
if (autoSetPermissions === false && autoSetRanks === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create our default roles.
|
||||
createRoles();
|
||||
|
||||
// Wait a bit to create the roles.
|
||||
setTimeout(function() {
|
||||
for (i in users) {
|
||||
try {
|
||||
if (hasRankOrPermission($.getIniDbString('discordToTwitch', users[i]))) {
|
||||
updateRoles(users[i], getRanksAndPermissions($.getIniDbString('discordToTwitch', users[i])));
|
||||
}
|
||||
} catch (e){
|
||||
$.log.error(e);
|
||||
}
|
||||
}
|
||||
}, 5e3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function updateRoles
|
||||
*
|
||||
* @param {Number} id
|
||||
* @param {Array} roles
|
||||
*/
|
||||
function updateRoles(id, roles) {
|
||||
var oldRoles = $.getIniDbString('discordRoles', id, ',').split(','),
|
||||
currentRoles = $.discordAPI.getUserRoles(id),
|
||||
newRoles = roles.join(','),
|
||||
idx,
|
||||
i;
|
||||
|
||||
// Build our roles list.
|
||||
for (i in currentRoles) {
|
||||
// If the user's current Discord role list contains an old role, and the new list does not have it, don't add it to the list.
|
||||
if ((oldRoles.length > 0 && hasRole(oldRoles, currentRoles[i].getName())) && newRoles.indexOf(currentRoles[i].getName()) === -1) {
|
||||
continue;
|
||||
} else {
|
||||
if (!hasRole(roles, currentRoles[i].getName())) {
|
||||
roles.push(currentRoles[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only update the user's role if there's a new one.
|
||||
for (i in roles) {
|
||||
if (!hasRole(currentRoles, roles[i], true)) {
|
||||
var roleObjs = $.discordAPI.getRoleObjects(roles);
|
||||
$.discordAPI.editUserRoles(id, roleObjs);
|
||||
$.setIniDbString('discordRoles', id, newRoles);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function createRoles
|
||||
*/
|
||||
function createRoles() {
|
||||
if (autoSetPermissions === true) {
|
||||
var keys = $.inidb.GetKeyList('groups', ''),
|
||||
group = '',
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
group = $.getIniDbString('groups', keys[i]).trim();
|
||||
|
||||
var hasTheRole = false;
|
||||
|
||||
try {
|
||||
hasTheRole = $.discordAPI.getRole(group) != null;
|
||||
} catch(e){}
|
||||
|
||||
if (!$.inidb.exists('blacklistedDiscordRoles', group.toLowerCase()) && !hasTheRole) {
|
||||
$.discordAPI.createRole(group);
|
||||
} else if (hasTheRole && $.inidb.exists('blacklistedDiscordRoles', group.toLowerCase())) {
|
||||
$.discordAPI.deleteRole(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (autoSetRanks === true) {
|
||||
var keys = $.inidb.GetKeyList('ranksMapping', ''),
|
||||
rank = '',
|
||||
i;
|
||||
|
||||
// Remove old ranks.
|
||||
cleanOldRanks();
|
||||
|
||||
for (i in keys) {
|
||||
rank = $.getIniDbString('ranksMapping', keys[i]).trim();
|
||||
|
||||
var hasTheRole = false;
|
||||
|
||||
try {
|
||||
hasTheRole = $.discordAPI.getRole(rank) != null;
|
||||
} catch(e){}
|
||||
|
||||
if (!$.inidb.exists('blacklistedDiscordRoles', rank.toLowerCase()) && !hasTheRole) {
|
||||
$.discordAPI.createRole(rank);
|
||||
$.setIniDbString('discordRanks', rank, keys[i]);
|
||||
} else if (hasTheRole && $.inidb.exists('blacklistedDiscordRoles', rank.toLowerCase())) {
|
||||
$.discordAPI.deleteRole(rank);
|
||||
$.inidb.del('discordRanks', rank);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function hasRole
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {String} role
|
||||
* @param {Boolean} getName
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasRole(array, role, getName) {
|
||||
for (var i in array) {
|
||||
if (!getName) {
|
||||
if (array[i].equalsIgnoreCase(role)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (array[i].getName().equalsIgnoreCase(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function cleanOldRanks
|
||||
*/
|
||||
function cleanOldRanks() {
|
||||
var keys = $.inidb.GetKeyList('discordRanks', ''),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (!$.getIniDbString('ranksMapping', $.getIniDbNumber('discordRanks', keys[i]), '').equalsIgnoreCase(keys[i])) {
|
||||
$.discordAPI.deleteRole(keys[i]);
|
||||
$.inidb.del('discordRanks', keys[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function hasRankOrPermission
|
||||
*
|
||||
* @param {String} username
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasRankOrPermission(username) {
|
||||
return (getRanksAndPermissions(username).length > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getRanksAndPermissions
|
||||
*
|
||||
* @param {String} username
|
||||
* @return {Array}
|
||||
*/
|
||||
function getRanksAndPermissions(username) {
|
||||
var roles = [],
|
||||
role;
|
||||
|
||||
if (autoSetPermissions === true) {
|
||||
if ($.inidb.exists('group', username) && !$.inidb.exists('blacklistedDiscordRoles', $.getIniDbString('group', username).toLowerCase())) {
|
||||
roles.push($.getIniDbString('groups', $.getIniDbString('group', username)));
|
||||
}
|
||||
}
|
||||
|
||||
if (autoSetRanks === true) {
|
||||
if ($.hasRank(username) && !$.inidb.exists('blacklistedDiscordRoles', $.getRank(username).toLowerCase())) {
|
||||
roles.push($.getRank(username));
|
||||
}
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
/*
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
if (command.equalsIgnoreCase('rolemanager')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager togglesyncpermissions - Makes the bot sync default permissions with those who have their accounts linked.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglesyncpermissions')) {
|
||||
autoSetPermissions = !autoSetPermissions;
|
||||
$.setIniDbBoolean('discordSettings', 'autoSetPermissions', autoSetPermissions);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (autoSetPermissions ? $.lang.get('discord.rolemanager.permission.sync.on') : $.lang.get('discord.rolemanager.permission.sync.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager togglesyncranks - Makes the bot sync ranks with those who have their accounts linked.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglesyncranks')) {
|
||||
autoSetRanks = !autoSetRanks;
|
||||
$.setIniDbBoolean('discordSettings', 'autoSetRanks', autoSetRanks);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (autoSetRanks ? $.lang.get('discord.rolemanager.ranks.sync.on') : $.lang.get('discord.rolemanager.ranks.sync.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager blacklist [add / remove] [permission or rank] - Blacklist a rank or permission from being used.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('blacklist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var blacklist = args.slice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('blacklistedDiscordRoles', blacklist, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.add.success', blacklist));
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.remove.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var blacklist = args.slice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('blacklistedDiscordRoles', blacklist);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.remove.success', blacklist));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/roleManager.js', 'rolemanager', 1);
|
||||
|
||||
setInterval(roleUpdateCheck, 3e4);
|
||||
});
|
||||
})();
|
||||
1
libs/phantombot/scripts/discord/custom/README.txt
Normal file
1
libs/phantombot/scripts/discord/custom/README.txt
Normal file
@@ -0,0 +1 @@
|
||||
Place custom scripts in this directory.
|
||||
74
libs/phantombot/scripts/discord/games/8ball.js
Normal file
74
libs/phantombot/scripts/discord/games/8ball.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the 8ball game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('8ball.answer.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath 8ball [question] - Ask the magic 8ball a question.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('8ball')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('8ball.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('8ball.discord.response', $.lang.get('8ball.answer.' + random)));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/8ball.js', '8ball', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
182
libs/phantombot/scripts/discord/games/gambling.js
Normal file
182
libs/phantombot/scripts/discord/games/gambling.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 winGainPercent = $.getSetIniDbNumber('discordGambling', 'winGainPercent', 30),
|
||||
winRange = $.getSetIniDbNumber('discordGambling', 'winRange', 50),
|
||||
max = $.getSetIniDbNumber('discordGambling', 'max', 100),
|
||||
min = $.getSetIniDbNumber('discordGambling', 'min', 5),
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
|
||||
/**
|
||||
* @function reloadGamble
|
||||
*/
|
||||
function reloadGamble() {
|
||||
winGainPercent = $.getIniDbNumber('discordGambling', 'winGainPercent');
|
||||
winRange = $.getIniDbNumber('discordGambling', 'winRange');
|
||||
max = $.getIniDbNumber('discordGambling', 'max');
|
||||
min = $.getIniDbNumber('discordGambling', 'min');
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function gamble
|
||||
*
|
||||
* @param {int amout}
|
||||
* @param {string} sender
|
||||
*/
|
||||
function gamble(channel, sender, mention, username, amount) {
|
||||
var winnings = 0,
|
||||
winSpot = 0,
|
||||
range = $.randRange(1, 100);
|
||||
|
||||
if ($.getUserPoints(sender) < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.need.points', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (max < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.max', $.getPointsString(max)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (min > amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.min', $.getPointsString(min)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (range <= winRange) {
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.lost', $.discord.userPrefix(mention), range, $.getPointsString(amount), $.getPointsString($.getUserPoints(sender) - amount), $.gameMessages.getLose(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
} else {
|
||||
winSpot = (range - winRange + 1);
|
||||
winnings = Math.floor(amount + ((amount + winSpot) * gain));
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.won', $.discord.userPrefix(mention), range, $.getPointsString(winnings), $.getPointsString($.getUserPoints(sender) + (winnings - amount)), $.gameMessages.getWin(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
$.inidb.incr('points', sender, winnings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @discordcommandpath gamble [amount] - Gamble your points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamble')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.usage'));
|
||||
} else {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
gamble(channel, twitchName, mention, sender, parseInt(action));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('gambling')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.main.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmax [amount] - Set how many points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmax')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max.usage'));
|
||||
return;
|
||||
}
|
||||
max = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'max', max);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max', $.getPointsString(max)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmin [amount] - Set the minimum amount of points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmin')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min.usage'));
|
||||
return;
|
||||
}
|
||||
min = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'min', min);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min', $.getPointsString(min)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setwinningrange [range] - Set the winning range from 0-100. The higher the less of a chance people have at winning.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setwinningrange')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range.usage'));
|
||||
return;
|
||||
}
|
||||
winRange = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winRange', winRange);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range', parseInt(winRange) + 1, winRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setgainpercent [amount in percent] - Set the winning gain percent.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setgainpercent')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent.usage'));
|
||||
return;
|
||||
}
|
||||
winGainPercent = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winGainPercent', winGainPercent);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent', winGainPercent));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./games/gambling.js', 'gamble', 0);
|
||||
$.discord.registerCommand('./games/gambling.js', 'gambling', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmax', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmin', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setwinningrange', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setgainpercent', 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/gambling.js')) {
|
||||
reloadGamble();
|
||||
}
|
||||
});
|
||||
})();
|
||||
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var selfMessageCount = 0,
|
||||
otherMessageCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('killcommand.self.' + i); i++) {
|
||||
selfMessageCount++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('killcommand.other.' + i); i++) {
|
||||
otherMessageCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function selfKill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} channel
|
||||
*/
|
||||
function selfKill(sender, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, selfMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.self.' + random, sender));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function kill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} username
|
||||
* @param {String} channel
|
||||
*/
|
||||
function kill(sender, username, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, otherMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.other.' + random, sender, username, $.getIniDbNumber('settings', 'killTimeoutTime', 60), $.botName).replace('(jail)', ''));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @discordcommandpath kill [username] - Kill a fellow viewer (not for real!).
|
||||
*/
|
||||
if (command.equalsIgnoreCase('kill')) {
|
||||
if (args.length === 0) {
|
||||
selfKill(sender, channel);
|
||||
} else {
|
||||
kill(sender, args[0], channel);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/kill.js', 'kill', 0);
|
||||
|
||||
if (otherMessageCount === 0 && selfMessageCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
65
libs/phantombot/scripts/discord/games/random.js
Normal file
65
libs/phantombot/scripts/discord/games/random.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('randomcommand.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath random - Will display something really random.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('random')) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.tags(event, $.lang.get('randomcommand.' + random), false));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/random.js', 'random', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 rewards = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordRollReward', 'rewards_0', 4);
|
||||
rewards[1] = $.getSetIniDbNumber('discordRollReward', 'rewards_1', 16);
|
||||
rewards[2] = $.getSetIniDbNumber('discordRollReward', 'rewards_2', 36);
|
||||
rewards[3] = $.getSetIniDbNumber('discordRollReward', 'rewards_3', 64);
|
||||
rewards[4] = $.getSetIniDbNumber('discordRollReward', 'rewards_4', 100);
|
||||
rewards[5] = $.getSetIniDbNumber('discordRollReward', 'rewards_5', 144);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function roll
|
||||
*
|
||||
* @param {String} channel
|
||||
* @param {String} sender
|
||||
* @param {String} twitchName
|
||||
* @param {String} mention
|
||||
*/
|
||||
function roll(channel, sender, twitchName, mention) {
|
||||
var dice1 = $.randRange(1, 6),
|
||||
dice2 = $.randRange(1, 6),
|
||||
resultMessage = $.lang.get('discord.roll.rolled', $.discord.userPrefix(mention), dice1, dice2);
|
||||
|
||||
if (dice1 == dice2) {
|
||||
switch (dice1) {
|
||||
case 1:
|
||||
resultMessage += $.lang.get('discord.roll.doubleone', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 2:
|
||||
resultMessage += $.lang.get('discord.roll.doubletwo', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 3:
|
||||
resultMessage += $.lang.get('discord.roll.doublethree', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 4:
|
||||
resultMessage += $.lang.get('discord.roll.doublefour', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 5:
|
||||
resultMessage += $.lang.get('discord.roll.doublefive', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 6:
|
||||
resultMessage += $.lang.get('discord.roll.doublesix', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
}
|
||||
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getWin(sender, 'roll'));
|
||||
$.inidb.incr('points', twitchName, rewards[dice1 - 1]);
|
||||
} else {
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getLose(sender, 'roll'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('roll')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
roll(channel, sender, twitchName, mention);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath roll rewards [rewards] - Sets the rewards for the dice roll
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 7 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5])) && !isNaN(parseInt(args[6]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.success'));
|
||||
$.inidb.set('discordRollReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordRollReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordRollReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordRollReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordRollReward', 'reward_4', args[5]);
|
||||
$.inidb.set('discordRollReward', 'reward_5', args[6]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roll.js', 'roll', 0);
|
||||
$.discord.registerSubCommand('roll', 'rewards', 1);
|
||||
loadRewards();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/roll.js')) {
|
||||
loadRewards();
|
||||
}
|
||||
});
|
||||
})();
|
||||
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCountWin = 0,
|
||||
responseCountLost = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('roulette.win.' + i); i++) {
|
||||
responseCountWin++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('roulette.lost.' + i); i++) {
|
||||
responseCountLost++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roulette')) {
|
||||
var r1 = $.randRange(1, 2),
|
||||
r2 = $.randRange(1, 2),
|
||||
random;
|
||||
|
||||
if (r1 == r2) {
|
||||
do {
|
||||
random = $.randRange(1, responseCountWin);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.win.' + random, sender));
|
||||
} else {
|
||||
do {
|
||||
random = $.randRange(1, responseCountLost);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.lost.' + random, sender));
|
||||
}
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roulette.js', 'roulette', 0);
|
||||
|
||||
if (responseCountWin === 0 && responseCountLost === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 rewards = [],
|
||||
emojis = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_0', 75);
|
||||
rewards[1] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_1', 150);
|
||||
rewards[2] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_2', 300);
|
||||
rewards[3] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_3', 450);
|
||||
rewards[4] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_4', 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadEmojis
|
||||
*/
|
||||
function loadEmojis() {
|
||||
emojis[0] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_0', ':cherries:');
|
||||
emojis[1] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_1', ':strawberry:');
|
||||
emojis[2] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_2', ':tangerine:');
|
||||
emojis[3] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_3', ':spades:');
|
||||
emojis[4] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_4', ':hearts:');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmoteKey
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getEmoteKey() {
|
||||
var rand = $.randRange(1, 1000);
|
||||
|
||||
if (rand <= 75) {
|
||||
return 4;
|
||||
} else if (rand > 75 && rand <= 200) {
|
||||
return 3;
|
||||
} else if (rand > 200 && rand <= 450) {
|
||||
return 2;
|
||||
} else if (rand > 450 && rand <= 700) {
|
||||
return 1;
|
||||
} else if (rand > 700) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function calculate
|
||||
*
|
||||
* @param {string} channel
|
||||
* @param {string} username
|
||||
* @param {string} mention
|
||||
* @param {string} twitchName
|
||||
*/
|
||||
function calculate(channel, username, mention, twitchName) {
|
||||
var e1 = getEmoteKey(),
|
||||
e2 = getEmoteKey(),
|
||||
e3 = getEmoteKey(),
|
||||
message = $.lang.get('discord.slotmachine.result.start', $.discord.userPrefix(mention).replace(', ', ''), emojis[e1], emojis[e2], emojis[e3]);
|
||||
|
||||
if (e1 == e2 && e2 == e3) {
|
||||
$.discord.say(channel, message + $.lang.get('discord.slotmachine.result.win', ($.getPointsString(rewards[e1]) + '.')) + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, rewards[e1]);
|
||||
} else if (e1 == e2 || (e2 == e3 && e3 == e1)) {
|
||||
$.discord.say(channel, message + $.lang.get('slotmachine.result.win', (e1 == e2 ? $.getPointsString(Math.floor(rewards[e1] * 0.3)) : $.getPointsString(Math.floor(rewards[e3] * 0.3))) + '.') + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, (e1 == e2 ? (Math.floor(rewards[e1] * 0.3)) : (Math.floor(rewards[e3] * 0.3))));
|
||||
} else {
|
||||
$.discord.say(channel, message + $.gameMessages.getLose(username, 'slot'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath slot - Play the slot machines for some points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('slot')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
calculate(channel, sender, mention, twitchName);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath slot rewards [rewards] - Sets the rewards for the slot machine
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 6 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.success'));
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_4', args[5]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/slotMachine.js', 'slot', 0);
|
||||
$.discord.registerSubCommand('slot', 'rewards', 1);
|
||||
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/slotMachine.js')) {
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
}
|
||||
})
|
||||
})();
|
||||
211
libs/phantombot/scripts/discord/handlers/bitsHandler.js
Normal file
211
libs/phantombot/scripts/discord/handlers/bitsHandler.js
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle bits notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'bitsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'bitsMessage', '(name) just cheered (amount) bits!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'bitsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/bitsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'bitsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'bitsMessage', '(name) just cheered (amount) bits!');
|
||||
channelName = $.getIniDbString('discordSettings', 'bitsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @function getCheerAmount
|
||||
*
|
||||
* @param {String} bits
|
||||
*/
|
||||
function getCheerAmount(bits) {
|
||||
bits = parseInt(bits);
|
||||
|
||||
switch (true) {
|
||||
case bits < 100:
|
||||
return '1';
|
||||
case bits >= 100 && bits < 1000:
|
||||
return '100';
|
||||
case bits >= 1000 && bits < 5000:
|
||||
return '1000';
|
||||
case bits >= 5000 && bits < 10000:
|
||||
return '5000';
|
||||
case bits >= 10000 && bits < 100000:
|
||||
return '10000';
|
||||
case bits >= 100000:
|
||||
return '100000';
|
||||
default:
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getBitsColor
|
||||
*
|
||||
* @param {String} bits
|
||||
*/
|
||||
function getBitsColor(bits) {
|
||||
bits = parseInt(bits);
|
||||
|
||||
switch (true) {
|
||||
case bits < 100:
|
||||
return 0xa1a1a1;
|
||||
case bits >= 100 && bits < 1000:
|
||||
return 0x8618fc;
|
||||
case bits >= 1000 && bits < 5000:
|
||||
return 0x00f7db;
|
||||
case bits >= 5000 && bits < 10000:
|
||||
return 0x2845bc;
|
||||
case bits >= 10000 && bits < 100000:
|
||||
return 0xd41818;
|
||||
case bits >= 100000:
|
||||
return 0xfffa34;
|
||||
default:
|
||||
return 0xa1a1a1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event twitchBits
|
||||
*/
|
||||
$.bind('twitchBits', function(event) {
|
||||
var username = event.getUsername(),
|
||||
bits = event.getBits(),
|
||||
ircMessage = event.getMessage(),
|
||||
emoteRegexStr = $.twitch.GetCheerEmotesRegex(),
|
||||
s = message;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/g)) {
|
||||
s = $.replace(s, '(amount)', bits);
|
||||
}
|
||||
|
||||
if ((ircMessage + '').length > 0) {
|
||||
if (emoteRegexStr.length() > 0) {
|
||||
emoteRegex = new RegExp(emoteRegexStr, 'gi');
|
||||
ircMessage = String(ircMessage).valueOf();
|
||||
ircMessage = ircMessage.replace(emoteRegex, '').trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (ircMessage.length > 0) {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(getBitsColor(bits))
|
||||
.withThumbnail('https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/' + getCheerAmount(bits) + '/1.gif')
|
||||
.withTitle($.lang.get('discord.bitshandler.bits.embed.title'))
|
||||
.appendDescription(s)
|
||||
.appendField($.lang.get('discord.bitsHandler.bits.embed.messagetitle'), ircMessage, true)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
} else {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(getBitsColor(bits))
|
||||
.withThumbnail('https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/' + getCheerAmount(bits) + '/1.gif')
|
||||
.withTitle($.lang.get('discord.bitshandler.bits.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('bitshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler toggle - Toggles bit announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'bitsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler message [message] - Sets the bit announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'bitsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler channel [channel name] - Sets the channel bit announcements will be made in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'bitsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/bitsHandler.js', 'bitshandler', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
164
libs/phantombot/scripts/discord/handlers/clipHandler.js
Normal file
164
libs/phantombot/scripts/discord/handlers/clipHandler.js
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Script : clipHandler.js
|
||||
* Purpose : Configures the automatic display of clips in chat and captures the events from Twitch.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'clipsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'clipsMessage', '(name) created a new clip!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'clipsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/clipHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'clipsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'clipsMessage', '(name) created a new clip!');
|
||||
channelName = $.getIniDbString('discordSettings', 'clipsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchClip
|
||||
*/
|
||||
$.bind('twitchClip', function(event) {
|
||||
var creator = event.getCreator(),
|
||||
url = event.getClipURL(),
|
||||
title = event.getClipTitle(),
|
||||
clipThumbnail = event.getThumbnailObject().getString("medium"),
|
||||
s = message;
|
||||
|
||||
/* Even though the Core won't even query the API if this is false, we still check here. */
|
||||
if (announce === false || toggle === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', creator);
|
||||
}
|
||||
|
||||
if (s.match(/\(url\)/g)) {
|
||||
s = $.replace(s, '(url)', url);
|
||||
}
|
||||
|
||||
if (s.match(/\(title\)/g)) {
|
||||
s = $.replace(s, '(title)', title);
|
||||
}
|
||||
|
||||
if (s.match(/\(embedurl\)/g)) {
|
||||
s = $.replace(s, '(embedurl)', url);
|
||||
}
|
||||
|
||||
if (message.indexOf('(embedurl)') !== -1) {
|
||||
$.discord.say(channelName, s);
|
||||
} else {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/clip-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.cliphandler.clip.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withUrl(url)
|
||||
.withImage(clipThumbnail)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
argsString = event.getArguments(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipstoggle - Toggles the clips announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipstoggle')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('discordSettings', 'clipsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (toggle ? $.lang.get('discord.cliphandler.toggle.on') : $.lang.get('discord.cliphandler.toggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipsmessage [message] - Sets a message for when someone creates a clip.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipsmessage')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = argsString;
|
||||
$.setIniDbString('discordSettings', 'clipsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.message.set', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipschannel [channel] - Sets the channel to send a message to for when someone creates a clip.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipschannel')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.channel.usage', channelName));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(action);
|
||||
$.setIniDbString('discordSettings', 'clipsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.channel.set', action));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath lastclip - Displays information about the last clip captured.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('lastclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'last_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.lastclip', url));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath topclip - Displays the top clip from the past day.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('topclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'most_viewed_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.topclip', url));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipstoggle', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipsmessage', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipschannel', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'lastclip', 0);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'topclip', 0);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
137
libs/phantombot/scripts/discord/handlers/followHandler.js
Normal file
137
libs/phantombot/scripts/discord/handlers/followHandler.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle follower announcements.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'followToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'followMessage', '(name) just followed!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'followChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/followHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'followToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'followMessage', '(name) just followed!');
|
||||
channelName = $.getIniDbString('discordSettings', 'followChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchFollowsInitialized
|
||||
*/
|
||||
$.bind('twitchFollowsInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchFollow
|
||||
*/
|
||||
$.bind('twitchFollow', function(event) {
|
||||
var follower = event.getFollower(),
|
||||
s = message;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', follower);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(20, 184, 102)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/follow-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.followhandler.follow.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('followhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler toggle - Toggles the follower announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'followToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler message [message] - Sets the follower announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'followMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'followChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/followHandler.js', 'followhandler', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'message', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
212
libs/phantombot/scripts/discord/handlers/hostHandler.js
Normal file
212
libs/phantombot/scripts/discord/handlers/hostHandler.js
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle hosts notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'hostToggle', false),
|
||||
hostMessage = $.getSetIniDbString('discordSettings', 'hostMessage', '(name) just hosted for (viewers) viewers!'),
|
||||
autoHostMessage = $.getSetIniDbString('discordSettings', 'autohostMessage', '(name) just auto-hosted!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'hostChannel', ''),
|
||||
hosters = {},
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/hostHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'hostToggle', false);
|
||||
hostMessage = $.getIniDbString('discordSettings', 'hostMessage', '(name) just hosted for (viewers) viewers!');
|
||||
autoHostMessage = $.getIniDbString('discordSettings', 'autohostMessage', '(name) just auto-hosted!');
|
||||
channelName = $.getIniDbString('discordSettings', 'hostChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchHostsInitialized
|
||||
*/
|
||||
$.bind('twitchHostsInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchAutoHosted
|
||||
*/
|
||||
$.bind('twitchAutoHosted', function(event) {
|
||||
var hoster = event.getHoster(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
now = $.systemTime(),
|
||||
s = autoHostMessage;
|
||||
|
||||
if (toggle === false || announce === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hosters[hoster] !== undefined) {
|
||||
if (hosters[hoster].time > now) {
|
||||
return;
|
||||
}
|
||||
hosters[hoster].time = now + 216e5;
|
||||
} else {
|
||||
hosters[hoster] = {};
|
||||
hosters[hoster].time = now + 216e5;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', hoster);
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', String(viewers));
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(255, 0, 0)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/host-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.hosthandler.auto.host.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchHosted
|
||||
*/
|
||||
$.bind('twitchHosted', function(event) {
|
||||
var hoster = event.getHoster(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
now = $.systemTime(),
|
||||
s = hostMessage;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hosters[hoster] !== undefined) {
|
||||
if (hosters[hoster].time > now) {
|
||||
return;
|
||||
}
|
||||
hosters[hoster].time = now + 216e5;
|
||||
} else {
|
||||
hosters[hoster] = {};
|
||||
hosters[hoster].time = now + 216e5;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', hoster);
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', String(viewers));
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(255, 0, 0)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/host-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.hosthandler.host.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('hosthandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler toggle - Toggles the hosts announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'hostToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler hostmessage [message] - Sets the host announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('hostmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
hostMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'hostMessage', hostMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.message.set', hostMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler hostmessage [message] - Sets the auto-host announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autohostmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.autohost.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
autoHostMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'autohostMessage', autohostMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.autohost.message.set', autoHostMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'hostChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/hostHandler.js', 'hosthandler', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'hostmessage', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'autohostmessage', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
140
libs/phantombot/scripts/discord/handlers/keywordHandler.js
Normal file
140
libs/phantombot/scripts/discord/handlers/keywordHandler.js
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle custom keywords in discord.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* @event discordChannelMessage
|
||||
*/
|
||||
$.bind('discordChannelMessage', function(event) {
|
||||
var message = event.getMessage().toLowerCase(),
|
||||
channel = event.getDiscordChannel(),
|
||||
keys = $.inidb.GetKeyList('discordKeywords', ''),
|
||||
keyword,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
// Some users use special symbols that may break regex so this will fix that.
|
||||
try {
|
||||
if (message.match('\\b' + keys[i] + '\\b') && !message.includes('!keyword')) {
|
||||
keyword = $.inidb.get('discordKeywords', keys[i]);
|
||||
$.discord.say(channel, $.discord.tags(event, keyword));
|
||||
break;
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex.message.toLowerCase().includes('invalid quantifier') || ex.message.toLowerCase().includes('syntax')) {
|
||||
if (message.includes(keys[i]) && !message.includes('!keyword')) {
|
||||
keyword = $.inidb.get('discordKeywords', keys[i]);
|
||||
$.discord.say(channel, $.discord.tags(event, keyword));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$.log.error('Failed to send keyword "' + keys[i] + '": ' + ex.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('keyword')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword add [keyword] [response] - Adds a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (subAction === undefined || args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.error'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordKeywords', subAction.toLowerCase(), args.slice(2).join(' '));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.success', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword edit [keyword] [response] - Edits a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('edit')) {
|
||||
if (subAction === undefined || args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.edit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordKeywords', subAction.toLowerCase(), args.slice(2).join(' '));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.edit.success', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword remove [keyword] - Removes a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.remove.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('discordKeywords', subAction.toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.remove.success', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/keywordHandler.js', 'keyword', 1);
|
||||
$.discord.registerSubCommand('keyword', 'add', 1);
|
||||
$.discord.registerSubCommand('keyword', 'edit', 1);
|
||||
$.discord.registerSubCommand('keyword', 'remove', 1);
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle streamelements notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'streamelementsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'streamelementsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'streamelementsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamElementsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'streamelementsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'streamelementsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'streamelementsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamElementsDonationInitialized
|
||||
*/
|
||||
$.bind('streamElementsDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamElementsDonation
|
||||
*/
|
||||
$.bind('streamElementsDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getString('_id'),
|
||||
paramObj = donationObj.getJSONObject('donation'),
|
||||
donationUsername = paramObj.getJSONObject('user').getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'streamelements' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'streamelements' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', String(parseInt(donationAmount.toFixed(2))));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', String(parseInt(donationAmount.toFixed(0))));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(87, 113, 220)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/streamelements-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.streamelementshandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamelementshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler toggle - Toggles the streamelements donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'streamelementsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler message [message] - Sets the streamelements donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'streamelementsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'streamelementsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamElementsHandler.js', 'streamelementshandler', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
402
libs/phantombot/scripts/discord/handlers/streamHandler.js
Normal file
402
libs/phantombot/scripts/discord/handlers/streamHandler.js
Normal file
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle online and offline events from Twitch.
|
||||
*/
|
||||
(function() {
|
||||
var onlineToggle = $.getSetIniDbBoolean('discordSettings', 'onlineToggle', false),
|
||||
onlineMessage = $.getSetIniDbString('discordSettings', 'onlineMessage', '(name) just went online on Twitch!'),
|
||||
offlineToggle = $.getSetIniDbBoolean('discordSettings', 'offlineToggle', false),
|
||||
offlineMessage = $.getSetIniDbString('discordSettings', 'offlineMessage', '(name) is now offline.'),
|
||||
gameToggle = $.getSetIniDbBoolean('discordSettings', 'gameToggle', false),
|
||||
gameMessage = $.getSetIniDbString('discordSettings', 'gameMessage', '(name) just changed game on Twitch!'),
|
||||
botGameToggle = $.getSetIniDbBoolean('discordSettings', 'botGameToggle', true),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'onlineChannel', ''),
|
||||
deleteMessageToggle = $.getSetIniDbBoolean('discordSettings', 'deleteMessageToggle', true),
|
||||
timeout = (6e4 * 5), // 5 minutes.
|
||||
lastEvent = 0,
|
||||
msg,
|
||||
liveMessages = [],
|
||||
offlineMessages = [];
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamHandler.js')) {
|
||||
onlineToggle = $.getIniDbBoolean('discordSettings', 'onlineToggle', false);
|
||||
onlineMessage = $.getIniDbString('discordSettings', 'onlineMessage', '(name) just went online on Twitch!');
|
||||
offlineToggle = $.getIniDbBoolean('discordSettings', 'offlineToggle', false);
|
||||
offlineMessage = $.getIniDbString('discordSettings', 'offlineMessage', '(name) is now offline.');
|
||||
gameToggle = $.getIniDbBoolean('discordSettings', 'gameToggle', false);
|
||||
gameMessage = $.getIniDbString('discordSettings', 'gameMessage', '(name) just changed game on Twitch!');
|
||||
botGameToggle = $.getIniDbBoolean('discordSettings', 'botGameToggle', true);
|
||||
channelName = $.getIniDbString('discordSettings', 'onlineChannel', '');
|
||||
deleteMessageToggle = $.getSetIniDbBoolean('discordSettings', 'deleteMessageToggle', true);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @function getTrimmedGameName
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
function getTrimmedGameName() {
|
||||
var game = $.getGame($.channelName) + '';
|
||||
|
||||
return (game.length > 15 ? game.substr(0, 15) + '...' : game);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event twitchOffline
|
||||
*/
|
||||
$.bind('twitchOffline', function(event) {
|
||||
// Make sure the channel is really offline before deleting and posting the data. Wait a minute and do another check.
|
||||
setTimeout(function() {
|
||||
// Delete live messages if any.
|
||||
if (deleteMessageToggle && liveMessages.length > 0) {
|
||||
while (liveMessages.length > 0) {
|
||||
$.discordAPI.deleteMessage(liveMessages.shift());
|
||||
}
|
||||
}
|
||||
|
||||
if (botGameToggle === true) {
|
||||
$.discord.removeGame();
|
||||
}
|
||||
|
||||
if (!$.isOnline($.channelName) && offlineToggle === true) {
|
||||
var keys = $.inidb.GetKeyList('discordStreamStats', ''),
|
||||
chatters = [],
|
||||
viewers = [],
|
||||
i;
|
||||
|
||||
// Get our data.
|
||||
for (i in keys) {
|
||||
switch (true) {
|
||||
case keys[i].indexOf('chatters_') !== -1:
|
||||
chatters.push($.getIniDbNumber('discordStreamStats', keys[i]));
|
||||
case keys[i].indexOf('viewers_') !== -1:
|
||||
viewers.push($.getIniDbNumber('discordStreamStats', keys[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Get average viewers.
|
||||
var avgViewers = 1;
|
||||
if (viewers.length > 0) {
|
||||
avgViewers = Math.round(viewers.reduce(function(a, b) {
|
||||
return (a + b);
|
||||
}) / (viewers.length < 1 ? 1 : viewers.length));
|
||||
} else {
|
||||
viewers = [0];
|
||||
}
|
||||
|
||||
// Get average chatters.
|
||||
var avgChatters = 1;
|
||||
if (chatters.length > 0) {
|
||||
avgChatters = Math.round(chatters.reduce(function(a, b) {
|
||||
return (a + b);
|
||||
}) / (chatters.length < 1 ? 1 : chatters.length));
|
||||
} else {
|
||||
chatters = [0];
|
||||
}
|
||||
|
||||
// Get new follows.
|
||||
var followersNow = $.getFollows($.channelName),
|
||||
follows = (followersNow - $.getIniDbNumber('discordStreamStats', 'followers', followersNow));
|
||||
|
||||
// Get max viewers.
|
||||
var maxViewers = Math.max.apply(null, viewers);
|
||||
|
||||
// Get max chatters.
|
||||
var maxChatters = Math.max.apply(null, chatters);
|
||||
|
||||
var s = offlineMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
msg = $.discord.say(channelName, s);
|
||||
if (deleteMessageToggle) {
|
||||
offlineMessages.push(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Send the message as an embed.
|
||||
msg = $.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.offline.game'), getTrimmedGameName(), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.viewers'), $.lang.get('discord.streamhandler.offline.viewers.stat', avgViewers, maxViewers), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.chatters'), $.lang.get('discord.streamhandler.offline.chatters.stat', avgChatters, maxChatters), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.followers'), $.lang.get('discord.streamhandler.offline.followers.stat', follows, followersNow), true)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withUrl('https://twitch.tv/' + $.channelName).build());
|
||||
if (deleteMessageToggle) {
|
||||
offlineMessages.push(msg);
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('discordStreamStats');
|
||||
}
|
||||
}, 6e4);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function(event) {
|
||||
// Wait a minute for Twitch to generate a real thumbnail and make sure again that we are online.
|
||||
setTimeout(function() {
|
||||
if ($.isOnline($.channelName) && ($.systemTime() - $.getIniDbNumber('discordSettings', 'lastOnlineEvent', 0) >= timeout)) {
|
||||
// Remove old stats, if any.
|
||||
$.inidb.RemoveFile('discordStreamStats');
|
||||
|
||||
// Delete offline messages if any.
|
||||
if (deleteMessageToggle && offlineMessages.length > 0) {
|
||||
while (offlineMessages.length > 0) {
|
||||
$.discordAPI.deleteMessage(offlineMessages.shift());
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineToggle === true && channelName !== '') {
|
||||
var s = onlineMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
msg = $.discord.say(channelName, s);
|
||||
if(deleteMessageToggle) {
|
||||
liveMessages.push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the message as an embed.
|
||||
msg = $.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.common.game'), getTrimmedGameName(), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.title'), $.getStatus($.channelName), false)
|
||||
.withUrl('https://twitch.tv/' + $.channelName)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withImage($.twitchcache.getPreviewLink() + '?=' + $.randRange(1, 99999)).build());
|
||||
if (deleteMessageToggle) {
|
||||
liveMessages.push(msg);
|
||||
}
|
||||
|
||||
$.setIniDbNumber('discordSettings', 'lastOnlineEvent', $.systemTime());
|
||||
}
|
||||
if (botGameToggle === true) {
|
||||
$.discord.setStream($.getStatus($.channelName), ('https://twitch.tv/' + $.channelName));
|
||||
}
|
||||
}
|
||||
}, 6e4);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchGameChange
|
||||
*/
|
||||
$.bind('twitchGameChange', function(event) {
|
||||
if (gameToggle === false || channelName == '' || $.isOnline($.channelName) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var s = gameMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
liveMessages.push($.discord.say(channelName, s));
|
||||
}
|
||||
liveMessages.push($.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.common.game'), getTrimmedGameName(), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.title'), $.getStatus($.channelName), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.uptime'), $.getStreamUptime($.channelName).toString(), false)
|
||||
.withUrl('https://twitch.tv/' + $.channelName)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withImage($.twitchcache.getPreviewLink() + '?=' + $.randRange(1, 99999)).build()));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggleonline - Toggles the stream online announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggleonline')) {
|
||||
onlineToggle = !onlineToggle;
|
||||
$.inidb.set('discordSettings', 'onlineToggle', onlineToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.toggle', (onlineToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler onlinemessage [message] - Sets the stream online announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('onlinemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
onlineMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'onlineMessage', onlineMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.message.set', onlineMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggleoffline - Toggles the stream offline announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggleoffline')) {
|
||||
offlineToggle = !offlineToggle;
|
||||
$.inidb.set('discordSettings', 'offlineToggle', offlineToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.toggle', (offlineToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler offlinemessage [message] - Sets the stream offline announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('offlinemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
offlineMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'offlineMessage', offlineMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.message.set', offlineMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler togglegame - Toggles the stream game change announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglegame')) {
|
||||
gameToggle = !gameToggle;
|
||||
$.inidb.set('discordSettings', 'gameToggle', gameToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.toggle', (gameToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler gamemessage [message] - Sets the stream game change announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('gamemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
gameMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'gameMessage', gameMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.message.set', gameMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler togglebotstatus - If enabled the bot will be marked as streaming with your Twitch title when you go live.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglebotstatus')) {
|
||||
botGameToggle = !botGameToggle;
|
||||
$.inidb.set('discordSettings', 'botGameToggle', botGameToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.bot.game.toggle', (botGameToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'onlineChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.channel.set', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggledeletemessage - Toggles if online announcements get deleted after stream.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggledeletemessage')) {
|
||||
deleteMessageToggle = !deleteMessageToggle;
|
||||
$.inidb.set('discordSettings', 'deleteMessageToggle', deleteMessageToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.delete.toggle', (deleteMessageToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamHandler.js', 'streamhandler', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'toggleonline', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'onlinemessage', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'togglegame', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'gamemessage', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'channel', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'toggledeletemessage', 1);
|
||||
|
||||
// Get our viewer and follower count every 30 minutes.
|
||||
// Not the most accurate way, but it will work.
|
||||
var interval = setInterval(function() {
|
||||
if ($.isOnline($.channelName)) {
|
||||
var now = $.systemTime();
|
||||
|
||||
// Save this every time to make an average.
|
||||
$.setIniDbNumber('discordStreamStats', 'chatters_' + now, $.users.length);
|
||||
// Save this every time to make an average.
|
||||
$.setIniDbNumber('discordStreamStats', 'viewers_' + now, $.getViewers($.channelName));
|
||||
// Only set this one to get the difference at the end.
|
||||
$.getSetIniDbNumber('discordStreamStats', 'followers', $.getFollows($.channelName));
|
||||
}
|
||||
}, 18e5);
|
||||
});
|
||||
})();
|
||||
166
libs/phantombot/scripts/discord/handlers/streamlabsHandler.js
Normal file
166
libs/phantombot/scripts/discord/handlers/streamlabsHandler.js
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle StreamLabs notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'streamlabsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'streamlabsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'streamlabsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamlabsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'streamlabsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'streamlabsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'streamlabsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamLabsDonationInitialized
|
||||
*/
|
||||
$.bind('streamLabsDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamLabsDonation
|
||||
*/
|
||||
$.bind('streamLabsDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var donationJsonStr = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationJson = new JSONObject(donationJsonStr),
|
||||
donationID = donationJson.get("donation_id"),
|
||||
donationCurrency = donationJson.getString("currency"),
|
||||
donationAmount = donationJson.getString("amount"),
|
||||
donationUsername = donationJson.getString("name"),
|
||||
donationMsg = donationJson.getString("message"),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'streamlabs' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'streamlabs' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/g)) {
|
||||
s = $.replace(s, '(amount)', parseInt(donationAmount).toFixed(2).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', parseInt(donationAmount).toFixed(0).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/g)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/g)) {
|
||||
s = $.replace(s, '(message)', donationMsg);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(49, 196, 162)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/streamlabs-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.streamlabshandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamlabshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler toggle - Toggles the StreamLabs donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'streamlabsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler message [message] - Sets the StreamLabs donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'streamlabsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'streamlabsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamlabsHandler.js', 'streamlabshandler', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
310
libs/phantombot/scripts/discord/handlers/subscribeHandler.js
Normal file
310
libs/phantombot/scripts/discord/handlers/subscribeHandler.js
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle subscriber notifications.
|
||||
*/
|
||||
(function() {
|
||||
var subMessage = $.getSetIniDbString('discordSettings', 'subMessage', '(name) just subscribed!'),
|
||||
primeMessage = $.getSetIniDbString('discordSettings', 'primeMessage', '(name) just subscribed with Twitch Prime!'),
|
||||
resubMessage = $.getSetIniDbString('discordSettings', 'resubMessage', '(name) just subscribed for (months) months in a row!'),
|
||||
giftsubMessage = $.getSetIniDbString('discordSettings', 'giftsubMessage', '(name) just gifted (recipient) a subscription!'),
|
||||
subToggle = $.getSetIniDbBoolean('discordSettings', 'subToggle', false),
|
||||
primeToggle = $.getSetIniDbBoolean('discordSettings', 'primeToggle', false),
|
||||
resubToggle = $.getSetIniDbBoolean('discordSettings', 'resubToggle', false),
|
||||
giftsubToggle = $.getSetIniDbBoolean('discordSettings', 'giftsubToggle', false),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'subChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/subscribeHandler.js')) {
|
||||
subMessage = $.getIniDbString('discordSettings', 'subMessage', '(name) just subscribed!');
|
||||
primeMessage = $.getIniDbString('discordSettings', 'primeMessage', '(name) just subscribed with Twitch Prime!');
|
||||
resubMessage = $.getIniDbString('discordSettings', 'resubMessage', '(name) just subscribed for (months) months in a row!');
|
||||
giftsubMessage = $.getSetIniDbString('discordSettings', 'giftsubMessage', '(name) just gifted (recipient) a subscription!');
|
||||
subToggle = $.getIniDbBoolean('discordSettings', 'subToggle', false);
|
||||
primeToggle = $.getIniDbBoolean('discordSettings', 'primeToggle', false);
|
||||
resubToggle = $.getIniDbBoolean('discordSettings', 'resubToggle', false);
|
||||
giftsubToggle = $.getSetIniDbBoolean('discordSettings', 'giftsubToggle', false);
|
||||
channelName = $.getIniDbString('discordSettings', 'subChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchSubscriber
|
||||
*/
|
||||
$.bind('twitchSubscriber', function(event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
s = subMessage;
|
||||
|
||||
if (announce === false || subToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.subscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchSubscriptionGift', function(event) {
|
||||
var gifter = event.getUsername(),
|
||||
recipient = event.getRecipient(),
|
||||
months = event.getMonths(),
|
||||
s = giftsubMessage;
|
||||
|
||||
if (announce === false || giftsubToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (s.match(/\(recipient\)/g)) {
|
||||
s = $.replace(s, '(recipient)', recipient);
|
||||
}
|
||||
|
||||
if (s.match(/\(months\)/g)) {
|
||||
s = $.replace(s, '(months)', months);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.giftsubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchPrimeSubscriber
|
||||
*/
|
||||
$.bind('twitchPrimeSubscriber', function(event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
s = primeMessage;
|
||||
|
||||
if (announce === false || primeToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.primesubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchReSubscriber
|
||||
*/
|
||||
$.bind('twitchReSubscriber', function(event) {
|
||||
var subscriber = event.getReSubscriber(),
|
||||
months = event.getMonths(),
|
||||
s = resubMessage;
|
||||
|
||||
if (announce === false || resubToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
if (s.match(/\(months\)/g)) {
|
||||
s = $.replace(s, '(months)', months);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.resubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('subscribehandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler subtoggle - Toggles subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('subtoggle')) {
|
||||
subToggle = !subToggle;
|
||||
$.inidb.set('discordSettings', 'subToggle', subToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.toggle', (subToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler giftsubtoggle - Toggles gifted subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('giftsubtoggle')) {
|
||||
giftsubToggle = !giftsubToggle;
|
||||
$.inidb.set('discordSettings', 'giftsubToggle', giftsubToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.toggle', (giftsubToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler primetoggle - Toggles Twitch Prime subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('primetoggle')) {
|
||||
primeToggle = !primeToggle;
|
||||
$.inidb.set('discordSettings', 'primeToggle', primeToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.toggle', (primeToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler resubtoggle - Toggles re-subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('resubtoggle')) {
|
||||
resubToggle = !resubToggle;
|
||||
$.inidb.set('discordSettings', 'resubToggle', resubToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.toggle', (resubToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler submessage [message] - Sets the subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('submessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'subMessage', subMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.message.set', subMessage));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler giftsubmessage [message] - Sets the gift subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('giftsubmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
giftsubMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'giftsubMessage', giftsubMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.message.set', giftsubMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler primemessage [message] - Sets the Twitch Prime subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('primemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.sub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
primeMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'primeMessage', primeMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.sub.message.set', primeMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler resubmessage [message] - Sets the re-subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('resubmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
resubMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'resubMessage', resubMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.message.set', resubMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'subChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/subscribeHandler.js', 'subscribehandler', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'subtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'giftsubtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'primetoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'resubtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'submessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'giftsubmessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'primemessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'resubmessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
172
libs/phantombot/scripts/discord/handlers/tipeeeStreamHandler.js
Normal file
172
libs/phantombot/scripts/discord/handlers/tipeeeStreamHandler.js
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle tipeeestream notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'tipeeestreamToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'tipeeestreamMessage', 'Thank you very much (name) for the tip of (formattedamount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'tipeeestreamChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/tipeeeStreamHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'tipeeestreamToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'tipeeestreamMessage', 'Thank you very much (name) for the tip of (formattedamount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'tipeeestreamChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event tipeeeStreamDonationInitialized
|
||||
*/
|
||||
$.bind('tipeeeStreamDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event tipeeeStreamDonation
|
||||
*/
|
||||
$.bind('tipeeeStreamDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getInt('id'),
|
||||
paramObj = donationObj.getJSONObject('parameters'),
|
||||
donationUsername = paramObj.getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
donationFormattedAmount = donationObj.getString('formattedAmount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'tipeeestream' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'tipeeestream' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', parseInt(donationAmount.toFixed(2)));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', parseInt(donationAmount.toFixed(0)));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
if (s.match(/\(formattedamount\)/)) {
|
||||
s = $.replace(s, '(formattedamount)', donationFormattedAmount);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(216, 67, 89)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/tipeeestream-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.tipeeestreamhandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('tipeeestreamhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler toggle - Toggles the TipeeeStream donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'tipeeestreamToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler message [message] - Sets the TipeeeStream donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'tipeeestreamMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'tipeeestreamChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/tipeeeStreamHandler.js', 'tipeeestreamhandler', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'message', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
124
libs/phantombot/scripts/discord/handlers/twitterHandler.js
Normal file
124
libs/phantombot/scripts/discord/handlers/twitterHandler.js
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle Twitter notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'twitterToggle', false),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'twitterChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/twitterHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'twitterToggle', false);
|
||||
channelName = $.getIniDbString('discordSettings', 'twitterChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitter
|
||||
*/
|
||||
$.bind('twitter', function(event) {
|
||||
if (toggle === false || announce === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getMentionUser() != null) {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withTitle($.twitter.getUsername())
|
||||
.withUrl('https://twitter.com/' + $.twitter.getUsername())
|
||||
.withColor(31, 158, 242)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitter')
|
||||
.withFooterIcon('https://abs.twimg.com/icons/apple-touch-icon-192x192.png')
|
||||
.withAuthorName($.lang.get('discord.twitterhandler.tweet'))
|
||||
.withDesc('[' + event.getMentionUser() + '](https://twitter.com/' + event.getMentionUser() + '): ' + event.getTweet())
|
||||
.build());
|
||||
} else {
|
||||
// Send the message as an embed.
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withTitle($.twitter.getUsername())
|
||||
.withUrl('https://twitter.com/' + $.twitter.getUsername())
|
||||
.withColor(31, 158, 242)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitter')
|
||||
.withFooterIcon('https://abs.twimg.com/icons/apple-touch-icon-192x192.png')
|
||||
.withAuthorName($.lang.get('discord.twitterhandler.tweet'))
|
||||
.withDesc(event.getTweet())
|
||||
.build());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('twitterhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath twitterhandler toggle - Toggles Twitter announcements. Note this module will use settings from the main Twitter module.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'twitterToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath twitterhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'twitterChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/twitterHandler.js', 'twitterhandler', 1);
|
||||
$.discord.registerSubCommand('twitterhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('twitterhandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
201
libs/phantombot/scripts/discord/systems/greetingsSystem.js
Normal file
201
libs/phantombot/scripts/discord/systems/greetingsSystem.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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 joinToggle = $.getSetIniDbBoolean('discordSettings', 'joinToggle', false),
|
||||
partToggle = $.getSetIniDbBoolean('discordSettings', 'partToggle', false),
|
||||
joinMessage = $.getSetIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!'),
|
||||
partMessage = $.getSetIniDbString('discordSettings', 'partMessage', '(name) just left the server!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'greetingsChannel', ''),
|
||||
joinGroup = $.getSetIniDbString('discordSettings', 'greetingsDefaultGroup', '');
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/systems/greetingsSystem.js')) {
|
||||
joinToggle = $.getIniDbBoolean('discordSettings', 'joinToggle', false);
|
||||
partToggle = $.getIniDbBoolean('discordSettings', 'partToggle', false);
|
||||
joinMessage = $.getIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!');
|
||||
partMessage = $.getIniDbString('discordSettings', 'partMessage', '(name) just left the server!');
|
||||
channelName = $.getIniDbString('discordSettings', 'greetingsChannel', '');
|
||||
joinGroup = $.getIniDbString('discordSettings', 'greetingsDefaultGroup', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelJoin
|
||||
*/
|
||||
$.bind('discordChannelJoin', function(event) {
|
||||
// Add the join group if there's one.
|
||||
if (joinGroup !== '' && joinGroup != null && joinGroup.length > 0) {
|
||||
$.discord.setRole(joinGroup, event.getDiscordUser());
|
||||
}
|
||||
|
||||
// Check for the toggle.
|
||||
if (joinToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var username = event.getUsername(),
|
||||
mention = event.getMention(),
|
||||
s = joinMessage;
|
||||
|
||||
if (s.match(/\(@name\)/)) {
|
||||
s = $.replace(s, '(@name)', mention);
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
if (s.match(/\(role\)/)) {
|
||||
s = $.replace(s, '(role)', joinGroup);
|
||||
}
|
||||
|
||||
$.discord.say(channelName, s);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelPart
|
||||
*/
|
||||
$.bind('discordChannelPart', function(event) {
|
||||
if (partToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var username = event.getUsername(),
|
||||
mention = event.getMention(),
|
||||
s = partMessage;
|
||||
|
||||
if (s.match(/\(@name\)/)) {
|
||||
s = $.replace(s, '(@name)', mention);
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
$.discord.say(channelName, s);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('greetingssystem')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem jointoggle - Toggles the announcement for when someone joins the server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('jointoggle')) {
|
||||
joinToggle = !joinToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'joinToggle', joinToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.toggle', (joinToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem parttoggle - Toggles the announcement for when someone leaves the server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('parttoggle')) {
|
||||
partToggle = !partToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'partToggle', partToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.toggle', (partToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem joinmessage [message] - Sets the message for when a user joins your server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('joinmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
joinMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('discordSettings', 'joinMessage', joinMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.set', joinMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem partmessage [message] - Sets the message for when a user leaves your server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('partmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
partMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('discordSettings', 'partMessage', partMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.set', partMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem channel [channel] - Sets the channel messages from this modules will be made in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.setIniDbString('discordSettings', 'greetingsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.set', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem joinrole [role name] - Sets the default role users will get when joining.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('joinrole')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
joinGroup = subAction;
|
||||
$.setIniDbString('discordSettings', 'greetingsDefaultGroup', joinGroup);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.set', joinGroup));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/greetingsSystem.js', 'greetingssystem', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'jointoggle', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'partoggle', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'joinmessage', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'partmessage', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
93
libs/phantombot/scripts/discord/systems/pointSystem.js
Normal file
93
libs/phantombot/scripts/discord/systems/pointSystem.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
/*
|
||||
* @function getUserPoints
|
||||
*
|
||||
* @param {Number} id
|
||||
* @return {Number}
|
||||
*/
|
||||
function getUserPoints(id) {
|
||||
var username = $.discord.resolveTwitchName(id);
|
||||
|
||||
if (username === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
username = username.toLowerCase();
|
||||
|
||||
return ($.inidb.exists('points', username) ? parseInt($.inidb.get('points', username)) : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function decrUserPoints
|
||||
*
|
||||
* @param {Number} id
|
||||
* @param {Number} amount
|
||||
*/
|
||||
function decrUserPoints(id, amount) {
|
||||
var username = $.discord.resolveTwitchName(id);
|
||||
|
||||
if (username !== null) {
|
||||
$.inidb.decr('points', username.toLowerCase(), amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
|
||||
/**
|
||||
* @discordcommandpath points - Tells you how many points you have if you linked in you Twitch account.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('points')) {
|
||||
if (action === undefined) {
|
||||
if (twitchName !== null) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.self.points', $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.linkrequired'));
|
||||
}
|
||||
} else if ($.user.isKnown(action.toLowerCase())) {
|
||||
twitchName = action.replace('@', '').toLowerCase();
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.other.points', twitchName, $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.no.points.other', $.pointNameMultiple));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/pointSystem.js', 'points', 0);
|
||||
});
|
||||
|
||||
/* Export to the API */
|
||||
$.discord.getUserPoints = getUserPoints;
|
||||
$.discord.decrUserPoints = decrUserPoints;
|
||||
})();
|
||||
469
libs/phantombot/scripts/discord/systems/promoteSystem.js
Normal file
469
libs/phantombot/scripts/discord/systems/promoteSystem.js
Normal file
@@ -0,0 +1,469 @@
|
||||
/**
|
||||
* promoteSystem.js
|
||||
*
|
||||
* TODO:
|
||||
* - Add controls to the Beta Panel once that is the formal release.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var showStats = $.getSetIniDbBoolean('promotesettings', 'showstats', true);
|
||||
var showBanner = $.getSetIniDbBoolean('promotesettings', 'showbanner', true);
|
||||
var promoteChannel = $.getSetIniDbString('promotesettings', 'channel', '');
|
||||
var streamChannel = $.getSetIniDbString('promotesettings', 'streamchannel', '');
|
||||
var allowSelfManage = $.getSetIniDbBoolean('promotesettings', 'allowselfmanage', true);
|
||||
var lastIdx = $.getSetIniDbNumber('promotesettings', 'lastidx', 0);
|
||||
var promoteInterval = $.getSetIniDbNumber('promotesettings', 'promoteinterval', 120);
|
||||
var promoteIntervalID = -1;
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
sender = event.getSender(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @discordcommandpath promoteadm channel discord_channel - Channel to send promotion messages to.
|
||||
* @discordcommandpath promoteadm streamchannel discord_channel - Channel to send go-live messages to.
|
||||
* @discordcommandpath promoteadm toggleselfmanage - If you do not want people to add themselves.
|
||||
* @discordcommandpath promoteadm setinterval - Change the interval for promotion messages from 120 minutes to something else.
|
||||
* @discordcommandpath promoteadm togglestats - Show follow and view stats or not.
|
||||
* @discordcommandpath promoteadm togglebanner - Display the channel banner or not.
|
||||
* @discordcommandpath promoteadm so - Shout out a user.
|
||||
* @discordcommandpath promoteadm add - Add a user based on their Twitch channel.
|
||||
* @discordcommandpath promoteadm delete - Delete a user based on their Twitch channel.
|
||||
* @discordcommandpath promoteadm revoke - Revoke the privilege of a user to be able to promote themselves.
|
||||
* @discordcommandpath promoteadm allow - Allow a user to be able to promote themselves.
|
||||
* @discordcommandpath promoteadm list - List the users currently configured.
|
||||
* @discordcommandpath promote add - Add yourself if permitted to do so.
|
||||
* @discordcommandpath promote delete - Delete yourself if permitted to do so.
|
||||
*/
|
||||
|
||||
if (command.equalsIgnoreCase('promote')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) {
|
||||
if (!allowSelfManage) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.noselfmanage'));
|
||||
return;
|
||||
}
|
||||
if (promoteChannel.length === 0 && streamChannel.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.nochannels'));
|
||||
return;
|
||||
}
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName === null || twitchName === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
return;
|
||||
}
|
||||
var twitchID = $.username.getID(twitchName);
|
||||
if ($.inidb.exists('promoterevoke', twitchID)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.revoked'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.nobio'));
|
||||
return;
|
||||
}
|
||||
var biography = args.splice(1).join(' ');
|
||||
if (biography.equalsIgnoreCase('none')) {
|
||||
biography = '';
|
||||
}
|
||||
$.inidb.set('promotebio', twitchID, biography);
|
||||
$.inidb.set('promoteids', twitchID, twitchName.toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.success', twitchName.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('delete')) {
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.del.success', twitchName.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('promoteadm')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) && (promoteChannel.length === 0 && streamChannel.length === 0)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.nochannels'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
if (args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nobio'));
|
||||
return;
|
||||
}
|
||||
var biography = args.splice(2).join(' ');
|
||||
if (biography.equalsIgnoreCase('none')) {
|
||||
biography = '';
|
||||
}
|
||||
$.inidb.set('promotebio', twitchID, biography);
|
||||
$.inidb.set('promoteids', twitchID, args[1].toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('delete')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.nochannel'));
|
||||
return;
|
||||
}
|
||||
|
||||
promoteChannel = $.discord.sanitizeChannelName(args[1]);
|
||||
if (promoteChannel.equals('clear')) {
|
||||
$.inidb.set('promotesettings', 'channel', '');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.cleared'));
|
||||
} else {
|
||||
$.inidb.set('promotesettings', 'channel', promoteChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.success', args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('streamchannel')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.nochannel'));
|
||||
return;
|
||||
}
|
||||
|
||||
streamChannel = $.discord.sanitizeChannelName(args[1]);
|
||||
if (streamChannel.equals('clear')) {
|
||||
streamChannel = '';
|
||||
$.inidb.set('promotesettings', 'streamchannel', '');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.cleared'));
|
||||
} else {
|
||||
$.inidb.set('promotesettings', 'streamchannel', streamChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.success', args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('revoke')) {
|
||||
if (args[1] == undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.inidb.set('promoterevoke', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('allow')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promoterevoke', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('toggleselfmanage')) {
|
||||
if (allowSelfManage) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.on'));
|
||||
}
|
||||
allowSelfManage = !allowSelfManage;
|
||||
$.setIniDbBoolean('promotesettings', 'allowselfmanage', allowSelfManage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('togglestats')) {
|
||||
if (showStats) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.on'));
|
||||
}
|
||||
showStats = !showStats;
|
||||
$.setIniDbBoolean('promotesettings', 'showstats', showStats);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('togglebanner')) {
|
||||
if (showBanner) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.on'));
|
||||
}
|
||||
showBanner = !showBanner;
|
||||
$.setIniDbBoolean('promotesettings', 'showbanner', showBanner);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (action.equalsIgnoreCase('list')) {
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.empty'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchNames = [];
|
||||
for (var i = 0; i < twitchIDs.length; i++) {
|
||||
twitchNames.push($.inidb.get('promoteids', twitchIDs[i]));
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.success', twitchNames.join(', ')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('setinterval')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[1])) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
|
||||
return;
|
||||
}
|
||||
var newPromoteInterval = parseInt(args[1]);
|
||||
if (newPromoteInterval < 15) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.toolow'));
|
||||
return;
|
||||
}
|
||||
$.setIniDbNumber('promotesettings', 'promoteinterval', newPromoteInterval);
|
||||
promoteInterval = newPromoteInterval;
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.success', promoteInterval));
|
||||
startPromote();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('so')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.nouser'));
|
||||
return;
|
||||
}
|
||||
var twitchID = $.inidb.GetKeyByValue('promoteids', '', args[1].toLowerCase());
|
||||
if (twitchID === null || twitchID === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.noexist'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchName = $.inidb.get('promoteids', twitchID);
|
||||
var biography = $.inidb.get('promotebio', twitchID);
|
||||
if (biography.equals('')) {
|
||||
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
|
||||
.withTitle('https://twitch.tv/' + twitchName)
|
||||
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
|
||||
.withColor(31, 158, 242)
|
||||
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
|
||||
.withUrl('https://twitch.tv/' + twitchName).build());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Check for online status of channels every minute.
|
||||
*/
|
||||
setInterval(function() {
|
||||
if ($.inidb.get('promotesettings', 'streamchannel').equals('')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
var start = 0;
|
||||
var end = 100;
|
||||
var total = twitchIDs.length;
|
||||
|
||||
do {
|
||||
var queryString = twitchIDs.slice(start, end).join(',') + '&stream_type=live';
|
||||
var jsonObject = $.twitch.GetStreams(queryString);
|
||||
|
||||
start += 100;
|
||||
end += 100;
|
||||
|
||||
if (!jsonObject.has('streams')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var liveStreamers = [];
|
||||
var jsonStreams = jsonObject.getJSONArray('streams');
|
||||
for (var i = 0; i < jsonStreams.length(); i++) {
|
||||
var twitchID = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('_id').toString();
|
||||
var logoUrl = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('logo');
|
||||
var url = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('url');
|
||||
var game = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('game');
|
||||
var title = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('status');
|
||||
var twitchName = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('display_name');
|
||||
var followers = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('followers');
|
||||
var views = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('views');
|
||||
var banner = null;
|
||||
if (jsonStreams.getJSONObject(i).getJSONObject('channel').has('profile_banner')) {
|
||||
if (jsonStreams.getJSONObject(i).getJSONObject('channel').isNull('profile_banner')) {
|
||||
banner = null;
|
||||
} else {
|
||||
banner = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('profile_banner');
|
||||
}
|
||||
}
|
||||
liveStreamers.push(twitchID);
|
||||
|
||||
if (title === null) {
|
||||
title = $.lang.get('discord.promotesystem.livemsg.missingtitle');
|
||||
}
|
||||
if (game === null) {
|
||||
game = $.lang.get('discord.promotesystem.livemsg.missinggame');
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('promoteonline', twitchID)) {
|
||||
if ($.systemTime() - $.getIniDbNumber('promoteonlinetime', twitchID, 0) >= (6e4 * 5)) {
|
||||
$.inidb.set('promoteonlinetime', twitchID, $.systemTime());
|
||||
var embedBuilder = new Packages.tv.phantombot.discord.util.EmbedBuilder();
|
||||
embedBuilder.withThumbnail(logoUrl)
|
||||
.withTitle($.lang.get('discord.promotesystem.livemsg.title', $.username.resolve(twitchName), twitchName))
|
||||
.withColor(100, 65, 164)
|
||||
.withTimestamp(Date.now())
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.nowplaying'), game, true)
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.streamtitle'), title, true);
|
||||
|
||||
if (showStats) {
|
||||
embedBuilder.appendField($.lang.get('discord.promotesystem.livemsg.followers'), followers, true)
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.views'), views, true);
|
||||
}
|
||||
if (banner !== null && showBanner) {
|
||||
embedBuilder.withImage(banner)
|
||||
}
|
||||
|
||||
embedBuilder.withFooterText($.inidb.get('promotebio', twitchID))
|
||||
.withUrl('https://twitch.tv/' + twitchName);
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'streamchannel'), embedBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('promoteonline');
|
||||
for (var i = 0; i < liveStreamers.length; i++) {
|
||||
$.inidb.set('promoteonline', liveStreamers[i], $.inidb.get('promoteids', liveStreamers[i]));
|
||||
}
|
||||
} while (start < total);
|
||||
}, 6e4, 'scripts::promote.js::checkstreams');
|
||||
|
||||
/**
|
||||
* Send out biography information every so often.
|
||||
*/
|
||||
function startPromote() {
|
||||
if (promoteIntervalID != -1) {
|
||||
$.consoleLn('Restarting the Promotion Interval Handler');
|
||||
clearInterval(promoteIntervalID);
|
||||
}
|
||||
|
||||
promoteIntervalID = setInterval(function() {
|
||||
if ($.inidb.get('promotesettings', 'channel').equals('')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (++lastIdx >= twitchIDs.length) {
|
||||
lastIdx = 0;
|
||||
}
|
||||
$.setIniDbNumber('promotesettings', 'lastidx', lastIdx);
|
||||
|
||||
var twitchName = $.inidb.get('promoteids', twitchIDs[lastIdx]);
|
||||
var biography = $.inidb.get('promotebio', twitchIDs[lastIdx]);
|
||||
if (biography.equals('')) {
|
||||
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
|
||||
.withTitle('https://twitch.tv/' + twitchName)
|
||||
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
|
||||
.withColor(31, 158, 242)
|
||||
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
|
||||
.withUrl('https://twitch.tv/' + twitchName).build());
|
||||
}, promoteInterval * 6e4, 'scripts::promote.js::biography');
|
||||
}
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promote', 0);
|
||||
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promoteadm', 1);
|
||||
$.discord.registerSubCommand('promote', 'add', 0);
|
||||
$.discord.registerSubCommand('promote', 'delete', 0);
|
||||
$.discord.registerSubCommand('promoteadm', 'add', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'delete', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'channel', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'streamchannel', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'revoke', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'allow', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'toggleselfmanage', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'list', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'setinterval', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'togglestats', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'togglebanner', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'so', 1);
|
||||
|
||||
startPromote();
|
||||
});
|
||||
})();
|
||||
75
libs/phantombot/scripts/games/8ball.js
Normal file
75
libs/phantombot/scripts/games/8ball.js
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 8ball.js
|
||||
*
|
||||
* A game that answers questions with random (Non-relating) answers
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
var i;
|
||||
for (i = 1; $.lang.exists('8ball.answer.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
$.consoleDebug($.lang.get('8ball.console.loaded', responseCount));
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
random;
|
||||
|
||||
/**
|
||||
* @commandpath 8ball [question] - Ask the 8ball for advice
|
||||
*/
|
||||
if (command.equalsIgnoreCase('8ball')) {
|
||||
if (!args[0]) {
|
||||
$.say($.resolveRank(sender) + ' ' + $.lang.get('8ball.usage'));
|
||||
$.returnCommandCost(sender, command, $.isModv3(sender, event.getTags()));
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.say($.lang.get('8ball.response', $.lang.get('8ball.answer.' + random)));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if (responseCount == 0) {
|
||||
loadResponses();
|
||||
}
|
||||
$.registerChatCommand('./games/8ball.js', '8ball', 7);
|
||||
});
|
||||
})();
|
||||
537
libs/phantombot/scripts/games/adventureSystem.js
Normal file
537
libs/phantombot/scripts/games/adventureSystem.js
Normal file
@@ -0,0 +1,537 @@
|
||||
/*
|
||||
* 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 joinTime = $.getSetIniDbNumber('adventureSettings', 'joinTime', 60),
|
||||
coolDown = $.getSetIniDbNumber('adventureSettings', 'coolDown', 900),
|
||||
gainPercent = $.getSetIniDbNumber('adventureSettings', 'gainPercent', 30),
|
||||
minBet = $.getSetIniDbNumber('adventureSettings', 'minBet', 10),
|
||||
maxBet = $.getSetIniDbNumber('adventureSettings', 'maxBet', 1000),
|
||||
enterMessage = $.getSetIniDbBoolean('adventureSettings', 'enterMessage', false),
|
||||
warningMessage = $.getSetIniDbBoolean('adventureSettings', 'warningMessage', false),
|
||||
coolDownAnnounce = $.getSetIniDbBoolean('adventureSettings', 'coolDownAnnounce', false),
|
||||
currentAdventure = {},
|
||||
stories = [],
|
||||
moduleLoaded = false,
|
||||
lastStory;
|
||||
|
||||
|
||||
function reloadAdventure() {
|
||||
joinTime = $.getIniDbNumber('adventureSettings', 'joinTime');
|
||||
coolDown = $.getIniDbNumber('adventureSettings', 'coolDown');
|
||||
gainPercent = $.getIniDbNumber('adventureSettings', 'gainPercent');
|
||||
minBet = $.getIniDbNumber('adventureSettings', 'minBet');
|
||||
maxBet = $.getIniDbNumber('adventureSettings', 'maxBet');
|
||||
enterMessage = $.getIniDbBoolean('adventureSettings', 'enterMessage');
|
||||
warningMessage = $.getIniDbBoolean('adventureSettings', 'warningMessage');
|
||||
coolDownAnnounce = $.getIniDbBoolean('adventureSettings', 'coolDownAnnounce');
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads stories from the prefixes 'adventuresystem.stories.default' (only if the language
|
||||
* property of 'adventuresystem.stories.default.enabled' is set to 'true') and
|
||||
* 'adventuresystem.stories'.
|
||||
*
|
||||
* Clears any previously loaded stories.
|
||||
*
|
||||
* @function loadStories
|
||||
*/
|
||||
function loadStories() {
|
||||
currentAdventure.users = [];
|
||||
currentAdventure.survivors = [];
|
||||
currentAdventure.caught = [];
|
||||
currentAdventure.gameState = 0;
|
||||
|
||||
stories = [];
|
||||
|
||||
// For backwards compatibility, load default stories if the variable is not set
|
||||
if (!$.lang.exists('adventuresystem.stories.default') || $.lang.get('adventuresystem.stories.default') === 'true') {
|
||||
loadStoriesFromPrefix('adventuresystem.stories');
|
||||
}
|
||||
|
||||
loadStoriesFromPrefix('adventuresystem.stories.custom');
|
||||
|
||||
$.consoleDebug($.lang.get('adventuresystem.loaded', stories.length));
|
||||
|
||||
for (var i in stories) {
|
||||
if (stories[i].game === null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$.log.warn('You must have at least one adventure that doesn\'t require a game to be set.');
|
||||
currentAdventure.gameState = 2;
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads stories from a specific prefix in the language table and adds them to the
|
||||
* global stories array.
|
||||
*
|
||||
* @param {string} prefix - The prefix underneath which the stories can be found
|
||||
* @example
|
||||
* // Import stories with adventuresystem.stories.custom.X.title as title and
|
||||
* // adventuresystem.stories.custom.X.chapter.Y as chapters
|
||||
* loadStoriesFromPrefix('adventuresystem.stories.custom');
|
||||
*/
|
||||
function loadStoriesFromPrefix(prefix) {
|
||||
var storyId = 1,
|
||||
chapterId,
|
||||
lines;
|
||||
|
||||
for (storyId; $.lang.exists(prefix + '.' + storyId + '.title'); storyId++) {
|
||||
lines = [];
|
||||
for (chapterId = 1; $.lang.exists(prefix + '.' + storyId + '.chapter.' + chapterId); chapterId++) {
|
||||
lines.push($.lang.get(prefix + '.' + storyId + '.chapter.' + chapterId));
|
||||
}
|
||||
|
||||
stories.push({
|
||||
game: ($.lang.exists(prefix + '.' + storyId + '.game') ? $.lang.get(prefix + '.' + storyId + '.game') : null),
|
||||
title: $.lang.get(prefix + '.' + storyId + '.title'),
|
||||
lines: lines,
|
||||
});
|
||||
}
|
||||
|
||||
$.consoleDebug($.lang.get('adventuresystem.loaded.prefix', storyId - 1, prefix));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function top5
|
||||
*/
|
||||
function top5() {
|
||||
var payoutsKeys = $.inidb.GetKeyList('adventurePayouts', ''),
|
||||
temp = [],
|
||||
counter = 1,
|
||||
top5 = [],
|
||||
i;
|
||||
|
||||
if (payoutsKeys.length == 0) {
|
||||
$.say($.lang.get('adventuresystem.top5.empty'));
|
||||
}
|
||||
|
||||
for (i in payoutsKeys) {
|
||||
if (payoutsKeys[i].equalsIgnoreCase($.ownerName) || payoutsKeys[i].equalsIgnoreCase($.botName)) {
|
||||
continue;
|
||||
}
|
||||
temp.push({
|
||||
username: payoutsKeys[i],
|
||||
amount: parseInt($.inidb.get('adventurePayouts', payoutsKeys[i])),
|
||||
});
|
||||
}
|
||||
|
||||
temp.sort(function(a, b) {
|
||||
return (a.amount < b.amount ? 1 : -1);
|
||||
});
|
||||
|
||||
for (i in temp) {
|
||||
if (counter <= 5) {
|
||||
top5.push(counter + '. ' + temp[i].username + ': ' + $.getPointsString(temp[i].amount));
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
$.say($.lang.get('adventuresystem.top5', top5.join(', ')));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function checkUserAlreadyJoined
|
||||
* @param {string} username
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function checkUserAlreadyJoined(username) {
|
||||
var i;
|
||||
for (i in currentAdventure.users) {
|
||||
if (currentAdventure.users[i].username == username) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function adventureUsersListJoin
|
||||
* @param {Array} list
|
||||
* @returns {string}
|
||||
*/
|
||||
function adventureUsersListJoin(list) {
|
||||
var temp = [],
|
||||
i;
|
||||
for (i in list) {
|
||||
temp.push($.username.resolve(list[i].username));
|
||||
}
|
||||
return temp.join(', ');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function calculateResult
|
||||
*/
|
||||
function calculateResult() {
|
||||
var i;
|
||||
for (i in currentAdventure.users) {
|
||||
if ($.randRange(0, 20) > 5) {
|
||||
currentAdventure.survivors.push(currentAdventure.users[i]);
|
||||
} else {
|
||||
currentAdventure.caught.push(currentAdventure.users[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function replaceTags
|
||||
* @param {string} line
|
||||
* @returns {string}
|
||||
*/
|
||||
function replaceTags(line) {
|
||||
if (line.indexOf('(caught)') > -1) {
|
||||
if (currentAdventure.caught.length > 0) {
|
||||
return line.replace('(caught)', adventureUsersListJoin(currentAdventure.caught));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
if (line.indexOf('(survivors)') > -1) {
|
||||
if (currentAdventure.survivors.length > 0) {
|
||||
return line.replace('(survivors)', adventureUsersListJoin(currentAdventure.survivors));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return line
|
||||
};
|
||||
|
||||
/**
|
||||
* @function startHeist
|
||||
* @param {string} username
|
||||
*/
|
||||
function startHeist(username) {
|
||||
currentAdventure.gameState = 1;
|
||||
|
||||
var t = setTimeout(function() {
|
||||
runStory();
|
||||
}, joinTime * 1e3);
|
||||
|
||||
$.say($.lang.get('adventuresystem.start.success', $.resolveRank(username), $.pointNameMultiple));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function joinHeist
|
||||
* @param {string} username
|
||||
* @param {Number} bet
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function joinHeist(username, bet) {
|
||||
if (stories.length < 1) {
|
||||
$.log.error('No adventures found; cannot start an adventure.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAdventure.gameState > 1) {
|
||||
if (!warningMessage) return;
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.join.notpossible'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkUserAlreadyJoined(username)) {
|
||||
if (!warningMessage) return;
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.alreadyjoined'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bet > $.getUserPoints(username)) {
|
||||
if (!warningMessage) return;
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.join.needpoints', $.getPointsString(bet), $.getPointsString($.getUserPoints(username))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bet < minBet) {
|
||||
if (!warningMessage) return;
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.join.bettoolow', $.getPointsString(bet), $.getPointsString(minBet)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bet > maxBet) {
|
||||
if (!warningMessage) return;
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.join.bettoohigh', $.getPointsString(bet), $.getPointsString(maxBet)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAdventure.gameState == 0) {
|
||||
startHeist(username);
|
||||
} else {
|
||||
if (enterMessage) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('adventuresystem.join.success', $.getPointsString(bet)));
|
||||
}
|
||||
}
|
||||
|
||||
currentAdventure.users.push({
|
||||
username: username,
|
||||
bet: parseInt(bet),
|
||||
});
|
||||
|
||||
$.inidb.decr('points', username, bet);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function runStory
|
||||
*/
|
||||
function runStory() {
|
||||
var progress = 0,
|
||||
temp = [],
|
||||
story,
|
||||
line,
|
||||
t;
|
||||
|
||||
currentAdventure.gameState = 2;
|
||||
calculateResult();
|
||||
|
||||
var game = $.getGame($.channelName);
|
||||
|
||||
for (var i in stories) {
|
||||
if (stories[i].game != null) {
|
||||
if (game.equalsIgnoreCase(stories[i].game)) {
|
||||
//$.consoleLn('gamespec::' + stories[i].title);
|
||||
temp.push({
|
||||
title: stories[i].title,
|
||||
lines: stories[i].lines
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//$.consoleLn('normal::' + stories[i].title);
|
||||
temp.push({
|
||||
title: stories[i].title,
|
||||
lines: stories[i].lines
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
story = $.randElement(temp);
|
||||
} while (story == lastStory && stories.length != 1);
|
||||
|
||||
$.say($.lang.get('adventuresystem.runstory', story.title, currentAdventure.users.length));
|
||||
|
||||
t = setInterval(function() {
|
||||
if (progress < story.lines.length) {
|
||||
line = replaceTags(story.lines[progress]);
|
||||
if (line != '') {
|
||||
$.say(line.replace(/\(game\)/g, $.twitchcache.getGameTitle() + ''));
|
||||
}
|
||||
} else {
|
||||
endHeist();
|
||||
clearInterval(t);
|
||||
}
|
||||
progress++;
|
||||
}, 7e3);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function endHeist
|
||||
*/
|
||||
function endHeist() {
|
||||
var i, pay, username, maxlength = 0;
|
||||
var temp = [];
|
||||
|
||||
for (i in currentAdventure.survivors) {
|
||||
pay = (currentAdventure.survivors[i].bet * (gainPercent / 100));
|
||||
$.inidb.incr('adventurePayouts', currentAdventure.survivors[i].username, pay);
|
||||
$.inidb.incr('adventurePayoutsTEMP', currentAdventure.survivors[i].username, pay);
|
||||
$.inidb.incr('points', currentAdventure.survivors[i].username, currentAdventure.survivors[i].bet + pay);
|
||||
}
|
||||
|
||||
for (i in currentAdventure.survivors) {
|
||||
username = currentAdventure.survivors[i].username;
|
||||
maxlength += username.length();
|
||||
temp.push($.username.resolve(username) + ' (+' + $.getPointsString($.inidb.get('adventurePayoutsTEMP', currentAdventure.survivors[i].username)) + ')');
|
||||
}
|
||||
|
||||
if (temp.length == 0) {
|
||||
$.say($.lang.get('adventuresystem.completed.no.win'));
|
||||
} else if (((maxlength + 14) + $.channelName.length) > 512) {
|
||||
$.say($.lang.get('adventuresystem.completed.win.total', currentAdventure.survivors.length, currentAdventure.caught.length)); //in case too many people enter.
|
||||
} else {
|
||||
$.say($.lang.get('adventuresystem.completed', temp.join(', ')));
|
||||
}
|
||||
|
||||
clearCurrentAdventure();
|
||||
temp = "";
|
||||
$.coolDown.set('adventure', false, coolDown, false);
|
||||
if (coolDownAnnounce) {
|
||||
setTimeout(function() {
|
||||
$.say($.lang.get('adventuresystem.reset', $.pointNameMultiple));
|
||||
}, coolDown*1000);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function clearCurrentAdventure
|
||||
*/
|
||||
function clearCurrentAdventure() {
|
||||
currentAdventure = {
|
||||
gameState: 0,
|
||||
users: [],
|
||||
survivors: [],
|
||||
caught: [],
|
||||
}
|
||||
$.inidb.RemoveFile('adventurePayoutsTEMP');
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
actionArg1 = args[1],
|
||||
actionArg2 = args[2];
|
||||
|
||||
/**
|
||||
* @commandpath adventure - Adventure command for starting, checking or setting options
|
||||
* @commandpath adventure [amount] - Start/join an adventure
|
||||
*/
|
||||
if (command.equalsIgnoreCase('adventure')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.adventure.usage', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isNaN(parseInt(action))) {
|
||||
joinHeist(sender, parseInt(action));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure top5 - Announce the top 5 adventurers in the chat (most points gained)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('top5')) {
|
||||
top5();
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set - Base command for controlling the adventure settings
|
||||
*/
|
||||
if (action.equalsIgnoreCase('set')) {
|
||||
if (actionArg1 === undefined || actionArg2 === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set jointime [seconds] - Set the join time
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('joinTime')) {
|
||||
if (isNaN(parseInt(actionArg2))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
joinTime = parseInt(actionArg2);
|
||||
$.inidb.set('adventureSettings', 'joinTime', parseInt(actionArg2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set cooldown [seconds] - Set cooldown time
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('coolDown')) {
|
||||
if (isNaN(parseInt(actionArg2))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
coolDown = parseInt(actionArg2);
|
||||
$.inidb.set('adventureSettings', 'coolDown', parseInt(actionArg2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set gainpercent [value] - Set the gain percent value
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('gainPercent')) {
|
||||
if (isNaN(parseInt(actionArg2))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
gainPercent = parseInt(actionArg2);
|
||||
$.inidb.set('adventureSettings', 'gainPercent', parseInt(actionArg2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set minbet [value] - Set the minimum bet
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('minBet')) {
|
||||
if (isNaN(parseInt(actionArg2))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
minBet = parseInt(actionArg2);
|
||||
$.inidb.set('adventureSettings', 'minBet', parseInt(actionArg2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set maxbet [value] - Set the maximum bet
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('maxBet')) {
|
||||
if (isNaN(parseInt(actionArg2))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.usage'));
|
||||
return;
|
||||
}
|
||||
maxBet = parseInt(actionArg2);
|
||||
$.inidb.set('adventureSettings', 'maxBet', parseInt(actionArg2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set warningmessages [true / false] - Sets the per-user warning messages
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('warningmessages')) {
|
||||
if (args[2].equalsIgnoreCase('true')) warningMessage = true, actionArg2 = $.lang.get('common.enabled');
|
||||
if (args[2].equalsIgnoreCase('false')) warningMessage = false, actionArg2 = $.lang.get('common.disabled');
|
||||
$.inidb.set('adventureSettings', 'warningMessage', warningMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set entrymessages [true / false] - Sets the per-user entry messages
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('entrymessages')) {
|
||||
if (args[2].equalsIgnoreCase('true')) enterMessage = true, actionArg2 = $.lang.get('common.enabled');
|
||||
if (args[2].equalsIgnoreCase('false')) enterMessage = false, actionArg2 = $.lang.get('common.disabled');
|
||||
$.inidb.set('adventureSettings', 'enterMessage', enterMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath adventure set cooldownannounce [true / false] - Sets the cooldown announcement
|
||||
*/
|
||||
if (actionArg1.equalsIgnoreCase('cooldownannounce')) {
|
||||
if (args[2].equalsIgnoreCase('true')) coolDownAnnounce = true, actionArg2 = $.lang.get('common.enabled');
|
||||
if (args[2].equalsIgnoreCase('false')) coolDownAnnounce = false, actionArg2 = $.lang.get('common.disabled');
|
||||
$.inidb.set('adventureSettings', 'coolDownAnnounce', coolDownAnnounce);
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('adventuresystem.set.success', actionArg1, actionArg2));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./games/adventureSystem.js', 'adventure', 7);
|
||||
$.registerChatSubcommand('adventure', 'set', 1);
|
||||
$.registerChatSubcommand('adventure', 'top5', 3);
|
||||
|
||||
loadStories();
|
||||
});
|
||||
|
||||
$.reloadAdventure = reloadAdventure;
|
||||
})();
|
||||
153
libs/phantombot/scripts/games/gambling.js
Normal file
153
libs/phantombot/scripts/games/gambling.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 winGainPercent = $.getSetIniDbNumber('gambling', 'winGainPercent', 30),
|
||||
winRange = $.getSetIniDbNumber('gambling', 'winRange', 50),
|
||||
max = $.getSetIniDbNumber('gambling', 'max', 100),
|
||||
min = $.getSetIniDbNumber('gambling', 'min', 5),
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
|
||||
/**
|
||||
* @function reloadGamble
|
||||
*/
|
||||
function reloadGamble() {
|
||||
winGainPercent = $.getIniDbNumber('gambling', 'winGainPercent');
|
||||
winRange = $.getIniDbNumber('gambling', 'winRange');
|
||||
max = $.getIniDbNumber('gambling', 'max');
|
||||
min = $.getIniDbNumber('gambling', 'min');
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function gamble
|
||||
*
|
||||
* @param {int amout}
|
||||
* @param {string} sender
|
||||
*/
|
||||
function gamble(sender, amount) {
|
||||
var winnings = 0,
|
||||
winSpot = 0,
|
||||
range = $.randRange(1, 100);
|
||||
|
||||
if ($.getUserPoints(sender) < amount) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.need.points', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (max < amount) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.error.max', $.getPointsString(max)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (min > amount) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.error.min', $.getPointsString(min)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (range <= winRange) {
|
||||
$.say($.lang.get('gambling.lost', $.resolveRank(sender), range, $.getPointsString(amount), $.getPointsString($.getUserPoints(sender) - amount), $.gameMessages.getLose(sender, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
} else {
|
||||
winnings = Math.floor(amount + (amount * gain));
|
||||
$.say($.lang.get('gambling.won', $.resolveRank(sender), range, $.getPointsString(winnings - amount), $.getPointsString($.getUserPoints(sender) + (winnings - amount)), $.gameMessages.getWin(sender, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
$.inidb.incr('points', sender, winnings);
|
||||
}
|
||||
}
|
||||
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath gamble [amount] - Gamble your points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamble')) {
|
||||
if (!parseInt(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
gamble(sender, parseInt(action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath gamblesetmax [amount] - Set how many points people can gamble.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamblesetmax')) {
|
||||
if (action === undefined || isNaN(parseInt(action)) || action < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.set.max.usage'));
|
||||
return;
|
||||
}
|
||||
max = action;
|
||||
$.inidb.set('gambling', 'max', max);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.set.max', $.getPointsString(max)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath gamblesetmin [amount] - Set the minumum amount of points people can gamble.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamblesetmin')) {
|
||||
if (action === undefined || isNaN(parseInt(action)) || action < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.set.min.usage'));
|
||||
return;
|
||||
}
|
||||
min = action;
|
||||
$.inidb.set('gambling', 'min', min);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.set.min', $.getPointsString(min)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath gamblesetwinningrange [range] - Set the winning range from 0-100.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamblesetwinningrange')) {
|
||||
if (action === undefined || isNaN(parseInt(action)) || action.includes('-') || action < 1 || action > 100) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.win.range.usage'));
|
||||
return;
|
||||
}
|
||||
winRange = action;
|
||||
$.inidb.set('gambling', 'winRange', winRange);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.win.range', parseInt(winRange) + 1, winRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath gamblesetgainpercent [amount in percent] - Set the winning gain percent.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamblesetgainpercent')) {
|
||||
if (action === undefined || isNaN(parseInt(action)) || action < 1 || action > 100) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.percent.usage'));
|
||||
return;
|
||||
}
|
||||
winGainPercent = action;
|
||||
$.inidb.set('gambling', 'winGainPercent', winGainPercent);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gambling.percent', winGainPercent));
|
||||
}
|
||||
});
|
||||
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./games/gambling.js', 'gamble', 7);
|
||||
$.registerChatCommand('./games/gambling.js', 'gamblesetmax', 1);
|
||||
$.registerChatCommand('./games/gambling.js', 'gamblesetmin', 1);
|
||||
$.registerChatCommand('./games/gambling.js', 'gamblesetwinningrange', 1);
|
||||
$.registerChatCommand('./games/gambling.js', 'gamblesetgainpercent', 1);
|
||||
});
|
||||
|
||||
$.reloadGamble = reloadGamble;
|
||||
})();
|
||||
128
libs/phantombot/scripts/games/killCommand.js
Normal file
128
libs/phantombot/scripts/games/killCommand.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* killCommand.js
|
||||
*
|
||||
* Viewers can show each other the love of REAL friends by expressing it in pain.
|
||||
*/
|
||||
(function() {
|
||||
var selfMessageCount = 0,
|
||||
otherMessageCount = 0,
|
||||
lastRandom = -1,
|
||||
jailTimeout = $.getSetIniDbNumber('settings', 'killTimeoutTime', 60),
|
||||
lang,
|
||||
rand;
|
||||
|
||||
/**
|
||||
* @function reloadKill
|
||||
*/
|
||||
function reloadKill() {
|
||||
jailTimeout = $.getIniDbNumber('settings', 'killTimeoutTime', 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
var i;
|
||||
for (i = 1; $.lang.exists('killcommand.self.' + i); i++) {
|
||||
selfMessageCount++;
|
||||
}
|
||||
for (i = 1; $.lang.exists('killcommand.other.' + i); i++) {
|
||||
otherMessageCount++;
|
||||
}
|
||||
$.consoleDebug($.lang.get('killcommand.console.loaded', selfMessageCount, otherMessageCount));
|
||||
};
|
||||
|
||||
function selfKill(sender) {
|
||||
do {
|
||||
rand = $.randRange(1, selfMessageCount);
|
||||
} while (rand == lastRandom);
|
||||
$.say($.lang.get('killcommand.self.' + rand, $.resolveRank(sender)));
|
||||
lastRandom = rand;
|
||||
};
|
||||
|
||||
function kill(sender, user) {
|
||||
var tries = 0;
|
||||
do {
|
||||
tries++;
|
||||
rand = $.randRange(1, otherMessageCount);
|
||||
} while (rand == lastRandom && tries < 5);
|
||||
lang = $.lang.get('killcommand.other.' + rand, $.resolveRank(sender), $.resolveRank(user), jailTimeout, $.botName);
|
||||
if (lang.startsWith('(jail)')) {
|
||||
lang = $.replace(lang, '(jail)', '');
|
||||
$.say(lang);
|
||||
if (!$.isMod(sender) && jailTimeout > 0) {
|
||||
setTimeout(function() {
|
||||
$.session.say('.timeout ' + sender + ' ' + jailTimeout);
|
||||
}, 1500);
|
||||
}
|
||||
} else {
|
||||
$.say(lang);
|
||||
}
|
||||
lastRandom = rand;
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @commandpath kill [username] - Kill a fellow viewer (not for real!), omit the username to kill yourself
|
||||
*/
|
||||
if (command.equalsIgnoreCase('kill')) {
|
||||
if (args.length <= 0 || args[0].toLowerCase() == sender) {
|
||||
selfKill(sender);
|
||||
} else {
|
||||
kill(sender, args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath jailtimeouttime [amount in seconds] - Set the timeout time for jail time on the kill command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('jailtimeouttime')) {
|
||||
if (args.length == 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('killcommand.jail.timeout.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
jailTimeout = args[0];
|
||||
$.inidb.set('settings', 'killTimeoutTime', args[0]);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('killcommand.jail.timeout.set', jailTimeout));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if (selfMessageCount == 0 && otherMessageCount == 0) {
|
||||
loadResponses();
|
||||
}
|
||||
|
||||
$.registerChatCommand('./games/killCommand.js', 'kill', 7);
|
||||
$.registerChatCommand('./games/killCommand.js', 'jailtimeouttime', 1);
|
||||
});
|
||||
|
||||
$.reloadKill = reloadKill;
|
||||
})();
|
||||
112
libs/phantombot/scripts/games/random.js
Normal file
112
libs/phantombot/scripts/games/random.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* random.js
|
||||
*
|
||||
* A command that randomly picks a random message from the the randoms stack and post it in the chat.
|
||||
*/
|
||||
(function() {
|
||||
var pg13toggle = $.getSetIniDbBoolean('randomSettings', 'pg13toggle', false),
|
||||
randomsCount = 0,
|
||||
lastRandom = 0,
|
||||
randomsPG13Count = 0,
|
||||
lastPG13Random = 0;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./games/random.js')) {
|
||||
pg13toggle = $.getIniDbBoolean('randomSettings', 'pg13toggle');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
var i;
|
||||
for (i = 1; $.lang.exists('randomcommand.' + i); i++) {
|
||||
randomsCount++;
|
||||
}
|
||||
for (i = 1; $.lang.exists('randomcommand.pg13.' + i); i++) {
|
||||
randomsPG13Count++;
|
||||
}
|
||||
$.consoleDebug($.lang.get('randomcommand.console.loaded', (randomsCount + randomsPG13Count)));
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
doPG13Random = false,
|
||||
rand;
|
||||
|
||||
/**
|
||||
* @commandpath random - Something random will happen
|
||||
* @commandpath random pg13toggle - Toggle PG-13 mode on and off
|
||||
*/
|
||||
if (command.equalsIgnoreCase('random')) {
|
||||
if (args[0] !== undefined) {
|
||||
if (args[0].equalsIgnoreCase('pg13toggle')) {
|
||||
pg13toggle = !pg13toggle;
|
||||
$.setIniDbBoolean('randomSettings', 'pg13toggle', pg13toggle);
|
||||
$.say($.lang.get('randomcommand.pg13toggle', pg13toggle));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pg13toggle) {
|
||||
if ($.randRange(1, 100) > 80) {
|
||||
doPG13Random = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (doPG13Random) {
|
||||
do {
|
||||
rand = $.randRange(1, randomsPG13Count);
|
||||
} while (rand == lastPG13Random);
|
||||
|
||||
lastPG13Random = rand;
|
||||
$.say($.tags(event, $.lang.get('randomcommand.pg13.' + rand), false));
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
rand = $.randRange(1, randomsCount);
|
||||
} while (rand == lastRandom);
|
||||
|
||||
lastRandom = rand;
|
||||
$.say($.tags(event, $.lang.get('randomcommand.' + rand), false));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if (randomsCount == 0) {
|
||||
loadResponses();
|
||||
}
|
||||
|
||||
$.registerChatCommand('./games/random.js', 'random');
|
||||
$.registerChatSubcommand('random', 'pg13toggle', 1);
|
||||
});
|
||||
})();
|
||||
135
libs/phantombot/scripts/games/roll.js
Normal file
135
libs/phantombot/scripts/games/roll.js
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* roll.js
|
||||
*
|
||||
* A game where the bot will generate two random dices and award the sender with the points corresponding to the output.
|
||||
*/
|
||||
(function() {
|
||||
var prizes = [];
|
||||
|
||||
/* Set default prices in the DB for the Panel */
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_0', 4);
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_1', 16);
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_2', 36);
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_3', 64);
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_4', 100);
|
||||
$.getSetIniDbNumber('rollprizes', 'prizes_5', 144);
|
||||
|
||||
/**
|
||||
* @function loadPrizes
|
||||
*/
|
||||
function loadPrizes() {
|
||||
prizes[0] = $.getSetIniDbNumber('rollprizes', 'prizes_0', 4);
|
||||
prizes[1] = $.getSetIniDbNumber('rollprizes', 'prizes_1', 16);
|
||||
prizes[2] = $.getSetIniDbNumber('rollprizes', 'prizes_2', 36);
|
||||
prizes[3] = $.getSetIniDbNumber('rollprizes', 'prizes_3', 64);
|
||||
prizes[4] = $.getSetIniDbNumber('rollprizes', 'prizes_4', 100);
|
||||
prizes[5] = $.getSetIniDbNumber('rollprizes', 'prizes_5', 144);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
dice1,
|
||||
dice2,
|
||||
resultMessage;
|
||||
|
||||
/**
|
||||
* @commandpath roll - Roll the dice for some points
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roll')) {
|
||||
|
||||
/**
|
||||
* @commandpath roll rewards [double 1's] [2's] [3's] [4's] [5's] [6's] - Set the reward for each set of doubles.
|
||||
*/
|
||||
if (args[0] !== undefined) {
|
||||
if (args[0].equalsIgnoreCase('rewards')) {
|
||||
if (args.length != 7) {
|
||||
loadPrizes();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5]) || isNaN(args[6])) {
|
||||
loadPrizes();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.usage', prizes.join(' ')));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roll.rewards.success'));
|
||||
$.inidb.set('rollprizes', 'prizes_0', args[1]);
|
||||
$.inidb.set('rollprizes', 'prizes_1', args[2]);
|
||||
$.inidb.set('rollprizes', 'prizes_2', args[3]);
|
||||
$.inidb.set('rollprizes', 'prizes_3', args[4]);
|
||||
$.inidb.set('rollprizes', 'prizes_4', args[5]);
|
||||
$.inidb.set('rollprizes', 'prizes_5', args[6]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dice1 = $.randRange(1, 6);
|
||||
dice2 = $.randRange(1, 6);
|
||||
resultMessage = $.lang.get('roll.rolled', $.resolveRank(sender), dice1, dice2);
|
||||
|
||||
if (dice1 == dice2) {
|
||||
loadPrizes();
|
||||
switch (dice1) {
|
||||
case 1:
|
||||
resultMessage += $.lang.get('roll.doubleone', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
case 2:
|
||||
resultMessage += $.lang.get('roll.doubletwo', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
case 3:
|
||||
resultMessage += $.lang.get('roll.doublethree', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
case 4:
|
||||
resultMessage += $.lang.get('roll.doublefour', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
case 5:
|
||||
resultMessage += $.lang.get('roll.doublefive', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
case 6:
|
||||
resultMessage += $.lang.get('roll.doublesix', $.getPointsString(prizes[dice1 - 1]));
|
||||
break;
|
||||
}
|
||||
|
||||
$.say(resultMessage + $.gameMessages.getWin(sender, 'roll'));
|
||||
$.inidb.incr('points', sender, prizes[dice1 - 1]);
|
||||
} else {
|
||||
$.say(resultMessage + $.gameMessages.getLose(sender, 'roll'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./games/roll.js', 'roll');
|
||||
$.registerChatSubcommand('roll', 'rewards', 1);
|
||||
});
|
||||
|
||||
|
||||
$.loadPrizes = loadPrizes;
|
||||
})();
|
||||
130
libs/phantombot/scripts/games/roulette.js
Normal file
130
libs/phantombot/scripts/games/roulette.js
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* roulette.js
|
||||
*
|
||||
* Resolve issues with a game of russian roulette.
|
||||
*/
|
||||
(function() {
|
||||
var timeoutTime = $.getSetIniDbNumber('roulette', 'timeoutTime', 60),
|
||||
responseCounts = {
|
||||
win: 0,
|
||||
lost: 0,
|
||||
},
|
||||
lastRandom = 0;
|
||||
|
||||
function reloadRoulette() {
|
||||
timeoutTime = $.getIniDbNumber('roulette', 'timeoutTime');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
var i;
|
||||
|
||||
for (i = 1; $.lang.exists('roulette.win.' + i); i++) {
|
||||
responseCounts.win++;
|
||||
}
|
||||
|
||||
for (i = 1; $.lang.exists('roulette.lost.' + i); i++) {
|
||||
responseCounts.lost++;
|
||||
}
|
||||
|
||||
$.consoleDebug($.lang.get('roulette.console.loaded', responseCounts.win, responseCounts.lost));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function timeoutUser
|
||||
* @param {string} username
|
||||
*/
|
||||
function timeoutUserR(username) {
|
||||
$.session.say('.timeout ' + username + ' ' + timeoutTime);
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
random,
|
||||
d1,
|
||||
d2;
|
||||
|
||||
/**
|
||||
* @commandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roulette')) {
|
||||
d1 = $.randRange(1, 2);
|
||||
d2 = $.randRange(1, 2);
|
||||
|
||||
if (d1 == d2) {
|
||||
do {
|
||||
random = $.randRange(1, responseCounts.win);
|
||||
} while (random == lastRandom);
|
||||
$.say($.lang.get('roulette.win.' + random, $.resolveRank(sender)));
|
||||
} else {
|
||||
do {
|
||||
random = $.randRange(1, responseCounts.lost);
|
||||
} while (random == lastRandom);
|
||||
$.say($.lang.get('roulette.lost.' + random, $.resolveRank(sender)));
|
||||
if (!$.isModv3(sender, event.getTags())) {
|
||||
if ($.getBotWhisperMode()) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roulette.timeout.notifyuser', timeoutTime));
|
||||
}
|
||||
timeoutUserR(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath roulettetimeouttime [seconds] - Sets for how long the user gets timed out for when loosing at roulette
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roulettetimeouttime')) {
|
||||
if (!$.isAdmin(sender)) {
|
||||
$.say($.whisperPrefix(sender) + $.adminMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(parseInt(args[0]))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roulette.set.timeouttime.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
timeoutTime = parseInt(args[0]);
|
||||
$.inidb.set('roulette', 'timeoutTime', timeoutTime);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('roulette.set.timeouttime.success', timeoutTime));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if (responseCounts.win == 0 && responseCounts.lost == 0) {
|
||||
loadResponses();
|
||||
}
|
||||
|
||||
$.registerChatCommand('./games/roulette.js', 'roulette', 7);
|
||||
$.registerChatCommand('./games/roulette.js', 'roulettetimeouttime', 1);
|
||||
});
|
||||
|
||||
$.reloadRoulette = reloadRoulette;
|
||||
})();
|
||||
188
libs/phantombot/scripts/games/slotMachine.js
Normal file
188
libs/phantombot/scripts/games/slotMachine.js
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* slotMachine.js
|
||||
*
|
||||
* When the user uses the slots, the bot will generate three random numbers.
|
||||
* These numbers represent an emote. Each emote has a value.
|
||||
* The amount of points; corresponding to the output, will be added to the user's balance.
|
||||
*/
|
||||
(function() {
|
||||
var prizes = [],
|
||||
emoteList = [];
|
||||
|
||||
/* Set default prizes and emotes in the DB for the Panel */
|
||||
$.getSetIniDbNumber('slotmachine', 'prizes_0', 75);
|
||||
$.getSetIniDbNumber('slotmachine', 'prizes_1', 150);
|
||||
$.getSetIniDbNumber('slotmachine', 'prizes_2', 300);
|
||||
$.getSetIniDbNumber('slotmachine', 'prizes_3', 450);
|
||||
$.getSetIniDbNumber('slotmachine', 'prizes_4', 1000);
|
||||
$.getSetIniDbString('slotmachineemotes', 'emote_0', 'Kappa');
|
||||
$.getSetIniDbString('slotmachineemotes', 'emote_1', 'KappaPride');
|
||||
$.getSetIniDbString('slotmachineemotes', 'emote_2', 'BloodTrail');
|
||||
$.getSetIniDbString('slotmachineemotes', 'emote_3', 'ResidentSleeper');
|
||||
$.getSetIniDbString('slotmachineemotes', 'emote_4', '4Head');
|
||||
|
||||
/**
|
||||
* @function loadEmotes
|
||||
*/
|
||||
function loadEmotes() {
|
||||
emoteList[0] = $.getIniDbString('slotmachineemotes', 'emote_0');
|
||||
emoteList[1] = $.getIniDbString('slotmachineemotes', 'emote_1');
|
||||
emoteList[2] = $.getIniDbString('slotmachineemotes', 'emote_2');
|
||||
emoteList[3] = $.getIniDbString('slotmachineemotes', 'emote_3');
|
||||
emoteList[4] = $.getIniDbString('slotmachineemotes', 'emote_4');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function loadPrizes
|
||||
*/
|
||||
function loadPrizes() {
|
||||
prizes[0] = $.getIniDbNumber('slotmachine', 'prizes_0');
|
||||
prizes[1] = $.getIniDbNumber('slotmachine', 'prizes_1');
|
||||
prizes[2] = $.getIniDbNumber('slotmachine', 'prizes_2');
|
||||
prizes[3] = $.getIniDbNumber('slotmachine', 'prizes_3');
|
||||
prizes[4] = $.getIniDbNumber('slotmachine', 'prizes_4');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmoteKey
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getEmoteKey() {
|
||||
var rand = $.randRange(1, 1000);
|
||||
loadEmotes();
|
||||
if (rand <= 75) {
|
||||
return 4;
|
||||
}
|
||||
if (rand > 75 && rand <= 200) {
|
||||
return 3;
|
||||
}
|
||||
if (rand > 200 && rand <= 450) {
|
||||
return 2;
|
||||
}
|
||||
if (rand > 450 && rand <= 700) {
|
||||
return 1;
|
||||
}
|
||||
if (rand > 700) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function calculateResult
|
||||
* @param {string} sender
|
||||
*/
|
||||
function calculateResult(sender) {
|
||||
var e1 = getEmoteKey(),
|
||||
e2 = getEmoteKey(),
|
||||
e3 = getEmoteKey(),
|
||||
message = $.lang.get('slotmachine.result.start', $.resolveRank(sender), emoteList[e1], emoteList[e2], emoteList[e3]);
|
||||
|
||||
loadPrizes();
|
||||
|
||||
if (e1 == e2 && e2 == e3) {
|
||||
message += $.lang.get('slotmachine.result.win', ($.getPointsString(prizes[e1]) + '.'));
|
||||
$.say(message + $.gameMessages.getWin(sender, 'slot'));
|
||||
$.inidb.incr('points', sender, prizes[e1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e1 == e2 || e2 == e3 || e3 == e1) {
|
||||
message += $.lang.get('slotmachine.result.win', (e1 == e2 ? $.getPointsString(Math.floor(prizes[e1] * 0.3)) : $.getPointsString(Math.floor(prizes[e3] * 0.3))) + '.');
|
||||
$.say(message + $.gameMessages.getWin(sender, 'slot'));
|
||||
$.inidb.incr('points', sender, (e1 == e2 ? (Math.floor(prizes[e1] * 0.3)) : (Math.floor(prizes[e3] * 0.3))));
|
||||
return;
|
||||
}
|
||||
$.say(message + $.gameMessages.getLose(sender, 'slot'));
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = (event.getCommand() + '').toLowerCase(),
|
||||
sender = event.getSender().toLowerCase(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @commandpath slot - Play the slot machines for some points
|
||||
*/
|
||||
if (command.equalsIgnoreCase('slot')) {
|
||||
/**
|
||||
* @commandpath slot rewards [val1] [val2] [val3] [val4] [val5] - Set the reward values for the slots.
|
||||
*/
|
||||
if (args[0] !== undefined) {
|
||||
if (args[0].equalsIgnoreCase('rewards')) {
|
||||
if (args.length != 6) {
|
||||
loadPrizes();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(args[1]) || isNaN(args[2]) || isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5])) {
|
||||
loadPrizes();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.usage', prizes.join(' ')));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.rewards.success'));
|
||||
$.inidb.set('slotmachine', 'prizes_0', args[1]);
|
||||
$.inidb.set('slotmachine', 'prizes_1', args[2]);
|
||||
$.inidb.set('slotmachine', 'prizes_2', args[3]);
|
||||
$.inidb.set('slotmachine', 'prizes_3', args[4]);
|
||||
$.inidb.set('slotmachine', 'prizes_4', args[5]);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath slot emotes [emote1] [emote2] [emote3] [emote4] [emote5] - Set the emotes for the slots.
|
||||
*/
|
||||
if (args[0].equalsIgnoreCase('emotes')) {
|
||||
if (args.length < 6) {
|
||||
loadEmotes();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.usage', emoteList.join(' ')));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('slotmachine.emote.success'));
|
||||
$.inidb.set('slotmachineemotes', 'emote_0', args[1]);
|
||||
$.inidb.set('slotmachineemotes', 'emote_1', args[2]);
|
||||
$.inidb.set('slotmachineemotes', 'emote_2', args[3]);
|
||||
$.inidb.set('slotmachineemotes', 'emote_3', args[4]);
|
||||
$.inidb.set('slotmachineemotes', 'emote_4', args[5]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Slot machine */
|
||||
calculateResult(sender);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./games/slotMachine.js', 'slot', 7);
|
||||
$.registerChatSubcommand('slot', 'rewards', 1);
|
||||
$.registerChatSubcommand('slot', 'emotes', 1);
|
||||
});
|
||||
|
||||
$.loadPrizesSlot = loadPrizes;
|
||||
})();
|
||||
162
libs/phantombot/scripts/handlers/bitsHandler.js
Normal file
162
libs/phantombot/scripts/handlers/bitsHandler.js
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This script is for announcing bits from Twitch, and rewarding the user with points if the caster wants too.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
var toggle = $.getSetIniDbBoolean('bitsSettings', 'toggle', false),
|
||||
message = $.getSetIniDbString('bitsSettings', 'message', '(name) just cheered (amount) bits!'),
|
||||
minimum = $.getSetIniDbNumber('bitsSettings', 'minimum', 0),
|
||||
announceBits = false;
|
||||
|
||||
/*
|
||||
* @function reloadBits
|
||||
*/
|
||||
function reloadBits() {
|
||||
toggle = $.getIniDbBoolean('bitsSettings', 'toggle', false);
|
||||
message = $.getIniDbString('bitsSettings', 'message', '(name) just cheered (amount) bits!');
|
||||
minimum = $.getIniDbNumber('bitsSettings', 'minimum', 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchBits
|
||||
*/
|
||||
$.bind('twitchBits', function (event) {
|
||||
var username = event.getUsername(),
|
||||
bits = event.getBits(),
|
||||
ircMessage = event.getMessage(),
|
||||
emoteRegexStr = $.twitch.GetCheerEmotesRegex(),
|
||||
s = message;
|
||||
|
||||
if (announceBits === false || toggle === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bits == 1) {
|
||||
s = $.replace(s, 'bits', 'bit');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/g)) {
|
||||
s = $.replace(s, '(amount)', bits);
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/g)) {
|
||||
s = $.replace(s, '(message)', ircMessage);
|
||||
if (emoteRegexStr.length() > 0) {
|
||||
emoteRegex = new RegExp(emoteRegexStr, 'gi');
|
||||
s = String(s).valueOf();
|
||||
s = s.replace(emoteRegex, '');
|
||||
}
|
||||
}
|
||||
|
||||
if (bits >= minimum) {
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$.say(s);
|
||||
}
|
||||
|
||||
$.writeToFile(username + ' ', './addons/bitsHandler/latestCheer.txt', false);
|
||||
$.writeToFile(username + ': ' + bits + ' ', './addons/bitsHandler/latestCheer&Bits.txt', false);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
argsString = event.getArguments(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @commandpath bitstoggle - Toggles the bits announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('bitstoggle')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('bitsSettings', 'toggle', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('bitshandler.toggle.on') : $.lang.get('bitshandler.toggle.off')))
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @commandpath bitsmessage - Sets a message for when someone cheers bits.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('bitsmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bitshandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = argsString;
|
||||
$.setIniDbString('bitsSettings', 'message', message);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bitshandler.message.set', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath bitsminimum - Set how many bits someone needs to cheer before announcing it.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('bitsminimum')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bitshandler.minimum.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
minimum = parseInt(action);
|
||||
$.setIniDbNumber('bitsSettings', 'minimum', minimum);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bitshandler.minimum.set', minimum));
|
||||
$.log.event(sender + ' changed the bits minimum to: ' + minimum + ' bits.');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/bitsHandler.js', 'bitstoggle', 1);
|
||||
$.registerChatCommand('./handlers/bitsHandler.js', 'bitsmessage', 1);
|
||||
$.registerChatCommand('./handlers/bitsHandler.js', 'bitsminimum', 1);
|
||||
announceBits = true;
|
||||
});
|
||||
|
||||
$.reloadBits = reloadBits;
|
||||
})();
|
||||
607
libs/phantombot/scripts/handlers/channelPointsHandler.js
Normal file
607
libs/phantombot/scripts/handlers/channelPointsHandler.js
Normal file
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle channel point redemption actions
|
||||
* Author: MzLiv
|
||||
*/
|
||||
|
||||
(function () {
|
||||
var transferToggle = $.getSetIniDbBoolean('channelPointsSettings', 'transferToggle', false),
|
||||
transferAmount = $.getSetIniDbNumber('channelPointsSettings', 'transferAmount', 0),
|
||||
transferID = $.getSetIniDbString('channelPointsSettings', 'transferID', 'noIDSet'),
|
||||
transferConfig = $.getSetIniDbBoolean('channelPointsSettings', 'transferConfig', false),
|
||||
transferReward = $.getSetIniDbString('channelPointsSettings', 'transferReward', 'noNameSet'),
|
||||
giveAllToggle = $.getSetIniDbBoolean('channelPointsSettings', 'giveAllToggle', false),
|
||||
giveAllAmount = $.getSetIniDbNumber('channelPointsSettings', 'giveAllAmount', 0),
|
||||
giveAllID = $.getSetIniDbString('channelPointsSettings', 'giveAllID', 'noIDSet'),
|
||||
giveAllConfig = $.getSetIniDbBoolean('channelPointsSettings', 'giveAllConfig', false),
|
||||
giveAllReward = $.getSetIniDbString('channelPointsSettings', 'giveAllReward', 'noNameSet'),
|
||||
emoteOnlyToggle = $.getSetIniDbBoolean('channelPointsSettings', 'emoteOnlyToggle', false),
|
||||
emoteOnlyDuration = $.getSetIniDbNumber('channelPointsSettings', 'emoteOnlyDuration', 0),
|
||||
emoteOnlyID = $.getSetIniDbString('channelPointsSettings', 'emoteOnlyID', 'noIDSet'),
|
||||
emoteOnlyConfig = $.getSetIniDbBoolean('channelPointsSettings', 'emoteOnlyConfig', false),
|
||||
emoteOnlyReward = $.getSetIniDbString('channelPointsSettings', 'emoteOnlyReward', 'noNameSet'),
|
||||
emoteOnlyStart = $.systemTime(),
|
||||
emoteOnlyMode = $.getSetIniDbBoolean('channelPointsSettings', 'timeoutToggle', false),
|
||||
timeoutToggle = $.getSetIniDbBoolean('channelPointsSettings', 'timeoutToggle', false),
|
||||
timeoutDuration = $.getSetIniDbNumber('channelPointsSettings', 'timeoutDuration', 0),
|
||||
timeoutID = $.getSetIniDbString('channelPointsSettings', 'timeoutID', 'noIDSet'),
|
||||
timeoutConfig = $.getSetIniDbBoolean('channelPointsSettings', 'timeoutConfig', false),
|
||||
timeoutReward = $.getSetIniDbString('channelPointsSettings', 'timeoutReward', 'noNameSet'),
|
||||
pointName = $.pointNameMultiple;
|
||||
|
||||
/*
|
||||
* @function updateChannelPointsConfig
|
||||
*/
|
||||
function updateChannelPointsConfig() {
|
||||
transferToggle = $.getIniDbBoolean('channelPointsSettings', 'transferToggle', false);
|
||||
transferAmount = $.getIniDbNumber('channelPointsSettings', 'transferAmount', 0);
|
||||
transferID = $.getIniDbString('channelPointsSettings', 'transferID', 'noIDSet');
|
||||
transferConfig = $.getIniDbBoolean('channelPointsSettings', 'transferConfig', false);
|
||||
transferReward = $.getIniDbString('channelPointsSettings', 'transferReward', 'noNameSet');
|
||||
giveAllToggle = $.getIniDbBoolean('channelPointsSettings', 'giveAllToggle', false);
|
||||
giveAllAmount = $.getIniDbNumber('channelPointsSettings', 'giveAllAmount', 0);
|
||||
giveAllID = $.getIniDbString('channelPointsSettings', 'giveAllID', 'noIDSet');
|
||||
giveAllConfig = $.getIniDbBoolean('channelPointsSettings', 'giveAllConfig', false);
|
||||
giveAllReward = $.getIniDbString('channelPointsSettings', 'giveAllReward', 'noNameSet');
|
||||
emoteOnlyMode = $.getIniDbBoolean('channelPointsSettings', 'timeoutToggle', false),
|
||||
emoteOnlyToggle = $.getIniDbBoolean('channelPointsSettings', 'emoteOnlyToggle', false);
|
||||
emoteOnlyDuration = $.getIniDbNumber('channelPointsSettings', 'emoteOnlyDuration', 0);
|
||||
emoteOnlyID = $.getIniDbString('channelPointsSettings', 'emoteOnlyID', 'noIDSet');
|
||||
emoteOnlyConfig = $.getIniDbBoolean('channelPointsSettings', 'emoteOnlyConfig', false);
|
||||
emoteOnlyReward = $.getIniDbString('channelPointsSettings', 'emoteOnlyReward', 'noNameSet');
|
||||
timeoutToggle = $.getIniDbBoolean('channelPointsSettings', 'timeoutToggle', false);
|
||||
timeoutDuration = $.getIniDbNumber('channelPointsSettings', 'timeoutDuration', 0);
|
||||
timeoutID = $.getIniDbString('channelPointsSettings', 'timeoutID', 'noIDSet');
|
||||
timeoutConfig = $.getIniDbBoolean('channelPointsSettings', 'timeoutConfig', false);
|
||||
timeoutReward = $.getIniDbString('channelPointsSettings', 'timeoutReward', 'noNameSet');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('channelpoints')) {
|
||||
if (action === undefined) {
|
||||
if (transferToggle === false && giveAllToggle === false && emoteOnlyToggle === false && timeoutToggle === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.notenabled'));
|
||||
return;
|
||||
}
|
||||
var config = '';
|
||||
if (transferToggle === true) {
|
||||
config += ' transfer';
|
||||
}
|
||||
if (giveAllToggle === true) {
|
||||
config += ' giveall';
|
||||
}
|
||||
if (emoteOnlyToggle === true) {
|
||||
config += ' emoteonly';
|
||||
}
|
||||
if (timeoutToggle === true) {
|
||||
config += ' timeout';
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.current', config));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath usage
|
||||
*/
|
||||
if (action.equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath info
|
||||
*/
|
||||
if (action.equalsIgnoreCase('info')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.info'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath transfer
|
||||
*/
|
||||
if (action.equalsIgnoreCase('transfer')) {
|
||||
if (args[1] === undefined) {
|
||||
|
||||
if (transferToggle === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.info'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.current', transferReward, transferAmount));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath transfer usage
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath transfer config
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('config')) {
|
||||
transferConfig = !transferConfig;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferConfig', transferConfig);
|
||||
if (transferConfig === true){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.config.start'));
|
||||
transferID = 'noIDSet';
|
||||
transferReward = 'noNameSet';
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferID', transferID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferReward', transferReward);
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.config.failed'));
|
||||
// config is closed when reward is successfully redeemed please see reward ID config in channel point events below
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath transfer amount
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('amount')) {
|
||||
if (args[2] === undefined) {
|
||||
if (transferAmount === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.amount.notset'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.amount.usage', transferAmount));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[2])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.nan'));
|
||||
return;
|
||||
}
|
||||
transferAmount = args[2];
|
||||
$.setIniDbNumber('channelPointsSettings', 'transferAmount', transferAmount);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.amount.message', transferAmount));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath transfer toggle
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('toggle')) {
|
||||
if (transferToggle === false){
|
||||
if (transferID.equals('noIDSet')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.toggle.id'));
|
||||
return;
|
||||
}
|
||||
if (transferAmount === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.transfer.toggle.amount'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
transferToggle = !transferToggle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferToggle', transferToggle);
|
||||
$.say($.whisperPrefix(sender) + (transferToggle ? $.lang.get('channelPointsHandler.transfer.enabled', transferReward) : $.lang.get('channelPointsHandler.transfer.disabled')));
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* @commandpath giveall
|
||||
*/
|
||||
if (action.equalsIgnoreCase('giveall')) {
|
||||
if (args[1] === undefined) {
|
||||
|
||||
if (giveAllToggle === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.info'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.current', giveAllReward, giveAllAmount));
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* @commandpath giveall usage
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giveall config
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('config')) {
|
||||
giveAllConfig = !giveAllConfig;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllConfig', giveAllConfig);
|
||||
if (giveAllConfig === true) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.config.start'));
|
||||
giveAllID = 'noIDSet';
|
||||
giveAllReward = 'noNameSet';
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllID', giveAllID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllReward', giveAllReward);
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.config.failed'));
|
||||
// config is closed when reward is successfully redeemed please see reward ID config in channel point events below
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giveall amount
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('amount')) {
|
||||
if (args[2] === undefined) {
|
||||
if (giveAllAmount === 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.amount.notset'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.amount.usage', giveAllAmount));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[2])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.nan'));
|
||||
return;
|
||||
}
|
||||
giveAllAmount = args[2];
|
||||
$.setIniDbNumber('channelPointsSettings', 'giveallAmount', giveAllAmount);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.amount.message', giveAllAmount));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giveall toggle
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('toggle')) {
|
||||
if (giveAllToggle === false) {
|
||||
if (giveAllID.equals('noIDSet')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.toggle.id'));
|
||||
return;
|
||||
}
|
||||
if (giveAllAmount === 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.giveall.toggle.amount'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
giveAllToggle = !giveAllToggle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveallToggle', giveAllToggle);
|
||||
$.say($.whisperPrefix(sender) + (giveAllToggle ? $.lang.get('channelPointsHandler.giveall.enabled', giveAllReward) : $.lang.get('channelPointsHandler.giveall.disabled')));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath emoteonly
|
||||
*/
|
||||
if (action.equalsIgnoreCase('emoteonly')) {
|
||||
if (args[1] === undefined) {
|
||||
|
||||
if (emoteOnlyToggle === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.info'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.current', emoteOnlyReward, emoteOnlyDuration));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath emoteonly usage
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath emoteonly config
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('config')) {
|
||||
emoteOnlyConfig = !emoteOnlyConfig;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyConfig', emoteOnlyConfig);
|
||||
if (emoteOnlyConfig === true){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.config.start'));
|
||||
emoteOnlyID = 'noIDSet';
|
||||
emoteOnlyReward = 'noNameSet';
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyID', emoteOnlyID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyReward', emoteOnlyReward);
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.config.failed'));
|
||||
// config is closed when reward is successfully redeemed please see reward ID config in channel point events below
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath emoteonly duration
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('duration')) {
|
||||
if (args[2] === undefined) {
|
||||
if (emoteOnlyDuration === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.duration.notset'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.duration.usage', emoteOnlyDuration));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[2])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.nan'));
|
||||
return;
|
||||
}
|
||||
emoteOnlyDuration = args[2];
|
||||
$.setIniDbNumber('channelPointsSettings', 'emoteOnlyDuration', emoteOnlyDuration);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.duration.message', emoteOnlyDuration));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath emoteonly toggle
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('toggle')) {
|
||||
if (emoteOnlyToggle === false){
|
||||
if (emoteOnlyID.equals('noIDSet')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.toggle.id'));
|
||||
return;
|
||||
}
|
||||
if (emoteOnlyDuration === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.emoteonly.toggle.duration'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
emoteOnlyToggle = !emoteOnlyToggle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyToggle', emoteOnlyToggle);
|
||||
$.say($.whisperPrefix(sender) + (emoteOnlyToggle ? $.lang.get('channelPointsHandler.emoteonly.enabled', emoteOnlyReward) : $.lang.get('channelPointsHandler.emoteonly.disabled')));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath timeout
|
||||
*/
|
||||
|
||||
if (action.equalsIgnoreCase('timeout')) {
|
||||
if (args[1] === undefined) {
|
||||
|
||||
if (timeoutToggle === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.info'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.current', timeoutReward, timeoutDuration));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath timeout usage
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath timeout config
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('config')) {
|
||||
timeoutConfig = !timeoutConfig;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutConfig', timeoutConfig);
|
||||
if (timeoutConfig === true){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.config.start'));
|
||||
timeoutID = 'noIDSet';
|
||||
timeoutReward = 'noNameSet';
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutID', timeoutID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutReward', timeoutReward);
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.config.failed'));
|
||||
// config is closed when reward is successfully redeemed please see reward ID config in channel point events below
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath timeout duration
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('duration')) {
|
||||
if (args[2] === undefined) {
|
||||
if (timeoutDuration === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.duration.notset'));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.duration.usage', timeoutDuration));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[2])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.nan'));
|
||||
return;
|
||||
}
|
||||
timeoutDuration = args[2];
|
||||
$.setIniDbNumber('channelPointsSettings', 'timeoutDuration', timeoutDuration);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.duration.message', timeoutDuration));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath timeout toggle
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase('toggle')) {
|
||||
if (timeoutToggle === false){
|
||||
if (timeoutID.equals('noIDSet')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.toggle.id'));
|
||||
return;
|
||||
}
|
||||
if (timeoutDuration === 0){
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('channelPointsHandler.timeout.toggle.duration'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
timeoutToggle = !timeoutToggle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutToggle', timeoutToggle);
|
||||
$.say($.whisperPrefix(sender) + (timeoutToggle ? $.lang.get('channelPointsHandler.timeout.enabled', timeoutReward) : $.lang.get('channelPointsHandler.timeout.disabled')));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
* @event channelPointRedemptions
|
||||
*/
|
||||
$.bind('PubSubChannelPoints', function (event) {
|
||||
var redemptionID = event.getRedemptionID(),
|
||||
rewardID = event.getRewardID(),
|
||||
userID = event.getUserID(),
|
||||
username = event.getUsername(),
|
||||
displayName = event.getDisplayName(),
|
||||
rewardTitle = event.getRewardTitle(),
|
||||
cost = event.getCost(),
|
||||
inputPromt = event.getInputPrompt(),
|
||||
userInput = event.getUserInput(),
|
||||
fulfillmentStatus = event.getFulfillmentStatus();
|
||||
|
||||
com.gmt2001.Console.debug.println("Channel point event " + rewardTitle + " parsed to javascript." + " ID is: " + rewardID);
|
||||
|
||||
/*
|
||||
* reward ID config
|
||||
*/
|
||||
if (transferConfig === true) {
|
||||
transferID = rewardID;
|
||||
transferReward = rewardTitle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferID', transferID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferReward', transferReward);
|
||||
transferConfig = false;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'transferConfig', transferConfig);
|
||||
$.say($.lang.get('channelPointsHandler.transfer.config.complete', transferReward));
|
||||
return;
|
||||
}
|
||||
|
||||
if (giveAllConfig === true) {
|
||||
giveAllID = rewardID;
|
||||
giveAllReward = rewardTitle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllID', giveAllID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllReward', giveAllReward);
|
||||
giveAllConfig = false;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'giveAllConfig', giveAllConfig);
|
||||
$.say($.lang.get('channelPointsHandler.giveAll.config.complete', giveAllReward));
|
||||
return;
|
||||
}
|
||||
|
||||
if (emoteOnlyConfig === true) {
|
||||
emoteOnlyID = rewardID;
|
||||
emoteOnlyReward = rewardTitle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyID', emoteOnlyID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyReward', emoteOnlyReward);
|
||||
emoteOnlyConfig = false;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'emoteOnlyConfig', emoteOnlyConfig);
|
||||
$.say($.lang.get('channelPointsHandler.emoteOnly.config.complete', emoteOnlyReward));
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeoutConfig === true) {
|
||||
if (userInput.equals('')){
|
||||
$.say($.lang.get('channelPointsHandler.timeout.nouserinput'));
|
||||
timeoutConfig = false;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutConfig', timeoutConfig);
|
||||
return;
|
||||
}
|
||||
timeoutID = rewardID;
|
||||
timeoutReward = rewardTitle;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutID', timeoutID);
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutReward', timeoutReward);
|
||||
timeoutConfig = false;
|
||||
$.setIniDbBoolean('channelPointsSettings', 'timeoutConfig', timeoutConfig);
|
||||
$.say($.lang.get('channelPointsHandler.timeout.config.complete', timeoutReward));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* transfer
|
||||
*/
|
||||
if (rewardID.equals(transferID)){
|
||||
if (transferToggle === true){
|
||||
com.gmt2001.Console.debug.println("transferRunStart");
|
||||
if (transferAmount < 2){
|
||||
pointName = $.pointNameSingle;
|
||||
}
|
||||
else{
|
||||
pointName = $.pointNameMultiple;
|
||||
}
|
||||
$.inidb.incr('points', username, transferAmount);
|
||||
$.say($.whisperPrefix(displayName) + ' you have been awarded ' + transferAmount + ' ' + pointName + ' by redeeming ' + rewardTitle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* give all
|
||||
*/
|
||||
if (rewardID.equals(giveAllID)){
|
||||
if (giveAllToggle === true){
|
||||
com.gmt2001.Console.debug.println("giveAllRunStart");
|
||||
$.giveAll(giveAllAmount, displayName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* emote only
|
||||
*/
|
||||
if (rewardID.equals(emoteOnlyID)){
|
||||
if (emoteOnlyToggle ===true){
|
||||
com.gmt2001.Console.debug.println("emoteOnlyRunStart" + emoteOnlyDuration);
|
||||
$.say('/emoteonly');
|
||||
setTimeout(emoteOnlyOff, emoteOnlyDuration * 1e3);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* timeout
|
||||
*/
|
||||
if (rewardID.equals(timeoutID)){
|
||||
if (timeoutToggle === true) {
|
||||
com.gmt2001.Console.debug.println("timeoutRunStart");
|
||||
userInput = $.user.sanitize(userInput);
|
||||
$.say('/timeout ' + userInput + ' ' + timeoutDuration);
|
||||
$.say(userInput + ' has been timed out for ' + timeoutDuration + ' seconds by ' + displayName);
|
||||
//TODO add check to ensure user is in chat
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
* add chat commands
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/channelPointsHandler.js', 'channelpoints', 1);
|
||||
});
|
||||
|
||||
/*
|
||||
* update API
|
||||
*/
|
||||
$.updateChannelPointsConfig = updateChannelPointsConfig();
|
||||
|
||||
})();
|
||||
|
||||
|
||||
/*
|
||||
* exit emote only mode after required time
|
||||
*/
|
||||
function emoteOnlyOff(){
|
||||
$.say('/emoteonlyoff')
|
||||
}
|
||||
145
libs/phantombot/scripts/handlers/clipHandler.js
Normal file
145
libs/phantombot/scripts/handlers/clipHandler.js
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Script : clipHandler.js
|
||||
* Purpose : Configures the automatic display of clips in chat and captures the events from Twitch.
|
||||
*/
|
||||
(function () {
|
||||
var toggle = $.getSetIniDbBoolean('clipsSettings', 'toggle', false),
|
||||
message = $.getSetIniDbString('clipsSettings', 'message', '(name) created a clip: (url)');
|
||||
|
||||
/*
|
||||
* @function reloadClips
|
||||
*/
|
||||
function reloadClips() {
|
||||
toggle = $.getIniDbBoolean('clipsSettings', 'toggle', false);
|
||||
message = $.getIniDbString('clipsSettings', 'message', '(name) created a clip: (url)');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchClip
|
||||
*/
|
||||
$.bind('twitchClip', function (event) {
|
||||
var creator = event.getCreator(),
|
||||
url = event.getClipURL(),
|
||||
title = event.getClipTitle(),
|
||||
s = message;
|
||||
|
||||
/* Even though the Core won't even query the API if this is false, we still check here. */
|
||||
if (toggle === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', creator);
|
||||
}
|
||||
|
||||
if (s.match(/\(url\)/g)) {
|
||||
s = $.replace(s, '(url)', url);
|
||||
}
|
||||
|
||||
if (s.match(/\(title\)/g)) {
|
||||
s = $.replace(s, '(title)', title);
|
||||
}
|
||||
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$.say(s);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
argsString = event.getArguments(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @commandpath clipstoggle - Toggles the clips announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipstoggle')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('clipsSettings', 'toggle', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('cliphandler.toggle.on') : $.lang.get('cliphandler.toggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath clipsmessage - Sets a message for when someone creates a clip.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipsmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = argsString;
|
||||
$.setIniDbString('clipsSettings', 'message', message);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.message.set', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath lastclip - Displays information about the last clip captured.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('lastclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'last_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.lastclip', url));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath topclip - Displays the top clip from the past day.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('topclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'most_viewed_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cliphandler.topclip', url));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/clipHandler.js', 'clipstoggle', 1);
|
||||
$.registerChatCommand('./handlers/clipHandler.js', 'clipsmessage', 1);
|
||||
$.registerChatCommand('./handlers/clipHandler.js', 'lastclip', 7);
|
||||
$.registerChatCommand('./handlers/clipHandler.js', 'topclip', 7);
|
||||
});
|
||||
|
||||
$.reloadClips = reloadClips;
|
||||
})();
|
||||
266
libs/phantombot/scripts/handlers/donationHandler.js
Normal file
266
libs/phantombot/scripts/handlers/donationHandler.js
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* donationHandler.js
|
||||
*
|
||||
* Detect and report donations from TwitchAlerts.
|
||||
*/
|
||||
(function () {
|
||||
var announceDonations = $.getSetIniDbBoolean('donations', 'announce', false),
|
||||
donationReward = $.getSetIniDbFloat('donations', 'reward', 0),
|
||||
donationMessage = $.getSetIniDbString('donations', 'message', $.lang.get('donationhandler.donation.new')),
|
||||
donationGroup = $.getSetIniDbBoolean('donations', 'donationGroup', false),
|
||||
donationGroupMin = $.getSetIniDbNumber('donations', 'donationGroupMin', 5),
|
||||
donationAddonDir = './addons/donationHandler',
|
||||
announceDonationsAllowed = false;
|
||||
|
||||
/*
|
||||
* @function donationpanelupdate
|
||||
*/
|
||||
function donationpanelupdate() {
|
||||
announceDonations = $.getIniDbBoolean('donations', 'announce');
|
||||
donationReward = $.getIniDbFloat('donations', 'reward');
|
||||
donationMessage = $.getIniDbString('donations', 'message');
|
||||
donationGroup = $.getIniDbBoolean('donations', 'donationGroup');
|
||||
donationGroupMin = $.getIniDbNumber('donations', 'donationGroupMin');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event streamLabsDonationInitialized
|
||||
*/
|
||||
$.bind('streamLabsDonationInitialized', function (event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/donationHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory(donationAddonDir)) {
|
||||
$.consoleDebug('>> Creating Donation Handler Directory: ' + donationAddonDir);
|
||||
$.mkDir(donationAddonDir);
|
||||
}
|
||||
|
||||
$.consoleLn('>> Enabling StreamLabs donation announcements');
|
||||
$.log.event('Donation announcements enabled');
|
||||
announceDonationsAllowed = true;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event streamLabsDonation
|
||||
*/
|
||||
$.bind('streamLabsDonation', function (event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/donationHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var donationJsonStr = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationJson = new JSONObject(donationJsonStr);
|
||||
|
||||
var donationID = donationJson.get("donation_id"),
|
||||
donationCreatedAt = donationJson.get("created_at"),
|
||||
donationCurrency = donationJson.getString("currency"),
|
||||
donationAmount = parseFloat(donationJson.getString("amount")),
|
||||
donationUsername = donationJson.getString("name"),
|
||||
donationMsg = donationJson.getString("message");
|
||||
|
||||
if ($.inidb.exists('donations', donationID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('streamInfo', 'lastDonator', $.username.resolve(donationUsername));
|
||||
|
||||
$.inidb.set('donations', donationID, donationJson);
|
||||
|
||||
$.inidb.set('donations', 'last_donation', donationID);
|
||||
|
||||
$.inidb.set('donations', 'last_donation_message', $.lang.get('main.donation.last.tip.message', donationUsername, donationCurrency, donationAmount.toFixed(2)));
|
||||
|
||||
$.writeToFile(donationUsername + ": " + donationAmount.toFixed(2) + " ", donationAddonDir + "/latestDonation.txt", false);
|
||||
|
||||
if (announceDonations && announceDonationsAllowed) {
|
||||
var rewardPoints = Math.round(donationAmount * donationReward);
|
||||
var donationSay = donationMessage;
|
||||
|
||||
donationSay = donationSay.replace('(name)', donationUsername);
|
||||
donationSay = donationSay.replace('(amount)', donationAmount.toFixed(2));
|
||||
donationSay = donationSay.replace('(amount.toFixed(0))', donationAmount.toFixed(0));
|
||||
donationSay = donationSay.replace('(points)', rewardPoints.toString());
|
||||
donationSay = donationSay.replace('(pointname)', (rewardPoints == 1 ? $.pointNameSingle : $.pointNameMultiple).toLowerCase());
|
||||
donationSay = donationSay.replace('(currency)', donationCurrency);
|
||||
donationSay = donationSay.replace('(message)', donationMsg);
|
||||
|
||||
if (donationSay.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = donationSay.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
donationSay = (donationSay + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (donationSay == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (donationSay.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(donationSay.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(donationSay.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
donationSay = $.replace(donationSay, donationSay.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (donationSay == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$.say(donationSay);
|
||||
}
|
||||
|
||||
if (donationGroup) {
|
||||
$.inidb.incr('donations', donationUsername.toLowerCase(), parseInt(donationAmount.toFixed(2)));
|
||||
if ($.inidb.exists('donations', donationUsername.toLowerCase()) && $.inidb.get('donations', donationUsername.toLowerCase()) >= donationGroupMin) {
|
||||
if ($.getUserGroupId(donationUsername.toLowerCase()) > 3) {
|
||||
$.setUserGroupById(donationUsername.toLowerCase(), '4');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rewardPoints > 0) {
|
||||
$.inidb.incr('points', donationUsername.toLowerCase(), rewardPoints);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs - Controls various options for donation handling
|
||||
*/
|
||||
if (command.equalsIgnoreCase('streamlabs')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs toggledonators - Toggles the Donator's group.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggledonators')) {
|
||||
donationGroup = !donationGroup;
|
||||
$.setIniDbBoolean('donations', 'donationGroup', donationGroup);
|
||||
$.say($.whisperPrefix(sender) + (donationGroup ? $.lang.get('donationhandler.enabled.donators') : $.lang.get('donationhandler.disabled.donators')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs minmumbeforepromotion - Set the minimum before people get promoted to a Donator
|
||||
*/
|
||||
if (action.equalsIgnoreCase('minmumbeforepromotion')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donators.min.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
donationGroupMin = subAction;
|
||||
$.setIniDbNumber('donations', 'donationGroupMin', donationGroupMin);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donators.min', donationGroupMin));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs announce - Toggles announcements for donations off and on
|
||||
*/
|
||||
if (action.equalsIgnoreCase('announce')) {
|
||||
announceDonations = !announceDonations;
|
||||
$.setIniDbBoolean('donations', 'announce', announceDonations);
|
||||
$.say($.whisperPrefix(sender) + (announceDonations ? $.lang.get('donationhandler.donations.announce.enable') : $.lang.get('donationhandler.donations.announce.disable')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs rewardmultiplier [n.n] - Set a reward multiplier for donations.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewardmultiplier')) {
|
||||
if (isNaN(parseFloat(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
donationReward = parseFloat(subAction);
|
||||
$.setIniDbFloat('donations', 'reward', donationReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.reward.success', subAction, (subAction == "1" ? $.pointNameSingle : $.pointNameMultiple).toLowerCase()));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs message [message text] - Set the donation message. Tags: (name), (amount), (points), (pointname), (message) and (currency)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message') || action.equalsIgnoreCase('lastmessage')) {
|
||||
var comArg = action.toLowerCase();
|
||||
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var message = args.splice(1).join(' ');
|
||||
if (message.search(/\(name\)/) === -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.message.no-name'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.setIniDbString('donations', comArg, message);
|
||||
|
||||
donationMessage = $.getIniDbString('donations', 'message');
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.donations.message.success', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamlabs currencycode [currencycode] - Set a currency code to convert all Streamlabs donations to.
|
||||
* @commandpath streamlabs currencycode erase - Removes the currency code.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('currencycode')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.streamlabs.currencycode.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('erase')) {
|
||||
$.inidb.del('donations', 'currencycode');
|
||||
Packages.com.illusionaryone.TwitchAlertsAPIv1.instance().SetCurrencyCode('');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.streamlabs.currencycode.success-erase'));
|
||||
} else {
|
||||
$.setIniDbString('donations', 'currencycode', subAction);
|
||||
Packages.com.illusionaryone.TwitchAlertsAPIv1.instance().SetCurrencyCode(subAction);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('donationhandler.streamlabs.currencycode.success', subAction));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Registers commands once the bot is fully loaded.
|
||||
*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/donationHandler.js', 'streamlabs', 1);
|
||||
});
|
||||
|
||||
$.donationpanelupdate = donationpanelupdate;
|
||||
})();
|
||||
172
libs/phantombot/scripts/handlers/emotesHandler.js
Normal file
172
libs/phantombot/scripts/handlers/emotesHandler.js
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* emotesHandler.js
|
||||
*
|
||||
* Pull down emotes from Twitch, BetterTTV and FrankerZ.
|
||||
*/
|
||||
(function() {
|
||||
var emotesRegExpList = [],
|
||||
loaded = false;
|
||||
|
||||
// Load an existing emote RegExp cache. Wait to see if there was a problem that needs us to load
|
||||
// from cache before doing so. This saves CPU cycles and memory.
|
||||
setTimeout(function() {
|
||||
if (emotesRegExpList.length === 0) {
|
||||
loadEmoteCache();
|
||||
}
|
||||
}, 3e4, 'scripts::handlers::emotesHandler.js');
|
||||
|
||||
/**
|
||||
* @event emotesGet
|
||||
*/
|
||||
$.bind('emotesGet', function(event) {
|
||||
buildEmotesDB(event.getBttvEmotes(), event.getBttvLocalEmotes(), event.getFfzEmotes(), event.getFfzLocalEmotes());
|
||||
});
|
||||
|
||||
/**
|
||||
* @function buildEmotesDB
|
||||
*/
|
||||
function buildEmotesDB(bttvEmotes, bttvLocalEmotes, ffzEmotes, ffzLocalEmotes) {
|
||||
var defaultSets = [],
|
||||
jsonArray = [],
|
||||
currentSet,
|
||||
emote,
|
||||
i, j,
|
||||
emoteRegExp,
|
||||
newEmotesRegExpList = [];
|
||||
|
||||
jsonArray = bttvEmotes.getJSONArray('data');
|
||||
for (i = 0; i < jsonArray.length(); i++) {
|
||||
emote = jsonArray.getJSONObject(i).getString('code');
|
||||
|
||||
// Check for emote at the beginning, middle and end of a string.
|
||||
emoteRegExp = '\\b' + emote + '\\b';
|
||||
newEmotesRegExpList.push(emoteRegExp);
|
||||
}
|
||||
|
||||
if (bttvLocalEmotes.has('channelEmotes')) {
|
||||
jsonArray = bttvLocalEmotes.getJSONArray('channelEmotes');
|
||||
for (i = 0; i < jsonArray.length(); i++) {
|
||||
emote = jsonArray.getJSONObject(i).getString('code');
|
||||
|
||||
// Check for emote at the beginning, middle and end of a string.
|
||||
emoteRegExp = '\\b' + emote + '\\b';
|
||||
newEmotesRegExpList.push(emoteRegExp);
|
||||
}
|
||||
}
|
||||
|
||||
if (bttvLocalEmotes.has('sharedEmotes')) {
|
||||
jsonArray = bttvLocalEmotes.getJSONArray('sharedEmotes');
|
||||
for (i = 0; i < jsonArray.length(); i++) {
|
||||
emote = jsonArray.getJSONObject(i).getString('code');
|
||||
|
||||
// Check for emote at the beginning, middle and end of a string.
|
||||
emoteRegExp = '\\b' + emote + '\\b';
|
||||
newEmotesRegExpList.push(emoteRegExp);
|
||||
}
|
||||
}
|
||||
|
||||
defaultSets = ffzEmotes.getJSONArray('default_sets');
|
||||
for (i = 0; i < defaultSets.length(); i++) {
|
||||
currentSet = String(defaultSets.getInt(i));
|
||||
jsonArray = ffzEmotes.getJSONObject('sets').getJSONObject(currentSet).getJSONArray('emoticons');
|
||||
for (j = 0; j < jsonArray.length(); j++) {
|
||||
emote = $.replace($.replace($.replace($.replace($.replace(jsonArray.getJSONObject(j).getString('name'), '(', '\\('), ')', '\\)'), '\'', '\\\''), '[', '\\['), ']', '\\]');
|
||||
|
||||
// Check for emote at the beginning, middle and end of a string.
|
||||
emoteRegExp = '\\b' + emote + '\\b';
|
||||
newEmotesRegExpList.push(emoteRegExp);
|
||||
}
|
||||
}
|
||||
|
||||
if (ffzLocalEmotes.has('room')) {
|
||||
currentSet = String(ffzLocalEmotes.getJSONObject('room').getInt('set'));
|
||||
jsonArray = ffzLocalEmotes.getJSONObject('sets').getJSONObject(currentSet).getJSONArray('emoticons');
|
||||
for (i = 0; i < jsonArray.length(); i++) {
|
||||
emote = $.replace($.replace($.replace($.replace($.replace(jsonArray.getJSONObject(j).getString('name'), '(', '\\('), ')', '\\)'), '\'', '\\\''), '[', '\\['), ']', '\\]');
|
||||
|
||||
// Check for emote at the beginning, middle and end of a string.
|
||||
emoteRegExp = '\\b' + emote + '\\b';
|
||||
newEmotesRegExpList.push(emoteRegExp);
|
||||
}
|
||||
}
|
||||
|
||||
emotesRegExpList = new RegExp(newEmotesRegExpList.join('|'), 'g');
|
||||
$.inidb.set('emotecache', 'regexp_cache', newEmotesRegExpList.join(','));
|
||||
|
||||
loaded = true;
|
||||
$.consoleDebug("Built " + newEmotesRegExpList.length + " regular expressions for emote handling.");
|
||||
newEmotesRegExpList = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadEmoteCache
|
||||
*/
|
||||
function loadEmoteCache() {
|
||||
if (!$.inidb.exists('emotecache', 'regexp_cache')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var regExpList = $.inidb.get('emotecache', 'regexp_cache').split(','),
|
||||
newEmotesRegExpList = [];
|
||||
|
||||
for (var i = 0; i < regExpList.length; i++) {
|
||||
newEmotesRegExpList.push(regExpList[i]);
|
||||
}
|
||||
|
||||
emotesRegExpList = new RegExp(newEmotesRegExpList.join('|'), 'g');
|
||||
|
||||
loaded = true;
|
||||
$.consoleDebug("Built " + newEmotesRegExpList.length + " regular expressions for emote handling from cache.");
|
||||
newEmotesRegExpList = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmotesRegExp
|
||||
* @export $.emotesHandler
|
||||
* @returns {List}{RegExp}
|
||||
*/
|
||||
function getEmotesRegExp() {
|
||||
return emotesRegExpList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmotesMatchCount
|
||||
* @export $.emotesHandler
|
||||
* @param {string}
|
||||
* @returns {number}
|
||||
*/
|
||||
function getEmotesMatchCount(message) {
|
||||
if (!loaded) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
var matched = message.match(emotesRegExpList);
|
||||
|
||||
return (matched !== null ? matched.length : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export functions to API
|
||||
*/
|
||||
$.emotesHandler = {
|
||||
getEmotesRegExp: getEmotesRegExp,
|
||||
getEmotesMatchCount: getEmotesMatchCount
|
||||
};
|
||||
})();
|
||||
237
libs/phantombot/scripts/handlers/followHandler.js
Normal file
237
libs/phantombot/scripts/handlers/followHandler.js
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* followHandler.js
|
||||
*
|
||||
* Register new followers and unfollows in the channel
|
||||
* Optionally supports rewarding points for a follow (Only the first time!)
|
||||
*
|
||||
* The follow train:
|
||||
* Checks if the previous follow was less than 5 minutes ago.
|
||||
* It will trigger on 3, 4, 5, 10 and 20+ followers.
|
||||
* anymore to reduce spam. Unless the 5 minutes have past, then it will start over.
|
||||
*
|
||||
*/
|
||||
(function () {
|
||||
var followToggle = $.getSetIniDbBoolean('settings', 'followToggle', false),
|
||||
followReward = $.getSetIniDbNumber('settings', 'followReward', 0),
|
||||
followMessage = $.getSetIniDbString('settings', 'followMessage', $.lang.get('followhandler.follow.message')),
|
||||
followDelay = $.getSetIniDbNumber('settings', 'followDelay', 5),
|
||||
followQueue = new java.util.concurrent.ConcurrentLinkedQueue,
|
||||
lastFollow = $.systemTime(),
|
||||
announceFollows = false;
|
||||
|
||||
/*
|
||||
* @function updateFollowConfig
|
||||
*/
|
||||
function updateFollowConfig() {
|
||||
followReward = $.getIniDbNumber('settings', 'followReward');
|
||||
followMessage = $.getIniDbString('settings', 'followMessage');
|
||||
followToggle = $.getIniDbBoolean('settings', 'followToggle');
|
||||
followDelay = $.getIniDbNumber('settings', 'followDelay');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function runFollows
|
||||
*/
|
||||
function runFollows() {
|
||||
if (!followQueue.isEmpty() && (lastFollow + (followDelay * 1e3)) < $.systemTime()) {
|
||||
var s = followQueue.poll();
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (s != '') {
|
||||
$.say(s);
|
||||
}
|
||||
lastFollow = $.systemTime();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchFollowsInitialized
|
||||
*/
|
||||
$.bind('twitchFollowsInitialized', function () {
|
||||
$.consoleLn('>> Enabling follower announcements');
|
||||
|
||||
announceFollows = true;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchFollow
|
||||
*/
|
||||
$.bind('twitchFollow', function (event) {
|
||||
var follower = event.getFollower(),
|
||||
s = followMessage;
|
||||
|
||||
if (announceFollows === true && followToggle === true) {
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve(follower));
|
||||
}
|
||||
|
||||
if (s.match(/\(reward\)/)) {
|
||||
s = $.replace(s, '(reward)', $.getPointsString(followReward));
|
||||
}
|
||||
|
||||
if (s.match(/^\/w/)) {
|
||||
s = s.replace('/w', ' /w');
|
||||
}
|
||||
|
||||
followQueue.add(s);
|
||||
|
||||
if (followReward > 0) {
|
||||
$.inidb.incr('points', follower, followReward);
|
||||
}
|
||||
|
||||
$.writeToFile(follower + ' ', './addons/followHandler/latestFollower.txt', false);
|
||||
$.inidb.set('streamInfo', 'lastFollow', follower);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @commandpath followreward [amount] - Set the points reward for following
|
||||
*/
|
||||
if (command.equalsIgnoreCase('followreward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followreward.usage', $.pointNameMultiple, followReward));
|
||||
return;
|
||||
}
|
||||
|
||||
followReward = parseInt(action);
|
||||
$.inidb.set('settings', 'followReward', followReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followreward.success', $.getPointsString(followReward)));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath followmessage [message] - Set the new follower message when there is a reward
|
||||
*/
|
||||
if (command.equalsIgnoreCase('followmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followmessage.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
followMessage = args.slice(0).join(' ');
|
||||
$.inidb.set('settings', 'followMessage', followMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followmessage.success', followMessage));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath followdelay [message] - Set the delay in seconds between follow announcements
|
||||
*/
|
||||
if (command.equalsIgnoreCase('followdelay')) {
|
||||
if (isNaN(parseInt(action)) || parseInt(action) < 5) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followdelay.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
followDelay = parseInt(action);
|
||||
$.inidb.set('settings', 'followDelay', followDelay);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.set.followdelay.success', followDelay));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath followtoggle - Enable or disable the anouncements for new followers
|
||||
*/
|
||||
if (command.equalsIgnoreCase('followtoggle')) {
|
||||
followToggle = !followToggle;
|
||||
$.setIniDbBoolean('settings', 'followToggle', followToggle);
|
||||
$.say($.whisperPrefix(sender) + (followToggle ? $.lang.get('followhandler.followtoggle.on') : $.lang.get('followhandler.followtoggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath checkfollow [username] - Check if a user is following the channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('checkfollow')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.check.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = $.user.sanitize(action);
|
||||
|
||||
if ($.user.isFollower(action)) {
|
||||
$.say($.lang.get('followhandler.check.follows', $.username.resolve(action)));
|
||||
} else {
|
||||
$.say($.lang.get('followhandler.check.notfollows', $.username.resolve(action)));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath shoutout [streamer] - Give a shout out to a streamer.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('shoutout')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('followhandler.shoutout.usage', command));
|
||||
return;
|
||||
}
|
||||
|
||||
var streamer = $.user.sanitize(args[0]),
|
||||
streamerDisplay = $.username.resolve(streamer),
|
||||
streamerGame = $.getGame(streamer),
|
||||
streamerURL = 'https://twitch.tv/' + streamer;
|
||||
|
||||
if (streamerGame == null || streamerGame.length === 0) {
|
||||
$.say($.lang.get('followhandler.shoutout.no.game', streamerDisplay, streamerURL));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isOnline(streamer)) {
|
||||
$.say($.lang.get('followhandler.shoutout.offline', streamerDisplay, streamerURL, streamerGame));
|
||||
} else {
|
||||
$.say($.lang.get('followhandler.shoutout.online', streamerDisplay, streamerURL, streamerGame));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'followreward', 1);
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'followtoggle', 1);
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'followdelay', 1);
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'followmessage', 1);
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'checkfollow', 2);
|
||||
$.registerChatCommand('./handlers/followHandler.js', 'shoutout', 2);
|
||||
|
||||
setInterval(runFollows, 2e3, 'scripts::handlers::followHandler.js');
|
||||
});
|
||||
|
||||
$.updateFollowConfig = updateFollowConfig;
|
||||
})();
|
||||
103
libs/phantombot/scripts/handlers/gameScanHandler.js
Normal file
103
libs/phantombot/scripts/handlers/gameScanHandler.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
/*
|
||||
* @event twitchGameChange
|
||||
*/
|
||||
$.bind('twitchGameChange', function(event) {
|
||||
if (!$.isOnline($.channelName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var gamesObj = ($.inidb.exists('pastgames', 'gamesList') ? JSON.parse($.getIniDbString('pastgames', 'gamesList')) : {}),
|
||||
date = $.logging.getLogDateString().replace(/-/g, '.'),
|
||||
game = (event.getGameTitle() + '').replace(/\s/g, '-').toLowerCase();
|
||||
|
||||
if (gamesObj[game] !== undefined) {
|
||||
gamesObj[game].push(date);
|
||||
} else {
|
||||
gamesObj[game] = [date];
|
||||
}
|
||||
|
||||
$.setIniDbString('pastgames', 'gamesList', JSON.stringify(gamesObj));
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function(event) {
|
||||
var gamesObj = ($.inidb.exists('pastgames', 'gamesList') ? JSON.parse($.getIniDbString('pastgames', 'gamesList')) : {}),
|
||||
date = $.logging.getLogDateString().replace(/-/g, '.'),
|
||||
game = ($.getGame($.channelName) + '').replace(/\s/g, '-').toLowerCase();
|
||||
|
||||
if (gamesObj[game] !== undefined) {
|
||||
gamesObj[game].push(date);
|
||||
} else {
|
||||
gamesObj[game] = [date];
|
||||
}
|
||||
|
||||
$.setIniDbString('pastgames', 'gamesList', JSON.stringify(gamesObj));
|
||||
});
|
||||
|
||||
/*
|
||||
* @function gameLookUp
|
||||
*
|
||||
* @param {String} gameName
|
||||
*/
|
||||
function gameLookUp(gameName) {
|
||||
var gamesObj = ($.inidb.exists('pastgames', 'gamesList') ? JSON.parse($.getIniDbString('pastgames', 'gamesList')) : {}),
|
||||
game = (gameName + '').replace(/\s/g, '-').toLowerCase();
|
||||
|
||||
if (gamesObj[game] === undefined) {
|
||||
$.say($.lang.get('gamescanhandler.gamescan.notplayed', $.username.resolve($.channelName), gameName));
|
||||
} else {
|
||||
if (gamesObj[game].length > 10) {
|
||||
$.say($.lang.get('gamescanhandler.gamescan.hasplayeddates', $.username.resolve($.channelName), gameName, gamesObj[game].slice(10).join(', '), (gamesObj[game].length - 10)));
|
||||
} else {
|
||||
$.say($.lang.get('gamescanhandler.gamescan.hasplayed', $.username.resolve($.channelName), gameName, gamesObj[game].join(', ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath gamescan [game name] - Scan for a recently played game and list the date in which the broadcaster played it.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamescan')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('gamescanhandler.gamescan.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
gameLookUp(args.join(' '));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/gameScanHandler.js', 'gamescan', 7);
|
||||
});
|
||||
})();
|
||||
396
libs/phantombot/scripts/handlers/hostHandler.js
Normal file
396
libs/phantombot/scripts/handlers/hostHandler.js
Normal file
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* hostHandler.js
|
||||
*
|
||||
* Register and announce (un)host events.
|
||||
* Optionally supports rewarding points for a host (Only every 6 hours!)
|
||||
*/
|
||||
(function () {
|
||||
var hostReward = $.getSetIniDbNumber('settings', 'hostReward', 0),
|
||||
autoHostReward = $.getSetIniDbNumber('settings', 'autoHostReward', 0),
|
||||
hostMinViewerCount = $.getSetIniDbNumber('settings', 'hostMinViewerCount', 0),
|
||||
hostMinCount = $.getSetIniDbNumber('settings', 'hostMinCount', 0),
|
||||
hostMessage = $.getSetIniDbString('settings', 'hostMessage', $.lang.get('hosthandler.host.message')),
|
||||
autoHostMessage = $.getSetIniDbString('settings', 'autoHostMessage', $.lang.get('hosthandler.autohost.message')),
|
||||
hostHistory = $.getSetIniDbBoolean('settings', 'hostHistory', true),
|
||||
hostToggle = $.getSetIniDbBoolean('settings', 'hostToggle', false),
|
||||
autoHostToggle = $.getSetIniDbBoolean('settings', 'autoHostToggle', false),
|
||||
hostTimeout = 216e5, // 6 hours = 6 * 60 * 60 * 1000
|
||||
hostList = {},
|
||||
announceHosts = false;
|
||||
|
||||
/*
|
||||
* @function updateHost
|
||||
*/
|
||||
function updateHost() {
|
||||
hostReward = $.getIniDbNumber('settings', 'hostReward');
|
||||
autoHostReward = $.getIniDbNumber('settings', 'autoHostReward');
|
||||
hostMinViewerCont = $.getIniDbNumber('settings', 'hostMinViewerCount');
|
||||
hostMinCount = $.getIniDbNumber('settings', 'hostMinCount');
|
||||
hostMessage = $.getIniDbString('settings', 'hostMessage');
|
||||
autoHostMessage = $.getIniDbString('settings', 'autoHostMessage');
|
||||
hostHistory = $.getIniDbBoolean('settings', 'hostHistory');
|
||||
hostToggle = $.getIniDbBoolean('settings', 'hostToggle');
|
||||
autoHostToggle = $.getIniDbBoolean('settings', 'autoHostToggle');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchHostsInitialized
|
||||
*/
|
||||
$.bind('twitchHostsInitialized', function (event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/hostHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.consoleLn('>> Enabling hosts announcements');
|
||||
announceHosts = true;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchAutoHosted
|
||||
*/
|
||||
$.bind('twitchAutoHosted', function (event) {
|
||||
var hoster = event.getHoster().toLowerCase(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
s = autoHostMessage;
|
||||
|
||||
if (announceHosts === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hostList[hoster] !== undefined) {
|
||||
if (hostList[hoster].hostTime < $.systemTime()) {
|
||||
hostList[hoster] = {
|
||||
hostTime: ($.systemTime() + hostTimeout)
|
||||
};
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
hostList[hoster] = {
|
||||
hostTime: ($.systemTime() + hostTimeout)
|
||||
};
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve(hoster));
|
||||
}
|
||||
|
||||
if (s.match(/\(reward\)/)) {
|
||||
s = $.replace(s, '(reward)', autoHostReward.toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/)) {
|
||||
s = $.replace(s, '(viewers)', viewers.toString());
|
||||
}
|
||||
|
||||
if (s.match(/^\/w/)) {
|
||||
s = s.replace('/w', ' /w');
|
||||
}
|
||||
|
||||
if (autoHostToggle === true && viewers >= hostMinCount) {
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s != '') {
|
||||
$.say(s);
|
||||
}
|
||||
}
|
||||
|
||||
$.writeToFile(hoster + ' ', './addons/hostHandler/latestAutoHost.txt', false);
|
||||
$.writeToFile(hoster + ' ', './addons/hostHandler/latestHostOrAutoHost.txt', false);
|
||||
if (autoHostReward > 0 && viewers >= hostMinViewerCount) {
|
||||
$.inidb.incr('points', hoster.toLowerCase(), autoHostReward);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchHosted
|
||||
*/
|
||||
$.bind('twitchHosted', function (event) {
|
||||
var hoster = event.getHoster().toLowerCase(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
s = hostMessage;
|
||||
|
||||
// Always update the Host History even if announcements are off or if they recently
|
||||
// hosted the channel and it would not be noted in chat. This was the caster does
|
||||
// have a log of all hosts that did occur, announced or not.
|
||||
//
|
||||
if ($.getIniDbBoolean('settings', 'hostHistory', false)) {
|
||||
var now = $.systemTime();
|
||||
var jsonObject = {
|
||||
'host': String(hoster),
|
||||
'time': now,
|
||||
'viewers': viewers
|
||||
};
|
||||
$.inidb.set('hosthistory', hoster + '_' + now, JSON.stringify(jsonObject));
|
||||
}
|
||||
|
||||
if (announceHosts === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hostList[hoster] !== undefined) {
|
||||
if (hostList[hoster].hostTime < $.systemTime()) {
|
||||
hostList[hoster] = {
|
||||
hostTime: ($.systemTime() + hostTimeout)
|
||||
};
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
hostList[hoster] = {
|
||||
hostTime: ($.systemTime() + hostTimeout)
|
||||
};
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve(hoster));
|
||||
}
|
||||
|
||||
if (s.match(/\(reward\)/)) {
|
||||
s = $.replace(s, '(reward)', hostReward.toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/)) {
|
||||
s = $.replace(s, '(viewers)', viewers.toString());
|
||||
}
|
||||
|
||||
if (s.match(/^\/w/)) {
|
||||
s = s.replace('/w', ' /w');
|
||||
}
|
||||
|
||||
if (hostToggle === true && viewers >= hostMinCount) {
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (s != '') {
|
||||
$.say(s);
|
||||
}
|
||||
}
|
||||
|
||||
$.writeToFile(hoster + ' ', './addons/hostHandler/latestHost.txt', false);
|
||||
$.writeToFile(hoster + ' ', './addons/hostHandler/latestHostOrAutoHost.txt', false);
|
||||
if (hostReward > 0 && viewers >= hostMinViewerCount) {
|
||||
$.inidb.incr('points', hoster.toLowerCase(), hostReward);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @commandpath hosttoggle - Toggles host announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hosttoggle')) {
|
||||
hostToggle = !hostToggle;
|
||||
$.setIniDbBoolean('settings', 'hostToggle', hostToggle);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.host.toggle', (hostToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath autohosttoggle - Toggles auto host announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('autohosttoggle')) {
|
||||
autoHostToggle = !autoHostToggle;
|
||||
$.setIniDbBoolean('settings', 'autoHostToggle', autoHostToggle);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.auto.host.toggle', (autoHostToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath hostreward [amount] - Set the amount of points to reward when a channel starts hosting
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hostreward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostreward.usage', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
hostReward = parseInt(action);
|
||||
$.setIniDbNumber('settings', 'hostReward', hostReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostreward.success', $.getPointsString(action)));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath autohostreward [amount] - Set the amount of points to reward when a channel starts autohosting
|
||||
*/
|
||||
if (command.equalsIgnoreCase('autohostreward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.autohostreward.usage', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
autoHostReward = parseInt(action);
|
||||
$.setIniDbNumber('settings', 'autoHostReward', autoHostReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.autohostreward.success', $.getPointsString(action)));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath hostrewardminviewers [amount] - The number of viewers in the hosted channel required to provide a reward.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hostrewardminviewers')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostrewardminviewers.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
hostMinViewerCount = parseInt(action);
|
||||
$.setIniDbNumber('settings', 'hostMinViewerCount', hostMinViewerCount);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostrewardminviewers.success', hostMinViewerCount));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath hostminviewers [amount] - The number of viewers in the hosted channel required to trigger the chat alert.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hostminviewers')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostminviewers.usage', hostMinCount));
|
||||
return;
|
||||
}
|
||||
|
||||
hostMinCount = parseInt(action);
|
||||
$.setIniDbNumber('settings', 'hostMinCount', hostMinCount);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostminviewers.success', hostMinCount));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath hostmessage [message] - Set a message given when a channel hosts
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hostmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostmessage.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
hostMessage = argsString;
|
||||
$.setIniDbString('settings', 'hostMessage', hostMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.hostmessage.success'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath autohostmessage [message] - Set a message given when a channel autohosts
|
||||
*/
|
||||
if (command.equalsIgnoreCase('autohostmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.autohostmessage.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
autoHostMessage = argsString;
|
||||
$.setIniDbString('settings', 'autoHostMessage', autoHostMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthandler.set.autohostmessage.success'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath hosthistory [on/off] - Enable or disable collection of host history data for the Panel.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('hosthistory')) {
|
||||
if (args.length < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthistory.usage', $.getIniDbBoolean('settings', 'hostHistory') ? "on" : "off"));
|
||||
return;
|
||||
}
|
||||
if (action.equalsIgnoreCase('on')) {
|
||||
$.setIniDbBoolean('settings', 'hostHistory', true);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthistory.change', $.getIniDbBoolean('settings', 'hostHistory') ? "on" : "off"));
|
||||
} else if (action.equalsIgnoreCase('off')) {
|
||||
$.setIniDbBoolean('settings', 'hostHistory', false);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthistory.change', $.getIniDbBoolean('settings', 'hostHistory') ? "on" : "off"));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('hosthistory.usage', $.getIniDbBoolean('settings', 'hostHistory') ? "on" : "off"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath host [channel name] - Will host that channel. Make sure to add your bot as a channel editor on your Twitch dashboard for this to work.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('host')) {
|
||||
if (action !== undefined) {
|
||||
$.say('.host ' + action);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath unhost - Will unhost the channel that is being hosted. Make sure to add your bot as a channel editor on your Twitch dashboard for this to work.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('unhost')) {
|
||||
$.say('.unhost');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hostmessage', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'autohostmessage', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hostreward', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'autohostreward', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hostrewardminviewers', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hosthistory', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hosttoggle', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'autohosttoggle', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'host', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'unhost', 1);
|
||||
$.registerChatCommand('./handlers/hostHandler.js', 'hostminviewers', 1);
|
||||
});
|
||||
|
||||
$.updateHost = updateHost;
|
||||
})();
|
||||
232
libs/phantombot/scripts/handlers/keywordHandler.js
Normal file
232
libs/phantombot/scripts/handlers/keywordHandler.js
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* 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 keywords = [];
|
||||
|
||||
/*
|
||||
* @function loadKeywords
|
||||
*/
|
||||
function loadKeywords() {
|
||||
var keys = $.inidb.GetKeyList('keywords', ''),
|
||||
i;
|
||||
|
||||
keywords = [];
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
var json = JSON.parse($.inidb.get('keywords', keys[i]));
|
||||
|
||||
if (json.isRegex) {
|
||||
try {
|
||||
json.regexKey = new RegExp(json.keyword, json.isCaseSensitive ? '' : 'i');
|
||||
} catch (ex) {
|
||||
$.log.error('Bad regex detected in keyword [' + keys[i] + ']: ' + ex.message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
keywords.push(json);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
function executeKeyword(json, event) {
|
||||
// Make sure the keyword isn't on cooldown.
|
||||
if ($.coolDownKeywords.get(json.keyword, sender) > 0) {
|
||||
return;
|
||||
}
|
||||
// If the keyword is a command, we need to send that command.
|
||||
else if (json.response.startsWith('command:')) {
|
||||
$.command.run(sender, json.response.substring(8), '', event.getTags());
|
||||
}
|
||||
// Keyword just has a normal response.
|
||||
else {
|
||||
json.response = $.replace(json.response, '(keywordcount)', '(keywordcount ' + json.keyword + ')');
|
||||
$.say($.tags(event, json.response, false));
|
||||
}
|
||||
}
|
||||
|
||||
var message = event.getMessage(),
|
||||
sender = event.getSender(),
|
||||
messagePartsLower = message.toLowerCase().split(' '),
|
||||
messageParts = message.split(' '),
|
||||
json;
|
||||
|
||||
// Don't say the keyword if someone tries to remove it.
|
||||
if (message.startsWith('!keyword')) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < keywords.length; i++) {
|
||||
json = keywords[i];
|
||||
|
||||
if (json.isRegex) {
|
||||
if (json.regexKey.test(message)) {
|
||||
executeKeyword(json, event);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
var str = '',
|
||||
caseAdjustedMessageParts = messageParts;
|
||||
if (!json.isCaseSensitive) {
|
||||
json.keyword = json.keyword.toLowerCase();
|
||||
caseAdjustedMessageParts = messagePartsLower;
|
||||
}
|
||||
for (var idx = 0; idx < caseAdjustedMessageParts.length; idx++) {
|
||||
// Create a string to match on the keyword.
|
||||
str += (caseAdjustedMessageParts[idx] + ' ');
|
||||
// Either match on the exact word or phrase if it contains it.
|
||||
if ((json.keyword.includes(' ') && str.includes(json.keyword)) || (caseAdjustedMessageParts[idx] + '') === (json.keyword + '')) {
|
||||
executeKeyword(json, event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argString = event.getArguments().trim(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
/*
|
||||
* @commandpath keyword - Base command for keyword options
|
||||
*/
|
||||
if (command.equalsIgnoreCase('keyword')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath keyword add [keyword] [response] - Adds a keyword and a response, use regex: at the start of the response to use regex.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
var isRegex = false,
|
||||
isCaseSensitive = false,
|
||||
keyword = null,
|
||||
response = null;
|
||||
|
||||
for (var i = 1; i < args.length; i++) {
|
||||
if (keyword == null) {
|
||||
if (args[i].equalsIgnoreCase('--regex')) {
|
||||
isRegex = true;
|
||||
} else if (args[i].equalsIgnoreCase('--case-sensitive')) {
|
||||
isCaseSensitive = true;
|
||||
} else {
|
||||
keyword = args[i] + '';
|
||||
}
|
||||
} else {
|
||||
response = args.splice(i).join(' ');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var json = JSON.stringify({
|
||||
keyword: keyword,
|
||||
response: response,
|
||||
isRegex: isRegex,
|
||||
isCaseSensitive: isCaseSensitive
|
||||
});
|
||||
|
||||
$.setIniDbString('keywords', keyword, json);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.added', keyword));
|
||||
loadKeywords();
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath keyword remove [keyword] - Removes a given keyword
|
||||
*/
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('keywords', subAction.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
subAction = args[1].toLowerCase();
|
||||
|
||||
$.inidb.del('keywords', subAction);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.removed', subAction));
|
||||
loadKeywords();
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath keyword cooldown [keyword] [seconds] - Sets a cooldown on the keyword. Use -1 to remove it. If you use the command: tag and you have a cooldown on that command it will use that cooldown
|
||||
*/
|
||||
if (action.equalsIgnoreCase('cooldown')) {
|
||||
if (subAction === undefined || isNaN(parseInt(args[2]))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('keywords', subAction.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.keyword.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[2] === -1) {
|
||||
$.inidb.del('coolkey', subAction.toLowerCase());
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.removed', subAction));
|
||||
$.coolDownKeywords.clear(subAction.toLowerCase());
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('coolkey', subAction.toLowerCase(), parseInt(args[2]));
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('keywordhandler.cooldown.set', subAction, args[2]));
|
||||
$.coolDownKeywords.clear(subAction.toLowerCase());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/keywordHandler.js', 'keyword', 1);
|
||||
|
||||
$.registerChatSubcommand('keyword', 'add', 1);
|
||||
$.registerChatSubcommand('keyword', 'remove', 1);
|
||||
$.registerChatSubcommand('keyword', 'cooldown', 1);
|
||||
loadKeywords();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./handlers/keywordHandler.js')) {
|
||||
loadKeywords();
|
||||
}
|
||||
});
|
||||
})();
|
||||
371
libs/phantombot/scripts/handlers/raidHandler.js
Normal file
371
libs/phantombot/scripts/handlers/raidHandler.js
Normal file
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* 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 raidToggle = $.getSetIniDbBoolean('raidSettings', 'raidToggle', false),
|
||||
newRaidIncMessage = $.getSetIniDbString('raidSettings', 'newRaidIncMessage', '(username) is raiding us with (viewers) viewers!'),
|
||||
raidIncMessage = $.getSetIniDbString('raidSettings', 'raidIncMessage', '(username) is raiding us with (viewers) viewers! This is the (times) time (username) has raided us!'),
|
||||
raidReward = $.getSetIniDbNumber('raidSettings', 'raidReward', 0),
|
||||
raidOutMessage = $.getSetIniDbString('raidSettings', 'raidOutMessage', 'We are going to raid (username)! Go to their channel (url) now!'),
|
||||
raidOutSpam = $.getSetIniDbNumber('raidSettings', 'raidOutSpam', 1);
|
||||
|
||||
/*
|
||||
* @function Reloads the raid variables from the panel.
|
||||
*/
|
||||
function reloadRaid() {
|
||||
raidToggle = $.getIniDbBoolean('raidSettings', 'raidToggle');
|
||||
newRaidIncMessage = $.getIniDbString('raidSettings', 'newRaidIncMessage');
|
||||
raidIncMessage = $.getIniDbString('raidSettings', 'raidIncMessage');
|
||||
raidReward = $.getIniDbNumber('raidSettings', 'raidReward');
|
||||
raidOutMessage = $.getIniDbString('raidSettings', 'raidOutMessage');
|
||||
raidOutSpam = $.getIniDbNumber('raidSettings', 'raidOutSpam');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function Saves the current raid from the user or adds it to the list if they raided in the past.
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} viewers
|
||||
*/
|
||||
function saveRaidFromUsername(username, viewers) {
|
||||
var raidObj = JSON.parse($.getIniDbString('incoming_raids', username, '{}'));
|
||||
|
||||
if (raidObj.hasOwnProperty('totalRaids')) {
|
||||
// Increase total raids.
|
||||
raidObj.totalRaids = parseInt(raidObj.totalRaids) + 1;
|
||||
// Increase total viewers which the user has raided for in total (all time).
|
||||
raidObj.totalViewers = (parseInt(raidObj.totalViewers) + parseInt(viewers));
|
||||
// Update last raid time.
|
||||
raidObj.lastRaidTime = $.systemTime();
|
||||
// Last raid viewers.
|
||||
raidObj.lastRaidViewers = viewers;
|
||||
// Push this raid to the raids array.
|
||||
//raidObj.raids.push({
|
||||
// time: $.systemTime(),
|
||||
// viewers: viewers,
|
||||
// username: username
|
||||
//});
|
||||
} else {
|
||||
// Increase total raids.
|
||||
raidObj.totalRaids = '1';
|
||||
// Increase total viewers.
|
||||
raidObj.totalViewers = viewers;
|
||||
// Update last raid time.
|
||||
raidObj.lastRaidTime = $.systemTime();
|
||||
// Last raid viewers.
|
||||
raidObj.lastRaidViewers = viewers;
|
||||
// Create new raid array.
|
||||
//raidObj.raids = [];
|
||||
// Push this raid to the raids array.
|
||||
//raidObj.raids.push({
|
||||
// time: $.systemTime(),
|
||||
// viewers: viewers,
|
||||
// username: username
|
||||
//});
|
||||
}
|
||||
|
||||
// Save the new object.
|
||||
$.setIniDbString('incoming_raids', username, JSON.stringify(raidObj));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function Saves the outgoing raid for the user or adds it to the list.
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} viewers
|
||||
*/
|
||||
function saveOutRaidForUsername(username, viewers) {
|
||||
var raidObj = JSON.parse($.getIniDbString('outgoing_raids', username, '{}'));
|
||||
|
||||
if (raidObj.hasOwnProperty('totalRaids')) {
|
||||
// Increase total raids.
|
||||
raidObj.totalRaids = parseInt(raidObj.totalRaids) + 1;
|
||||
// Increase total viewers which the channel has raided the other channel for (all time).
|
||||
raidObj.totalViewers = (parseInt(raidObj.totalViewers) + parseInt(viewers));
|
||||
// Update last raid time.
|
||||
raidObj.lastRaidTime = $.systemTime();
|
||||
// Last raid viewers.
|
||||
raidObj.lastRaidViewers = viewers;
|
||||
} else {
|
||||
// Increase total raids.
|
||||
raidObj.totalRaids = '1';
|
||||
// Increase total viewers.
|
||||
raidObj.totalViewers = viewers;
|
||||
// Update last raid time.
|
||||
raidObj.lastRaidTime = $.systemTime();
|
||||
// Last raid viewers.
|
||||
raidObj.lastRaidViewers = viewers;
|
||||
}
|
||||
|
||||
// Save the new object.
|
||||
$.setIniDbString('outgoing_raids', username, JSON.stringify(raidObj));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function Handles sending the messages in chat for outgoing raids.
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function handleOutRaid(username) {
|
||||
var message = raidOutMessage;
|
||||
|
||||
// Replace tags.
|
||||
if (message.match(/\(username\)/)) {
|
||||
message = $.replace(message, '(username)', $.username.resolve(username));
|
||||
}
|
||||
|
||||
if (message.match(/\(url\)/)) {
|
||||
message = $.replace(message, '(url)', 'https://twitch.tv/' + username);
|
||||
}
|
||||
|
||||
// Spam the message, if needed.
|
||||
for (var i = 0; i < raidOutSpam; i++) {
|
||||
$.say(message);
|
||||
}
|
||||
|
||||
// Use the .raid command.
|
||||
$.say('.raid ' + username);
|
||||
// Increase out going raids.
|
||||
saveOutRaidForUsername(username + '', $.getViewers($.channelName) + '');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchRaid
|
||||
*/
|
||||
$.bind('twitchRaid', function (event) {
|
||||
var username = event.getUsername(),
|
||||
viewers = event.getViewers(),
|
||||
hasRaided = false,
|
||||
raidObj,
|
||||
message;
|
||||
|
||||
if (raidToggle === true) {
|
||||
// If the user has raided before.
|
||||
if ((hasRaided = $.inidb.exists('incoming_raids', username))) {
|
||||
// Set the message.
|
||||
message = raidIncMessage;
|
||||
// Get the raid object.
|
||||
raidObj = JSON.parse($.getIniDbString('incoming_raids', username));
|
||||
} else {
|
||||
message = newRaidIncMessage;
|
||||
}
|
||||
|
||||
// Replace tags.
|
||||
if (message.match(/\(username\)/)) {
|
||||
message = $.replace(message, '(username)', username);
|
||||
}
|
||||
|
||||
if (message.match(/\(viewers\)/)) {
|
||||
message = $.replace(message, '(viewers)', viewers);
|
||||
}
|
||||
|
||||
if (message.match(/\(url\)/)) {
|
||||
message = $.replace(message, '(url)', 'https://twitch.tv/' + username);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/)) {
|
||||
message = $.replace(message, '(reward)', raidReward);
|
||||
}
|
||||
|
||||
if (message.match(/\(game\)/)) {
|
||||
message = $.replace(message, '(game)', $.getGame(username));
|
||||
}
|
||||
|
||||
if (hasRaided && message.match(/\(times\)/)) {
|
||||
message = $.replace(message, '(times)', raidObj.totalRaids);
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (message == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (message == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$.say(message);
|
||||
}
|
||||
|
||||
// Add reward.
|
||||
if (raidReward > 0) {
|
||||
$.inidb.incr('points', username, raidReward);
|
||||
}
|
||||
|
||||
// Save the raid to the database.
|
||||
saveRaidFromUsername(username + '', viewers + '');
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('raid')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid toggle - Toggles if the bot should welcome raiders.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
raidToggle = !raidToggle;
|
||||
$.setIniDbBoolean('raidSettings', 'raidToggle', raidToggle);
|
||||
$.say($.whisperPrefix(sender) + (raidToggle ? $.lang.get('raidhandler.toggle.enabled') : $.lang.get('raidhandler.toggle.disabled')));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid setreward [amount] - Sets the amount of points given to raiders.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setreward')) {
|
||||
if (isNaN(subAction)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raidReward = parseInt(subAction);
|
||||
$.setIniDbNumber('raidSettings', 'raidReward', raidReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.reward.set', $.getPointsString(raidReward)));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid setincomingmessage [message] - Sets the incoming raid message - Tags: (username), (viewers), (url), (times), (reward) and (game)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setincomingmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.inc.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raidIncMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('raidSettings', 'raidIncMessage', raidIncMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.inc.message.set'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid setnewincomingmessage [message] - Sets the incoming raid message for first time raiders - Tags: (username), (viewers), (url), (reward) and (game)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setnewincomingmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.new.inc.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
newRaidIncMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('raidSettings', 'newRaidIncMessage', newRaidIncMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.new.inc.message.set'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid setoutgoingmessage [message] - Sets the outgoing message for when you raid someone - Tags (username) and (url)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setoutgoingmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.out.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raidOutMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('raidSettings', 'raidOutMessage', raidOutMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.out.message.set'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid setoutgoingmessagespam [amount] - Sets the amount of times that the outgoing raid message is sent in chat. Maximum is 10 times.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setoutgoingmessagespam')) {
|
||||
if (isNaN(subAction) || parseInt(subAction) > 10 || parseInt(subAction) < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.spam.amount.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raidOutSpam = parseInt(subAction);
|
||||
$.setIniDbNumber('raidSettings', 'raidOutSpam', raidOutSpam);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.spam.amount.set'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath raid lookup [username] - Shows the amount of times the username has raided the channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('lookup')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.lookup.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.inidb.exists('incoming_raids', subAction.toLowerCase())) {
|
||||
var raidObj = JSON.parse($.inidb.get('incoming_raids', subAction.toLowerCase())),
|
||||
displayName = $.username.resolve(subAction);
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.lookup.user', displayName, raidObj.totalRaids, new Date(raidObj.lastRaidTime).toLocaleString(), raidObj.lastRaidViewers));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.lookup.user.404', displayName));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the user exists on Twitch.
|
||||
if ($.username.exists(action)) {
|
||||
handleOutRaid(action);
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('raidhandler.usage'));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/raidHandler.js', 'raid', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'toggle', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'setreward', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'lookup', 2);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'setincomingmessage', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'setnewincomingmessage', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'setoutgoingmessage', 1);
|
||||
$.registerChatSubcommand('./handlers/raidHandler.js', 'raid', 'setoutgoingmessagespam', 1);
|
||||
});
|
||||
|
||||
/* Export to API */
|
||||
$.reloadRaid = reloadRaid;
|
||||
})();
|
||||
247
libs/phantombot/scripts/handlers/streamElementsHandler.js
Normal file
247
libs/phantombot/scripts/handlers/streamElementsHandler.js
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* streamElementsHandler.js
|
||||
*
|
||||
* Gets donation from the StreamElements API and posts them in Twitch chat.
|
||||
*/
|
||||
(function() {
|
||||
var message = $.getSetIniDbString('streamElementsHandler', 'message', $.lang.get('streamElements.donation.new')),
|
||||
toggle = $.getSetIniDbBoolean('streamElementsHandler', 'toggle', false),
|
||||
reward = $.getSetIniDbFloat('streamElementsHandler', 'reward', 0),
|
||||
group = $.getSetIniDbBoolean('streamElementsHandler', 'group', false),
|
||||
groupMin = $.getSetIniDbNumber('streamElementsHandler', 'groupMin', 5),
|
||||
dir = './addons/streamElements',
|
||||
announce = false;
|
||||
|
||||
/*
|
||||
* @function reloadStreamElements
|
||||
*/
|
||||
function reloadStreamElements() {
|
||||
message = $.getIniDbString('streamElementsHandler', 'message');
|
||||
toggle = $.getIniDbBoolean('streamElementsHandler', 'toggle');
|
||||
reward = $.getIniDbFloat('streamElementsHandler', 'reward');
|
||||
group = $.getIniDbBoolean('streamElementsHandler', 'group');
|
||||
groupMin = $.getIniDbNumber('streamElementsHandler', 'groupMin');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event streamElementsDonationInitialized
|
||||
*/
|
||||
$.bind('streamElementsDonationInitialized', function(event) {
|
||||
if (!$.isDirectory(dir)) {
|
||||
$.consoleDebug('>> Creating the StreamElements Handler Directory: ' + dir);
|
||||
$.mkDir(dir);
|
||||
}
|
||||
|
||||
$.consoleLn('>> Enabling StreamElements donation announcements');
|
||||
$.log.event('StreamElements donation announcements enabled');
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event streamElementsDonation
|
||||
*/
|
||||
$.bind('streamElementsDonation', function(event) {
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getString('_id'),
|
||||
paramObj = donationObj.getJSONObject('donation'),
|
||||
donationUsername = paramObj.getJSONObject('user').getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('donations', donationID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('streamInfo', 'lastDonator', donationUsername);
|
||||
|
||||
$.inidb.set('donations', donationID, donationObj);
|
||||
|
||||
$.inidb.set('donations', 'last_donation', donationID);
|
||||
|
||||
$.inidb.set('donations', 'last_donation_message', $.lang.get('main.donation.last.tip.message', donationUsername, donationCurrency, donationAmount));
|
||||
|
||||
$.writeToFile(donationUsername + ": " + donationAmount + " ", dir + '/latestDonation.txt', false);
|
||||
|
||||
if (toggle === true && announce === true) {
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', String(parseInt(donationAmount.toFixed(2))));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', String(parseInt(donationAmount.toFixed(0))));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
if (s.match(/\(reward\)/)) {
|
||||
s = $.replace(s, '(reward)', $.getPointsString(Math.floor(parseFloat(donationAmount) * reward)));
|
||||
}
|
||||
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$.say(s);
|
||||
}
|
||||
|
||||
if (reward > 0) {
|
||||
$.inidb.incr('points', donationUsername.toLowerCase(), Math.floor(parseFloat(donationAmount) * reward));
|
||||
}
|
||||
|
||||
if (group === true) {
|
||||
donationUsername = donationUsername.toLowerCase();
|
||||
$.inidb.incr('donations', donationUsername, donationAmount);
|
||||
if ($.inidb.exists('donations', donationUsername) && $.inidb.get('donations', donationUsername) >= groupMin) {
|
||||
if ($.getUserGroupId(donationUsername) > 3) {
|
||||
$.setUserGroupById(donationUsername, '4');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/*
|
||||
* @commandpath streamelements - Controls various options for donation handling
|
||||
*/
|
||||
if (command.equalsIgnoreCase('streamelements')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamelements toggledonators - Toggles the Donator's group.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggledonators')) {
|
||||
group = !group;
|
||||
$.setIniDbBoolean('streamElementsHandler', 'group', group);
|
||||
$.say($.whisperPrefix(sender) + (group ? $.lang.get('streamelements.enabled.donators') : $.lang.get('streamelements.disabled.donators')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamelements minmumbeforepromotion - Set the minimum before people get promoted to a Donator
|
||||
*/
|
||||
if (action.equalsIgnoreCase('minmumbeforepromotion')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donators.min.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
groupMin = subAction;
|
||||
$.setIniDbNumber('streamElementsHandler', 'groupMin', groupMin);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donators.min', groupMin));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamelements announce - Toggles announcements for donations off and on
|
||||
*/
|
||||
if (action.equalsIgnoreCase('announce')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('streamElementsHandler', 'toggle', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('streamelements.donations.announce.enable') : $.lang.get('streamelements.donations.announce.disable')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamelements rewardmultiplier [n.n] - Set a reward multiplier for donations.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewardmultiplier')) {
|
||||
if (isNaN(parseFloat(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
reward = parseFloat(subAction);
|
||||
$.setIniDbFloat('streamElementsHandler', 'reward', reward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.reward.success', subAction, (subAction == "1" ? $.pointNameSingle : $.pointNameMultiple).toLowerCase()));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath streamelements message [message text] - Set the donation message. Tags: (name), (amount), (reward), (message) and (currency)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = args.splice(1).join(' ');
|
||||
if (msg.search(/\(name\)/) == -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.message.no-name'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.setIniDbString('streamElementsHandler', 'message', msg);
|
||||
|
||||
message = $.getIniDbString('streamElementsHandler', 'message');
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('streamelements.donations.message.success', msg));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/streamElementsHandler.js', 'streamelements', 1);
|
||||
});
|
||||
|
||||
$.reloadStreamElements = reloadStreamElements;
|
||||
})();
|
||||
789
libs/phantombot/scripts/handlers/subscribeHandler.js
Normal file
789
libs/phantombot/scripts/handlers/subscribeHandler.js
Normal file
@@ -0,0 +1,789 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* subscribehandler.js
|
||||
*
|
||||
* Register new subscribers and unsubscribers in the channel
|
||||
*/
|
||||
(function () {
|
||||
var subMessage = $.getSetIniDbString('subscribeHandler', 'subscribeMessage', '(name) just subscribed!'),
|
||||
primeSubMessage = $.getSetIniDbString('subscribeHandler', 'primeSubscribeMessage', '(name) just subscribed with Twitch Prime!'),
|
||||
reSubMessage = $.getSetIniDbString('subscribeHandler', 'reSubscribeMessage', '(name) just subscribed for (months) months in a row!'),
|
||||
giftSubMessage = $.getSetIniDbString('subscribeHandler', 'giftSubMessage', '(name) just gifted (recipient) a subscription!'),
|
||||
giftAnonSubMessage = $.getSetIniDbString('subscribeHandler', 'giftAnonSubMessage', 'An anonymous viewer gifted (recipient) a subscription!'),
|
||||
massGiftSubMessage = $.getSetIniDbString('subscribeHandler', 'massGiftSubMessage', '(name) just gifted (amount) subscriptions to random users in the channel!'),
|
||||
massAnonGiftSubMessage = $.getSetIniDbString('subscribeHandler', 'massAnonGiftSubMessage', 'An anonymous viewer gifted (amount) subscriptions to random viewers!'),
|
||||
subWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle', true),
|
||||
primeSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle', true),
|
||||
reSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle', true),
|
||||
giftSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle', true),
|
||||
giftAnonSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'giftAnonSubWelcomeToggle', true),
|
||||
massGiftSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'massGiftSubWelcomeToggle', true),
|
||||
massAnonGiftSubWelcomeToggle = $.getSetIniDbBoolean('subscribeHandler', 'massAnonGiftSubWelcomeToggle', true),
|
||||
subReward = $.getSetIniDbNumber('subscribeHandler', 'subscribeReward', 0),
|
||||
reSubReward = $.getSetIniDbNumber('subscribeHandler', 'reSubscribeReward', 0),
|
||||
giftSubReward = $.getSetIniDbNumber('subscribeHandler', 'giftSubReward', 0),
|
||||
massGiftSubReward = $.getSetIniDbNumber('subscribeHandler', 'massGiftSubReward', 0),
|
||||
customEmote = $.getSetIniDbString('subscribeHandler', 'resubEmote', ''),
|
||||
subPlan1000 = $.getSetIniDbString('subscribeHandler', 'subPlan1000', 'Tier 1'),
|
||||
subPlan2000 = $.getSetIniDbString('subscribeHandler', 'subPlan2000', 'Tier 2'),
|
||||
subPlan3000 = $.getSetIniDbString('subscribeHandler', 'subPlan3000', 'Tier 3'),
|
||||
announce = false,
|
||||
emotes = [],
|
||||
i;
|
||||
|
||||
/*
|
||||
* @function updateSubscribeConfig
|
||||
*/
|
||||
function updateSubscribeConfig() {
|
||||
subMessage = $.getIniDbString('subscribeHandler', 'subscribeMessage');
|
||||
primeSubMessage = $.getIniDbString('subscribeHandler', 'primeSubscribeMessage');
|
||||
reSubMessage = $.getIniDbString('subscribeHandler', 'reSubscribeMessage');
|
||||
giftSubMessage = $.getIniDbString('subscribeHandler', 'giftSubMessage');
|
||||
giftAnonSubMessage = $.getIniDbString('subscribeHandler', 'giftAnonSubMessage');
|
||||
massGiftSubMessage = $.getIniDbString('subscribeHandler', 'massGiftSubMessage');
|
||||
massAnonGiftSubMessage = $.getIniDbString('subscribeHandler', 'massAnonGiftSubMessage');
|
||||
subWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle');
|
||||
primeSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle');
|
||||
reSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle');
|
||||
giftSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle');
|
||||
giftAnonSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'giftAnonSubWelcomeToggle');
|
||||
massGiftSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'massGiftSubWelcomeToggle');
|
||||
massAnonGiftSubWelcomeToggle = $.getIniDbBoolean('subscribeHandler', 'massAnonGiftSubWelcomeToggle');
|
||||
subReward = $.getIniDbNumber('subscribeHandler', 'subscribeReward');
|
||||
reSubReward = $.getIniDbNumber('subscribeHandler', 'reSubscribeReward');
|
||||
giftSubReward = $.getIniDbNumber('subscribeHandler', 'giftSubReward');
|
||||
massGiftSubReward = $.getIniDbNumber('subscribeHandler', 'massGiftSubReward');
|
||||
customEmote = $.getIniDbString('subscribeHandler', 'resubEmote');
|
||||
subPlan1000 = $.getIniDbString('subscribeHandler', 'Tier 1');
|
||||
subPlan2000 = $.getIniDbString('subscribeHandler', 'Tier 2');
|
||||
subPlan3000 = $.getIniDbString('subscribeHandler', 'Tier 3');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getPlanName
|
||||
*/
|
||||
function getPlanName(plan) {
|
||||
if (plan.equals('1000')) {
|
||||
return subPlan1000;
|
||||
} else if (plan.equals('2000')) {
|
||||
return subPlan2000;
|
||||
} else if (plan.equals('3000')) {
|
||||
return subPlan3000;
|
||||
} else if (plan.equals('Prime')) {
|
||||
return 'Prime';
|
||||
}
|
||||
|
||||
return 'Unknown Tier';
|
||||
}
|
||||
|
||||
/*
|
||||
* @event twitchSubscriber
|
||||
*/
|
||||
$.bind('twitchSubscriber', function (event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
tier = event.getPlan(),
|
||||
message = subMessage;
|
||||
|
||||
if (subWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', subscriber);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(subReward));
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
$.addSubUsersList(subscriber);
|
||||
$.restoreSubscriberStatus(subscriber);
|
||||
$.writeToFile(subscriber + ' ', './addons/subscribeHandler/latestSub.txt', false);
|
||||
$.inidb.set('streamInfo', 'lastSub', subscriber);
|
||||
if (subReward > 0) {
|
||||
$.inidb.incr('points', subscriber, subReward);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchPrimeSubscriber
|
||||
*/
|
||||
$.bind('twitchPrimeSubscriber', function (event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
message = primeSubMessage;
|
||||
|
||||
if (primeSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', subscriber);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(subReward));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
$.addSubUsersList(subscriber);
|
||||
$.restoreSubscriberStatus(subscriber);
|
||||
$.writeToFile(subscriber + ' ', './addons/subscribeHandler/latestSub.txt', false);
|
||||
$.inidb.set('streamInfo', 'lastSub', subscriber);
|
||||
if (subReward > 0) {
|
||||
$.inidb.incr('points', subscriber, subReward);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchReSubscriber
|
||||
*/
|
||||
$.bind('twitchReSubscriber', function (event) {
|
||||
var resubscriber = event.getReSubscriber(),
|
||||
months = event.getMonths(),
|
||||
tier = event.getPlan(),
|
||||
message = reSubMessage,
|
||||
emotes = [];
|
||||
|
||||
if (reSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', resubscriber);
|
||||
}
|
||||
|
||||
if (message.match(/\(months\)/g)) {
|
||||
message = $.replace(message, '(months)', months);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(reSubReward));
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(customemote\)/)) {
|
||||
for (i = 0; i < months; i++, emotes.push(customEmote))
|
||||
;
|
||||
message = $.replace(message, '(customemote)', emotes.join(' '));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
$.addSubUsersList(resubscriber);
|
||||
$.restoreSubscriberStatus(resubscriber);
|
||||
$.writeToFile(resubscriber + ' ', './addons/subscribeHandler/latestResub.txt', false);
|
||||
$.writeToFile(resubscriber + ': ' + months + ' ', './addons/subscribeHandler/latestResub&Months.txt', false);
|
||||
$.inidb.set('streamInfo', 'lastReSub', resubscriber);
|
||||
if (reSubReward > 0) {
|
||||
$.inidb.incr('points', resubscriber, reSubReward);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchSubscriptionGift', function (event) {
|
||||
var gifter = event.getUsername(),
|
||||
recipient = event.getRecipient(),
|
||||
months = event.getMonths(),
|
||||
tier = event.getPlan(),
|
||||
message = giftSubMessage;
|
||||
|
||||
if (giftSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (message.match(/\(recipient\)/g)) {
|
||||
message = $.replace(message, '(recipient)', recipient);
|
||||
}
|
||||
|
||||
if (message.match(/\(months\)/g)) {
|
||||
message = $.replace(message, '(months)', months);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(subReward));
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(customemote\)/)) {
|
||||
for (i = 0; i < months; i++, emotes.push(customEmote))
|
||||
;
|
||||
message = $.replace(message, '(customemote)', emotes.join(' '));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
|
||||
$.addSubUsersList(recipient);
|
||||
$.restoreSubscriberStatus(recipient);
|
||||
|
||||
$.writeToFile(recipient + ' ', './addons/subscribeHandler/latestSub.txt', false);
|
||||
|
||||
$.inidb.set('streamInfo', 'lastSub', recipient);
|
||||
if (subReward > 0) {
|
||||
$.inidb.incr('points', recipient, subReward);
|
||||
}
|
||||
if (giftSubReward > 0) {
|
||||
$.inidb.incr('points', gifter, giftSubReward);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchMassSubscriptionGifted', function (event) {
|
||||
var gifter = event.getUsername(),
|
||||
amount = event.getAmount(),
|
||||
tier = event.getPlan(),
|
||||
message = massGiftSubMessage;
|
||||
|
||||
if (massGiftSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (message.match(/\(amount\)/g)) {
|
||||
message = $.replace(message, '(amount)', amount);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(massGiftSubReward * parseInt(amount)));
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
|
||||
if (massGiftSubReward > 0) {
|
||||
$.inidb.incr('points', gifter, massGiftSubReward * parseInt(amount));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchAnonymousSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchAnonymousSubscriptionGift', function (event) {
|
||||
var gifter = event.getUsername(),
|
||||
recipient = event.getRecipient(),
|
||||
months = event.getMonths(),
|
||||
tier = event.getPlan(),
|
||||
message = giftAnonSubMessage;
|
||||
|
||||
if (giftAnonSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (message.match(/\(recipient\)/g)) {
|
||||
message = $.replace(message, '(recipient)', recipient);
|
||||
}
|
||||
|
||||
if (message.match(/\(months\)/g)) {
|
||||
message = $.replace(message, '(months)', months);
|
||||
}
|
||||
|
||||
if (message.match(/\(reward\)/g)) {
|
||||
message = $.replace(message, '(reward)', String(subReward));
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
|
||||
$.addSubUsersList(recipient);
|
||||
$.restoreSubscriberStatus(recipient);
|
||||
|
||||
$.writeToFile(recipient + ' ', './addons/subscribeHandler/latestSub.txt', false);
|
||||
|
||||
$.inidb.set('streamInfo', 'lastSub', recipient);
|
||||
if (subReward > 0) {
|
||||
$.inidb.incr('points', recipient, subReward);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchMassAnonymousSubscriptionGifted
|
||||
*/
|
||||
$.bind('twitchMassAnonymousSubscriptionGifted', function (event) {
|
||||
var gifter = event.getUsername(),
|
||||
amount = event.getAmount(),
|
||||
tier = event.getPlan(),
|
||||
message = massAnonGiftSubMessage;
|
||||
|
||||
if (massAnonGiftSubWelcomeToggle === true && announce === true) {
|
||||
if (message.match(/\(name\)/g)) {
|
||||
message = $.replace(message, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (message.match(/\(amount\)/g)) {
|
||||
message = $.replace(message, '(amount)', amount);
|
||||
}
|
||||
|
||||
if (message.match(/\(plan\)/g)) {
|
||||
message = $.replace(message, '(plan)', getPlanName(tier));
|
||||
}
|
||||
|
||||
if (message.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = message.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
message = (message + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
}
|
||||
|
||||
if (message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
message = $.replace(message, message.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
}
|
||||
|
||||
if (message != '') {
|
||||
$.say(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function (event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
planId;
|
||||
|
||||
/*
|
||||
* @commandpath subwelcometoggle - Enable or disable subscription alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('subwelcometoggle')) {
|
||||
subWelcomeToggle = !subWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'subscriberWelcomeToggle', subWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (subWelcomeToggle ? $.lang.get('subscribehandler.new.sub.toggle.on') : $.lang.get('subscribehandler.new.sub.toggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath primesubwelcometoggle - Enable or disable Twitch Prime subscription alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('primesubwelcometoggle')) {
|
||||
primeSubWelcomeToggle = !primeSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'primeSubscriberWelcomeToggle', primeSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (primeSubWelcomeToggle ? $.lang.get('subscribehandler.new.primesub.toggle.on') : $.lang.get('subscribehandler.new.primesub.toggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath resubwelcometoggle - Enable or disable resubsciption alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('resubwelcometoggle')) {
|
||||
reSubWelcomeToggle = !reSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'reSubscriberWelcomeToggle', reSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (reSubWelcomeToggle ? $.lang.get('subscribehandler.resub.toggle.on') : $.lang.get('subscribehandler.resub.toggle.off')))
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giftsubwelcometoggle - Enable or disable subgifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('giftsubwelcometoggle')) {
|
||||
giftSubWelcomeToggle = !giftSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'giftSubWelcomeToggle', giftSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (giftSubWelcomeToggle ? $.lang.get('subscribehandler.giftsub.toggle.on') : $.lang.get('subscribehandler.giftsub.toggle.off')))
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giftanonsubwelcometoggle - Enable or disable anonymous subgifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('giftanonsubwelcometoggle')) {
|
||||
giftAnonSubWelcomeToggle = !giftAnonSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'giftAnonSubWelcomeToggle', giftAnonSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (giftAnonSubWelcomeToggle ? $.lang.get('subscribehandler.anongiftsub.toggle.on') : $.lang.get('subscribehandler.anongiftsub.toggle.off')))
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath massgiftsubwelcometoggle - Enable or disable subgifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('massgiftsubwelcometoggle')) {
|
||||
massGiftSubWelcomeToggle = !massGiftSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'massGiftSubWelcomeToggle', massGiftSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (massGiftSubWelcomeToggle ? $.lang.get('subscribehandler.massgiftsub.toggle.on') : $.lang.get('subscribehandler.massgiftsub.toggle.off')))
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath massanongiftsubwelcometoggle - Enable or disable mass anonymous subgifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('massanongiftsubwelcometoggle')) {
|
||||
massAnonGiftSubWelcomeToggle = !massAnonGiftSubWelcomeToggle;
|
||||
$.setIniDbBoolean('subscribeHandler', 'massAnonGiftSubWelcomeToggle', massAnonGiftSubWelcomeToggle);
|
||||
$.say($.whisperPrefix(sender) + (massAnonGiftSubWelcomeToggle ? $.lang.get('subscribehandler.anonmassgiftsub.toggle.on') : $.lang.get('subscribehandler.anonmassgiftsub.toggle.off')))
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath submessage [message] - Set a welcome message for new subscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('submessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'subscribeMessage', subMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath primesubmessage [message] - Set a welcome message for new Twitch Prime subscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('primesubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.primesub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
primeSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'primeSubscribeMessage', primeSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.primesub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath resubmessage [message] - Set a message for resubscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('resubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
reSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'reSubscribeMessage', reSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giftsubmessage [message] - Set a message for resubscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('giftsubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
giftSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'giftSubMessage', giftSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath giftanonsubmessage[message] - Set a message for anonymous gifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('giftanonsubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftanonsub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
giftAnonSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'giftAnonSubMessage', giftAnonSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftanonsub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath massgiftsubmessage [message] - Set a message for gifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('massgiftsubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.massgiftsub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
massGiftSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'massGiftSubMessage', massGiftSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.massgiftsub.msg.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath massanongiftsubmessage [message] - Set a message for mass anonymous gifting alerts.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('massanongiftsubmessage')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.anonmassgiftsub.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
massAnonGiftSubMessage = argsString;
|
||||
$.setIniDbString('subscribeHandler', 'massAnonGiftSubMessage', massAnonGiftSubMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.anonmassgiftsub.msg.set'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath subscribereward [points] - Set an award for subscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('subscribereward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subReward = parseInt(action);
|
||||
$.setIniDbNumber('subscribeHandler', 'subscribeReward', subReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.sub.reward.set'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath resubscribereward [points] - Set an award for resubscribers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('resubscribereward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
reSubReward = parseInt(action);
|
||||
$.setIniDbNumber('subscribeHandler', 'reSubscribeReward', reSubReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resub.reward.set'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath giftsubreward [points] - Set an award for gifted subs.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('giftsubreward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
giftSubReward = parseInt(action);
|
||||
$.setIniDbNumber('subscribeHandler', 'giftSubReward', giftSubReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.giftsub.reward.set'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath massgiftsubreward [points] - Set an award for mass subs. This is a multiplier.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('massgiftsubreward')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.massgiftsub.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
massGiftSubReward = parseInt(action);
|
||||
$.setIniDbNumber('subscribeHandler', 'massGiftSubReward', massGiftSubReward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.massgiftsub.reward.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath resubemote [emote] - The (customemote) tag will be replace with that emote. The emote will be added the amount of months the user subscribed for.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('resubemote')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resubemote.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
customEmote = action;
|
||||
$.setIniDbString('subscribeHandler', 'resubEmote', customEmote);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.resubemote.set'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath namesubplan [1|2|3] [name of plan] - Name a subscription plan, Twitch provides three tiers.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('namesubplan')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!action.equals('1') && !action.equals('2') && !action.equals('3')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equals('1')) {
|
||||
planId = 'subPlan1000';
|
||||
} else if (action.equals('2')) {
|
||||
planId = 'subPlan2000';
|
||||
} else if (action.equals('3')) {
|
||||
planId = 'subPlan3000';
|
||||
}
|
||||
|
||||
if (args[1] === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.show', action, $.getIniDbString('subscribeHandler', planId)));
|
||||
return;
|
||||
}
|
||||
|
||||
argsString = args.splice(1).join(' ');
|
||||
if (planId.equals('subPlan1000')) {
|
||||
subPlan1000 = argsString;
|
||||
} else if (planId.equals('subPlan2000')) {
|
||||
subPlan2000 = argsString;
|
||||
} else if (planId.equals('subPlan3000')) {
|
||||
subPlan3000 = argsString;
|
||||
}
|
||||
$.setIniDbString('subscribeHandler', planId, argsString);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('subscribehandler.namesubplan.set', action, argsString));
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function () {
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'subwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'resubemote', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'primesubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'resubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'giftanonsubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'massgiftsubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'massanongiftsubwelcometoggle', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'subscribereward', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'resubscribereward', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubreward', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'massgiftsubreward', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'submessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'primesubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'resubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'giftsubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'giftanonsubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'massgiftsubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'massanongiftsubmessage', 1);
|
||||
$.registerChatCommand('./handlers/subscribeHandler.js', 'namesubplan', 1);
|
||||
announce = true;
|
||||
});
|
||||
|
||||
$.updateSubscribeConfig = updateSubscribeConfig;
|
||||
})();
|
||||
262
libs/phantombot/scripts/handlers/tipeeeStreamHandler.js
Normal file
262
libs/phantombot/scripts/handlers/tipeeeStreamHandler.js
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* tipeeestreamHandler.js
|
||||
*
|
||||
* Gets donation from the TipeeeStream API and posts them in Twitch chat.
|
||||
*/
|
||||
(function() {
|
||||
var message = $.getSetIniDbString('tipeeeStreamHandler', 'message', $.lang.get('tipeeestream.donation.new')),
|
||||
toggle = $.getSetIniDbBoolean('tipeeeStreamHandler', 'toggle', false),
|
||||
reward = $.getSetIniDbFloat('tipeeeStreamHandler', 'reward', 0),
|
||||
group = $.getSetIniDbBoolean('tipeeeStreamHandler', 'group', false),
|
||||
groupMin = $.getSetIniDbNumber('tipeeeStreamHandler', 'groupMin', 5),
|
||||
dir = './addons/tipeeeStream',
|
||||
announce = false;
|
||||
|
||||
/*
|
||||
* @function reloadTipeeeStream
|
||||
*/
|
||||
function reloadTipeeeStream() {
|
||||
message = $.getIniDbString('tipeeeStreamHandler', 'message');
|
||||
toggle = $.getIniDbBoolean('tipeeeStreamHandler', 'toggle');
|
||||
reward = $.getIniDbFloat('tipeeeStreamHandler', 'reward');
|
||||
group = $.getIniDbBoolean('tipeeeStreamHandler', 'group');
|
||||
groupMin = $.getIniDbNumber('tipeeeStreamHandler', 'groupMin');
|
||||
}
|
||||
|
||||
/*
|
||||
* @event tipeeeStreamDonationInitialized
|
||||
*/
|
||||
$.bind('tipeeeStreamDonationInitialized', function(event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/tipeeeStreamHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.isDirectory(dir)) {
|
||||
$.consoleDebug('>> Creating the TipeeeStream Handler Directory: ' + dir);
|
||||
$.mkDir(dir);
|
||||
}
|
||||
|
||||
$.consoleLn('>> Enabling TipeeeStream donation announcements');
|
||||
$.log.event('TipeeeStream donation announcements enabled');
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/*
|
||||
* @event tipeeeStreamDonation
|
||||
*/
|
||||
$.bind('tipeeeStreamDonation', function(event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/tipeeeStreamHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getInt('id'),
|
||||
paramObj = donationObj.getJSONObject('parameters'),
|
||||
donationUsername = paramObj.getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
donationFormattedAmount = donationObj.getString('formattedAmount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('donations', donationID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('streamInfo', 'lastDonator', donationUsername);
|
||||
|
||||
$.inidb.set('donations', donationID, donationObj);
|
||||
|
||||
$.inidb.set('donations', 'last_donation', donationID);
|
||||
|
||||
$.inidb.set('donations', 'last_donation_message', $.lang.get('main.donation.last.tip.message', donationUsername, donationCurrency, donationAmount));
|
||||
|
||||
$.writeToFile(donationUsername + ": " + donationAmount + " ", dir + '/latestDonation.txt', false);
|
||||
|
||||
if (toggle === true && announce === true) {
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', parseInt(donationAmount.toFixed(2)));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', parseInt(donationAmount.toFixed(0)));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
if (s.match(/\(formattedamount\)/)) {
|
||||
s = $.replace(s, '(formattedamount)', donationFormattedAmount);
|
||||
}
|
||||
|
||||
if (s.match(/\(reward\)/)) {
|
||||
s = $.replace(s, '(reward)', $.getPointsString(Math.floor(parseFloat(donationAmount) * reward)));
|
||||
}
|
||||
|
||||
if (s.match(/\(alert [,.\w\W]+\)/g)) {
|
||||
var filename = s.match(/\(alert ([,.\w\W]+)\)/)[1];
|
||||
$.alertspollssocket.alertImage(filename);
|
||||
s = (s + '').replace(/\(alert [,.\w\W]+\)/, '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/g)) {
|
||||
if (!$.audioHookExists(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1])) {
|
||||
$.log.error('Could not play audio hook: Audio hook does not exist.');
|
||||
return null;
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[1]);
|
||||
s = $.replace(s, s.match(/\(playsound\s([a-zA-Z1-9_]+)\)/)[0], '');
|
||||
if (s == '') {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (s != '') {
|
||||
$.say(s);
|
||||
}
|
||||
}
|
||||
|
||||
if (reward > 0) {
|
||||
$.inidb.incr('points', donationUsername.toLowerCase(), Math.floor(parseFloat(donationAmount) * reward));
|
||||
}
|
||||
|
||||
if (group === true) {
|
||||
donationUsername = donationUsername.toLowerCase();
|
||||
$.inidb.incr('donations', donationUsername, donationAmount);
|
||||
if ($.inidb.exists('donations', donationUsername) && $.inidb.get('donations', donationUsername) >= groupMin) {
|
||||
if ($.getUserGroupId(donationUsername) > 3) {
|
||||
$.setUserGroupById(donationUsername, '4');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream - Controls various options for donation handling
|
||||
*/
|
||||
if (command.equalsIgnoreCase('tipeeestream')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream toggledonators - Toggles the Donator's group.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggledonators')) {
|
||||
group = !group;
|
||||
$.setIniDbBoolean('tipeeeStreamHandler', 'group', group);
|
||||
$.say($.whisperPrefix(sender) + (group ? $.lang.get('tipeeestream.enabled.donators') : $.lang.get('tipeeestream.disabled.donators')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream minmumbeforepromotion - Set the minimum before people get promoted to a Donator
|
||||
*/
|
||||
if (action.equalsIgnoreCase('minmumbeforepromotion')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donators.min.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
groupMin = subAction;
|
||||
$.setIniDbNumber('tipeeeStreamHandler', 'groupMin', groupMin);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donators.min', groupMin));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream announce - Toggles announcements for donations off and on
|
||||
*/
|
||||
if (action.equalsIgnoreCase('announce')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('tipeeeStreamHandler', 'toggle', toggle);
|
||||
$.say($.whisperPrefix(sender) + (toggle ? $.lang.get('tipeeestream.donations.announce.enable') : $.lang.get('tipeeestream.donations.announce.disable')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream rewardmultiplier [n.n] - Set a reward multiplier for donations.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewardmultiplier')) {
|
||||
if (isNaN(parseFloat(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
reward = parseFloat(subAction);
|
||||
$.setIniDbFloat('tipeeeStreamHandler', 'reward', reward);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.reward.success', subAction, (subAction == "1" ? $.pointNameSingle : $.pointNameMultiple).toLowerCase()));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath tipeeestream message [message text] - Set the donation message. Tags: (name), (amount), (reward), (message) and (currency)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = args.splice(1).join(' ');
|
||||
if (msg.search(/\(name\)/) == -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.message.no-name'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.setIniDbString('tipeeeStreamHandler', 'message', msg);
|
||||
|
||||
message = $.getIniDbString('tipeeeStreamHandler', 'message');
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('tipeeestream.donations.message.success', msg));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/tipeeeStreamHandler.js', 'tipeeestream', 1);
|
||||
});
|
||||
|
||||
$.reloadTipeeeStream = reloadTipeeeStream;
|
||||
})();
|
||||
580
libs/phantombot/scripts/handlers/twitterHandler.js
Normal file
580
libs/phantombot/scripts/handlers/twitterHandler.js
Normal file
@@ -0,0 +1,580 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* twitterHandler.js
|
||||
*
|
||||
* Interfaces with Twitter. Provides the connection to the Core to be provided
|
||||
* with Tweets and configuration of the module. As the Core directly reads the
|
||||
* DB for configuration, there is not a need for local variables in this module.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Anything you modify or remove in this script is at your own risk with Twitter.
|
||||
*/
|
||||
(function() {
|
||||
var randPrev = 0,
|
||||
onlinePostDelay = 480 * 6e4, // 8 hour cooldown
|
||||
gameChangeDelay = 60 * 6e4, // 1 hour cooldown
|
||||
interval;
|
||||
|
||||
/* Set default values for all configuration items. */
|
||||
$.getSetIniDbString('twitter', 'message_online', 'Starting up a stream (twitchurl)');
|
||||
$.getSetIniDbString('twitter', 'message_gamechange', 'Changing game over to (game) (twitchurl)');
|
||||
$.getSetIniDbString('twitter', 'message_update', 'Still streaming (game) [(uptime)] (twitchurl)');
|
||||
|
||||
$.getSetIniDbNumber('twitter', 'polldelay_mentions', 60);
|
||||
$.getSetIniDbNumber('twitter', 'polldelay_retweets', 60);
|
||||
$.getSetIniDbNumber('twitter', 'polldelay_hometimeline', 60);
|
||||
$.getSetIniDbNumber('twitter', 'polldelay_usertimeline', 15);
|
||||
$.getSetIniDbNumber('twitter', 'postdelay_update', 180);
|
||||
$.getSetIniDbNumber('twitter', 'reward_points', 100);
|
||||
$.getSetIniDbNumber('twitter', 'reward_cooldown', 4);
|
||||
|
||||
$.getSetIniDbBoolean('twitter', 'poll_mentions', false);
|
||||
$.getSetIniDbBoolean('twitter', 'poll_retweets', false);
|
||||
$.getSetIniDbBoolean('twitter', 'poll_hometimeline', false);
|
||||
$.getSetIniDbBoolean('twitter', 'poll_usertimeline', false);
|
||||
$.getSetIniDbBoolean('twitter', 'post_online', false);
|
||||
$.getSetIniDbBoolean('twitter', 'post_gamechange', false);
|
||||
$.getSetIniDbBoolean('twitter', 'post_update', false);
|
||||
$.getSetIniDbBoolean('twitter', 'reward_toggle', false);
|
||||
$.getSetIniDbBoolean('twitter', 'reward_announce', false);
|
||||
|
||||
/**
|
||||
* @event twitter
|
||||
*/
|
||||
$.bind('twitter', function(event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/twitterHandler.js')) {
|
||||
return;
|
||||
}
|
||||
if (event.getMentionUser() != null) {
|
||||
$.say($.lang.get('twitter.tweet.mention', event.getMentionUser(), event.getTweet()).replace('(twitterid)', $.twitter.getUsername() + ''));
|
||||
} else {
|
||||
$.say($.lang.get('twitter.tweet', event.getTweet()).replace('(twitterid)', $.twitter.getUsername() + ''));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitterRetweet
|
||||
*/
|
||||
$.bind('twitterRetweet', function(event) {
|
||||
if (!$.bot.isModuleEnabled('./handlers/twitterHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* The core only generates this event if reward_toggle is enabled, therefore, we do not check the toggle here. */
|
||||
if ($.getIniDbNumber('twitter', 'reward_points') == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var userNameArray = event.getUserNameArray(),
|
||||
i,
|
||||
twitterUserName,
|
||||
rewardNameArray = [],
|
||||
lastRetweet,
|
||||
userName,
|
||||
reward = $.getIniDbNumber('twitter', 'reward_points'),
|
||||
cooldown = $.getIniDbFloat('twitter', 'reward_cooldown') * 3.6e6,
|
||||
now = $.systemTime();
|
||||
|
||||
for (i in userNameArray) {
|
||||
twitterUserName = userNameArray[i].toLowerCase();
|
||||
userName = $.inidb.GetKeyByValue('twitter_mapping', '', twitterUserName);
|
||||
if (userName === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lastRetweet = $.getIniDbNumber('twitter_user_last_retweet', userName, 0);
|
||||
if (now - lastRetweet > cooldown) {
|
||||
rewardNameArray.push(userName);
|
||||
$.inidb.incr('points', userName, reward);
|
||||
$.setIniDbNumber('twitter_user_last_retweet', userName, now);
|
||||
}
|
||||
}
|
||||
|
||||
if (rewardNameArray.length > 0 && $.getIniDbBoolean('twitter', 'reward_announce')) {
|
||||
$.say($.lang.get('twitter.reward.announcement', rewardNameArray.join(', '), $.getPointsString(reward)));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function(event) {
|
||||
var randNum,
|
||||
now = $.systemTime(),
|
||||
message = $.getIniDbString('twitter', 'message_online');
|
||||
|
||||
if (!$.bot.isModuleEnabled('./handlers/twitterHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.getIniDbBoolean('twitter', 'post_online', false)) {
|
||||
if (now > $.getIniDbNumber('twitter', 'last_onlinepost', 0) + onlinePostDelay) {
|
||||
$.inidb.set('twitter', 'last_onlinepost', now + onlinePostDelay);
|
||||
do {
|
||||
randNum = $.randRange(1, 9999);
|
||||
} while (randNum == randPrev);
|
||||
randPrev = randNum;
|
||||
$.twitter.updateStatus(String(message).replace('(title)', $.twitchcache.getStreamStatus()).replace('(game)', $.twitchcache.getGameTitle()).replace('(twitchurl)', 'https://www.twitch.tv/' + $.ownerName + '?' + randNum).replace(/\(enter\)/g, '\r\n'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchGameChange
|
||||
*/
|
||||
$.bind('twitchGameChange', function(event) {
|
||||
var now = $.systemTime(),
|
||||
message = $.getIniDbString('twitter', 'message_gamechange');
|
||||
if (!$.bot.isModuleEnabled('./handlers/twitterHandler.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.twitchcache.getGameTitle() == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.getIniDbBoolean('twitter', 'post_gamechange', false) && $.isOnline($.channelName)) {
|
||||
if (now > $.getIniDbNumber('twitter', 'last_gamechange', 0) + gameChangeDelay) {
|
||||
$.inidb.set('twitter', 'last_gamechange', now + gameChangeDelay);
|
||||
var randNum,
|
||||
uptimeSec = $.getStreamUptimeSeconds($.channelName),
|
||||
hrs = (uptimeSec / 3600 < 10 ? '0' : '') + Math.floor(uptimeSec / 3600),
|
||||
min = ((uptimeSec % 3600) / 60 < 10 ? '0' : '') + Math.floor((uptimeSec % 3600) / 60);
|
||||
|
||||
do {
|
||||
randNum = $.randRange(1, 9999);
|
||||
} while (randNum == randPrev);
|
||||
randPrev = randNum;
|
||||
$.twitter.updateStatus(String(message).replace('(title)', $.twitchcache.getStreamStatus()).replace('(game)', $.twitchcache.getGameTitle()).replace('(uptime)', hrs + ':' + min).replace('(twitchurl)', 'https://www.twitch.tv/' + $.ownerName + '?' + randNum).replace(/\(enter\)/g, '\r\n'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
commandArg = args[0],
|
||||
subCommandArg = args[1],
|
||||
setCommandArg = args[2],
|
||||
setCommandVal = args[3],
|
||||
setCommandList = ['mentions', 'retweets', 'hometimeline', 'usertimeline'],
|
||||
setRewardCommandList = ['toggle', 'points', 'cooldown', 'announce'],
|
||||
minVal;
|
||||
|
||||
/**
|
||||
* @commandpath twitter - Twitter base command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('twitter')) {
|
||||
if (commandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.id', $.ownerName, $.twitter.getUsername() + '') + ' ' + $.lang.get('twitter.usage.id'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter usage - Display the Twitter usage
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('usage')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set - Twitter configuration base command
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('set')) {
|
||||
if (subCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set reward - Base command for retweet rewards
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('reward')) {
|
||||
if (setCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set reward toggle [on/off] - Reward users that retweet.
|
||||
* @commandpath twitter set reward points [points] - Amount of points to reward a retweet.
|
||||
* @commandpath twitter set reward cooldown [hours] - Number of hours to wait between another retweet reward.
|
||||
* @commandpath twitter set reward announce [on/off] - Announce retweet rewards in chat.
|
||||
*/
|
||||
if (setRewardCommandList.indexOf(setCommandArg + '') === -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.usage'));
|
||||
return;
|
||||
}
|
||||
if (setCommandVal === undefined) {
|
||||
if (setCommandArg.equalsIgnoreCase('toggle') || setCommandArg.equalsIgnoreCase('announce')) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'reward_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
} else {
|
||||
setCommandVal = $.getIniDbFloat('twitter', 'reward_' + setCommandArg);
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (setCommandArg.equalsIgnoreCase('toggle') || setCommandArg.equalsIgnoreCase('announce')) {
|
||||
if (!setCommandVal.equalsIgnoreCase('on') && !setCommandVal.equalsIgnoreCase('off')) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'reward_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.' + setCommandArg + '.success', setCommandVal.toLowerCase()));
|
||||
setCommandVal = setCommandVal.equalsIgnoreCase('on') ? 'true' : 'false';
|
||||
$.inidb.set('twitter', 'reward_' + setCommandArg, setCommandVal);
|
||||
} else {
|
||||
if (isNaN(setCommandVal)) {
|
||||
setCommandVal = $.getIniDbNumber('twitter', 'reward_' + setCommandArg);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
$.inidb.set('twitter', 'reward_' + setCommandArg, setCommandVal);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.reward.' + setCommandArg + '.success', setCommandVal));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set polldelay - Twitter poll delay base command
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('polldelay')) {
|
||||
if (setCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set polldelay mentions [seconds] - Poll delay for mentions in seconds. Minimum is 60.
|
||||
* @commandpath twitter set polldelay retweets [seconds] - Poll delay for retweets in seconds. Minimum is 60.
|
||||
* @commandpath twitter set polldelay hometimeline [seconds] - Poll delay for home timeline in seconds. Minimum is 60.
|
||||
* @commandpath twitter set polldelay usertimeline [seconds] - Poll delay for user timeline in seconds. Minimum is 15.
|
||||
*/
|
||||
if (setCommandList.indexOf(setCommandArg + '') === -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.usage'));
|
||||
return;
|
||||
}
|
||||
if (setCommandVal === undefined) {
|
||||
setCommandVal = $.getIniDbNumber('twitter', 'polldelay_' + setCommandArg, setCommandArg.equalsIgnoreCase('usertimeline') ? 15 : 60);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (isNaN(setCommandVal)) {
|
||||
setCommandVal = $.getIniDbNumber('twitter', 'polldelay_' + setCommandArg, setCommandArg.equalsIgnoreCase('usertimeline') ? 15 : 60);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
minVal = setCommandArg.equalsIgnoreCase('usertimeline') ? 15 : 60;
|
||||
if (parseInt(setCommandVal) < minVal) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.minerror', minVal));
|
||||
return;
|
||||
}
|
||||
$.inidb.set('twitter', 'polldelay_' + setCommandArg, setCommandVal);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.polldelay.' + setCommandArg + '.success', setCommandVal));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set poll - Twitter poll configuration base command
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('poll')) {
|
||||
if (setCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.poll.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set poll mentions [on/off] - Poll mentions from Twitter.
|
||||
* @commandpath twitter set poll retweets [on/off] - Poll retweets from Twitter.
|
||||
* @commandpath twitter set poll hometimeline [on/off] - Poll home timeline from Twitter. Disables all other polling in the Core.
|
||||
* @commandpath twitter set poll usertimeline [on/off] - Poll user timeline from Twitter.
|
||||
*/
|
||||
if (setCommandList.indexOf(setCommandArg + '') === -1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.poll.usage'));
|
||||
return;
|
||||
}
|
||||
if (setCommandVal === undefined) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'poll_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.poll.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (!setCommandVal.equalsIgnoreCase('on') && !setCommandVal.equalsIgnoreCase('off')) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'poll_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.poll.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.poll.' + setCommandArg + '.success', setCommandVal.toLowerCase()));
|
||||
setCommandVal = setCommandVal.equalsIgnoreCase('on') ? 'true' : 'false';
|
||||
$.inidb.set('twitter', 'poll_' + setCommandArg, setCommandVal);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set post - Twitter automatic post configuration base command
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('post')) {
|
||||
if (setCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.post.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set post online [on/off] - Automatically post when the stream is detected as going online.
|
||||
* @commandpath twitter set post gamechange [on/off] - Automatically post when a game change is peformed via the !game command.
|
||||
* @commandpath twitter set post update [on/off] - Automatically post an update to Twitter on a timed interval (!twitter set updatetimer).
|
||||
*/
|
||||
if (!setCommandArg.equalsIgnoreCase('online') && !setCommandArg.equalsIgnoreCase('gamechange') && !setCommandArg.equalsIgnoreCase('update')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.post.usage'));
|
||||
return;
|
||||
}
|
||||
if (setCommandVal === undefined) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'post_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.post.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (!setCommandVal.equalsIgnoreCase('on') && !setCommandVal.equalsIgnoreCase('off')) {
|
||||
setCommandVal = $.getIniDbBoolean('twitter', 'post_' + setCommandArg, false);
|
||||
setCommandVal = setCommandVal ? 'on' : 'off';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.post.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.post.' + setCommandArg + '.success', setCommandVal.toLowerCase()));
|
||||
setCommandVal = setCommandVal.equalsIgnoreCase('on') ? 'true' : 'false';
|
||||
$.inidb.set('twitter', 'post_' + setCommandArg, setCommandVal);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set updatetimer [minutes] - Twitter automatic post timer. Posts updates about the stream in progress.
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('updatetimer')) {
|
||||
setCommandVal = setCommandArg;
|
||||
if (setCommandVal == undefined) {
|
||||
setCommandVal = $.getIniDbNumber('twitter', 'postdelay_update');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.updatetimer.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (isNaN(setCommandVal)) {
|
||||
setCommandVal = $.getIniDbNumber('twitter', 'postdelay_update');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.updatetimer.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
if (parseInt(setCommandVal) <= 180) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.updatetimer.toosmall', setCommandVal));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.updatetimer.success', setCommandVal));
|
||||
$.inidb.set('twitter', 'postdelay_update', setCommandVal);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set message - Twitter automatic post message configuration base command
|
||||
*/
|
||||
if (subCommandArg.equalsIgnoreCase('message')) {
|
||||
if (setCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter set message online [message] - Configures message that is sent out when stream goes online. Tags: (game) (twitchurl)
|
||||
* @commandpath twitter set message gamechange [message] - Configures message that is sent out on game change. Tags: (game) (twitchurl)
|
||||
* @commandpath twitter set message update [message] - Configures message that is sent out on an interval basis. Tags: (game) (twitchurl) (uptime)
|
||||
*/
|
||||
if (!setCommandArg.equalsIgnoreCase('online') && !setCommandArg.equalsIgnoreCase('gamechange') && !setCommandArg.equalsIgnoreCase('update')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.message.usage'));
|
||||
return;
|
||||
}
|
||||
if (setCommandVal === undefined) {
|
||||
setCommandVal = $.getIniDbString('twitter', 'message_' + setCommandArg);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.message.' + setCommandArg + '.usage', setCommandVal));
|
||||
return;
|
||||
}
|
||||
setCommandVal = args.splice(3).join(' ');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.set.message.' + setCommandArg + '.success', setCommandVal));
|
||||
$.inidb.set('twitter', 'message_' + setCommandArg, setCommandVal);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter post [message] - Post a message to Twitter
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('post')) {
|
||||
if (args.length === 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.post.usage'));
|
||||
return;
|
||||
}
|
||||
var retval = $.twitter.updateStatus(String(args.splice(1).join(' ')).replace(/\(enter\)/g, '\r\n')) + '';
|
||||
if (retval.equals('true')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.post.sent', args.splice(1).join(' ')));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.post.failed'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter lasttweet - Display the last Tweet on the home or user timeline
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('lasttweet')) {
|
||||
if ($.getIniDbBoolean('twitter', 'poll_hometimeline', false)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lasttweet', $.getIniDbString('twitter', 'last_hometimeline', 'No Tweets have been pulled yet!')));
|
||||
return;
|
||||
}
|
||||
if ($.getIniDbBoolean('twitter', 'poll_usertimeline', false)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lasttweet', $.getIniDbString('twitter', 'last_usertimeline', 'No Tweets have been pulled yet!')));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lasttweet.disabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter lastmention - Display the last @mention from Twitter
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('lastmention')) {
|
||||
if ($.getIniDbBoolean('twitter', 'poll_mentions', false)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lastmention', $.getIniDbString('twitter', 'last_mentions', 'No Mentions have been pulled yet!')));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lastmention.disabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter lastretweet - Display the last retweeted message on Twitter
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('lastretweet')) {
|
||||
if ($.getIniDbBoolean('twitter', 'poll_retweets', false)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lastretweet', $.getIniDbString('twitter', 'last_retweets', 'No Retweets have been pulled yet!')));
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.lastretweet.disabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter id - Display the configured Twitter ID for the caster
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('id')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.id', $.ownerName, $.twitter.getUsername() + ''));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter register [twitter_id] - Register your Twitter username
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('register')) {
|
||||
if (subCommandArg === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.register.usage', $.getIniDbString('twitter_mapping', sender, $.lang.get('twitter.register.notregistered'))));
|
||||
return;
|
||||
}
|
||||
if ($.inidb.GetKeyByValue('twitter_mapping', '', subCommandArg.toLowerCase()) !== null) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.register.inuse', subCommandArg.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
$.setIniDbString('twitter_mapping', sender, subCommandArg.toLowerCase());
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.register.success', subCommandArg.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath twitter unregister - Unregister your Twitter username
|
||||
*/
|
||||
if (commandArg.equalsIgnoreCase('unregister')) {
|
||||
$.inidb.del('twitter_mapping', sender);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('twitter.unregister'));
|
||||
return;
|
||||
}
|
||||
|
||||
} /* if (command.equalsIgnoreCase('twitter')) */
|
||||
}); /* @event command */
|
||||
|
||||
/**
|
||||
* @function checkAutoUpdate
|
||||
*/
|
||||
function checkAutoUpdate() {
|
||||
var message = $.getIniDbString('twitter', 'message_update');
|
||||
|
||||
/*
|
||||
* If not online, nothing to do. The last_autoupdate is reset to ensure that
|
||||
* the moment a stream comes online an additional Tweet is not sent out.
|
||||
*/
|
||||
if (!$.isOnline($.channelName)) {
|
||||
$.inidb.set('twitter', 'last_autoupdate', $.systemTime());
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.getIniDbBoolean('twitter', 'post_update', false)) {
|
||||
var lastUpdateTime = $.getSetIniDbNumber('twitter', 'last_autoupdate', $.systemTime());
|
||||
|
||||
if (($.systemTime() - lastUpdateTime) >= ($.getIniDbNumber('twitter', 'postdelay_update', 180) * 6e4)) { // 3 hour cooldown
|
||||
var DownloadHTTP = Packages.com.illusionaryone.ImgDownload;
|
||||
var success = DownloadHTTP.downloadHTTP($.twitchcache.getPreviewLink(), 'twitch-preview.jpg'),
|
||||
uptimeSec = $.getStreamUptimeSeconds($.channelName),
|
||||
hrs = (uptimeSec / 3600 < 10 ? '0' : '') + Math.floor(uptimeSec / 3600),
|
||||
min = ((uptimeSec % 3600) / 60 < 10 ? '0' : '') + Math.floor((uptimeSec % 3600) / 60);
|
||||
|
||||
$.inidb.set('twitter', 'last_autoupdate', $.systemTime());
|
||||
|
||||
if (success.equals('true')) {
|
||||
$.twitter.updateStatus(String(message).replace('(title)', $.twitchcache.getStreamStatus()).replace('(game)', $.twitchcache.getGameTitle()).replace('(twitchurl)', 'https://www.twitch.tv/' + $.ownerName + '?' + uptimeSec).replace(/\(enter\)/g, '\r\n').replace('(uptime)', hrs + ':' + min),
|
||||
'./addons/downloadHTTP/twitch-preview.jpg');
|
||||
} else {
|
||||
$.twitter.updateStatus(String(message).replace('(title)', $.twitchcache.getStreamStatus()).replace('(game)', $.twitchcache.getGameTitle()).replace('(twitchurl)', 'https://www.twitch.tv/' + $.ownerName + '?' + uptimeSec).replace('(uptime)', hrs + ':' + min).replace(/\(enter\)/g, '\r\n'));
|
||||
}
|
||||
$.log.event('Sent Auto Update to Twitter');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interval = setInterval(function() {
|
||||
checkAutoUpdate();
|
||||
}, 8e4);
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/twitterHandler.js', 'twitter', 7);
|
||||
$.registerChatSubcommand('twitter', 'set', 1);
|
||||
$.registerChatSubcommand('twitter', 'post', 1);
|
||||
$.registerChatSubcommand('twitter', 'lasttweet', 7);
|
||||
$.registerChatSubcommand('twitter', 'lastmention', 7);
|
||||
$.registerChatSubcommand('twitter', 'lastretweet', 7);
|
||||
$.registerChatSubcommand('twitter', 'id', 7);
|
||||
$.registerChatSubcommand('twitter', 'register', 7);
|
||||
$.registerChatSubcommand('twitter', 'unregister', 7);
|
||||
});
|
||||
})();
|
||||
115
libs/phantombot/scripts/handlers/wordCounter.js
Normal file
115
libs/phantombot/scripts/handlers/wordCounter.js
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @commandpath wordcounter - Configures various option for the wordcounter
|
||||
*/
|
||||
if (command.equalsIgnoreCase('wordcounter')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('wordcounter.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath wordcounter add [word] - Adds a word that will be counted every time someone says it
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (!subAction) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('wordcounter.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subAction = subAction.replace(action, '').toLowerCase();
|
||||
$.inidb.set('wordCounter', subAction, 0);
|
||||
$.say(subAction + $.lang.get('wordcounter.added'));
|
||||
$.log.event(sender + ' added "' + subAction + '" to the word counter list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath wordcounter remove [word] - Removes the given word which will no longer be counted every time someone says it
|
||||
*/
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (!subAction) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('wordcounter.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('wordCounter', subAction)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('wordcounter.err.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
subAction = subAction.replace(action, '').toLowerCase();
|
||||
$.inidb.del('wordCounter', subAction);
|
||||
$.say(subAction + $.lang.get('wordcounter.removed'));
|
||||
$.log.event(sender + ' removed "' + subAction + '" from the word counter list');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath count [word] - Tells you how many times that word as been said in chat.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('count')) {
|
||||
if (!action || !$.inidb.exists('wordCounter', action.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('wordcounter.err.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.lang.get('wordcounter.count', action, $.inidb.get('wordCounter', action.toLowerCase())));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
var message = event.getMessage().toLowerCase(),
|
||||
keys = $.inidb.GetKeyList('wordCounter', ''),
|
||||
word,
|
||||
key;
|
||||
|
||||
if ($.bot.isModuleEnabled('./handlers/wordCounter.js')) {
|
||||
for (i in keys) {
|
||||
key = keys[i].toLowerCase();
|
||||
word = new RegExp('\\b' + key + '\\b', 'ig');
|
||||
if (word.exec(message)) {
|
||||
$.inidb.incr('wordCounter', key, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./handlers/wordCounter.js', 'wordcounter', 1);
|
||||
$.registerChatCommand('./handlers/wordCounter.js', 'count', 7);
|
||||
});
|
||||
})();
|
||||
1124
libs/phantombot/scripts/init.js
Normal file
1124
libs/phantombot/scripts/init.js
Normal file
File diff suppressed because it is too large
Load Diff
6
libs/phantombot/scripts/lang/custom/README
Normal file
6
libs/phantombot/scripts/lang/custom/README
Normal file
@@ -0,0 +1,6 @@
|
||||
You may copy any of the lang files into this directory, matching
|
||||
the subdirectories if you desire, or just placing all of the files
|
||||
in this directory. You may then edit the files and PhantomBot will
|
||||
override the default language settings with the ones you provide
|
||||
here. This allows you to customize your language settings and
|
||||
not have them overwritten during a release.
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('customcommands.add.error', 'That command already exists');
|
||||
$.lang.register('customcommands.add.success', 'Command !$1 has been created!');
|
||||
$.lang.register('customcommands.add.usage', 'Usage: !addcom (command) (message)');
|
||||
$.lang.register('customcommands.add.commandtag.notfirst', '(command) tag must be at the start of a custom command when used.');
|
||||
$.lang.register('customcommands.add.commandtag.invalid', '(command) tag command does not exist: $1');
|
||||
$.lang.register('customcommands.alias.delete.error.alias.404', 'Alias does not exist: !$1');
|
||||
$.lang.register('customcommands.alias.delete.success', 'The alias !$1 was successfully deleted!');
|
||||
$.lang.register('customcommands.alias.delete.usage', 'Usage: !delalias (alias name)');
|
||||
$.lang.register('customcommands.alias.error', 'An alias already exists for !$1. Delete it first.');
|
||||
$.lang.register('customcommands.alias.error.target404', 'The target command does not exist!');
|
||||
$.lang.register('customcommands.alias.error.exists', 'The command you want to alias to already exists.');
|
||||
$.lang.register('customcommands.add.disabled', 'That command is currently disabled. Re-enable the command or delete it to add a new command with that name.');
|
||||
$.lang.register('customcommands.alias.success', 'The command !$1 was successfully aliased to !$2');
|
||||
$.lang.register('customcommands.alias.usage', 'Usage: !aliascom (alias name) (existing command) [optional parameters]');
|
||||
$.lang.register('customcommands.delete.success', 'Command !$1 has been removed!');
|
||||
$.lang.register('customcommands.delete.usage', 'Usage: !delcom (command)');
|
||||
$.lang.register('customcommands.edit.404', 'You cannot overwrite a default command.');
|
||||
$.lang.register('customcommands.edit.editcom.alias', 'You cannot edit an alias, please use the following: !editcom !$1 $2');
|
||||
$.lang.register('customcommands.set.perm.error.target404', 'The command !$1 does not exist!');
|
||||
$.lang.register('customcommands.set.perm.success', 'Permissions for command: $1 set for group: $2 and higher.');
|
||||
$.lang.register('customcommands.set.perm.unset.success', 'All recursive permissions for the command: $1 and any of its aliases have been removed.');
|
||||
$.lang.register('customcommands.set.perm.usage', 'Usage: !permcom (command name) (group id/name). Restricts usage of a command to viewers with a certain permission level.');
|
||||
$.lang.register('customcommands.set.perm.404', 'Command could not be found: $1');
|
||||
$.lang.register('customcommands.set.price.error.404', 'Please select a command that exists and is available to non-mods.');
|
||||
$.lang.register('customcommands.set.price.error.invalid', 'Please enter a valid price of 0 or greater.');
|
||||
$.lang.register('customcommands.set.price.success', 'The price for !$1 has been set to $2 $3.');
|
||||
$.lang.register('customcommands.set.price.usage', 'Usage: !pricecom (command) [subcommand] [subaction] (price). Optional: subcommand and subaction');
|
||||
$.lang.register('customcommands.set.pay.error.404', 'Please select a command that exists and is available to non-mods.');
|
||||
$.lang.register('customcommands.set.pay.error.invalid', 'Please enter a valid payment of 0 or greater.');
|
||||
$.lang.register('customcommands.set.pay.success', 'The payment for !$1 has been set to $2 $3.');
|
||||
$.lang.register('customcommands.set.pay.usage', 'Usage: !paycom (command) (price)');
|
||||
$.lang.register('customcommands.404.no.commands', 'There are no custom commands, add one with !addcom');
|
||||
$.lang.register('customcommands.cmds', 'Current custom commands: $1');
|
||||
$.lang.register('customcommands.edit.usage', 'Usage: !editcom (command) (message)');
|
||||
$.lang.register('customcommands.edit.success', 'Command !$1 has been edited!');
|
||||
$.lang.register('customcommands.token.usage', 'Usage: !tokencom (command) (token) -- 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!');
|
||||
$.lang.register('customcommands.token.success', 'Token set for command !$1! Make sure you put a (token) subtag in the customapi url for this command in the spot you want it to appear');
|
||||
$.lang.register('customcommands.touser.offline', 'Sorry, but $1 appears to be offline!');
|
||||
$.lang.register('customcommands.customapi.404', 'The !$1 command requires parameters.');
|
||||
$.lang.register('customcommands.customapijson.err', '!$1: An error occurred processing the API.');
|
||||
$.lang.register('customcommands.datetime.format.invalid', 'unrecognized date format "$1"');
|
||||
$.lang.register('customcommands.disable.usage', 'Usage: !disablecom (command)');
|
||||
$.lang.register('customcommands.disable.404', 'That command does not exist.');
|
||||
$.lang.register('customcommands.disable.err', 'That command is already disabled.');
|
||||
$.lang.register('customcommands.disable.success', 'Command !$1 has been disabled.');
|
||||
$.lang.register('customcommands.enable.usage', 'Usage: !enablecom (command)');
|
||||
$.lang.register('customcommands.enable.404', 'That command does not exist.');
|
||||
$.lang.register('customcommands.enable.err', 'That command is not disabled.');
|
||||
$.lang.register('customcommands.enable.success', 'Command !$1 has been re-enabled.');
|
||||
$.lang.register('customcommands.keyword.404', 'unknown keyword "$1"');
|
||||
$.lang.register('customcommands.lasttip.404', 'No donations found.');
|
||||
$.lang.register('customcommands.playsound.404', 'unknown audio hook "$1"');
|
||||
$.lang.register('customcommands.file.404', 'file not found: $1');
|
||||
$.lang.register('customcommands.reset.usage', 'Usage: !resetcom (command) (count). If no (count) then reset to 0.');
|
||||
$.lang.register('customcommands.reset.success', 'The counter for !$1 has been reset.');
|
||||
$.lang.register('customcommands.reset.change.fail', 'Invalid counter value: $1');
|
||||
$.lang.register('customcommands.reset.change.success', 'The counter for !$1 has been set to $2.');
|
||||
$.lang.register('customcommands.teamapi.team.404', 'you\'re not part of team "$1"');
|
||||
$.lang.register('customcommands.teamapi.member.404', 'member "$1" is not in team "$2"');
|
||||
$.lang.register('customcommands.botcommands', 'Commands: $1');
|
||||
$.lang.register('customcommands.botcommands.error', 'Provide a number to find a page.');
|
||||
$.lang.register('customcommands.botcommands.total', 'Total Pages: $1 [See also: https://phantombot.github.io/PhantomBot/guides/#guide=content/commands/commands]');
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('deathcounter.set-error', 'Provide a new valid death counter value.');
|
||||
$.lang.register('deathcounter.set-success', 'Death counter for $1 set to $2.');
|
||||
$.lang.register('deathcounter.add-success', '$1 has died again in $2, bringing the total to $3.');
|
||||
$.lang.register('deathcounter.sub-success', 'Calling back a death, the total is now $2 in $1.');
|
||||
$.lang.register('deathcounter.sub-zero', 'The death counter for $1 is already zero, can\'t go any lower!');
|
||||
$.lang.register('deathcounter.counter', '$1 has died $3 times in $2.');
|
||||
$.lang.register('deathcounter.none', '$1 has not died in $2....yet.');
|
||||
$.lang.register('deathcounter.reset', 'Reset the death counter back to 0 from $2 for $1.');
|
||||
$.lang.register('deathcounter.reset-nil', 'The death counter for $1 is already 0.');
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('dualstreamcommand.usage', 'Usage: !multi [set / clear / timer / timerinterval]');
|
||||
$.lang.register('dualstreamcommand.set.usage', 'Usage: !multi set [channel(s)]');
|
||||
$.lang.register('dualstreamcommand.link.set', 'Multi link set! - http://multistre.am/$1');
|
||||
$.lang.register('dualstreamcommand.clear', 'Multi command cleared, and disabled.');
|
||||
$.lang.register('dualstreamcommand.timer.usage', 'Usage: !multi timer [on / off]');
|
||||
$.lang.register('dualstreamcommand.timer.enabled', 'Multi timer enabled.');
|
||||
$.lang.register('dualstreamcommand.timer.disabled', 'Multi timer disabled.');
|
||||
$.lang.register('dualstreamcommand.timerinterval.usage', 'Usage: !multi timerinterval (time in minutes)');
|
||||
$.lang.register('dualstreamcommand.timerinterval.err', 'Minimum for the timer is 5 minutes.');
|
||||
$.lang.register('dualstreamcommand.timerinterval.set', 'Timer interval set to $1 minutes!');
|
||||
$.lang.register('dualstreamcommand.link', 'http://multistre.am/');
|
||||
$.lang.register('dualstreamcommand.req.usage', 'Usage: !multi reqmessage (amount of messages)');
|
||||
$.lang.register('dualstreamcommand.reqmessages.set', 'Req message set to $1 messages!');
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('highlightcommand.highlight.offline', 'Highlights can only be set when the stream is online.');
|
||||
$.lang.register('highlightcommand.highlight.usage', 'Usage: !highlight [description] (Using date stamp for timezone: $1)');
|
||||
$.lang.register('highlightcommand.highlight.success', 'Highlight successfully saved with a timestamp of $1.');
|
||||
$.lang.register('highlightcommand.gethighlights.no-highlights', 'There are currently no highlights.');
|
||||
$.lang.register('highlightcommand.clearhighlights.success', 'Highlights have been cleared.');
|
||||
$.lang.register('highlightcommand.highlights', 'Highlights: $1');
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('killcommand.self.1', '$1 managed to kill themself.');
|
||||
$.lang.register('killcommand.self.2', '$1 died from an unknown cause.');
|
||||
$.lang.register('killcommand.self.3', '$1 was crushed by a boulder, or some peice of debris.');
|
||||
$.lang.register('killcommand.self.4', '$1 exploded.');
|
||||
$.lang.register('killcommand.self.5', '$1 forgot how to breathe.');
|
||||
$.lang.register('killcommand.self.6', '$1 learned that cellular respiration uses oxygen, not sand.');
|
||||
$.lang.register('killcommand.self.7', '$1 died.');
|
||||
$.lang.register('killcommand.self.8', '$1 tried to befriend a wild grizzly bear.');
|
||||
$.lang.register('killcommand.self.9', '$1 suffocated.');
|
||||
$.lang.register('killcommand.self.10', '$1 tested the bounds of time and space, and lost.');
|
||||
$.lang.register('killcommand.self.11', '$1 imploded.');
|
||||
$.lang.register('killcommand.self.12', '$1 drowned.');
|
||||
$.lang.register('killcommand.self.13', '$1 ceased to be.');
|
||||
$.lang.register('killcommand.self.14', '$1 went kablewy!');
|
||||
$.lang.register('killcommand.self.15', '$1 figured out how to divide by 0!');
|
||||
$.lang.register('killcommand.self.16', '$1 took a long walk off a short pier.');
|
||||
$.lang.register('killcommand.self.17', '$1 fell off a ladder.');
|
||||
$.lang.register('killcommand.self.18', '$1 fell off a tree.');
|
||||
$.lang.register('killcommand.self.19', '$1 fell off of the roof.');
|
||||
$.lang.register('killcommand.self.20', '$1 burst into flames.');
|
||||
$.lang.register('killcommand.self.21', '$1 was struck by lightning.');
|
||||
$.lang.register('killcommand.self.22', '$1 starved to death.');
|
||||
$.lang.register('killcommand.self.23', '$1 was stabbed to death.');
|
||||
$.lang.register('killcommand.self.24', '$1 fell victim to gravity.');
|
||||
$.lang.register('killcommand.self.25', '$1\'s plead for death was answered.');
|
||||
$.lang.register('killcommand.self.26', '$1\'s vital organs were ruptured.');
|
||||
$.lang.register('killcommand.self.27', '$1\'s innards were made outwards.');
|
||||
$.lang.register('killcommand.self.28', '$1 was licked to death. Don\'t ask.');
|
||||
$.lang.register('killcommand.self.29', '$1 was deleted.');
|
||||
$.lang.register('killcommand.self.30', '$1 had to split. Literally..');
|
||||
$.lang.register('killcommand.self.31', '$1 has bled to death.');
|
||||
$.lang.register('killcommand.self.32', '$1 Food is a gift from God. Spices are a gift from the devil. I guess it was a little too spicy for you.');
|
||||
$.lang.register('killcommand.self.33', '$1 has died due to a vehicular explosion!');
|
||||
$.lang.register('killcommand.self.34', '$1 has killed themself!');
|
||||
$.lang.register('killcommand.self.35', '$1 has been blown up by a landmine!');
|
||||
$.lang.register('killcommand.self.36', '$1 died due to holding their breath for too long!');
|
||||
$.lang.register('killcommand.self.37', '$1 burned to death.');
|
||||
$.lang.register('killcommand.self.38', '$1 was blown up by a missile!');
|
||||
$.lang.register('killcommand.self.39', '$1 froze to death.');
|
||||
$.lang.register('killcommand.self.40', '$1 was dissolved in acid.');
|
||||
$.lang.register('killcommand.self.41', '$1 tried to swim in acid.');
|
||||
$.lang.register('killcommand.self.42', '$1 tried to swim in lava.');
|
||||
$.lang.register('killcommand.self.43', '$1 experienced kinetic energy.');
|
||||
$.lang.register('killcommand.self.44', '$1 blew up.');
|
||||
$.lang.register('killcommand.self.45', '$1 fell into a patch of fire.');
|
||||
$.lang.register('killcommand.self.46', '$1 fell out of a plane.');
|
||||
$.lang.register('killcommand.self.47', '$1 went up in flames.');
|
||||
$.lang.register('killcommand.self.48', '$1 withered away.');
|
||||
$.lang.register('killcommand.self.49', '$1 went skydiving, and forgot the parachute.');
|
||||
$.lang.register('killcommand.self.50', '$1 spontaneously combusted.');
|
||||
$.lang.register('killcommand.self.51', '$1 was struck with a bolt of inspiration, I mean lightning.');
|
||||
$.lang.register('killcommand.self.52', '$1 ended it all. Goodbye cruel world!');
|
||||
$.lang.register('killcommand.self.53', '$1 passed the event horizon.');
|
||||
|
||||
|
||||
$.lang.register('killcommand.other.1', '$1 murdered $2 with a unicorn\'s horn!');
|
||||
$.lang.register('killcommand.other.2', '$2 was killed by $1!');
|
||||
$.lang.register('killcommand.other.3', '$2 was mauled by $1 dressed up as a chicken.');
|
||||
$.lang.register('killcommand.other.4', '$2 was ripped apart by $1, daaaaaaamn!');
|
||||
$.lang.register('killcommand.other.5', '$2 was brutally murdered by $1 with a car!');
|
||||
$.lang.register('killcommand.other.6', '$1 covered $2 in meat sauce and threw them in a cage with a starved tiger.');
|
||||
$.lang.register('killcommand.other.7', '$1 genetically modified a Venus flytrap to grow abnormally large, and trapped $2 in a room with it.');
|
||||
$.lang.register('killcommand.other.8', '$1 shanked $2\'s butt, over and over again.');
|
||||
$.lang.register('killcommand.other.9', '$1 just wrote $2\'s name in their Death Note.');
|
||||
$.lang.register('killcommand.other.10', '$1 put $2 out of their misery.');
|
||||
$.lang.register('killcommand.other.11', '$1 destroyed $2!');
|
||||
$.lang.register('killcommand.other.12', '$1 atacó a $2 con un consolador grande!');
|
||||
$.lang.register('killcommand.other.13', '$2 was poked a bit too hard by $1 with a spork!');
|
||||
$.lang.register('killcommand.other.14', 'ZA WARUDO! $1 stopped time and throw hundreds of knives at $2. END!');
|
||||
$.lang.register('killcommand.other.15', '$1 attacked $2 with a rusty spork...and managed to kill $2 with very little effort.');
|
||||
$.lang.register('killcommand.other.16', '$1 stole a car known as \'KITT\' and ran over $2.');
|
||||
$.lang.register('killcommand.other.17', '$1 tickled $2 to death!');
|
||||
$.lang.register('killcommand.other.18', '$2\'s skull was crushed by $1!');
|
||||
$.lang.register('killcommand.other.19', '$2 is in several pieces after a tragic accident involving $1 and cutlery.');
|
||||
$.lang.register('killcommand.other.20', '$1 licked $2 until $2 was squishy, yeah.. squishy.');
|
||||
$.lang.register('killcommand.other.21', '$1 catapulted a huge load of rusty sporks on to $2. $2 died.');
|
||||
$.lang.register('killcommand.other.22', '$1 ran out of rusty sporks and unicorn horns to kill $2 with, so instead they used a rusty hanger.');
|
||||
$.lang.register('killcommand.other.23', '$1 came in like a mystical being of awesomeness and destroyed $2!');
|
||||
$.lang.register('killcommand.other.24', '$2 drowned whilst trying to escape from $1');
|
||||
$.lang.register('killcommand.other.25', '$2 walked into a cactus while running from $1');
|
||||
$.lang.register('killcommand.other.26', '$2 was attacked by $1 behind a Taco Bell.');
|
||||
$.lang.register('killcommand.other.27', '$1 went back in time to prevent himself from killing $2, apparently the time machine landed on $2 when $1 jumped back in time.');
|
||||
$.lang.register('killcommand.other.28', '$1 rekt $2 30-4 by doing a 360 no-scope.');
|
||||
$.lang.register('killcommand.other.33', '$1 struck the final blow and ended $2.');
|
||||
|
||||
/** Add "(jail)" at the start of the lang for the user to get timed out for the jailTime you set. You can also use $3 for the jail timeout time to be displayed. $4 = botname. */
|
||||
$.lang.register('killcommand.other.29', '(jail) $1 tried to kill $2 with a unicorn\'s horn, but police showed up before $1 had time.');
|
||||
$.lang.register('killcommand.other.30', '(jail) $1 tried to murder $2, but swat was hiding in the bushes and jumped on $1 before it could be done.');
|
||||
$.lang.register('killcommand.other.31', '(jail) $1 was going to hit $2 with a hammer. However $2 was trained in the Secret Nippon Arts!');
|
||||
$.lang.register('killcommand.other.32', '(jail) $4 was paid by $1 to assassinate $2. $1\'s plan failed because $4 was actually a undercover officer!');
|
||||
$.lang.register('killcommand.other.44', '(jail) $1 attacked $2 with a plastic spoon, but then suddenly a swarm of police surrounded $1 and detained them.');
|
||||
$.lang.register('killcommand.other.45', '(jail) $2 is protected by an unknown force which repels $1.');
|
||||
/** Jail End **/
|
||||
|
||||
$.lang.register('killcommand.other.34', '$1 was justly ended by $2.');
|
||||
$.lang.register('killcommand.other.35', '$1 was blown up by $2.');
|
||||
$.lang.register('killcommand.other.36', '$1 was shot off a ladder by $2.');
|
||||
$.lang.register('killcommand.other.37', '$1 tried to swim in lava while trying to escape $2.');
|
||||
$.lang.register('killcommand.other.38', '$1 got finished off by $2.');
|
||||
$.lang.register('killcommand.other.39', '$1 delivered the fatal blow on $2.');
|
||||
$.lang.register('killcommand.other.40', '$1 has punched $2 to death.');
|
||||
$.lang.register('killcommand.other.41', '$1 ruffled $2\'s fluff, and died!');
|
||||
$.lang.register('killcommand.other.42', '$1 hugged $2 a little too tight.');
|
||||
$.lang.register('killcommand.other.43', '$1 sent $2 to an awesome farm in the country.');
|
||||
|
||||
$.lang.register('killcommand.jail.timeout.usage', 'Usage: !jailtimeouttime (amount in seconds)');
|
||||
$.lang.register('killcommand.jail.timeout.set', 'Jail timeout time set to: $1 seconds.');
|
||||
|
||||
$.lang.register('killcommand.console.loaded', 'Found kill command messages: $1 self, $2 other.');
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('lastseen.404', 'I haven\'t seen $1 yet.');
|
||||
$.lang.register('lastseen.response', '$1 has last been seen on $2 @ $3');
|
||||
$.lang.register('lastseen.usage', 'Usage: !lastseen [username].');
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('namechange.default', 'Usage: !namechange [old name] [new name]');
|
||||
$.lang.register('namechange.updating', 'Updating name $1 to $2 in all the database tables. This may take time.');
|
||||
$.lang.register('namechange.success', 'Username $1 has been updated to $2 in $3 tables!');
|
||||
$.lang.register('namechange.notfound', 'Username $1 was not found in any tables.');
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('streamcommand.vod.404', 'No videos were found.');
|
||||
$.lang.register('streamcommand.vod.online', 'Stream Uptime: $1 [$2]');
|
||||
$.lang.register('streamcommand.vod.offline', 'Stream is offline. Last video created: [$1] [Length: $2]');
|
||||
$.lang.register('streamcommand.playtime.offline', '$1 is not streaming right now.');
|
||||
$.lang.register('streamcommand.playtime.online', '$1 has been playing $2 for $3');
|
||||
$.lang.register('streamcommand.title.offline', 'Current Status: $1');
|
||||
$.lang.register('streamcommand.title.no.title', 'There\'s no status set.');
|
||||
$.lang.register('streamcommand.title.online', 'Current Status: $1. Uptime: $2');
|
||||
$.lang.register('streamcommand.title.set.usage', 'Usage: !settitle [stream title]. Currently: $1');
|
||||
$.lang.register('streamcommand.game.online', 'Current Game: $1. Playtime: $2');
|
||||
$.lang.register('streamcommand.game.offline', 'Current Game: $1');
|
||||
$.lang.register('streamcommand.game.no.game', 'There\'s no game set.');
|
||||
$.lang.register('streamcommand.game.set.usage', 'Usage: !setgame [game title]. Currently: $1');
|
||||
$.lang.register('streamcommand.communities.set.usage', 'Usage: !setcommunities [communities]. Currently: $1');
|
||||
$.lang.register('streamcommand.viewers', 'Currently $1 viewers are watching.');
|
||||
$.lang.register('streamcommand.online.offline', 'Stream is offline.');
|
||||
$.lang.register('streamcommand.online.online', 'Stream is online.');
|
||||
$.lang.register('streamcommand.createdat.404', 'Please provide a channel');
|
||||
$.lang.register('streamcommand.createdat.error', 'The channel does not exist or a Twitch API error occurred.');
|
||||
$.lang.register('streamcommand.createdat', 'Channel: $1 | Created At: $2');
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('top5.default', 'Top $1 $2: $3');
|
||||
$.lang.register('top5.points-disabled', 'Points are disabled.');
|
||||
$.lang.register('top5.amount.points.usage', 'Usage: !topamount (amount) - Set how many viewers will appear in the !top points list.');
|
||||
$.lang.register('top5.amount.max', 'The max amount of users is 15.');
|
||||
$.lang.register('top5.amount.points.set', '$1 users will now show in the !top command.');
|
||||
$.lang.register('top5.amount.time.usage', 'Usage: !toptimeamount (amount) - Set how many viewers will appear in the !toptime list.');
|
||||
$.lang.register('top5.amount.time.set', '$1 viwers will now show in the !toptime command.');
|
||||
$.lang.register('top5.reloadtopbots', 'Deprecated. Please run !reloadbots');
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('discord.customcommands.addcom.usage', 'Usage: !addcom [command] [response]');
|
||||
$.lang.register('discord.customcommands.addcom.err', 'That command already exists.');
|
||||
$.lang.register('discord.customcommands.addcom.success', 'Command !$1 has been added!');
|
||||
$.lang.register('discord.customcommands.editcom.usage', 'Usage: !editcom [command] [response]');
|
||||
$.lang.register('discord.customcommands.editcom.404', 'That command does not exist.');
|
||||
$.lang.register('discord.customcommands.editcom.success', 'Command !$1 has been edited!');
|
||||
$.lang.register('discord.customcommands.delcom.usage', 'Usage: !delcom [command] [response]');
|
||||
$.lang.register('discord.customcommands.delcom.404', 'That command does not exist.');
|
||||
$.lang.register('discord.customcommands.delcom.success', 'Command !$1 has been removed!');
|
||||
$.lang.register('discord.customcommands.permcom.usage', 'Usage: !permcom [command] [permission]');
|
||||
$.lang.register('discord.customcommands.permcom.404', 'That command does not exist.');
|
||||
$.lang.register('discord.customcommands.permcom.syntax.error', 'Usage: !permcom [command] [permission] - Either 0 which is everyone or 1 is administrators.');
|
||||
$.lang.register('discord.customcommands.permcom.success', 'Permission for command !$1 has been set to permission $2');
|
||||
$.lang.register('discord.customcommands.coolcom.usage', 'Usage: !coolcom [command] [time in seconds]');
|
||||
$.lang.register('discord.customcommands.coolcom.404', 'That command does not exist.');
|
||||
$.lang.register('discord.customcommands.coolcom.removed', 'Cooldown for command !$1 has been removed.');
|
||||
$.lang.register('discord.customcommands.coolcom.success', 'Cooldown for command !$1 has been set to $2 seconds.');
|
||||
$.lang.register('discord.customcommands.channelcom.usage', 'Usage: !channelcom [command] [channel / --global / --list] - Separate the channels with commas (no spaces) for multiple.');
|
||||
$.lang.register('discord.customcommands.channelcom.global', 'Command !$1 will now work in every channel.');
|
||||
$.lang.register('discord.customcommands.channelcom.success', 'Command !$1 will now only work in channel(s): $2.');
|
||||
$.lang.register('discord.customcommands.channelcom.404', 'No channels are set on that command.');
|
||||
$.lang.register('discord.customcommands.commands', 'Commands: $1');
|
||||
$.lang.register('discord.customcommands.bot.commands', 'Bot Commands: $1');
|
||||
$.lang.register('discord.customcommands.pricecom.usage', 'Usage: !pricecom [command] [amount]');
|
||||
$.lang.register('discord.customcommands.pricecom.success', 'Cost for command !$1 has been set to $2.');
|
||||
$.lang.register('discord.customcommands.aliascom.usage', 'Usage: !aliascom [alias] [command]');
|
||||
$.lang.register('discord.customcommands.aliascom.success', 'Command !$2 has been aliased to !$1');
|
||||
$.lang.register('discord.customcommands.delalias.usage', 'Usage: !delalias [alias]');
|
||||
$.lang.register('discord.customcommands.delalias.success', 'Alias !$1 has been removed.');
|
||||
$.lang.register('discord.customcommands.404', 'That command does not exist.');
|
||||
$.lang.register('discord.customcommands.alias.404', 'That alias does not exist.');
|
||||
$.lang.register('discord.customcommands.customapi.404', 'The !$1 command requires parameters.');
|
||||
$.lang.register('discord.customcommands.customapijson.err', '!$1: An error occurred processing the API.');
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('discord.accountlink.usage.nolink', 'In order to use this module, make sure the bot is not blocked from private messaging you on Discord.\nTo link your Discord and Twitch accounts please use the following command **!account link**');
|
||||
$.lang.register('discord.accountlink.usage.link', 'Your Discord account is currently linked to **https://twitch.tv/$1**.\nYou can change it using **!account link** or remove it using **!account remove**');
|
||||
$.lang.register('discord.accountlink.link', '**NOTE: This expires in 10 minutes**.\nTo complete the process of linking your Discord and Twitch accounts, please login to Twitch, go to **https://twitch.tv/$1**, and send the command **!account link $2**');
|
||||
$.lang.register('discord.accountlink.link.relink', '**NOTE: This expires in 10 minutes**.\n**This will automatically remove your previous account link.** \nTo complete the process of linking your Discord account to your Twitch account, please login to Twitch, go to **https://twitch.tv/$1**, and send the command **!account link $2**');
|
||||
$.lang.register('discord.accountlink.link.success', 'Your Discord account has been successfully linked to **https://twitch.tv/$1**.\nPlease note that if you change your name on Twitch, you will have to redo this.');
|
||||
$.lang.register('discord.accountlink.link.fail', 'Sorry, that is an invalid or expired token. Make sure you copy the account linking command EXACTLY. If you are sure you typed it correctly, please restart the account linking process from a chat channel in the Discord server.');
|
||||
$.lang.register('discord.accountlink.link.remove', 'Your Discord account has been unlinked from all Twitch accounts.\nTo link your Discord account to your Twitch account, use **!account link** in a regular chat channel on the Discord server');
|
||||
$.lang.register('discord.accountlink.linkrequired', 'Sorry, that command is only available in Discord after your Twitch account has been linked using **!account**');
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('discord.cooldown.coolcom.usage', 'Usage: !coolcom [command] [seconds] [type (global / user)] - Using -1 for the seconds removes the cooldown.');
|
||||
$.lang.register('discord.cooldown.coolcom.set', 'Cooldown for command !$1 has been set to $2 seconds.');
|
||||
$.lang.register('discord.cooldown.coolcom.remove', 'Cooldown for command !$1 has been removed.');
|
||||
$.lang.register('discord.cooldown.cooldown.usage', 'Usage: !cooldown [setdefault]');
|
||||
$.lang.register('discord.cooldown.default.set', 'The default cooldown for commands without one has been set to $1 seconds.');
|
||||
$.lang.register('discord.cooldown.default.usage', 'Usage: !cooldown setdefault [seconds] - Set a cooldown for commands that don\'t have one.');
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('discord.misc.module.usage', 'Usage: !module [enable / disable / list]');
|
||||
$.lang.register('discord.misc.module.enabled', 'Module: $1 has been enabled.');
|
||||
$.lang.register('discord.misc.module.disabled', 'Module: $1 has been disabled.');
|
||||
$.lang.register('discord.misc.module.list', 'Discord Module list: \r\n $1');
|
||||
$.lang.register('discord.misc.module.404', 'That module does not exist: $1');
|
||||
$.lang.register('discord.misc.game.set.usage', 'Usage: !setgame [game name]');
|
||||
$.lang.register('discord.misc.game.set', 'Bot game updated to: $1');
|
||||
$.lang.register('discord.misc.game.stream.set.usage', 'Usage: !setstream [twitch url] [game name]');
|
||||
$.lang.register('discord.misc.game.stream.set', 'Bot stream changed to: $1 and game to: $2');
|
||||
$.lang.register('discord.misc.game.removed', 'Bot game has been removed.');
|
||||
$.lang.register('discord.misc.reconnect', 'A Discord reconnect is being attempted.');
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('moderation.usage', 'Usage: !moderation [links / caps / spam / blacklist / whitelist / cleanup / logs]');
|
||||
$.lang.register('moderation.links.usage', 'Usage: !moderation links [toggle / permittime]');
|
||||
$.lang.register('moderation.links.toggle', 'Link moderation has been $1.');
|
||||
$.lang.register('moderation.links.permit.time.usage', 'Usage: !moderation links permittime [seconds]');
|
||||
$.lang.register('moderation.links.permit.time.set', 'Permit time has been set to $1 seconds!');
|
||||
$.lang.register('moderation.caps.usage', 'Usage: !moderation caps [toggle / triggerlength / limitpercent]');
|
||||
$.lang.register('moderation.caps.toggle', 'Cap moderation has been $1.');
|
||||
$.lang.register('moderation.caps.trigger.usage', 'Usage: !moderation caps triggerlength [characters]');
|
||||
$.lang.register('moderation.caps.trigger.set', 'Caps trigger limit has been set to $1%');
|
||||
$.lang.register('moderation.caps.limit.usage', 'Usage: !moderation caps limitpercent [percent]');
|
||||
$.lang.register('moderation.caps.limit.set', 'Caps limit has been set to $1%');
|
||||
$.lang.register('moderation.long.message.usage', 'Usage: !moderation longmessage [toggle / limit]');
|
||||
$.lang.register('moderation.long.message.toggle', 'Message length moderation has been $1.');
|
||||
$.lang.register('moderation.long.message.limit.usage', 'Usage: !moderation longmessage limit [characters]');
|
||||
$.lang.register('moderation.long.message.limit.set', 'Long message limit has been set to $1 characters!');
|
||||
$.lang.register('moderation.spam.usage', 'Usage: !moderation spam [toggle / limit]');
|
||||
$.lang.register('moderation.spam.toggle', 'Spam moderation has been $1.');
|
||||
$.lang.register('moderation.spam.limit.usage', 'Usage: !moderation spam limit [messages]');
|
||||
$.lang.register('moderation.spam.limit.set', 'Spam limit has been set to $1 messages!');
|
||||
$.lang.register('moderation.blacklist.usage', 'Usage: !moderation blacklist [add / remove / list]');
|
||||
$.lang.register('moderation.blacklist.add.usage', 'Usage: !moderation blacklist add [phrase]');
|
||||
$.lang.register('moderation.blacklist.add.success', 'Phrase added the to the blacklist!');
|
||||
$.lang.register('moderation.blacklist.remove.usage', 'Usage: !moderation blacklist remove [phrase]');
|
||||
$.lang.register('moderation.blacklist.remove.404', 'That phrase is not in the blacklist.');
|
||||
$.lang.register('moderation.blacklist.remove.success', 'Phrase removed from the blacklist!');
|
||||
$.lang.register('moderation.blacklist.list.404', 'The blacklist is empty.');
|
||||
$.lang.register('moderation.blacklist.list', 'Blacklist: ```$1```');
|
||||
$.lang.register('moderation.whitelist.usage', 'Usage: !moderation whitelist [add / remove / list]');
|
||||
$.lang.register('moderation.whitelist.add.usage', 'Usage: !moderation whitelist add [phrase or username#discriminator]');
|
||||
$.lang.register('moderation.whitelist.add.success', 'Phrase or username added the to the whitelist!');
|
||||
$.lang.register('moderation.whitelist.remove.usage', 'Usage: !moderation whitelist remove [phrase or username#discriminator]');
|
||||
$.lang.register('moderation.whitelist.remove.404', 'That phrase or username is not in the whitelist.');
|
||||
$.lang.register('moderation.whitelist.remove.success', 'Phrase or username removed from the whitelist!');
|
||||
$.lang.register('moderation.whitelist.list.404', 'The whitelist is empty.');
|
||||
$.lang.register('moderation.whitelist.list', 'Whitelist: ```$1```');
|
||||
$.lang.register('moderation.cleanup.usage', 'Usage: !moderation cleanup [channel] [amount]');
|
||||
$.lang.register('moderation.cleanup.err.amount', 'You can only delete 2 to 10000 messages.');
|
||||
$.lang.register('moderation.cleanup.err.unknownchannel', 'Unknown channel: $1. Try discord\'s auto-completion.');
|
||||
$.lang.register('moderation.cleanup.failed', 'Failed to perform bulk message deletion: Currently deleting messages.');
|
||||
$.lang.register('moderation.cleanup.failed.err', 'Failed to perform bulk message deletion.');
|
||||
$.lang.register('moderation.cleanup.done', 'Deleted $1 messages!');
|
||||
$.lang.register('moderation.logs.toggle.usage', 'Usage: !moderation logs [toggle / channel] - Will toggle Twitch moderation logs being posted in Discord.');
|
||||
$.lang.register('moderation.logs.toggle', 'Twitch moderation logs have been $1. **[Requires bot restart]**');
|
||||
$.lang.register('moderation.logs.channel.usage', 'Usage: !moderation logs channel [channel name]');
|
||||
$.lang.register('moderation.logs.channel.set', 'Twitch moderation log announcements will now be made in channel $1');
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
$.lang.register('discord.rolemanager.usage', 'Usage: !rolemanager [togglesyncpermissions / togglesyncranks / blacklist]');
|
||||
$.lang.register('discord.rolemanager.permission.sync.on', 'Bot permissions will now be synced with users who have their account linked with the bot.');
|
||||
$.lang.register('discord.rolemanager.permission.sync.off', 'Bot permissions will no longer be synced.');
|
||||
$.lang.register('discord.rolemanager.ranks.sync.on', 'Ranks will now be synced with users who have their account linked with the bot.');
|
||||
$.lang.register('discord.rolemanager.ranks.sync.off', 'Ranks will no longer be synced.');
|
||||
$.lang.register('discord.rolemanager.blacklist.usage', 'Usage: !rolemanager blacklist [add / remove] [permission or rank] - Blacklist a ranks or permissions from being set.');
|
||||
$.lang.register('discord.rolemanager.blacklist.add.usage', 'Usage: !rolemanager blacklist add [permission or rank] - Blacklist a ranks or permissions from being set.');
|
||||
$.lang.register('discord.rolemanager.blacklist.add.success', 'Group $1 has been added to the blacklist!');
|
||||
$.lang.register('discord.rolemanager.blacklist.remove.usage', 'Usage: !rolemanager blacklist remove [permission or rank]');
|
||||
$.lang.register('discord.rolemanager.blacklist.remove.success', 'Group $1 has been removed from the blacklist.');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user