init commit
This commit is contained in:
239
libs/phantombot/scripts/systems/auctionSystem.js
Normal file
239
libs/phantombot/scripts/systems/auctionSystem.js
Normal file
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* 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 auction = {
|
||||
increments: 0,
|
||||
minimum: 0,
|
||||
topUser: 0,
|
||||
topPoints: 0,
|
||||
timer: 0,
|
||||
status: false,
|
||||
},
|
||||
a,
|
||||
b;
|
||||
|
||||
/**
|
||||
* @function openAuction
|
||||
*
|
||||
* @param {string} user
|
||||
* @param {int} increments
|
||||
* @param {int} minimum
|
||||
* @param {int} timer
|
||||
*/
|
||||
function openAuction(user, increments, minimum, timer) {
|
||||
if (auction.status) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.err.opened'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!increments || !minimum) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (increments) {
|
||||
auction.increments = parseInt(increments);
|
||||
}
|
||||
|
||||
if (minimum) {
|
||||
auction.minimum = parseInt(minimum);
|
||||
}
|
||||
|
||||
if (timer) {
|
||||
auction.timer = parseInt(timer);
|
||||
}
|
||||
|
||||
auction.status = true;
|
||||
|
||||
$.say($.lang.get('auctionsystem.opened', $.getPointsString(increments), $.getPointsString(minimum)));
|
||||
|
||||
if (timer > 0) {
|
||||
$.say($.lang.get('auctionsystem.auto.timer.msg', timer));
|
||||
a = setTimeout(function() {
|
||||
warnAuction(true);
|
||||
clearInterval(a);
|
||||
}, (timer / 2) * 1000);
|
||||
b = setTimeout(function() {
|
||||
closeAuction();
|
||||
clearInterval(b);
|
||||
}, timer * 1000);
|
||||
}
|
||||
$.inidb.set('auctionSettings', 'isActive', 'true');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function closeAuction
|
||||
*
|
||||
* @param {string} user
|
||||
*/
|
||||
function closeAuction(user) {
|
||||
if (!auction.status) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.err.closed'));
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(a);
|
||||
clearInterval(b);
|
||||
|
||||
if (!auction.topUser) {
|
||||
auction.status = false;
|
||||
$.say($.lang.get('auctionsystem.err.no.bids'));
|
||||
return;
|
||||
}
|
||||
|
||||
auction.status = false;
|
||||
$.inidb.decr('points', auction.topUser, auction.topPoints);
|
||||
$.say($.lang.get('auctionsystem.closed', auction.topUser, $.getPointsString(auction.topPoints)));
|
||||
setTimeout(function() {
|
||||
resetAuction();
|
||||
}, 1000);
|
||||
$.inidb.set('auctionSettings', 'isActive', 'false');
|
||||
};
|
||||
|
||||
/**
|
||||
* @function warnAuction
|
||||
*
|
||||
* @param {boolean} force
|
||||
*/
|
||||
function warnAuction(force, user) {
|
||||
if (!auction.status) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.err.closed'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (force) {
|
||||
$.say($.lang.get('auctionsystem.warn.force', auction.topUser, $.getPointsString(auction.topPoints), $.getPointsString((auction.topPoints + auction.increments))));
|
||||
} else {
|
||||
$.say($.lang.get('auctionsystem.warn', auction.topUser, $.getPointsString(auction.topPoints)));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function bid
|
||||
*
|
||||
* @param {string} user
|
||||
* @param {int} amount
|
||||
*/
|
||||
function bid(user, amount) {
|
||||
if (!auction.status) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.err.closed'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(amount = parseInt(amount))) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.bid.usage'));
|
||||
return;
|
||||
} else if (amount < auction.minimum) {
|
||||
$.say($.lang.get('auctionsystem.err.bid.minimum', $.getPointsString(auction.minimum)));
|
||||
return;
|
||||
} else if (amount > $.getUserPoints(user)) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('auctionsystem.err.points', $.pointNameMultiple));
|
||||
return;
|
||||
} else if (amount < (auction.topPoints + auction.increments)) {
|
||||
$.say($.lang.get('auctionsystem.err.increments', $.getPointsString(auction.increments)));
|
||||
return;
|
||||
}
|
||||
|
||||
auction.topUser = user;
|
||||
auction.topPoints = amount;
|
||||
|
||||
$.inidb.set('auctionresults', 'winner', auction.topUser);
|
||||
$.inidb.set('auctionresults', 'amount', auction.topPoints);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function resetAuction
|
||||
*/
|
||||
function resetAuction() {
|
||||
clearInterval(a);
|
||||
clearInterval(b);
|
||||
auction.increments = 0;
|
||||
auction.minimum = 0;
|
||||
auction.topUser = 0;
|
||||
auction.topPoints = 0;
|
||||
auction.timer = 0;
|
||||
$.inidb.set('auctionSettings', 'isActive', 'false');
|
||||
$.inidb.del('auctionresults', 'winner');
|
||||
$.inidb.del('auctionresults', 'amount');
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath auction - Primary auction command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('auction')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('auctionsystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath auction open [increments] [minimum bet] [timer] - Opens an auction; timer is optional.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
openAuction(sender, args[1], args[2], args[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath auction close - Closes an open auction
|
||||
*/
|
||||
if (action.equalsIgnoreCase('close')) {
|
||||
closeAuction(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath auction reset - Resets the auction.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('reset')) {
|
||||
resetAuction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath auction warn - Shows the top bidder in an auction
|
||||
*/
|
||||
if (action.equalsIgnoreCase('warn')) {
|
||||
warnAuction(sender);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath bid [amount] - Amount to bid on the current auction
|
||||
*/
|
||||
if (command.equalsIgnoreCase('bid')) {
|
||||
bid(sender, action);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/auctionSystem.js', 'auction', 2);
|
||||
$.registerChatCommand('./systems/auctionSystem.js', 'bid', 7);
|
||||
|
||||
$.inidb.set('auctionSettings', 'isActive', 'false');
|
||||
});
|
||||
})();
|
||||
352
libs/phantombot/scripts/systems/audioPanelSystem.js
Normal file
352
libs/phantombot/scripts/systems/audioPanelSystem.js
Normal file
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* audioPanelSystem.js
|
||||
*
|
||||
* Play audio on the PhantomBot Control Panel Audio Panel
|
||||
*/
|
||||
(function() {
|
||||
var messageToggle = $.getSetIniDbBoolean('settings', 'audiohookmessages', false);
|
||||
|
||||
/**
|
||||
* @function updateAudioHookDB
|
||||
*/
|
||||
function updateAudioHookDB() {
|
||||
var audioHookFiles = $.findFiles('./config/audio-hooks/', ''),
|
||||
audioHookNames = {},
|
||||
dbAudioHookNames,
|
||||
reFileExt = new RegExp(/\.mp3$|\.ogg$|\.aac$/);
|
||||
|
||||
for (var i in audioHookFiles) {
|
||||
var fileName = audioHookFiles[i] + '';
|
||||
audioHookNames[fileName.replace(reFileExt, '')] = fileName;
|
||||
}
|
||||
|
||||
var keys = Object.keys(audioHookNames);
|
||||
|
||||
for (var i in keys) {
|
||||
if (!$.inidb.exists('audio_hooks', keys[i])) {
|
||||
$.inidb.set('audio_hooks', keys[i], audioHookNames[keys[i]]);
|
||||
} else {
|
||||
var hook = $.inidb.get('audio_hooks', keys[i]);
|
||||
|
||||
if (hook != null && hook.indexOf('.') === -1) {
|
||||
$.inidb.set('audio_hooks', keys[i], audioHookNames[keys[i]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbAudioHookNames = $.inidb.GetKeyList('audio_hooks', '');
|
||||
for (i in dbAudioHookNames) {
|
||||
if (audioHookNames[dbAudioHookNames[i]] === undefined) {
|
||||
$.inidb.del('audio_hooks', dbAudioHookNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
$.panelsocketserver.doAudioHooksUpdate();
|
||||
};
|
||||
|
||||
/**
|
||||
* @function audioHookExists
|
||||
* @param {string} hook
|
||||
*/
|
||||
function audioHookExists(hook) {
|
||||
var keys = $.inidb.GetKeyList('audio_hooks', ''),
|
||||
hookList = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (keys[i].equalsIgnoreCase(hook)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getAudioHookCommands
|
||||
*/
|
||||
function getAudioHookCommands() {
|
||||
var keys = $.inidb.GetKeyList('audioCommands', ''),
|
||||
hooks = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
hooks.push('!' + keys[i]);
|
||||
}
|
||||
|
||||
return hooks;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function loadAudioHookCommands
|
||||
*
|
||||
* @param {String} cmd
|
||||
*/
|
||||
function loadAudioHookCommands(cmd) {
|
||||
if (cmd !== undefined) {
|
||||
$.unregisterChatCommand(cmd);
|
||||
} else {
|
||||
if ($.bot.isModuleEnabled('./systems/audioPanelSystem.js')) {
|
||||
var commands = $.inidb.GetKeyList('audioCommands', ''),
|
||||
i;
|
||||
|
||||
for (i in commands) {
|
||||
if (!$.commandExists(commands[i])) {
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', commands[i], 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* @function removeAudioHook
|
||||
*
|
||||
* @param {String} audioHookName
|
||||
*/
|
||||
function removeAudioHook(audioHookName) {
|
||||
if ($.inidb.exists('audio_hooks', audioHookName)) {
|
||||
var files = $.findFiles('./config/audio-hooks/', '');
|
||||
|
||||
for (var i in files) {
|
||||
var fileName = files[i].substring(0, files[i].indexOf('.'));
|
||||
if (fileName.equalsIgnoreCase(audioHookName)) {
|
||||
$.deleteFile('./config/audio-hooks/' + files[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.del('audio_hooks', audioHookName);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
subCommand = args[0],
|
||||
action = args[1],
|
||||
subAction = args[2],
|
||||
actionArgs = args[3],
|
||||
audioHook = args[1],
|
||||
audioHookListStr,
|
||||
isModv3 = $.isModv3(sender, event.getTags());
|
||||
|
||||
/* Control Panel call to update the Audio Hooks DB. */
|
||||
if (command.equalsIgnoreCase('reloadaudiopanelhooks')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
updateAudioHookDB();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Control Panel remove audio hook */
|
||||
if (command.equalsIgnoreCase('panelremoveaudiohook')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
removeAudioHook(subCommand);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Control Panel reload audio commands */
|
||||
if (command.equalsIgnoreCase('panelloadaudiohookcmds')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
loadAudioHookCommands(subCommand);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the command is an audio hook
|
||||
*/
|
||||
if ($.inidb.exists('audioCommands', command)) {
|
||||
if ($.inidb.get('audioCommands', command).match(/\(list\)/g)) {
|
||||
$.paginateArray(getAudioHookCommands(), 'audiohook.list', ', ', true, sender);
|
||||
return;
|
||||
}
|
||||
if (messageToggle) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.play.success', $.inidb.get('audioCommands', command)));
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel($.inidb.get('audioCommands', command));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath audiohook [play | list] - Base command for audio hooks.
|
||||
* @commandpath audiohook play [audio_hook] - Sends the audio_hook request to the Panel.
|
||||
* @commandpath audiohook list - Lists the audio hooks.
|
||||
* @commandpath audiohook togglemessages - Enables the success message once a sfx is sent.
|
||||
* @commandpath audiohook customcommand [add / remove] [command] [sound] - Adds a custom command that will trigger that sound. Use tag "(list)" to display all the commands.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('audiohook')) {
|
||||
var hookKeys = $.inidb.GetKeyList('audio_hooks', ''),
|
||||
hookList = [],
|
||||
idx;
|
||||
|
||||
for (idx in hookKeys) {
|
||||
hookList[hookKeys[idx]] = hookKeys[idx];
|
||||
}
|
||||
|
||||
if (subCommand === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.usage'));
|
||||
$.returnCommandCost(sender, command, $.isModv3(sender, event.getTags()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subCommand.equalsIgnoreCase('play')) {
|
||||
if (audioHook === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.play.usage'));
|
||||
$.returnCommandCost(sender, command, $.isModv3(sender, event.getTags()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!audioHookExists(audioHook)) {
|
||||
$.returnCommandCost(sender, command, $.isModv3(sender, event.getTags()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Moved this from init since only this command can have three commands. Why slow down all of the command with
|
||||
// 3 db calls just for this?
|
||||
if ((((isModv3 && $.getIniDbBoolean('settings', 'pricecomMods', false) && !$.isBot(sender)) || !isModv3)) && $.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
var commandCost = $.getCommandPrice(command, subCommand, action);
|
||||
if ($.getUserPoints(sender) < commandCost) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cmd.needpoints', $.getPointsString(commandCost)));
|
||||
return;
|
||||
} else {
|
||||
$.inidb.decr('points', sender, commandCost);
|
||||
}
|
||||
}
|
||||
|
||||
if (messageToggle) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.play.success', audioHook));
|
||||
}
|
||||
$.alertspollssocket.triggerAudioPanel(audioHook);
|
||||
}
|
||||
|
||||
if (subCommand.equalsIgnoreCase('togglemessages')) {
|
||||
if (messageToggle) {
|
||||
messageToggle = false;
|
||||
$.inidb.set('settings', 'audiohookmessages', messageToggle);
|
||||
} else {
|
||||
messageToggle = true;
|
||||
$.inidb.set('settings', 'audiohookmessages', messageToggle);
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.toggle', messageToggle));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subCommand.equalsIgnoreCase('list')) {
|
||||
if (args[1] === undefined) {
|
||||
var totalPages = $.paginateArray(hookKeys, 'audiohook.list', ', ', true, sender, 1);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.list.total', totalPages));
|
||||
} else if (isNaN(args[1])) {
|
||||
var totalPages = $.paginateArray(hookKeys, 'audiohook.list', ', ', true, sender, 1);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.list.total', totalPages));
|
||||
} else {
|
||||
$.paginateArray(hookKeys, 'audiohook.list', ', ', true, sender, parseInt(args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (subCommand.equalsIgnoreCase('customcommand')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (subAction === undefined || actionArgs === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subAction = subAction.replace('!', '');
|
||||
|
||||
if ($.commandExists(subAction.toLowerCase()) || $.aliasExists(subAction.toLowerCase()) || $.inidb.exists('audioCommands', subAction.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.add.error.exists'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArgs.equalsIgnoreCase('(list)')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.add.list', subAction));
|
||||
$.inidb.set('audioCommands', subAction.toLowerCase(), actionArgs);
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', subAction.toLowerCase(), 7);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!audioHookExists(actionArgs)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.add.error.fx.null'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('audioCommands', subAction.toLowerCase(), actionArgs);
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', subAction.toLowerCase(), 7);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.add.success', subAction, actionArgs));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.remove.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subAction = subAction.replace('!', '');
|
||||
|
||||
if (!$.inidb.exists('audioCommands', subAction.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.remove.error.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('audioCommands', subAction.toLowerCase());
|
||||
$.unregisterChatCommand(subAction.toLowerCase());
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('audiohook.customcommand.remove.success', subAction));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', 'reloadaudiopanelhooks', 30);
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', 'panelremoveaudiohook', 30);
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', 'panelloadaudiohookcmds', 30);
|
||||
|
||||
$.registerChatCommand('./systems/audioPanelSystem.js', 'audiohook', 1);
|
||||
$.registerChatSubcommand('audiohook', 'play', 1);
|
||||
$.registerChatSubcommand('audiohook', 'list', 1);
|
||||
$.registerChatSubcommand('audiohook', 'togglemessages', 1);
|
||||
$.registerChatSubcommand('audiohook', 'customcommand', 1);
|
||||
|
||||
loadAudioHookCommands();
|
||||
updateAudioHookDB();
|
||||
});
|
||||
|
||||
$.loadAudioHookCommands = loadAudioHookCommands;
|
||||
$.audioHookExists = audioHookExists;
|
||||
})();
|
||||
450
libs/phantombot/scripts/systems/bettingSystem.js
Normal file
450
libs/phantombot/scripts/systems/bettingSystem.js
Normal file
@@ -0,0 +1,450 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Betting system, a system use to bet about thing to win or lose points in Twitch chat.
|
||||
* bettingSystem.js
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var bets = {},
|
||||
timeout,
|
||||
gain = $.getSetIniDbNumber('bettingSettings', 'gain', 40),
|
||||
saveBets = $.getSetIniDbBoolean('bettingSettings', 'save', true),
|
||||
saveFormat = $.getSetIniDbString('bettingSettings', 'format', 'yyyy.M.dd'),
|
||||
warningMessages = $.getSetIniDbBoolean('bettingSettings', 'warningMessages', false),
|
||||
bet = {
|
||||
status: false,
|
||||
opened: false,
|
||||
entries: 0,
|
||||
total: 0,
|
||||
minimum: 0,
|
||||
maximum: 0,
|
||||
timer: 0,
|
||||
pointsWon: 0,
|
||||
title: '',
|
||||
winners: '',
|
||||
options: {},
|
||||
opt: []
|
||||
};
|
||||
|
||||
/**
|
||||
* @function reloadBet
|
||||
* @info Used to update the bet settings from the panel.
|
||||
*/
|
||||
function reloadBet() {
|
||||
gain = $.getIniDbNumber('bettingSettings', 'gain');
|
||||
saveBets = $.getIniDbBoolean('bettingSettings', 'save');
|
||||
saveFormat = $.getIniDbString('bettingSettings', 'format');
|
||||
warningMessages = $.getIniDbBoolean('bettingSettings', 'warningMessages')
|
||||
}
|
||||
|
||||
/**
|
||||
* @function open
|
||||
* @info Used to open bets.
|
||||
*
|
||||
* @param {string} sender
|
||||
* @param {string} title
|
||||
* @param {string} options
|
||||
* @param {int} minimum
|
||||
* @param {int} maximum
|
||||
* @param {int} timer
|
||||
*/
|
||||
function open(sender, title, options, minimum, maximum, timer) {
|
||||
if (title === undefined || options === undefined || isNaN(parseInt(minimum)) || isNaN(parseInt(maximum))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
|
||||
return;
|
||||
} else if (bet.status === true && bet.opened === false) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error'));
|
||||
return;
|
||||
} else if (bet.status === true) {
|
||||
if (sender == $.botName) return;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.error.opened'));
|
||||
return;
|
||||
} else if (!options.includes(', ')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.open.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the old files.
|
||||
$.inidb.RemoveFile('bettingPanel');
|
||||
$.inidb.RemoveFile('bettingVotes');
|
||||
|
||||
bet.title = title;
|
||||
bet.minimum = parseInt(minimum);
|
||||
bet.maximum = parseInt(maximum);
|
||||
bet.status = true;
|
||||
bet.opened = true;
|
||||
|
||||
if (timer !== undefined && !isNaN(parseInt(timer)) && timer > 0) {
|
||||
bet.timer = timer;
|
||||
timeout = setTimeout(function() {
|
||||
stop();
|
||||
}, timer * 6e4);
|
||||
}
|
||||
|
||||
// Trim first spaces.
|
||||
var split = options.trim().split(', ');
|
||||
|
||||
for (var i = 0; i < split.length; i++) {
|
||||
// Trim other spaces.
|
||||
split[i] = split[i].trim().toLowerCase();
|
||||
|
||||
bet.options[split[i]] = {
|
||||
bets: 0,
|
||||
total: 0
|
||||
};
|
||||
bet.opt.push(split[i]);
|
||||
$.inidb.set('bettingVotes', (split[i] + '').replace(/\s/, '%space_option%'), 0);
|
||||
}
|
||||
|
||||
$.say($.lang.get('bettingsystem.open.success', title, split.join(', ')));
|
||||
$.inidb.set('bettingPanel', 'title', title);
|
||||
$.inidb.set('bettingPanel', 'options', split.join('%space_option%'));
|
||||
$.inidb.set('bettingPanel', 'isActive', 'true');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function close
|
||||
* @info Used to close bets.
|
||||
*
|
||||
* @param {string} sender.
|
||||
* @param {string} winning option.
|
||||
*/
|
||||
function close(sender, option) {
|
||||
if (option === undefined && bet.opened === true) {
|
||||
bet.opened = false;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.error.usage'));
|
||||
return;
|
||||
} else if (option === undefined) {
|
||||
if (sender == $.botName) return;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.close.usage'));
|
||||
return;
|
||||
} else if (bet.options[option] === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.bet.null'));
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(timeout);
|
||||
|
||||
$.inidb.set('bettingPanel', 'isActive', 'false');
|
||||
|
||||
bet.status = false;
|
||||
bet.opened = false;
|
||||
|
||||
var winners = [],
|
||||
total = 0,
|
||||
give = 0,
|
||||
i;
|
||||
|
||||
$.say($.lang.get('bettingsystem.close.success', option));
|
||||
|
||||
|
||||
for (i in bets) {
|
||||
if (bets[i].option.equalsIgnoreCase(option)) {
|
||||
winners.push(i.toLowerCase());
|
||||
give = (((bet.total / bet.options[option].bets) * parseFloat(gain / 100)) + parseInt(bets[i].amount));
|
||||
total += give;
|
||||
$.inidb.incr('points', i.toLowerCase(), Math.floor(give));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bet.winners = winners.join(', ');
|
||||
bet.pointsWon = total;
|
||||
|
||||
$.say($.lang.get('bettingsystem.close.success.winners', winners.length, $.getPointsString(Math.floor(total)), option));
|
||||
$.inidb.set('bettingSettings', 'lastBet', winners.length + '___' + $.getPointsString(Math.floor(total)));
|
||||
save();
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function stop
|
||||
* @info Used to stop entries in the bet.
|
||||
*
|
||||
*/
|
||||
function stop() {
|
||||
bet.opened = false;
|
||||
$.say($.lang.get('bettingsystem.close.semi.success'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @function save
|
||||
* @info Used to save old bet results if the user wants too.
|
||||
*
|
||||
*/
|
||||
function save() {
|
||||
if (saveBets) {
|
||||
var dateFormat = new java.text.SimpleDateFormat(saveFormat),
|
||||
date = dateFormat.format(new Date());
|
||||
|
||||
if (!$.inidb.exists('bettingResults', date)) {
|
||||
$.inidb.set('bettingResults', date, $.lang.get('bettingsystem.save.format', bet.title, bet.opt.join(', '), bet.total, bet.entries, bet.pointsWon));
|
||||
} else {
|
||||
var keys = $.inidb.GetKeyList('bettingResults', ''),
|
||||
a = 1,
|
||||
i;
|
||||
for (i in keys) {
|
||||
if (keys[i].includes(date)) {
|
||||
a++;
|
||||
}
|
||||
}
|
||||
$.inidb.set('bettingResults', (date + '_' + a), $.lang.get('bettingsystem.save.format', bet.title, bet.opt.join(', '), bet.total, bet.entries, bet.pointsWon));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function clear
|
||||
* @info Used to clear the bet results after a bet.
|
||||
*
|
||||
*/
|
||||
function clear() {
|
||||
clearInterval(timeout);
|
||||
bets = {};
|
||||
bet = {
|
||||
status: false,
|
||||
opened: false,
|
||||
entries: 0,
|
||||
total: 0,
|
||||
minimum: 0,
|
||||
maximum: 0,
|
||||
timer: 0,
|
||||
pointsWon: 0,
|
||||
title: '',
|
||||
winners: '',
|
||||
options: {},
|
||||
opt: []
|
||||
};
|
||||
$.inidb.set('bettingPanel', 'isActive', 'false');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function reset
|
||||
* @info Resets the bet and gives points back.
|
||||
*
|
||||
* @param refund, if everyones points should be given back.
|
||||
*/
|
||||
function reset(refund) {
|
||||
if (refund) {
|
||||
var betters = Object.keys(bets);
|
||||
|
||||
|
||||
for (var i = 0; i < betters.length; i++) {
|
||||
$.inidb.incr('points', betters[i], bets[betters[i]].amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function message
|
||||
* @info used to send messages
|
||||
*
|
||||
* @param {string} sender
|
||||
* @param {string} message
|
||||
*/
|
||||
function message(sender, message) {
|
||||
if (warningMessages) {
|
||||
$.say($.whisperPrefix(sender) + message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function bet
|
||||
* @info Used to place a bet on a option.
|
||||
*
|
||||
* @param {string} sender
|
||||
* @param {int} amount
|
||||
* @param {string} option
|
||||
*/
|
||||
function vote(sender, amount, option) {
|
||||
if (bet.status === false || bet.opened === false) {
|
||||
// $.say($.whisperPrefix(sender) + 'There\'s no bet opened.');
|
||||
return;
|
||||
} else if (isNaN(parseInt(amount)) || option.length === 0) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.usage'));
|
||||
return;
|
||||
} else if (amount < 1) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.error.neg', $.pointNameMultiple));
|
||||
return;
|
||||
} else if (bet.minimum > amount) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.error.min', bet.minimum));
|
||||
return;
|
||||
} else if (bet.maximum < amount && bet.maximum !== 0) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.error.max', bet.maximum));
|
||||
return;
|
||||
} else if ($.getUserPoints(sender) < amount) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.error.points', $.pointNameMultiple));
|
||||
return;
|
||||
} else if (bets[sender] !== undefined) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.betplaced', $.getPointsString(bets[sender].amount), bets[sender].option))
|
||||
return;
|
||||
} else if (bet.options[option] === undefined) {
|
||||
message(sender, $.lang.get('bettingsystem.bet.null'));
|
||||
return;
|
||||
}
|
||||
|
||||
bet.entries++;
|
||||
bet.total += parseInt(amount);
|
||||
bet.options[option].bets++;
|
||||
bet.options[option].total += parseInt(amount);
|
||||
bets[sender] = {
|
||||
option: option,
|
||||
amount: amount
|
||||
};
|
||||
$.inidb.decr('points', sender, amount);
|
||||
$.inidb.incr('bettingVotes', option.replace(/\s/, '%space_option%'), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
* @info Used for commands.
|
||||
*
|
||||
* @param {object} event
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('bet')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.global.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath bet open ["title"] ["option1, option2, option3"] [minimum bet] [maximum bet] [close timer] - Opens a bet with those options.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
open(sender, args[1], args[2], args[3], args[4], args[5]);
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet close ["winning option"] - Closes the current bet.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('close')) {
|
||||
close(sender, (args[1] === undefined ? undefined : args.slice(1).join(' ').toLowerCase().trim()));
|
||||
return;
|
||||
|
||||
// Used by panel.
|
||||
} else if (action.equalsIgnoreCase('reset')) {
|
||||
reset(subAction !== undefined && subAction.equalsIgnoreCase('-refund'));
|
||||
|
||||
/**
|
||||
* @commandpath bet save - Toggle if bet results get saved or not after closing one.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('save')) {
|
||||
saveBets = !saveBets;
|
||||
$.inidb.set('bettingSettings', 'save', saveBets);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.toggle.save', (saveBets === true ? $.lang.get('bettingsystem.now') : $.lang.get('bettingsystem.not'))));
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet togglemessages - Toggles bet warning messages on or off.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('togglemessages')) {
|
||||
warningMessages = !warningMessages;
|
||||
$.inidb.set('bettingSettings', 'warningMessages', warningMessages);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.warning.messages', (warningMessages === true ? $.lang.get('bettingsystem.now') : $.lang.get('bettingsystem.not'))));
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet saveformat [date format] - Changes the date format past bets are saved in default is yyyy.mm.dd
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('saveformat')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.saveformat.usage'));
|
||||
return;
|
||||
}
|
||||
saveFormat = subAction;
|
||||
$.inidb.set('bettingSettings', 'format', saveFormat);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.saveformat.set', saveFormat));
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet gain [percent] - Changes the point gain percent users get when they win a bet.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('gain')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.gain.usage'));
|
||||
return;
|
||||
}
|
||||
gain = subAction
|
||||
$.inidb.set('bettingSettings', 'gain', gain);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.gain.set', gain));
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet lookup [date] - Displays the results of a bet made on that day. If you made multiple bets you will have to add "_#" to specify the bet.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('lookup')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.lookup.usage', saveFormat));
|
||||
return;
|
||||
}
|
||||
if (saveBets) {
|
||||
if ($.inidb.exists('bettingResults', subAction)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.lookup.show', subAction, $.inidb.get('bettingResults', subAction)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('bettingsystem.lookup.null'));
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet current - Shows current bet stats.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('current')) {
|
||||
if (bet.status === true) {
|
||||
$.say($.lang.get('bettingsystem.results', bet.title, bet.opt.join(', '), bet.total, bet.entries));
|
||||
}
|
||||
return;
|
||||
|
||||
/**
|
||||
* @commandpath bet [amount] [option] - Bets on that option.
|
||||
*/
|
||||
} else {
|
||||
vote(sender, args[0], args.splice(1).join(' ').toLowerCase().trim());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/bettingSystem.js', 'bet', 7);
|
||||
$.registerChatSubcommand('bet', 'current', 7);
|
||||
$.registerChatSubcommand('bet', 'results', 7);
|
||||
$.registerChatSubcommand('bet', 'open', 2);
|
||||
$.registerChatSubcommand('bet', 'close', 2);
|
||||
$.registerChatSubcommand('bet', 'reset', 2);
|
||||
$.registerChatSubcommand('bet', 'save', 1);
|
||||
$.registerChatSubcommand('bet', 'saveformat', 1);
|
||||
$.registerChatSubcommand('bet', 'gain', 1);
|
||||
});
|
||||
|
||||
/* export to the $ api */
|
||||
$.reloadBet = reloadBet;
|
||||
})();
|
||||
133
libs/phantombot/scripts/systems/cleanupSystem.js
Normal file
133
libs/phantombot/scripts/systems/cleanupSystem.js
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* cleanupSystem.js
|
||||
*
|
||||
* A module that enables channel owners to clean the bot's database.
|
||||
*/
|
||||
(function() {
|
||||
var logName = 'cleanUpSystem',
|
||||
running = false;
|
||||
|
||||
function cleanUp(table, amount, sender) {
|
||||
if (table.equalsIgnoreCase('time')) {
|
||||
var keys = $.inidb.GetKeyList('time', ''),
|
||||
time = parseInt(amount),
|
||||
count = 0,
|
||||
i;
|
||||
|
||||
$.consoleLn('>>> Process is starting this might take a few minutes...');
|
||||
running = true;
|
||||
for (i in keys) {
|
||||
if (parseInt($.inidb.get('time', keys[i])) <= time) {
|
||||
$.consoleLn('>> Removing ' + keys[i] + ' from the time table with ' + $.inidb.get('time', keys[i]) + ' time.');
|
||||
$.inidb.del('time', keys[i]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
$.consoleLn('> Process done. ' + count + ' users have been removed from the times table.');
|
||||
$.log.file(logName, '' + 'Cleanup ran for the time table by ' + sender + '. (Removed ' + count + ' users from the time table)');
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table.equalsIgnoreCase('points')) {
|
||||
var keys = $.inidb.GetKeyList('points', ''),
|
||||
points = parseInt(amount),
|
||||
count = 0,
|
||||
i;
|
||||
|
||||
$.consoleLn('>>> Process is starting this might take a few minutes...');
|
||||
running = true;
|
||||
for (i in keys) {
|
||||
if (parseInt($.inidb.get('points', keys[i])) <= points) {
|
||||
$.consoleLn('>> Removing ' + keys[i] + ' from the points table with ' + $.inidb.get('points', keys[i]) + ' points.');
|
||||
$.inidb.del('points', keys[i]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
$.consoleLn('> Process done. ' + count + ' users have been removed from the points table.');
|
||||
$.log.file(logName, '' + 'Cleanup ran for the points table by ' + sender + '. (Removed ' + count + ' users from the points table)');
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (table.equalsIgnoreCase('all')) {
|
||||
var keys = $.inidb.GetKeyList('visited', ''),
|
||||
time = parseInt(amount),
|
||||
count = 0,
|
||||
t,
|
||||
i;
|
||||
|
||||
$.consoleLn('>>> Process is starting this might take a few minutes...');
|
||||
running = true;
|
||||
for (i in keys) {
|
||||
t = ($.inidb.exists('time', keys[i]) ? parseInt($.inidb.get('time', keys[i])) : 0);
|
||||
if (t <= time) {
|
||||
$.inidb.del('time', keys[i]);
|
||||
$.inidb.del('points', keys[i]);
|
||||
$.inidb.del('heistPayouts', keys[i]);
|
||||
$.inidb.del('lastseen', keys[i]);
|
||||
$.inidb.del('followed', keys[i]);
|
||||
$.inidb.del('visited', keys[i]);
|
||||
$.consoleLn('>> Removed ' + keys[i] + ' from the database.');
|
||||
count++;
|
||||
}
|
||||
}
|
||||
$.consoleLn('> Process done. ' + count + ' users have been removed from the database.');
|
||||
$.log.file(logName, '' + 'Cleanup ran by ' + sender + '. (Removed ' + count + ' users from the database)');
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
$.log.error('commands: cleanup [time / points / all] [amount of time in seconds or points if cleaning points]');
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = parseInt(args[1]);
|
||||
|
||||
/**
|
||||
* @commandpath cleanup time [amount in seconds] - Will remove users from the times table with less then the seconds you chose.
|
||||
* @commandpath cleanup points [amount of points] - Will remove users from the points table with less then the points you chose.
|
||||
* @commandpath cleanup all [time in seconds] - Will remove users from all the db tables with less then the seconds you chose.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('cleanup') && !running) {
|
||||
if (!action || !subAction) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cleanupsystem.run.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cleanupsystem.run.progress', $.botName));
|
||||
cleanUp(action, subAction, sender);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('cleanupsystem.run.success'));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/cleanupSystem.js', 'cleanup', 1);
|
||||
});
|
||||
})();
|
||||
211
libs/phantombot/scripts/systems/commercialSystem.js
Normal file
211
libs/phantombot/scripts/systems/commercialSystem.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/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var commercialLength = $.getSetIniDbNumber('commercialSettings', 'length', 30),
|
||||
commercialInterval = $.getSetIniDbNumber('commercialSettings', 'interval', 10),
|
||||
commercialMessage = $.getSetIniDbString('commercialSettings', 'message', ''),
|
||||
commercialTimer = $.getSetIniDbBoolean('commercialSettings', 'commercialtimer', false),
|
||||
lastCommercial = 0,
|
||||
interval;
|
||||
|
||||
/**
|
||||
* @function startCommercialTimer
|
||||
*/
|
||||
function startCommercialTimer() {
|
||||
lastCommercial = $.systemTime();
|
||||
|
||||
interval = setInterval(function() {
|
||||
if (commercialTimer && $.bot.isModuleEnabled('./systems/commercialSystem.js')) {
|
||||
if ((lastCommercial + (commercialInterval * 6e4)) <= $.systemTime()) {
|
||||
if ($.isOnline($.channelName)) {
|
||||
var result = $.twitch.RunCommercial($.channelName, commercialLength);
|
||||
lastCommercial = $.systemTime();
|
||||
|
||||
if (commercialMessage.length > 0 && result.getInt("_http") != 422) {
|
||||
$.say(commercialMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1e4, 'scripts::systems::commercialSystem.js');
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments().trim(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath commercial - Command for manually running comemrcials or managing the commercial autotimer
|
||||
*/
|
||||
if (command.equalsIgnoreCase('commercial')) {
|
||||
if (args.length == 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath commercial autotimer - Manages the autotimer
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autotimer')) {
|
||||
if (args.length <= 1) {
|
||||
if (commercialTimer) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on', commercialLength, commercialInterval));
|
||||
if (commercialMessage.length > 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on-msg', commercialMessage));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on-nomsg'));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-off'));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
/**
|
||||
* @commandpath commercial autotimer off - Disables the autotimer
|
||||
*/
|
||||
if (args[1].equalsIgnoreCase("off")) {
|
||||
$.inidb.set('commercialSettings', 'commercialtimer', false.toString());
|
||||
commercialTimer = false;
|
||||
clearInterval(interval);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-off'));
|
||||
/**
|
||||
* @commandpath commercial autotimer nomessage - Removes the message sent when autotimer starts a commercial
|
||||
*/
|
||||
} else if (args[1].equalsIgnoreCase("nomessage")) {
|
||||
$.inidb.set('commercialSettings', 'message', '');
|
||||
commercialMessage = '';
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.msg-del'));
|
||||
/**
|
||||
* @commandpath commercial autotimer message (message) - Adds/changes the message sent when autotimer starts a commercial
|
||||
*/
|
||||
} else if (args.length >= 3 && args[1].equalsIgnoreCase("message") && args[2].length() > 0) {
|
||||
argsString = args.slice(2).join(' ');
|
||||
$.inidb.set('commercialSettings', 'message', argsString);
|
||||
commercialMessage = argsString;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.msg-set', argsString));
|
||||
/**
|
||||
* @commandpath commercial autotimer (interval_mins) (length_secs) [message] - Sets the autotimer
|
||||
*/
|
||||
} else {
|
||||
var valid_lengths = ["30", "60", "90", "120", "150", "180"];
|
||||
if (args.length < 3 || isNaN(args[1]) || isNaN(args[2]) || args[1] < 8 || !valid_lengths.includes(args[2])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.bad-parm'));
|
||||
return;
|
||||
}
|
||||
|
||||
argsString = '';
|
||||
|
||||
if (args.length > 3) {
|
||||
argsString = args.slice(3).join(' ');
|
||||
}
|
||||
|
||||
$.inidb.set('commercialSettings', 'length', args[2]);
|
||||
$.inidb.set('commercialSettings', 'interval', args[1]);
|
||||
$.inidb.set('commercialSettings', 'message', argsString);
|
||||
$.inidb.set('commercialSettings', 'commercialtimer', true.toString());
|
||||
|
||||
commercialLength = parseInt(args[2]);
|
||||
commercialInterval = parseInt(args[1]);
|
||||
commercialMessage = argsString;
|
||||
commercialTimer = true;
|
||||
|
||||
startCommercialTimer();
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on', commercialLength, commercialInterval));
|
||||
if (commercialMessage.length() > 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on-msg', commercialMessage));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.autotimer.status-on-nomsg'));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath commercial (length) [silent] - Runs a commercial, optionally does not post a success message to chat
|
||||
*/
|
||||
if (args.length >= 1 && !isNaN(args[0])) {
|
||||
var result = $.twitch.RunCommercial($.channelName, args[0]);
|
||||
|
||||
if (result.getInt("_http") === 422) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('commercialsystem.422'));
|
||||
} else {
|
||||
lastCommercial = $.systemTime();
|
||||
|
||||
if (args.length < 2 || !args[1].equalsIgnoreCase("silent")) {
|
||||
$.say($.lang.get('commercialsystem.run', args[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/commercialSystem.js', 'commercial', 2);
|
||||
$.registerChatSubcommand('commercial', 'autotimer', 1);
|
||||
|
||||
// Set the interval to run commercials
|
||||
if (commercialTimer) {
|
||||
startCommercialTimer();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./systems/commercialSystem.js')) {
|
||||
var action = event.getArgs()[0];
|
||||
|
||||
if (action.equalsIgnoreCase('setautotimer')) {
|
||||
var msg = '';
|
||||
|
||||
if (event.getArgs().length > 3) {
|
||||
msg = event.getArgs().slice(3).join(' ');
|
||||
}
|
||||
|
||||
$.inidb.set('commercialSettings', 'length', event.getArgs()[2]);
|
||||
$.inidb.set('commercialSettings', 'interval', event.getArgs()[1]);
|
||||
$.inidb.set('commercialSettings', 'message', msg);
|
||||
$.inidb.set('commercialSettings', 'commercialtimer', true.toString());
|
||||
|
||||
commercialLength = parseInt(event.getArgs()[2]);
|
||||
commercialInterval = parseInt(event.getArgs()[1]);
|
||||
commercialMessage = msg;
|
||||
commercialTimer = true;
|
||||
|
||||
startCommercialTimer();
|
||||
} else if (action.equalsIgnoreCase('autotimeroff')) {
|
||||
$.inidb.set('commercialSettings', 'commercialtimer', false.toString());
|
||||
commercialTimer = false;
|
||||
clearInterval(interval);
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
202
libs/phantombot/scripts/systems/greetingSystem.js
Normal file
202
libs/phantombot/scripts/systems/greetingSystem.js
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* greetingSystem.js
|
||||
*
|
||||
* Tags in greetings:
|
||||
* - (name) The username corresponding to the target user
|
||||
*/
|
||||
(function() {
|
||||
var autoGreetEnabled = $.getSetIniDbBoolean('greeting', 'autoGreetEnabled', false),
|
||||
defaultJoinMessage = $.getSetIniDbString('greeting', 'defaultJoin', '(name) joined!'),
|
||||
greetingCooldown = $.getSetIniDbNumber('greeting', 'cooldown', (6 * 36e5)),
|
||||
/* 6 Hours */
|
||||
greetingQueue = new java.util.concurrent.ConcurrentLinkedQueue,
|
||||
lastAutoGreet = $.systemTime();
|
||||
|
||||
/**
|
||||
* @event ircChannelJoin
|
||||
*/
|
||||
$.bind('ircChannelJoin', function(event) {
|
||||
if ($.isOnline($.channelName) && autoGreetEnabled) {
|
||||
var sender = event.getUser().toLowerCase(),
|
||||
username = $.resolveRank(sender),
|
||||
message = $.getIniDbString('greeting', sender, ''),
|
||||
lastUserGreeting = $.getIniDbNumber('greetingCoolDown', sender, 0),
|
||||
now = $.systemTime();
|
||||
|
||||
if (lastUserGreeting + greetingCooldown < now) {
|
||||
if (message) {
|
||||
greetingQueue.add(message.replace('(name)', username));
|
||||
$.inidb.set('greetingCoolDown', sender, now);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @function doUserGreetings
|
||||
* Provides timer function for sending greetings into chat. Will delete messages if the
|
||||
* host disables autoGreetings in the middle of a loop. The reason for a delay is to
|
||||
* ensure that the output queue does not become overwhelmed.
|
||||
*/
|
||||
function doUserGreetings() {
|
||||
setInterval(function() {
|
||||
|
||||
/* Send a greeting out into chat. */
|
||||
if (!greetingQueue.isEmpty() && autoGreetEnabled) {
|
||||
$.say(greetingQueue.poll());
|
||||
}
|
||||
|
||||
/* There are greetings, however, autoGreet has been disabled, so destroy the queue. */
|
||||
if (!greetingQueue.isEmpty() && !autoGreetEnabled) {
|
||||
greetingQueue = new java.util.concurrent.ConcurrentLinkedQueue;
|
||||
}
|
||||
|
||||
}, 15000, 'scripts::systems::greetingSystem.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function greetingspanelupdate
|
||||
*/
|
||||
function greetingspanelupdate() {
|
||||
autoGreetEnabled = $.getIniDbBoolean('greeting', 'autoGreetEnabled');
|
||||
defaultJoinMessage = $.getIniDbString('greeting', 'defaultJoin');
|
||||
greetingCooldown = $.getIniDbNumber('greeting', 'cooldown');
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
cooldown,
|
||||
message;
|
||||
|
||||
/**
|
||||
* @commandpath greeting - Base command for controlling greetings.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('greeting')) {
|
||||
if (!action) {
|
||||
if ($.isAdmin(sender)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.generalusage.admin'));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.generalusage.other'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath greeting cooldown [hours] - Cooldown in hours before displaying a greeting for a person rejoining chat.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('cooldown')) {
|
||||
if (!args[1]) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.cooldown.usage'));
|
||||
return;
|
||||
}
|
||||
cooldown = parseInt(args[1]);
|
||||
if (isNaN(cooldown)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.cooldown.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
greetingCooldown = cooldown * 36e5; // Convert hours to ms
|
||||
$.inidb.set('greeting', 'cooldown', greetingCooldown);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.cooldown.success', cooldown));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath greeting toggle - Enable/disable the greeting system.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
autoGreetEnabled = !autoGreetEnabled;
|
||||
$.setIniDbBoolean('greeting', 'autoGreetEnabled', autoGreetEnabled);
|
||||
if (autoGreetEnabled) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.set.autogreet.enabled', $.username.resolve($.botName)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.set.autogreet.disabled', $.username.resolve($.botName)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath greeting setdefault - Set the default greeting message
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setdefault')) {
|
||||
message = args.splice(1, args.length - 1).join(' ');
|
||||
|
||||
if (!message) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.generalusage.admin'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('greeting', 'defaultJoin', message);
|
||||
defaultJoinMessage = message;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.set.default.success', defaultJoinMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath greeting enable [default | message] - Enable greetings and use the default or set a message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('enable')) {
|
||||
message = args.splice(1, args.length - 1).join(' ');
|
||||
|
||||
if (!message) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.generalusage.other'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.equalsIgnoreCase('default')) {
|
||||
$.inidb.set('greeting', sender, defaultJoinMessage);
|
||||
} else {
|
||||
$.inidb.set('greeting', sender, message);
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.set.personal.success', $.inidb.get('greeting', sender)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath greeting disable - Delete personal greeting and automated greeting at join
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disable')) {
|
||||
if ($.inidb.exists('greeting', sender)) {
|
||||
$.inidb.del('greeting', sender);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('greetingsystem.remove.personal.success'));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/greetingSystem.js', 'greeting', 6);
|
||||
$.registerChatSubcommand('greeting', 'cooldown', 1);
|
||||
$.registerChatSubcommand('greeting', 'toggle', 1);
|
||||
$.registerChatSubcommand('greeting', 'setdefault', 2);
|
||||
$.registerChatSubcommand('greeting', 'enable', 6);
|
||||
$.registerChatSubcommand('greeting', 'disable', 6);
|
||||
|
||||
doUserGreetings();
|
||||
});
|
||||
|
||||
$.greetingspanelupdate = greetingspanelupdate;
|
||||
})();
|
||||
366
libs/phantombot/scripts/systems/noticeSystem.js
Normal file
366
libs/phantombot/scripts/systems/noticeSystem.js
Normal file
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* noticeSystem.js
|
||||
*
|
||||
* Will say a message or a command every x amount of minutes.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var noticeReqMessages = $.getSetIniDbNumber('noticeSettings', 'reqmessages', 25),
|
||||
noticeInterval = $.getSetIniDbNumber('noticeSettings', 'interval', 10),
|
||||
noticeToggle = $.getSetIniDbBoolean('noticeSettings', 'noticetoggle', false),
|
||||
numberOfNotices = (parseInt($.inidb.GetKeyList('notices', '').length) ? parseInt($.inidb.GetKeyList('notices', '').length) : 0),
|
||||
noticeOffline = $.getSetIniDbBoolean('noticeSettings', 'noticeOfflineToggle', false),
|
||||
isReloading = false,
|
||||
messageCount = 0,
|
||||
RandomNotice = 0,
|
||||
lastNoticeSent = 0,
|
||||
interval;
|
||||
|
||||
/**
|
||||
* @function reloadNotices
|
||||
*/
|
||||
function reloadNotices() {
|
||||
if (!isReloading) {
|
||||
isReloading = true;
|
||||
var keys = $.inidb.GetKeyList('notices', ''),
|
||||
count = 0,
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
if ($.inidb.get('notices', keys[i]) != null) {
|
||||
temp[i] = $.inidb.get('notices', keys[i])
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('notices');
|
||||
|
||||
for (i = 0; i < temp.length; i++) {
|
||||
$.inidb.set('notices', 'message_' + count, temp[i]);
|
||||
count++;
|
||||
}
|
||||
|
||||
numberOfNotices = $.inidb.GetKeyList('notices', '').length;
|
||||
if (RandomNotice >= numberOfNotices) {
|
||||
RandomNotice = 0;
|
||||
}
|
||||
isReloading = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function sendNotice
|
||||
*/
|
||||
function sendNotice() {
|
||||
var EventBus = Packages.tv.phantombot.event.EventBus,
|
||||
CommandEvent = Packages.tv.phantombot.event.command.CommandEvent,
|
||||
start = RandomNotice,
|
||||
notice = null;
|
||||
|
||||
do {
|
||||
notice = $.inidb.get('notices', 'message_' + RandomNotice);
|
||||
|
||||
RandomNotice++;
|
||||
|
||||
if (RandomNotice >= numberOfNotices) {
|
||||
RandomNotice = 0;
|
||||
}
|
||||
|
||||
if (notice && notice.match(/\(gameonly=.*\)/g)) {
|
||||
var game = notice.match(/\(gameonly=(.*)\)/)[1];
|
||||
if ($.getGame($.channelName).equalsIgnoreCase(game)) {
|
||||
notice = $.replace(notice, notice.match(/(\(gameonly=.*\))/)[1], "");
|
||||
} else {
|
||||
notice = null;
|
||||
}
|
||||
}
|
||||
} while(!notice && start !== RandomNotice);
|
||||
|
||||
if (notice == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (notice.startsWith('command:')) {
|
||||
notice = notice.substring(8).replace('!', '');
|
||||
EventBus.instance().post(new CommandEvent($.botName, notice, ' '));
|
||||
} else if (notice.startsWith('!')) {
|
||||
notice = notice.substring(1);
|
||||
EventBus.instance().post(new CommandEvent($.botName, notice, ' '));
|
||||
} else {
|
||||
$.say(notice);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function reloadNoticeSettings
|
||||
*/
|
||||
function reloadNoticeSettings() {
|
||||
noticeReqMessages = $.getIniDbNumber('noticeSettings', 'reqmessages');
|
||||
noticeToggle = $.getIniDbBoolean('noticeSettings', 'noticetoggle');
|
||||
noticeOffline = $.getIniDbBoolean('noticeSettings', 'noticeOfflineToggle');
|
||||
noticeInterval = $.getIniDbNumber('noticeSettings', 'interval');
|
||||
};
|
||||
|
||||
/**
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
messageCount++;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments().trim(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
message = '';
|
||||
|
||||
/**
|
||||
* @commandpath notice - Base command for managing notices
|
||||
*/
|
||||
if (command.equalsIgnoreCase('notice')) {
|
||||
if (args.length == 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice get [id] - Gets the notice related to the ID
|
||||
*/
|
||||
if (action.equalsIgnoreCase('get')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-get-usage', numberOfNotices));
|
||||
return;
|
||||
} else if (!$.inidb.exists('notices', 'message_' + args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-error-notice-404'));
|
||||
return;
|
||||
} else {
|
||||
$.say($.inidb.get('notices', 'message_' + args[1]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice edit [id] [new message] - Replace the notice at the given ID
|
||||
*/
|
||||
if (action.equalsIgnoreCase('edit')) {
|
||||
if (args.length < 3) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-edit-usage', numberOfNotices));
|
||||
return;
|
||||
} else if (!$.inidb.exists('notices', 'message_' + args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-error-notice-404'));
|
||||
return;
|
||||
} else {
|
||||
argsString = args.slice(2).join(' ');
|
||||
$.inidb.set('notices', 'message_' + args[1], argsString);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-edit-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* USED FOR THE PANEL
|
||||
*/
|
||||
if (action.equalsIgnoreCase('editsilent')) {
|
||||
if (args.length < 3) {
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-edit-usage', numberOfNotices));
|
||||
return;
|
||||
} else if (!$.inidb.exists('notices', 'message_' + args[1])) {
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-error-notice-404'));
|
||||
return;
|
||||
} else {
|
||||
argsString = args.slice(2).join(' ');
|
||||
$.inidb.set('notices', 'message_' + args[1], argsString);
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-edit-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @commandpath notice remove [id] - Removes the notice related to the given ID
|
||||
*/
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-remove-usage', numberOfNotices));
|
||||
return;
|
||||
} else if (!$.inidb.exists('notices', 'message_' + args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-error-notice-404'));
|
||||
return;
|
||||
} else {
|
||||
$.inidb.del('notices', 'message_' + args[1]);
|
||||
numberOfNotices--;
|
||||
reloadNotices();
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-remove-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* USED BY THE PANEL
|
||||
*/
|
||||
if (action.equalsIgnoreCase('removesilent')) {
|
||||
if (args.length < 2) {
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-remove-usage', numberOfNotices));
|
||||
return;
|
||||
} else if (!$.inidb.exists('notices', 'message_' + args[1])) {
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-error-notice-404'));
|
||||
return;
|
||||
} else {
|
||||
$.inidb.del('notices', 'message_' + args[1]);
|
||||
numberOfNotices--;
|
||||
reloadNotices();
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-remove-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice add [message or command] - Adds a notice, with a custom message, or a command ex: !notice add command:COMMANDS_NAME
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-add-usage'));
|
||||
return;
|
||||
} else {
|
||||
argsString = args.slice(1).join(' ');
|
||||
$.inidb.set('notices', 'message_' + numberOfNotices, argsString);
|
||||
numberOfNotices++;
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-add-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* USED BY THE PANEL
|
||||
*/
|
||||
if (action.equalsIgnoreCase('addsilent')) {
|
||||
if (args.length < 2) {
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-add-usage'));
|
||||
return;
|
||||
} else {
|
||||
argsString = args.slice(1).join(' ');
|
||||
$.inidb.set('notices', 'message_' + numberOfNotices, argsString);
|
||||
numberOfNotices++;
|
||||
//$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-add-success'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice interval [minutes] - Sets the notice interval in minutes
|
||||
*/
|
||||
if (action.equalsIgnoreCase('interval')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-interval-usage'));
|
||||
return;
|
||||
} else if (isNaN(args[1]) || parseInt(args[1]) < 5) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-interval-404'));
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('noticeSettings', 'interval', parseInt(args[1]));
|
||||
noticeInterval = parseInt(args[1]);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-inteval-success'));
|
||||
reloadNoticeSettings();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice req [message count] - Set the number of messages needed to trigger a notice
|
||||
*/
|
||||
if (action.equalsIgnoreCase('req')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-req-usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('noticeSettings', 'reqmessages', args[1]);
|
||||
noticeReqMessages = parseInt(args[1]);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-req-success'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice config - Shows current notice configuration
|
||||
*/
|
||||
if (action.equalsIgnoreCase('config')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-config', noticeToggle, noticeInterval, noticeReqMessages, numberOfNotices, noticeOffline));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice toggle - Toggles notices on and off
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
if (noticeToggle) {
|
||||
noticeToggle = false;
|
||||
$.inidb.set('noticeSettings', 'noticetoggle', 'false');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-disabled'));
|
||||
} else {
|
||||
noticeToggle = true;
|
||||
$.inidb.set('noticeSettings', 'noticetoggle', 'true');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-enabled'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath notice toggleoffline - Toggles on and off if notices can be said in chat if the channel is offline
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggleoffline')) {
|
||||
if (noticeOffline) {
|
||||
noticeOffline = false;
|
||||
$.inidb.set('noticeSettings', 'noticeOfflineToggle', 'false');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-disabled.offline'));
|
||||
} else {
|
||||
noticeOffline = true;
|
||||
$.inidb.set('noticeSettings', 'noticeOfflineToggle', 'true');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('noticehandler.notice-enabled.offline'));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Set the interval to announce
|
||||
interval = setInterval(function() {
|
||||
if (noticeToggle && $.bot.isModuleEnabled('./systems/noticeSystem.js') && numberOfNotices > 0) {
|
||||
if ((noticeReqMessages < 0 || messageCount >= noticeReqMessages) && (lastNoticeSent + (noticeInterval * 6e4)) <= $.systemTime()) {
|
||||
if ((noticeOffline && !$.isOnline($.channelName)) || $.isOnline($.channelName)) {
|
||||
sendNotice();
|
||||
messageCount = 0;
|
||||
lastNoticeSent = $.systemTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1e4, 'scripts::handlers::noticeSystem.js');
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/noticeSystem.js', 'notice', 1);
|
||||
});
|
||||
|
||||
$.reloadNoticeSettings = reloadNoticeSettings;
|
||||
})();
|
||||
854
libs/phantombot/scripts/systems/pointSystem.js
Normal file
854
libs/phantombot/scripts/systems/pointSystem.js
Normal file
@@ -0,0 +1,854 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* pointSystem.js
|
||||
*
|
||||
* Manage user loyalty points and export and API to manipulate points in other modules
|
||||
* Use the $ API
|
||||
*/
|
||||
(function() {
|
||||
var pointsTimedGain = $.getSetIniDbBoolean('pointSettings', 'pointsTimedGain', true),
|
||||
onlineGain = $.getSetIniDbNumber('pointSettings', 'onlineGain', 1),
|
||||
offlineGain = $.getSetIniDbNumber('pointSettings', 'offlineGain', 1),
|
||||
onlinePayoutInterval = $.getSetIniDbNumber('pointSettings', 'onlinePayoutInterval', 10),
|
||||
offlinePayoutInterval = $.getSetIniDbNumber('pointSettings', 'offlinePayoutInterval', 0),
|
||||
activeBonus = $.getSetIniDbNumber('pointSettings', 'activeBonus', 0),
|
||||
lastPayout = 0,
|
||||
penaltys = [],
|
||||
pointsBonus = false,
|
||||
pointsBonusAmount = 0,
|
||||
pointNameSingle = $.getSetIniDbString('pointSettings', 'pointNameSingle', 'point'),
|
||||
pointNameMultiple = $.getSetIniDbString('pointSettings', 'pointNameMultiple', 'points'),
|
||||
pointsMessage = $.getSetIniDbString('pointSettings', 'pointsMessage', '(userprefix) you currently have (pointsstring) and you have been in the chat for (time).'),
|
||||
userCache = {};
|
||||
|
||||
/**
|
||||
* @function updateSettings
|
||||
*/
|
||||
function updateSettings() {
|
||||
var tempPointNameSingle,
|
||||
tempPointNameMultiple;
|
||||
|
||||
pointsTimedGain = $.getIniDbBoolean('pointSettings', 'pointsTimedGain');
|
||||
onlineGain = $.getIniDbNumber('pointSettings', 'onlineGain');
|
||||
offlineGain = $.getIniDbNumber('pointSettings', 'offlineGain');
|
||||
onlinePayoutInterval = $.getIniDbNumber('pointSettings', 'onlinePayoutInterval');
|
||||
offlinePayoutInterval = $.getIniDbNumber('pointSettings', 'offlinePayoutInterval');
|
||||
pointNameSingle = $.getIniDbString('pointSettings', 'pointNameSingle');
|
||||
pointNameMultiple = $.getIniDbString('pointSettings', 'pointNameMultiple');
|
||||
pointsMessage = $.getIniDbString('pointSettings', 'pointsMessage');
|
||||
activeBonus = $.getIniDbNumber('pointSettings', 'activeBonus');
|
||||
|
||||
if (!pointNameMultiple.equalsIgnoreCase('points') || !pointNameSingle.equalsIgnoreCase('point')) {
|
||||
tempPointNameSingle = pointNameSingle;
|
||||
tempPointNameMultiple = pointNameMultiple;
|
||||
}
|
||||
|
||||
if (!pointNameMultiple.equalsIgnoreCase('points') || !pointNameSingle.equalsIgnoreCase('point')) {
|
||||
registerNewPointsCommands(tempPointNameSingle, tempPointNameMultiple, true);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function registerPointCommands
|
||||
*/
|
||||
function registerNewPointsCommands(newName, newName2, newCommand) {
|
||||
newName = newName.toLowerCase();
|
||||
newName2 = newName2.toLowerCase();
|
||||
|
||||
if (newName && newCommand && !$.commandExists(newName)) {
|
||||
$.registerChatCommand('./systems/pointSystem.js', newName, 7);
|
||||
$.registerChatSubcommand(newName, 'add', 1);
|
||||
$.registerChatSubcommand(newName, 'give', 1);
|
||||
$.registerChatSubcommand(newName, 'take', 1);
|
||||
$.registerChatSubcommand(newName, 'remove', 1);
|
||||
$.registerChatSubcommand(newName, 'set', 1);
|
||||
$.registerChatSubcommand(newName, 'all', 1);
|
||||
$.registerChatSubcommand(newName, 'takeall', 1);
|
||||
$.registerChatSubcommand(newName, 'setname', 1);
|
||||
$.registerChatSubcommand(newName, 'setgain', 1);
|
||||
$.registerChatSubcommand(newName, 'setofflinegain', 1);
|
||||
$.registerChatSubcommand(newName, 'setinterval', 1);
|
||||
$.registerChatSubcommand(newName, 'user', 7);
|
||||
$.registerChatSubcommand(newName, 'check', 7);
|
||||
$.registerChatSubcommand(newName, 'bonus', 1);
|
||||
$.registerChatSubcommand(newName, 'resetall', 1);
|
||||
$.registerChatSubcommand(newName, 'setmessage', 1);
|
||||
$.registerChatSubcommand(newName, 'setactivebonus', 1);
|
||||
}
|
||||
|
||||
|
||||
if (newName2 && newCommand && !$.commandExists(newName2)) {
|
||||
$.registerChatCommand('./systems/pointSystem.js', newName2, 7);
|
||||
$.registerChatSubcommand(newName2, 'add', 1);
|
||||
$.registerChatSubcommand(newName2, 'give', 1);
|
||||
$.registerChatSubcommand(newName2, 'take', 1);
|
||||
$.registerChatSubcommand(newName2, 'remove', 1);
|
||||
$.registerChatSubcommand(newName2, 'set', 1);
|
||||
$.registerChatSubcommand(newName2, 'all', 1);
|
||||
$.registerChatSubcommand(newName2, 'takeall', 1);
|
||||
$.registerChatSubcommand(newName2, 'setname', 1);
|
||||
$.registerChatSubcommand(newName2, 'setgain', 1);
|
||||
$.registerChatSubcommand(newName2, 'setofflinegain', 1);
|
||||
$.registerChatSubcommand(newName2, 'setinterval', 1);
|
||||
$.registerChatSubcommand(newName2, 'user', 7);
|
||||
$.registerChatSubcommand(newName2, 'check', 7);
|
||||
$.registerChatSubcommand(newName2, 'bonus', 1);
|
||||
$.registerChatSubcommand(newName2, 'resetall', 1);
|
||||
$.registerChatSubcommand(newName2, 'setmessage', 1);
|
||||
$.registerChatSubcommand(newName2, 'setactivebonus', 1);
|
||||
}
|
||||
|
||||
if (newName && newName != 'points' && !newCommand) {
|
||||
$.unregisterChatCommand(newName);
|
||||
}
|
||||
|
||||
if (newName2 && newName2 != 'points' && !newCommand) {
|
||||
$.unregisterChatCommand(newName2);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getUserPoints
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @returns {*}
|
||||
*/
|
||||
function getUserPoints(username) {
|
||||
return ($.inidb.exists('points', username.toLowerCase()) ? parseInt($.inidb.get('points', username.toLowerCase())) : 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getPointsString
|
||||
* @export $
|
||||
* @param {Number} points
|
||||
* @returns {string}
|
||||
*/
|
||||
function getPointsString(points) {
|
||||
if (parseInt(points) === 1) {
|
||||
return points + ' ' + pointNameSingle;
|
||||
}
|
||||
return points + ' ' + pointNameMultiple;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function runPointsPayout
|
||||
*/
|
||||
function runPointsPayout() {
|
||||
var now = $.systemTime(),
|
||||
normalPayoutUsers = [], // users that get the normal online payout, nothing custom.
|
||||
isOnline = false,
|
||||
username,
|
||||
amount,
|
||||
i;
|
||||
|
||||
if (!$.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((isOnline = $.isOnline($.channelName))) {
|
||||
if (onlinePayoutInterval > 0 && (lastPayout + (onlinePayoutInterval * 6e4)) <= now) {
|
||||
amount = onlineGain;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (offlinePayoutInterval > 0 && (lastPayout + (offlinePayoutInterval * 6e4)) <= now) {
|
||||
amount = offlineGain;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i in $.users) {
|
||||
username = $.users[i].toLowerCase();
|
||||
if (isOnline) {
|
||||
if ($.isMod(username) && $.isSub(username) || $.isAdmin(username) && $.isSub(username)) {
|
||||
if (parseInt($.inidb.get('grouppoints', 'Subscriber')) > 0) {
|
||||
amount = parseInt($.inidb.get('grouppoints', 'Subscriber'));
|
||||
} else {
|
||||
amount = onlineGain;
|
||||
}
|
||||
} else {
|
||||
if ($.inidb.exists('grouppoints', $.getUserGroupName(username))) {
|
||||
amount = (parseInt($.inidb.get('grouppoints', $.getUserGroupName(username))) < 0 ? onlineGain : parseInt($.inidb.get('grouppoints', $.getUserGroupName(username))));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($.isMod(username) && $.isSub(username) || $.isAdmin(username) && $.isSub(username)) {
|
||||
if (parseInt($.inidb.get('grouppointsoffline', 'Subscriber')) > 0) {
|
||||
amount = parseInt($.inidb.get('grouppointsoffline', 'Subscriber'));
|
||||
} else {
|
||||
amount = offlineGain;
|
||||
}
|
||||
} else {
|
||||
if ($.inidb.exists('grouppointsoffline', $.getUserGroupName(username))) {
|
||||
amount = (parseInt($.inidb.get('grouppointsoffline', $.getUserGroupName(username))) < 0 ? offlineGain : parseInt($.inidb.get('grouppointsoffline', $.getUserGroupName(username))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (userCache[username] !== undefined) {
|
||||
if (userCache[username] - lastPayout > 0) {
|
||||
delete userCache[username];
|
||||
amount += activeBonus;
|
||||
} else {
|
||||
delete userCache[username];
|
||||
}
|
||||
}
|
||||
|
||||
if (getUserPenalty(username)) {
|
||||
for (i in penaltys) {
|
||||
var time = penaltys[i].time - now;
|
||||
if (time <= 0) {
|
||||
penaltys.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pointsBonus) {
|
||||
amount = (amount + pointsBonusAmount);
|
||||
}
|
||||
|
||||
if (!getUserPenalty(username)) {
|
||||
if (amount == onlineGain || amount == offlineGain) {
|
||||
normalPayoutUsers.push(username);
|
||||
} else {
|
||||
$.inidb.incr('points', username, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update points for all users with the same amount of online/offline gain.
|
||||
$.inidb.IncreaseBatchString('points', '', normalPayoutUsers, (isOnline ? onlineGain : offlineGain));
|
||||
|
||||
lastPayout = now;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function setPenalty
|
||||
*/
|
||||
function setPenalty(sender, username, time, silent) {
|
||||
if (!username || !time) {
|
||||
if (!silent) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.err.penalty'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var newTime = (time * 6e4) + $.systemTime();
|
||||
username = username.toLowerCase();
|
||||
|
||||
penaltys.push({
|
||||
user: username,
|
||||
time: newTime
|
||||
});
|
||||
|
||||
if (!silent) {
|
||||
time = $.getTimeStringMinutes((time * 6e4) / 1000);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.penalty.set', username, time));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @function getUserPenalty
|
||||
* @param username
|
||||
*/
|
||||
function getUserPenalty(username) {
|
||||
for (var i in penaltys) {
|
||||
if (penaltys[i].user.equalsIgnoreCase(username)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function setTempBonus
|
||||
* @param {Number} amount
|
||||
* @param {Number} time
|
||||
*/
|
||||
function setTempBonus(amount, time) {
|
||||
var newTime = (time * 6e4);
|
||||
if (!amount || !time) {
|
||||
return;
|
||||
}
|
||||
|
||||
pointsBonus = true;
|
||||
pointsBonusAmount = parseInt(amount);
|
||||
|
||||
setTimeout(function() {
|
||||
pointsBonus = false;
|
||||
pointsBonusAmount = 0;
|
||||
}, newTime);
|
||||
|
||||
if (time >= 60) {
|
||||
newTime = $.getTimeString((time * 6e4) / 1000, true);
|
||||
} else {
|
||||
newTime = $.getTimeStringMinutes((time * 6e4) / 1000);
|
||||
}
|
||||
|
||||
$.say($.lang.get('pointsystem.bonus.say', newTime, pointsBonusAmount, pointNameMultiple));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function giveAll
|
||||
* @param {Number} action
|
||||
*/
|
||||
function giveAll(amount, sender) {
|
||||
if (amount < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.add.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (i in $.users) {
|
||||
$.inidb.incr('points', $.users[i].toLowerCase(), amount);
|
||||
}
|
||||
|
||||
|
||||
$.say($.lang.get('pointsystem.add.all.success', getPointsString(amount)));
|
||||
};
|
||||
|
||||
/**
|
||||
* @function takeAll
|
||||
* @param {Number} action
|
||||
*/
|
||||
function takeAll(amount, sender) {
|
||||
if (amount < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.take.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (i in $.users) {
|
||||
if (getUserPoints($.users[i].toLowerCase()) > amount) {
|
||||
$.inidb.decr('points', $.users[i].toLowerCase(), amount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$.say($.lang.get('pointsystem.take.all.success', getPointsString(amount)));
|
||||
};
|
||||
|
||||
/*
|
||||
* @function getPointsMessage
|
||||
*/
|
||||
function getPointsMessage(username, displayName) {
|
||||
var s = pointsMessage;
|
||||
|
||||
if (s.match(/\(userprefix\)/)) {
|
||||
s = $.replace(s, '(userprefix)', $.whisperPrefix(username));
|
||||
}
|
||||
|
||||
if (s.match(/\(user\)/)) {
|
||||
s = $.replace(s, '(user)', displayName);
|
||||
}
|
||||
|
||||
if (s.match(/\(pointsstring\)/)) {
|
||||
s = $.replace(s, '(pointsstring)', String(getPointsString(getUserPoints(username))));
|
||||
}
|
||||
|
||||
if (s.match(/\(points\)/)) {
|
||||
s = $.replace(s, '(points)', String(getUserPoints(username)));
|
||||
}
|
||||
|
||||
if (s.match(/\(pointsname\)/)) {
|
||||
s = $.replace(s, '(pointsname)', String(pointNameMultiple));
|
||||
}
|
||||
|
||||
if (s.match(/\(time\)/)) {
|
||||
s = $.replace(s, '(time)', $.getUserTimeString(username));
|
||||
}
|
||||
|
||||
if (s.match(/\(rank\)/)) {
|
||||
s = $.replace(s, '(rank)', ($.hasRank(username) ? String($.getRank(username)) : ''));
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
/*
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
if (activeBonus > 0) {
|
||||
userCache[event.getSender()] = $.systemTime();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
username = $.username.resolve(sender, event.getTags()),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
actionArg1 = args[1],
|
||||
actionArg2 = args[2],
|
||||
temp,
|
||||
user,
|
||||
i;
|
||||
|
||||
/**
|
||||
* @commandpath points - Announce points in chat when no parameters are given.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('points') || command.equalsIgnoreCase('point') || command.equalsIgnoreCase(pointNameMultiple) || command.equalsIgnoreCase(pointNameSingle)) {
|
||||
if (!action) {
|
||||
$.say(getPointsMessage(sender, username));
|
||||
} else {
|
||||
// Replace everything that is not \w
|
||||
action = $.user.sanitize(action);
|
||||
if ($.user.isKnown(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.user.success', $.username.resolve(action), getPointsString(getUserPoints(action))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points add [username] [amount] - Add an amount of points to a user's balance
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('add') || action.equalsIgnoreCase('give')) {
|
||||
actionArg1 = (actionArg1 + '').toLowerCase();
|
||||
actionArg2 = parseInt(actionArg2);
|
||||
if (isNaN(actionArg2) || !actionArg1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg1.equalsIgnoreCase('all')) {
|
||||
giveAll(actionArg2, sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace everything that is not \w
|
||||
actionArg1 = $.user.sanitize(actionArg1);
|
||||
|
||||
if (!$.user.isKnown(actionArg1) || $.isTwitchBot(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', actionArg1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg2 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.add.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.user.isKnown(actionArg1)) {
|
||||
$.inidb.incr('points', actionArg1, actionArg2);
|
||||
$.say($.lang.get('pointsystem.add.success',
|
||||
$.getPointsString(actionArg2), $.username.resolve(actionArg1), getPointsString(getUserPoints(actionArg1))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points take [username] [amount] - Take an amount of points from the user's balance
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('take') || action.equalsIgnoreCase('remove')) {
|
||||
actionArg1 = (actionArg1 + '').toLowerCase();
|
||||
actionArg2 = parseInt(actionArg2);
|
||||
if (isNaN(actionArg2) || !actionArg1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.take.usage'));
|
||||
return
|
||||
}
|
||||
|
||||
if (actionArg1.equalsIgnoreCase('all')) {
|
||||
takeAll(actionArg2, sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace everything that is not \w
|
||||
actionArg1 = $.user.sanitize(actionArg1);
|
||||
|
||||
if (!$.user.isKnown(actionArg1) || $.isTwitchBot(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', actionArg1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg2 > $.getUserPoints(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.take.error.toomuch', username, pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.decr('points', actionArg1, actionArg2);
|
||||
$.say($.lang.get('pointsystem.take.success',
|
||||
$.getPointsString(actionArg2), $.username.resolve(actionArg1), getPointsString(getUserPoints(actionArg1))))
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points set [username] [amount] - Set the user's points balance to an amount
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('set')) {
|
||||
actionArg1 = (actionArg1 + '').toLowerCase();
|
||||
actionArg2 = parseInt(actionArg2);
|
||||
if (isNaN(actionArg2) || !actionArg1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.setbalance.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace everything that is not \w
|
||||
actionArg1 = $.user.sanitize(actionArg1);
|
||||
|
||||
if (!$.user.isKnown(actionArg1) || $.isTwitchBot(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', actionArg1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg2 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.setbalance.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('points', actionArg1, actionArg2);
|
||||
$.say($.lang.get('pointsystem.setbalance.success',
|
||||
pointNameSingle, $.username.resolve(actionArg1), getPointsString(getUserPoints(actionArg1))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points all [amount] - Send an amount of points to all users in the chat
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('all')) {
|
||||
if (!parseInt(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.add.all.usage'));
|
||||
return;
|
||||
}
|
||||
giveAll(actionArg1, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points takeall [amount] - Remove an amount of points to all users in the chat
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('takeall')) {
|
||||
if (!parseInt(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.take.all.usage'));
|
||||
return;
|
||||
}
|
||||
takeAll(actionArg1, sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setname single [name] - Set the points name for single points
|
||||
* @commandpath points setname multiple [name] - Set the points name for plural points
|
||||
* @commandpath points setname delete - Deletes single and multiple custom names
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setname')) {
|
||||
(actionArg1 + '');
|
||||
(actionArg2 + '');
|
||||
|
||||
if (actionArg1 == undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.usage'));
|
||||
return;
|
||||
}
|
||||
if (actionArg1.equalsIgnoreCase('single') && actionArg2) {
|
||||
temp = pointNameSingle;
|
||||
if (actionArg2.equalsIgnoreCase($.inidb.get('pointSettings', 'pointNameSingle'))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.duplicate'));
|
||||
return;
|
||||
}
|
||||
pointNameSingle = actionArg2.toLowerCase();
|
||||
$.inidb.set('pointSettings', 'pointNameSingle', pointNameSingle);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.single.success', temp, pointNameSingle));
|
||||
updateSettings();
|
||||
return;
|
||||
}
|
||||
if (actionArg1.equalsIgnoreCase('multiple') && actionArg2) {
|
||||
temp = pointNameMultiple;
|
||||
if (actionArg2.equalsIgnoreCase($.inidb.get('pointSettings', 'pointNameMultiple'))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.duplicate'));
|
||||
return;
|
||||
}
|
||||
pointNameMultiple = actionArg2.toLowerCase();
|
||||
$.inidb.set('pointSettings', 'pointNameMultiple', pointNameMultiple);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.multiple.success', temp, pointNameMultiple));
|
||||
updateSettings();
|
||||
return;
|
||||
}
|
||||
if (actionArg1.equalsIgnoreCase('delete')) {
|
||||
$.inidb.set('pointSettings', 'pointNameSingle', 'point');
|
||||
$.inidb.set('pointSettings', 'pointNameMultiple', 'points');
|
||||
$.unregisterChatCommand(pointNameSingle);
|
||||
$.unregisterChatCommand(pointNameMultiple);
|
||||
pointNameSingle = "point";
|
||||
pointNameMultiple = "points";
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.delete'));
|
||||
updateSettings();
|
||||
return;
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.name.usage'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setgain [amount] - Set the amount of points gained per payout interval while the channel is online, can be overriden by group settings
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setgain')) {
|
||||
actionArg1 = parseInt(actionArg1);
|
||||
if (isNaN(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg1 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
onlineGain = actionArg1;
|
||||
$.inidb.set('pointSettings', 'onlineGain', onlineGain);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.success', pointNameSingle, getPointsString(onlineGain), onlinePayoutInterval));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setofflinegain [amount] - Set the amount of points gained per interval while the channel is offline, can be overridden by group settings
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setofflinegain')) {
|
||||
actionArg1 = parseInt(actionArg1);
|
||||
if (isNaN(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.offline.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg1 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
offlineGain = actionArg1;
|
||||
$.inidb.set('pointSettings', 'offlineGain', offlineGain);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.gain.offline.success',
|
||||
pointNameSingle, $.getPointsString(offlineGain), offlinePayoutInterval));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setinterval [minutes] - Set the points payout interval for when the channel is online
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setinterval')) {
|
||||
actionArg1 = parseInt(actionArg1);
|
||||
if (isNaN(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.interval.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg1 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.interval.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
onlinePayoutInterval = actionArg1;
|
||||
$.inidb.set('pointSettings', 'onlinePayoutInterval', onlinePayoutInterval);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.interval.success', pointNameSingle, onlinePayoutInterval));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setofflineinterval [minutes] - Set the points payout interval for when the channel is offline
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setofflineinterval')) {
|
||||
actionArg1 = parseInt(actionArg1);
|
||||
if (isNaN(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.interval.offline.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionArg1 < 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.set.interval.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
offlinePayoutInterval = actionArg1;
|
||||
$.inidb.set('pointSettings', 'offlinePayoutInterval', offlinePayoutInterval);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get("pointsystem.set.interval.offline.success", pointNameSingle, offlinePayoutInterval));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setmessage [message] - Set the points message for when someone uses the points command. - Tags: (userprefix), (user), (points), (pointsname), (pointsstring), (time), and (rank)
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setmessage')) {
|
||||
if (!actionArg1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
pointsMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('pointSettings', 'pointsMessage', pointsMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.message.set', pointsMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points bonus [amount] [time in minutes] - Gives a bonus amount of points at each payouts
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('bonus')) {
|
||||
if (!actionArg1 || !actionArg2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.bonus.usage'));
|
||||
return;
|
||||
}
|
||||
setTempBonus(actionArg1, actionArg2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points resetall - Deletes everyones points
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('resetall')) {
|
||||
$.inidb.RemoveFile('points');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.reset.all'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath points setactivebonus [points] - Sets a bonus amount of points user get if they are active between the last payout.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('setactivebonus')) {
|
||||
if (actionArg1 === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.active.bonus.usage'));
|
||||
return;
|
||||
}
|
||||
activeBonus = parseInt(actionArg1);
|
||||
$.setIniDbNumber('pointSettings', 'activeBonus', activeBonus);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.active.bonus.set', getPointsString(activeBonus)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get("pointsystem.usage.invalid", "!" + command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @commandpath makeitrain [amount] - Send a random amount of points to each user in the channel
|
||||
*/
|
||||
if (command.equalsIgnoreCase('makeitrain')) {
|
||||
var lastAmount = 0,
|
||||
amount = 0,
|
||||
totalAmount = 0;
|
||||
|
||||
action = parseInt(action);
|
||||
if (isNaN(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.makeitrain.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.makeitrain.error.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
for (i in $.users) {
|
||||
do {
|
||||
amount = $.randRange(1, action);
|
||||
} while (amount == lastAmount);
|
||||
totalAmount += amount;
|
||||
$.inidb.incr('points', $.users[i].toLowerCase(), amount);
|
||||
}
|
||||
|
||||
if (totalAmount > 0) {
|
||||
$.say($.lang.get('pointsystem.makeitrain.success', username, action, pointNameMultiple));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath gift [user] [amount] - Give points to a friend.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gift')) {
|
||||
if (!action || isNaN(parseInt(actionArg1)) || action.equalsIgnoreCase(sender)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.gift.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parseInt(args[1]) > getUserPoints(sender)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.gift.shortpoints'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (parseInt(args[1]) <= 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.err.negative', pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace everything that is not \w
|
||||
action = $.user.sanitize(action);
|
||||
|
||||
if (!$.user.isKnown(action) || $.isTwitchBot(action)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.gift.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.incr('points', action, parseInt(args[1]));
|
||||
$.inidb.decr('points', sender, parseInt(args[1]));
|
||||
$.say($.lang.get('pointsystem.gift.success', $.username.resolve(sender), getPointsString(parseInt(args[1])), $.username.resolve(action)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath penalty [user] [time] - Stop a user from gaining points for X amount of minutes.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('penalty')) {
|
||||
if (action === undefined || isNaN(actionArg1)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pointsystem.err.penalty'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender.equalsIgnoreCase($.botName)) { // Used for the panel.
|
||||
setPenalty(sender, action.toLowerCase(), parseInt(actionArg1), true);
|
||||
return;
|
||||
}
|
||||
setPenalty(sender, action.toLowerCase(), parseInt(actionArg1));
|
||||
}
|
||||
});
|
||||
|
||||
// Set the timer for the points payouts
|
||||
var interval = setInterval(function() {
|
||||
runPointsPayout();
|
||||
}, 6e4, 'scripts::systems::pointSystem.js');
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/pointSystem.js', 'makeitrain', 1);
|
||||
$.registerChatCommand('./systems/pointSystem.js', 'points', 7);
|
||||
$.registerChatCommand('./systems/pointSystem.js', 'gift', 7);
|
||||
$.registerChatCommand('./systems/pointSystem.js', 'penalty', 2);
|
||||
|
||||
$.registerChatSubcommand('points', 'add', 1);
|
||||
$.registerChatSubcommand('points', 'give', 1);
|
||||
$.registerChatSubcommand('points', 'take', 1);
|
||||
$.registerChatSubcommand('points', 'remove', 1);
|
||||
$.registerChatSubcommand('points', 'set', 1);
|
||||
$.registerChatSubcommand('points', 'all', 1);
|
||||
$.registerChatSubcommand('points', 'takeall', 1);
|
||||
$.registerChatSubcommand('points', 'setname', 1);
|
||||
$.registerChatSubcommand('points', 'setgain', 1);
|
||||
$.registerChatSubcommand('points', 'setofflinegain', 1);
|
||||
$.registerChatSubcommand('points', 'setinterval', 1);
|
||||
$.registerChatSubcommand('points', 'bonus', 1);
|
||||
$.registerChatSubcommand('points', 'resetall', 1);
|
||||
$.registerChatSubcommand('points', 'setmessage', 1);
|
||||
$.registerChatSubcommand('points', 'setactivebonus', 1);
|
||||
|
||||
if (pointNameSingle != 'point' || pointNameMultiple != 'points') {
|
||||
updateSettings();
|
||||
}
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.pointNameSingle = pointNameSingle;
|
||||
$.pointNameMultiple = pointNameMultiple;
|
||||
$.getUserPoints = getUserPoints;
|
||||
$.getPointsString = getPointsString;
|
||||
$.getPointsMessage = getPointsMessage;
|
||||
$.updateSettings = updateSettings;
|
||||
$.setTempBonus = setTempBonus;
|
||||
$.giveAll = giveAll;
|
||||
})();
|
||||
362
libs/phantombot/scripts/systems/pollSystem.js
Normal file
362
libs/phantombot/scripts/systems/pollSystem.js
Normal file
@@ -0,0 +1,362 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* pollSystem.js
|
||||
*
|
||||
* This module enables the channel owner to start/manage polls
|
||||
* Start/stop polls is exported to $.poll for use in other scripts
|
||||
*/
|
||||
(function() {
|
||||
var poll = {
|
||||
pollId: 0,
|
||||
options: [],
|
||||
votes: [],
|
||||
voters: [],
|
||||
callback: function() {},
|
||||
pollRunning: false,
|
||||
pollMaster: '',
|
||||
time: 0,
|
||||
question: '',
|
||||
minVotes: 0,
|
||||
result: '',
|
||||
hasTie: 0,
|
||||
counts: [],
|
||||
},
|
||||
timeout;
|
||||
var objOBS = [];
|
||||
|
||||
/**
|
||||
* @function hasKey
|
||||
* @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;
|
||||
};
|
||||
|
||||
// Compile regular expressions.
|
||||
var rePollOpenFourOptions = new RegExp(/"([\w\W]+)"\s+"([\w\W]+)"\s+(\d+)\s+(\d+)/),
|
||||
rePollOpenThreeOptions = new RegExp(/"([\w\W]+)"\s+"([\w\W]+)"\s+(\d+)/),
|
||||
rePollOpenTwoOptions = new RegExp(/"([\w\W]+)"\s+"([\w\W]+)"/);
|
||||
|
||||
/**
|
||||
* @function runPoll
|
||||
* @export $.poll
|
||||
* @param {string} question
|
||||
* @param {Array} options
|
||||
* @param {Number} time
|
||||
* @param {string} pollMaster
|
||||
* @param {Number} [minVotes]
|
||||
* @param {Function} callback
|
||||
* @param {string} [initialVote]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function runPoll(question, options, time, pollMaster, minVotes, callback) {
|
||||
var optionsStr = "";
|
||||
|
||||
if (poll.pollRunning) {
|
||||
return false
|
||||
}
|
||||
|
||||
objOBS = [];
|
||||
|
||||
poll.pollRunning = true;
|
||||
poll.pollMaster = pollMaster;
|
||||
poll.time = (parseInt(time) * 1000);
|
||||
poll.callback = callback;
|
||||
poll.question = question;
|
||||
poll.options = options;
|
||||
poll.minVotes = (minVotes ? minVotes : 1);
|
||||
poll.votes = [];
|
||||
poll.voters = [];
|
||||
poll.counts = [];
|
||||
poll.hasTie = 0;
|
||||
|
||||
// Remove the old files.
|
||||
$.inidb.RemoveFile('pollPanel');
|
||||
$.inidb.RemoveFile('pollVotes');
|
||||
|
||||
|
||||
for (var i = 0; i < poll.options.length; i++) {
|
||||
optionsStr += (i + 1) + ") " + poll.options[i] + " ";
|
||||
$.inidb.set('pollVotes', poll.options[i], 0);
|
||||
objOBS.push({
|
||||
'label': poll.options[i],
|
||||
'votes': 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (poll.time > 0) {
|
||||
$.say($.lang.get('pollsystem.poll.started', $.resolveRank(pollMaster), time, poll.minVotes, poll.question, optionsStr));
|
||||
|
||||
timeout = setTimeout(function() {
|
||||
endPoll();
|
||||
}, poll.time);
|
||||
} else {
|
||||
$.say($.lang.get('pollsystem.poll.started.nottime', $.resolveRank(pollMaster), poll.minVotes, poll.question, optionsStr));
|
||||
}
|
||||
|
||||
var msg = JSON.stringify({
|
||||
'start_poll': 'true',
|
||||
'data': JSON.stringify(objOBS)
|
||||
});
|
||||
$.alertspollssocket.sendJSONToAll(msg);
|
||||
|
||||
$.inidb.set('pollPanel', 'title', question);
|
||||
$.inidb.set('pollPanel', 'options', options.join(','));
|
||||
$.inidb.set('pollPanel', 'isActive', 'true');
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function vote
|
||||
* @param {string} sender
|
||||
* @param {string} voteText
|
||||
*/
|
||||
function vote(sender, voteText) {
|
||||
var optionIndex;
|
||||
|
||||
if (!poll.pollRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasKey(poll.voters, sender.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.vote.already'));
|
||||
return;
|
||||
}
|
||||
|
||||
optionIndex = parseInt(voteText);
|
||||
if (isNaN(optionIndex) || optionIndex < 1 || optionIndex > poll.options.length) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.vote.invalid', voteText));
|
||||
return;
|
||||
}
|
||||
|
||||
optionIndex--;
|
||||
poll.voters.push(sender);
|
||||
poll.votes.push(optionIndex);
|
||||
for (var i = 0; i < objOBS.length; i++) {
|
||||
if (objOBS[i].label == poll.options[optionIndex])
|
||||
objOBS[i].votes++;
|
||||
}
|
||||
var msg = JSON.stringify({
|
||||
'new_vote': 'true',
|
||||
'data': JSON.stringify(objOBS)
|
||||
});
|
||||
$.alertspollssocket.sendJSONToAll(msg);
|
||||
$.inidb.incr('pollVotes', poll.options[optionIndex], 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @function endPoll
|
||||
* @export $.poll
|
||||
*/
|
||||
function endPoll() {
|
||||
var mostVotes = -1,
|
||||
i;
|
||||
|
||||
if (!poll.pollRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
$.inidb.set('pollPanel', 'isActive', 'false');
|
||||
var msg = JSON.stringify({
|
||||
'end_poll': 'true'
|
||||
});
|
||||
$.alertspollssocket.sendJSONToAll(msg);
|
||||
if (poll.minVotes > 0 && poll.votes.length < poll.minVotes) {
|
||||
poll.result = '';
|
||||
poll.pollMaster = '';
|
||||
poll.pollRunning = false;
|
||||
poll.callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < poll.options.length; poll.counts.push(0), i++);
|
||||
for (i = 0; i < poll.votes.length; poll.counts[poll.votes[i++]] += 1);
|
||||
for (i = 0; i < poll.counts.length; winner = ((poll.counts[i] > mostVotes) ? i : winner), mostVotes = ((poll.counts[i] > mostVotes) ? poll.counts[i] : mostVotes), i++);
|
||||
for (i = 0; i < poll.counts.length;
|
||||
(i != winner && poll.counts[i] == poll.counts[winner] ? poll.hasTie = 1 : 0), (poll.hasTie == 1 ? i = poll.counts.length : 0), i++);
|
||||
|
||||
poll.result = poll.options[winner];
|
||||
poll.pollMaster = '';
|
||||
poll.pollRunning = false;
|
||||
|
||||
// Store the results for the Panel to read.
|
||||
$.inidb.set('pollresults', 'question', poll.question);
|
||||
$.inidb.set('pollresults', 'result', poll.result);
|
||||
$.inidb.set('pollresults', 'votes', poll.votes.length);
|
||||
$.inidb.set('pollresults', 'options', poll.options.join(','));
|
||||
$.inidb.set('pollresults', 'counts', poll.counts.join(','));
|
||||
$.inidb.set('pollresults', 'istie', poll.hasTie);
|
||||
poll.callback(poll.result);
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender().toLowerCase(),
|
||||
command = event.getCommand(),
|
||||
argsString = event.getArguments().trim(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('vote') && action !== undefined) {
|
||||
if (poll.pollRunning) {
|
||||
vote(sender, action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath poll - Announce information about a poll, if one is running.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('poll')) {
|
||||
if (!action) {
|
||||
if (poll.pollRunning) {
|
||||
var optionsStr = "";
|
||||
for (var i = 0; i < poll.options.length; i++) {
|
||||
optionsStr += (i + 1) + ") " + poll.options[i] + (i == poll.options.length - 1 ? "" : " ");
|
||||
}
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.poll.running', poll.question, optionsStr));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.poll.usage'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath poll results - Announce result information about the last run poll (Poll information is retained until shutdown)
|
||||
*/
|
||||
if (action.equalsIgnoreCase('results')) {
|
||||
if (poll.pollRunning) {
|
||||
$.say($.lang.get('pollsystem.results.running'));
|
||||
} else if (poll.result != '') {
|
||||
if (poll.hasTie) {
|
||||
$.say($.lang.get('pollsystem.results.lastpoll', poll.question, poll.votes.length, "Tie!", poll.options.join(', '), poll.counts.join(', ')));
|
||||
} else {
|
||||
$.say($.lang.get('pollsystem.results.lastpoll', poll.question, poll.votes.length, poll.result, poll.options.join(', '), poll.counts.join(', ')));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.results.404'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath poll open ["poll question"] ["option1, option2, ..."] [seconds] [min votes] - Starts a poll with question and options. Optionally provide seconds and min votes.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
var time = 0,
|
||||
question = '',
|
||||
options = [],
|
||||
minVotes = 1;
|
||||
|
||||
argsString = argsString + ""; // Cast as a JavaScript string.
|
||||
|
||||
if (argsString.match(rePollOpenFourOptions)) {
|
||||
question = argsString.match(rePollOpenFourOptions)[1];
|
||||
options = argsString.match(rePollOpenFourOptions)[2].split(/,\s*/);
|
||||
time = parseInt(argsString.match(rePollOpenFourOptions)[3]);
|
||||
minVotes = parseInt(argsString.match(rePollOpenFourOptions)[4]);
|
||||
} else if (argsString.match(rePollOpenThreeOptions)) {
|
||||
question = argsString.match(rePollOpenThreeOptions)[1];
|
||||
options = argsString.match(rePollOpenThreeOptions)[2].split(/,\s*/);
|
||||
time = parseInt(argsString.match(rePollOpenThreeOptions)[3]);
|
||||
} else if (argsString.match(rePollOpenTwoOptions)) {
|
||||
question = argsString.match(rePollOpenTwoOptions)[1];
|
||||
options = argsString.match(rePollOpenTwoOptions)[2].split(/,\s*/);
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.open.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!question || !options || options.length === 0 || isNaN(minVotes) || minVotes < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.open.usage'));
|
||||
return;
|
||||
}
|
||||
if (options.length === 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.open.moreoptions'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (runPoll(question, options, parseInt(time), sender, minVotes, function(winner) {
|
||||
if (winner === false) {
|
||||
$.say($.lang.get('pollsystem.runpoll.novotes', question));
|
||||
return;
|
||||
}
|
||||
if (poll.hasTie) {
|
||||
$.say($.lang.get('pollsystem.runpoll.tie', question));
|
||||
} else {
|
||||
$.say($.lang.get('pollsystem.runpoll.winner', question, winner));
|
||||
}
|
||||
})) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.runpoll.started'));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.results.running'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath poll close - Close the current poll and tally the votes
|
||||
*/
|
||||
if (action.equalsIgnoreCase('close')) {
|
||||
if (!poll.pollRunning) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('pollsystem.close.nopoll'));
|
||||
return;
|
||||
}
|
||||
endPoll();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/pollSystem.js', 'poll', 2);
|
||||
$.registerChatCommand('./systems/pollSystem.js', 'vote', 7);
|
||||
$.registerChatSubcommand('poll', 'results', 2);
|
||||
$.registerChatSubcommand('poll', 'open', 2);
|
||||
$.registerChatSubcommand('poll', 'close', 2);
|
||||
});
|
||||
|
||||
/** Export functions to API */
|
||||
$.poll = {
|
||||
runPoll: runPoll,
|
||||
endPoll: endPoll
|
||||
};
|
||||
})();
|
||||
447
libs/phantombot/scripts/systems/queueSystem.js
Normal file
447
libs/phantombot/scripts/systems/queueSystem.js
Normal file
@@ -0,0 +1,447 @@
|
||||
/*
|
||||
* 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 isOpened = false,
|
||||
info = {},
|
||||
queue = {};
|
||||
|
||||
/*
|
||||
* @function open
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {Number} size
|
||||
* @param {String} title
|
||||
*/
|
||||
function open(username, size, title) {
|
||||
if (isOpened === true) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.open.error.opened'));
|
||||
return;
|
||||
} else if (size === undefined || isNaN(parseInt(size))) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.open.error.usage'));
|
||||
return;
|
||||
} else if (title === undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.open.usage'));
|
||||
return;
|
||||
} else if (Object.keys(queue).length !== 0) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.open.error.clear'));
|
||||
return;
|
||||
}
|
||||
|
||||
info = {
|
||||
size: parseInt(size),
|
||||
time: new Date(),
|
||||
title: title
|
||||
};
|
||||
|
||||
if (parseInt(size) === 0) {
|
||||
$.say($.lang.get('queuesystem.open.normal', title));
|
||||
} else {
|
||||
$.say($.lang.get('queuesystem.open.limit', size, title));
|
||||
}
|
||||
isOpened = true;
|
||||
$.inidb.set('queueSettings', 'isActive', 'true');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function close
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function close(username) {
|
||||
if (isOpened === false) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.close.error'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.lang.get('queuesystem.close.success'));
|
||||
isOpened = false;
|
||||
$.inidb.set('queueSettings', 'isActive', 'false');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function clear
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function clear(username) {
|
||||
queue = {};
|
||||
info = {};
|
||||
isOpened = false;
|
||||
$.inidb.RemoveFile('queue');
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.clear.success'));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function join
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} action
|
||||
*/
|
||||
function join(username, action, command) {
|
||||
if (queue[username] !== undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.join.error.joined'));
|
||||
$.returnCommandCost(username, command, $.isMod(username));
|
||||
return;
|
||||
} else if (info.size !== 0 && (info.size <= Object.keys(queue).length)) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.join.error.full'));
|
||||
$.returnCommandCost(username, command, $.isMod(username));
|
||||
return;
|
||||
} else if (isOpened === false) {
|
||||
$.returnCommandCost(username, command, $.isMod(username));
|
||||
return;
|
||||
}
|
||||
|
||||
queue[username] = {
|
||||
tag: (action === undefined ? '' : action),
|
||||
position: Object.keys(queue).length,
|
||||
time: new Date(),
|
||||
username: username
|
||||
};
|
||||
|
||||
var temp = {
|
||||
'tag': String((action === undefined ? '' : action)),
|
||||
'time': String(date(new Date(), true)),
|
||||
'position': String(Object.keys(queue).length),
|
||||
'username': String(username)
|
||||
};
|
||||
$.inidb.set('queue', username, JSON.stringify(temp));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function remove
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} action
|
||||
*/
|
||||
function remove(username, action) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.remove.usage'));
|
||||
return;
|
||||
} else if (queue[action.toLowerCase()] === undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.remove.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
delete queue[action.toLowerCase()];
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.remove.removed', action));
|
||||
}
|
||||
|
||||
/*
|
||||
* @function stats
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function stats(username) {
|
||||
if (isOpened === true) {
|
||||
$.say($.lang.get('queuesystem.info.success', info.title, Object.keys(queue).length, info.size, date(info.time)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.close.error'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function date
|
||||
*
|
||||
* @param {Number} time
|
||||
* @return {String}
|
||||
*/
|
||||
function date(time, simple) {
|
||||
var date = new Date(time),
|
||||
format = new java.text.SimpleDateFormat('HH:mm:ss z'),
|
||||
seconds = Math.floor((new Date() - time) / 1000),
|
||||
string = $.getTimeString(seconds);
|
||||
|
||||
format.setTimeZone(java.util.TimeZone.getTimeZone(($.inidb.exists('settings', 'timezone') ? $.inidb.get('settings', 'timezone') : 'GMT')));
|
||||
if (simple === undefined) {
|
||||
return format.format(date) + ' ' + $.lang.get('queuesystem.time.info', string);
|
||||
} else {
|
||||
return format.format(date);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function position
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} action
|
||||
*/
|
||||
function position(username, action) {
|
||||
if (action === undefined) {
|
||||
if (queue[username] !== undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.position.self', queue[username].position, date(queue[username].time)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.position.self.error'));
|
||||
}
|
||||
} else {
|
||||
action = action.toLowerCase();
|
||||
if (queue[action] !== undefined) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.position.other', action, queue[action].position, date(queue[action].time)));
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.position.other.error', action));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function list
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function list(username) {
|
||||
var keys = Object.keys(queue),
|
||||
temp = [],
|
||||
id = 1,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
temp.push('#' + (id++) + ': ' + queue[keys[i]].username);
|
||||
}
|
||||
|
||||
if (temp.length !== 0) {
|
||||
if (temp.length < 10) {
|
||||
$.say($.lang.get('queuesystem.queue.list', temp.join(', ')));
|
||||
} else {
|
||||
$.say($.lang.get('queuesystem.queue.list.limited', temp.splice(0, 5).join(', '), (temp.length - 5)));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.queue.list.empty'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function next
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} action
|
||||
*/
|
||||
function next(username, action) {
|
||||
var total = (action === undefined || isNaN(parseInt(action)) ? 1 : parseInt(action)),
|
||||
keys = Object.keys(queue),
|
||||
temp = [],
|
||||
t = 1,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (total >= t && temp.length < 400) {
|
||||
temp.push('#' + t + ': ' + queue[keys[i]].username);
|
||||
t++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp.length !== 0) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.queue.next', temp.join(', ')));
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.queue.list.empty'));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function resetPosition
|
||||
*/
|
||||
function resetPosition(splice) {
|
||||
var keys = Object.keys(queue),
|
||||
t = 0,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (splice !== -1 && t <= splice) {
|
||||
$.inidb.del('queue', keys[i]);
|
||||
delete queue[keys[i]];
|
||||
}
|
||||
t++;
|
||||
}
|
||||
|
||||
keys = Object.keys(queue);
|
||||
t = 1;
|
||||
|
||||
for (i in keys) {
|
||||
queue[keys[i]].position = t;
|
||||
var temp = JSON.parse($.inidb.get('queue', keys[i]));
|
||||
temp.position = t;
|
||||
$.inidb.set('queue', keys[i], JSON.stringify(temp));
|
||||
t++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @function pick
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} action
|
||||
*/
|
||||
function pick(username, action) {
|
||||
var total = (action === undefined || isNaN(parseInt(action)) ? 1 : parseInt(action)),
|
||||
keys = Object.keys(queue),
|
||||
temp = [],
|
||||
t = 1,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (total >= t && temp.length < 400) {
|
||||
temp.push('#' + t + ': ' + queue[keys[i]].username + (queue[keys[i]].tag !== '' ? ' ' + $.lang.get('queuesystem.gamertag', queue[keys[i]].tag) : ''));
|
||||
t++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp.length !== 0) {
|
||||
$.say($.lang.get('queuesystem.pick', temp.join(', ')));
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('queuesystem.queue.list.empty'));
|
||||
}
|
||||
|
||||
resetPosition(t - 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* @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('queue')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('queuesystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue open [max size] [title] - Opens a new queue. Max size is optional.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
open(sender, (isNaN(parseInt(subAction)) ? 0 : subAction), (isNaN(parseInt(subAction)) ? args.slice(1).join(' ') : args.slice(2).join(' ')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue close - Closes the current queue that is opened.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('close')) {
|
||||
close(sender);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue clear - Closes and resets the current queue.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('clear')) {
|
||||
clear(sender);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue remove [username] - Removes that username from the queue.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('remove')) {
|
||||
remove(sender, subAction);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue list - Gives you the current queue list. Note that if the queue list is very long it will only show the first 5 users in the queue.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('list')) {
|
||||
list(sender);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue next [amount] - Shows the players that are to be picked next. Note if the amount is not specified it will only show one.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('next')) {
|
||||
next(sender, subAction);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue pick [amount] - Picks the players next in line from the queue. Note if the amount is not specified it will only pick one.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('pick')) {
|
||||
pick(sender, subAction);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue position [username] - Tells what position that user is in the queue and at what time he joined.
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('position')) {
|
||||
position(sender, subAction);
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath queue info - Gives you the current information about the queue that is opened
|
||||
*/
|
||||
else if (action.equalsIgnoreCase('info')) {
|
||||
stats(sender);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath joinqueue [gamertag] - Adds you to the current queue. Note that the gamertag part is optional.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('joinqueue')) {
|
||||
join(sender, args.join(' '), command);
|
||||
}
|
||||
});
|
||||
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/queueSystem.js', 'joinqueue', 7);
|
||||
$.registerChatCommand('./systems/queueSystem.js', 'queue', 7);
|
||||
|
||||
$.registerChatSubcommand('queue', 'open', 1);
|
||||
$.registerChatSubcommand('queue', 'close', 1);
|
||||
$.registerChatSubcommand('queue', 'clear', 1);
|
||||
$.registerChatSubcommand('queue', 'remove', 1);
|
||||
$.registerChatSubcommand('queue', 'pick', 1);
|
||||
$.registerChatSubcommand('queue', 'list', 7);
|
||||
$.registerChatSubcommand('queue', 'next', 7);
|
||||
$.registerChatSubcommand('queue', 'info', 7);
|
||||
$.registerChatSubcommand('queue', 'position', 7);
|
||||
|
||||
$.inidb.set('queueSettings', 'isActive', 'false');
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./systems/queueSystem.js')) {
|
||||
var action = event.getArgs()[0];
|
||||
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
open($.channelName, event.getArgs()[1], event.getArgs().slice(2).join(' '));
|
||||
} else if (action.equalsIgnoreCase('close')) {
|
||||
close($.channelName);
|
||||
} else if (action.equalsIgnoreCase('pick')) {
|
||||
pick($.channelName, event.getArgs()[1]);
|
||||
} else if (action.equalsIgnoreCase('remove')) {
|
||||
if (event.getArgs()[1] !== undefined && queue[event.getArgs()[1]] !== undefined) {
|
||||
delete queue[event.getArgs()[1].toLowerCase()];
|
||||
$.inidb.del('queue', event.getArgs()[1].toLowerCase());
|
||||
resetPosition(-1);
|
||||
}
|
||||
} else if (action.equalsIgnoreCase('clear')) {
|
||||
queue = {};
|
||||
info = {};
|
||||
isOpened = false;
|
||||
$.inidb.RemoveFile('queue');
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
355
libs/phantombot/scripts/systems/quoteSystem.js
Normal file
355
libs/phantombot/scripts/systems/quoteSystem.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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* quoteSystem.js
|
||||
*
|
||||
* Have the bot remember the most epic/derpy oneliners
|
||||
*/
|
||||
(function() {
|
||||
|
||||
var quoteMode = $.getSetIniDbBoolean('settings', 'quoteMode', true),
|
||||
isDeleting = false;
|
||||
|
||||
/**
|
||||
* @function updateQuote
|
||||
* @param {Number} quoteid
|
||||
* @param {Array} quote data
|
||||
*/
|
||||
function updateQuote(quoteid, quote) {
|
||||
// Specify String() for objects as they were being treated as an object rather than a String on stringify().
|
||||
quote[0] = String(quote[0]).replace(/"/g, '\'\'');
|
||||
quote[1] = String(quote[1]).replace(/"/g, '\'\'');
|
||||
quote[3] = String(quote[3]).replace(/"/g, '\'\'');
|
||||
|
||||
$.inidb.set('quotes', quoteid, JSON.stringify([String(quote[0]), String(quote[1]), String(quote[2]), String(quote[3])]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @function saveQuote
|
||||
* @param {string} username
|
||||
* @param {string} quote
|
||||
* @returns {Number}
|
||||
*/
|
||||
function saveQuote(username, quote) {
|
||||
var newKey = $.inidb.GetKeyList('quotes', '').length,
|
||||
game = ($.getGame($.channelName) != '' ? $.getGame($.channelName) : "Some Game");
|
||||
|
||||
if ($.inidb.exists('quotes', newKey)) {
|
||||
newKey++;
|
||||
}
|
||||
quote = String(quote).replace(/"/g, '\'\'');
|
||||
$.inidb.set('quotes', newKey, JSON.stringify([username, quote, $.systemTime(), game + '']));
|
||||
return newKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function deleteQuote
|
||||
* @param {Number} quoteId
|
||||
* @returns {Number}
|
||||
*/
|
||||
function deleteQuote(quoteId) {
|
||||
var quoteKeys,
|
||||
quotes = [],
|
||||
i;
|
||||
|
||||
if (isDeleting) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ($.inidb.exists('quotes', quoteId)) {
|
||||
isDeleting = true;
|
||||
$.inidb.del('quotes', quoteId);
|
||||
quoteKeys = $.inidb.GetKeyList('quotes', '');
|
||||
|
||||
|
||||
for (i in quoteKeys) {
|
||||
quotes.push($.inidb.get('quotes', quoteKeys[i]));
|
||||
$.inidb.del('quotes', quoteKeys[i]);
|
||||
}
|
||||
|
||||
for (i in quotes) {
|
||||
$.inidb.set('quotes', i, quotes[i]);
|
||||
}
|
||||
|
||||
isDeleting = false;
|
||||
return (quotes.length ? quotes.length : 0);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getQuote
|
||||
* @param {String} quoteId: id or search query
|
||||
* @returns {Array}
|
||||
*/
|
||||
function getQuote(quoteId) {
|
||||
var quote;
|
||||
|
||||
if (!quoteId) {
|
||||
quoteId = $.rand($.inidb.GetKeyList('quotes', '').length);
|
||||
} else if (isNaN(quoteId)) {
|
||||
quoteId = String(quoteId).toLowerCase();
|
||||
var quotes = $.inidb.GetKeyValueList('quotes', '');
|
||||
var ids = [];
|
||||
for (var i = 0; i < quotes.length; i++) {
|
||||
if (String(quotes[i].getValue()).toLowerCase().indexOf(quoteId) >= 0) {
|
||||
ids.push(quotes[i].getKey());
|
||||
}
|
||||
}
|
||||
quoteId = ids.length > 0 ? $.randElement(ids) : $.rand(quotes.length);
|
||||
}
|
||||
|
||||
if ($.inidb.exists('quotes', quoteId)) {
|
||||
quote = JSON.parse($.inidb.get('quotes', quoteId));
|
||||
quote.push(quoteId);
|
||||
return quote;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
quote,
|
||||
quoteStr;
|
||||
|
||||
/**
|
||||
* @commandpath editquote [id] [user|game|quote] [text] - Edit quotes.
|
||||
*/
|
||||
if (command.equalsIgnoreCase("editquote")) {
|
||||
if (args.length < 3) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
quote = getQuote(args[0]);
|
||||
if (quote.length > 0) {
|
||||
if (args[1].equalsIgnoreCase("user")) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.user.success', args[0], args[2]));
|
||||
quote[0] = args[2];
|
||||
updateQuote(args[0], quote);
|
||||
} else if (args[1].equalsIgnoreCase("game")) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.game.success', args[0], args.splice(2).join(' ')));
|
||||
quote[3] = args.splice(2).join(' ');
|
||||
updateQuote(args[0], quote);
|
||||
} else if (args[1].equalsIgnoreCase("quote")) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.quote.success', args[0], args.splice(2).join(' ')));
|
||||
quote[1] = args.splice(2).join(' ');
|
||||
updateQuote(args[0], quote);
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.usage'));
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.edit.404'));
|
||||
}
|
||||
|
||||
$.log.event(sender + ' edited quote #' + quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath quotemodetoggle - toggle between !addquote function modes
|
||||
*/
|
||||
if (command.equalsIgnoreCase('quotemodetoggle')) {
|
||||
if (quoteMode) {
|
||||
quoteMode = false;
|
||||
$.inidb.set('settings', 'quoteMode', 'false');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.add.usage2'));
|
||||
return;
|
||||
} else {
|
||||
quoteMode = true;
|
||||
$.inidb.set('settings', 'quoteMode', 'true');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.add.usage1'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath addquote [quote text] - Save a quote
|
||||
*/
|
||||
if (command.equalsIgnoreCase('addquote')) {
|
||||
if (quoteMode) {
|
||||
if (args.length < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.add.usage1'));
|
||||
return;
|
||||
}
|
||||
quote = args.splice(0).join(' ');
|
||||
$.say($.lang.get('quotesystem.add.success', $.username.resolve(sender), saveQuote(String($.username.resolve(sender)), quote)));
|
||||
$.log.event(sender + ' added a quote "' + quote + '".');
|
||||
return;
|
||||
} else {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.add.usage2'));
|
||||
return;
|
||||
}
|
||||
var useTwitchNames = ($.inidb.exists('settings', 'quoteTwitchNamesToggle')) ? $.inidb.get('settings', 'quoteTwitchNamesToggle') == "true" : true;
|
||||
var target = useTwitchNames ? args[0].toLowerCase() : args[0].substring(0, 1).toUpperCase() + args[0].substring(1).toLowerCase();
|
||||
if (useTwitchNames && !$.user.isKnown(target)) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('common.user.404', target));
|
||||
return;
|
||||
}
|
||||
quote = args.splice(1).join(' ');
|
||||
var username = useTwitchNames ? $.username.resolve(target) : target;
|
||||
$.say($.lang.get('quotesystem.add.success', username, saveQuote(String(username), quote)));
|
||||
$.log.event(sender + ' added a quote "' + quote + '".');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* USED BY THE PANEL
|
||||
*/
|
||||
if (command.equalsIgnoreCase('addquotesilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
quote = args.splice(0).join(' ');
|
||||
saveQuote(String($.username.resolve(sender)), quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath delquote [quoteId] - Delete a quote
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delquote')) {
|
||||
if (!args[0] || isNaN(args[0])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.del.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var newCount;
|
||||
|
||||
if ((newCount = deleteQuote(args[0])) >= 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.del.success', args[0], newCount));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.del.404', args[0]));
|
||||
}
|
||||
|
||||
$.log.event(sender + ' removed quote with id: ' + args[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* USED BY THE PANEL
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delquotesilent')) {
|
||||
if (!$.isBot(sender)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var newCount;
|
||||
|
||||
if ((newCount = deleteQuote(args[0])) >= 0) {} else {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath quote [quoteId] - Announce a quote by its Id, omit the id parameter to get a random quote
|
||||
*/
|
||||
if (command.equalsIgnoreCase('quote')) {
|
||||
quote = getQuote(args[0]);
|
||||
if (quote.length > 0) {
|
||||
quoteStr = ($.inidb.exists('settings', 'quoteMessage') ? $.inidb.get('settings', 'quoteMessage') : $.lang.get('quotesystem.get.success'));
|
||||
quoteStr = quoteStr.replace('(id)', (quote.length == 5 ? quote[4].toString() : quote[3].toString())).
|
||||
replace('(quote)', quote[1]).
|
||||
replace('(user)', $.resolveRank(quote[0])).
|
||||
replace('(game)', (quote.length == 5 ? quote[3] : "Some Game")).
|
||||
replace('(date)', $.getLocalTimeString('dd-MM-yyyy', parseInt(quote[2])));
|
||||
$.say(quoteStr);
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.get.404', (typeof args[0] != 'undefined' ? args[0] : '')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath quotemessage [message] - Sets the quote string with tags: (id) (quote) (user) (game) (date)
|
||||
*/
|
||||
if (command.equalsIgnoreCase('quotemessage')) {
|
||||
if (!args[0]) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.quotemessage.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
quoteStr = args.splice(0).join(' ');
|
||||
$.inidb.set('settings', 'quoteMessage', quoteStr);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.quotemessage.success'));
|
||||
$.log.event(sender + ' changed the quote message to: ' + quoteStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath searchquote [string] - Searches the quotes for a string and returns a list of IDs
|
||||
*/
|
||||
if (command.equalsIgnoreCase('searchquote')) {
|
||||
if (!args[0]) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.searchquote.usage'));
|
||||
return;
|
||||
}
|
||||
var searchString = args.join(' ');
|
||||
if (searchString.length < 5) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.searchquote.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var matchingKeys = $.inidb.searchByValue('quotes', searchString);
|
||||
if (matchingKeys.length == 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.searchquote.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.searchquote.found', matchingKeys.join(', ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath quotetwitchnamestoggle - Toggles on and off if quote names need to have been seen in chat before
|
||||
*/
|
||||
if (command.equalsIgnoreCase('quotetwitchnamestoggle')) {
|
||||
var useTwitchNames = $.inidb.get('settings', 'quoteTwitchNamesToggle') == "true";
|
||||
if (useTwitchNames) {
|
||||
useTwitchNames = false;
|
||||
$.inidb.set('settings', 'quoteTwitchNamesToggle', 'false');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.twitchnames-disabled'));
|
||||
} else {
|
||||
useTwitchNames = true;
|
||||
$.inidb.set('settings', 'quoteTwitchNamesToggle', 'true');
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('quotesystem.twitchnames-enabled'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'quotemodetoggle', 2);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'searchquote', 7);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'addquote', 2);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'addquotesilent', 1);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'delquote', 2);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'delquotesilent', 1);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'editquote', 2);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'quote');
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'quotemessage', 1);
|
||||
$.registerChatCommand('./systems/quoteSystem.js', 'quotetwitchnamestoggle', 1);
|
||||
});
|
||||
})();
|
||||
516
libs/phantombot/scripts/systems/raffleSystem.js
Normal file
516
libs/phantombot/scripts/systems/raffleSystem.js
Normal file
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* raffleSystem.js made for giveaways on Twitch
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var entries = [],
|
||||
entered = [],
|
||||
keyword = '',
|
||||
entryFee = 0,
|
||||
timerTime = 0,
|
||||
followers = false,
|
||||
subscribers = false,
|
||||
usePoints = true,
|
||||
status = false,
|
||||
sendMessages = $.getSetIniDbBoolean('raffleSettings', 'raffleMSGToggle', false),
|
||||
whisperWinner = $.getSetIniDbBoolean('raffleSettings', 'raffleWhisperWinner', false),
|
||||
allowRepick = $.getSetIniDbBoolean('raffleSettings', 'noRepickSame', true),
|
||||
raffleMessage = $.getSetIniDbString('raffleSettings', 'raffleMessage', 'A raffle is still opened! Type (keyword) to enter. (entries) users have entered so far.'),
|
||||
messageInterval = $.getSetIniDbNumber('raffleSettings', 'raffleMessageInterval', 0),
|
||||
subscriberBonus = $.getSetIniDbNumber('raffleSettings', 'subscriberBonusRaffle', 1),
|
||||
regularBonus = $.getSetIniDbNumber('raffleSettings', 'regularBonusRaffle', 1),
|
||||
interval, timeout, followMessage = '',
|
||||
timerMessage = '';
|
||||
|
||||
/**
|
||||
* @function reloadRaffle
|
||||
* @info used for the panel.
|
||||
*/
|
||||
function reloadRaffle() {
|
||||
sendMessages = $.getIniDbBoolean('raffleSettings', 'raffleMSGToggle');
|
||||
allowRepick = $.getIniDbBoolean('raffleSettings', 'noRepickSame');
|
||||
whisperWinner = $.getIniDbBoolean('raffleSettings', 'raffleWhisperWinner');
|
||||
raffleMessage = $.getIniDbString('raffleSettings', 'raffleMessage');
|
||||
messageInterval = $.getIniDbNumber('raffleSettings', 'raffleMessageInterval');
|
||||
subscriberBonus = $.getIniDbNumber('raffleSettings', 'subscriberBonusRaffle');
|
||||
regularBonus = $.getIniDbNumber('raffleSettings', 'regularBonusRaffle');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function open
|
||||
* @info opens a raffle
|
||||
*
|
||||
* @param {string} username
|
||||
* @param {arguments} arguments
|
||||
*/
|
||||
function open(username, arguments) {
|
||||
var args,
|
||||
i = 1;
|
||||
|
||||
/* Check if there's a raffle already opened */
|
||||
if (status) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('rafflesystem.open.error.opened'));
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
/* Check if the caster wants to use time or points for the raffle */
|
||||
if (arguments.match('-usetime')) {
|
||||
usePoints = false;
|
||||
arguments = arguments.replace('-usetime ', '');
|
||||
} else if (arguments.match('-usepoints')) {
|
||||
arguments = arguments.replace('-usepoints ', '');
|
||||
usePoints = true;
|
||||
} else {
|
||||
usePoints = null;
|
||||
}
|
||||
|
||||
/* Check if the caster wants the raffle to be for followers only or not */
|
||||
if (arguments.match('-followers')) {
|
||||
followers = true;
|
||||
followMessage = ' ' + $.lang.get('rafflesystem.common.following');
|
||||
}
|
||||
|
||||
/* Check if the caster wants the raffle to be for susbcribers only or not */
|
||||
if (arguments.match('-subscribers')) {
|
||||
subscribers = true;
|
||||
}
|
||||
|
||||
/* Now split the arguments string up as we could have removed some items. */
|
||||
args = arguments.split(' ');
|
||||
|
||||
/* Check the entry fee of points, or the minimum time */
|
||||
if (!isNaN(parseInt(args[i])) && usePoints !== null) {
|
||||
if (usePoints) {
|
||||
entryFee = parseInt(args[i]);
|
||||
} else {
|
||||
entryFee = (parseInt(args[i]) * 60);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Check for the keyword */
|
||||
if (args[i] !== undefined) {
|
||||
keyword = args[i].toLowerCase();
|
||||
i++;
|
||||
|
||||
if (keyword.startsWith('!')) {
|
||||
keyword = ('!' + keyword.match(/(!+)(.+)/)[2]);
|
||||
}
|
||||
|
||||
/* Ensure that keyword is not already a registered command. */
|
||||
if (keyword.startsWith('!') && $.commandExists(keyword.substring(1))) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('rafflesystem.open.keyword-exists', keyword));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('rafflesystem.open.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Check if the caster wants a auto close timer */
|
||||
if (!isNaN(parseInt(args[i])) && parseInt(args[i]) !== 0) {
|
||||
timerTime = parseInt(args[i]);
|
||||
timeout = setTimeout(function() {
|
||||
close();
|
||||
}, (timerTime * 6e4));
|
||||
timerMessage = $.lang.get('rafflesystem.common.timer', timerTime);
|
||||
}
|
||||
|
||||
/* Say in chat that the raffle is now opened. */
|
||||
if (!usePoints && usePoints !== null) {
|
||||
$.say($.lang.get('rafflesystem.open.time', keyword, Math.floor(entryFee / 60), followMessage, timerMessage));
|
||||
} else if (usePoints && entryFee !== 0) {
|
||||
$.say($.lang.get('rafflesystem.open.points', keyword, $.getPointsString(entryFee) + followMessage, timerMessage));
|
||||
} else {
|
||||
$.say($.lang.get('rafflesystem.open', keyword, followMessage, timerMessage));
|
||||
}
|
||||
|
||||
if (parseInt(messageInterval) !== 0) {
|
||||
interval = setInterval(function() {
|
||||
$.say(raffleMessage.replace('(keyword)', keyword).replace('(entries)', String(Object.keys(entered).length)));
|
||||
}, messageInterval * 6e4);
|
||||
}
|
||||
|
||||
/* Clear the old raffle data */
|
||||
entries = [];
|
||||
$.raffleCommand = keyword;
|
||||
$.inidb.RemoveFile('raffleList');
|
||||
$.inidb.set('raffleresults', 'raffleEntries', 0);
|
||||
// Mark the raffle as on for the panel.
|
||||
$.inidb.set('raffleSettings', 'isActive', 'true');
|
||||
|
||||
/* Mark the raffle as opened */
|
||||
status = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function close
|
||||
* @info closes the raffle
|
||||
*
|
||||
* @param {string} username
|
||||
*/
|
||||
function close(username) {
|
||||
/* Clear the timer if there is one active. */
|
||||
clearInterval(timeout);
|
||||
clearInterval(interval);
|
||||
|
||||
/* Check if there's a raffle opened */
|
||||
if (!status) {
|
||||
$.say($.whisperPrefix(username) + $.lang.get('rafflesystem.close.error.closed'));
|
||||
return;
|
||||
}
|
||||
|
||||
status = false;
|
||||
|
||||
$.say($.lang.get('rafflesystem.close.success'));
|
||||
|
||||
// Mark the raffle as off for the panel.
|
||||
$.inidb.set('raffleSettings', 'isActive', 'false');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function winner
|
||||
* @info chooses a winner for the raffle
|
||||
*/
|
||||
function draw(sender) {
|
||||
/* Check if anyone entered the raffle */
|
||||
if (entries.length === 0) {
|
||||
$.say($.lang.get('rafflesystem.winner.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
var username = $.randElement(entries),
|
||||
isFollowing = $.user.isFollower(username.toLowerCase()),
|
||||
followMsg = (isFollowing ? $.lang.get('rafflesystem.isfollowing') : $.lang.get('rafflesystem.isnotfollowing'));
|
||||
|
||||
$.say($.lang.get('rafflesystem.winner', username, followMsg));
|
||||
$.inidb.set('raffleresults', 'winner', username + ' ' + followMsg);
|
||||
|
||||
/* whisper the winner if the toggle is on */
|
||||
if (whisperWinner && isFollowing) {
|
||||
$.say($.whisperPrefix(username, true) + $.lang.get('rafflesystem.whisper.winner', $.channelName));
|
||||
}
|
||||
|
||||
/* Remove the user from the array if we are not allowed to have multiple repicks. */
|
||||
if (allowRepick) {
|
||||
for (var i in entries) {
|
||||
if (entries[i].equalsIgnoreCase(username)) {
|
||||
entries.splice(i, 1);
|
||||
}
|
||||
}
|
||||
$.inidb.del('raffleList', username);
|
||||
$.inidb.decr('raffleresults', 'raffleEntries', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function message
|
||||
* @info messages that user if the raffle toggles are on
|
||||
*
|
||||
* @param {string} username
|
||||
* @param {string} message
|
||||
*/
|
||||
function message(username, message) {
|
||||
if (sendMessages) {
|
||||
$.say($.whisperPrefix(username) + message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function enter
|
||||
* @info enters the user into the raffle
|
||||
*
|
||||
* @param {string} username
|
||||
*/
|
||||
function enter(username, tags) {
|
||||
/* Check if the user already entered the raffle */
|
||||
if (entered[username] !== undefined) {
|
||||
message(username, $.lang.get('rafflesystem.enter.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if the user is a subscriber */
|
||||
if (subscribers && !$.isSubv3(username, tags)) {
|
||||
message(username, $.lang.get('rafflesystem.enter.subscriber'));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if the user is following the channel. */
|
||||
/*if (followers && !$.user.isFollower(username)) {
|
||||
message(username, $.lang.get('rafflesystem.enter.following'));
|
||||
return;
|
||||
}*/
|
||||
|
||||
/* Check the entry fee */
|
||||
if (entryFee > 0 && usePoints !== null) {
|
||||
/* If we are using points */
|
||||
if (usePoints) {
|
||||
if (entryFee > $.getUserPoints(username)) {
|
||||
message(username, $.lang.get('rafflesystem.enter.points', $.pointNameMultiple));
|
||||
return;
|
||||
} else {
|
||||
$.inidb.decr('points', username, entryFee);
|
||||
}
|
||||
} else {
|
||||
if (entryFee > $.getUserTime(username)) {
|
||||
message(username, $.lang.get('rafflesystem.enter.time'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Push the user into the array */
|
||||
entered[username] = true;
|
||||
entries.push(username);
|
||||
if (subscriberBonus > 0 && $.isSubv3(username, tags)) {
|
||||
for (var i = 0; i < subscriberBonus; i++) {
|
||||
entries.push(username);
|
||||
}
|
||||
} else if (regularBonus > 0 && $.isReg(username)) {
|
||||
for (var i = 0; i < regularBonus; i++) {
|
||||
entries.push(username);
|
||||
}
|
||||
}
|
||||
|
||||
/* Push the panel stats */
|
||||
$.inidb.set('raffleList', username, true);
|
||||
$.inidb.set('raffleresults', 'raffleEntries', Object.keys(entered).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function clear
|
||||
* @info resets the raffle information
|
||||
*/
|
||||
function clear() {
|
||||
/* Clear the timer if there is one active. */
|
||||
clearInterval(timeout);
|
||||
clearInterval(interval);
|
||||
keyword = '';
|
||||
followMessage = '';
|
||||
timerMessage = '';
|
||||
usePoints = false;
|
||||
followers = false;
|
||||
subscribers = false;
|
||||
status = false;
|
||||
entryFee = 0;
|
||||
timerTime = 0;
|
||||
entered = [];
|
||||
entries = [];
|
||||
$.raffleCommand = null;
|
||||
$.inidb.RemoveFile('raffleList');
|
||||
$.inidb.set('raffleresults', 'raffleEntries', 0);
|
||||
// Mark the raffle as off for the panel.
|
||||
$.inidb.set('raffleSettings', 'isActive', 'false');
|
||||
}
|
||||
|
||||
/**
|
||||
* @event ircChannelMessage
|
||||
*/
|
||||
$.bind('ircChannelMessage', function(event) {
|
||||
if (status === true && event.getMessage().equalsIgnoreCase(keyword)) {
|
||||
enter(event.getSender(), event.getTags());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
* @info handles the command event
|
||||
* @param {object} event
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('raffle')) {
|
||||
if (action === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle open [entry fee] [keyword] [close timer] [-usepoints / -usetime / -followers] - Opens a custom raffle.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
open(sender, arguments);
|
||||
$.log.event('A raffle was opened by: ' + sender + '. Arguments (' + arguments + ')');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle close - Closes the current raffle.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('close')) {
|
||||
close(sender);
|
||||
$.log.event('A raffle was closed by: ' + sender + '.');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle draw - Draws a winner from the current raffle list.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('draw')) {
|
||||
draw(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle reset - Resets the raffle.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('reset')) {
|
||||
clear();
|
||||
if (sender != $.botName.toLowerCase()) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.reset'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle results - Give you the current raffle information if there is one active.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('results')) {
|
||||
if (status) {
|
||||
$.say($.lang.get('rafflesystem.results', keyword + (usePoints ? $.lang.get('rafflesystem.fee', $.getPointsString(entryFee)) : ''), Object.keys(entered).length))
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle subscriberbonus [1-10] - Sets the bonus luck for subscribers.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('subscriberbonus')) {
|
||||
if (subAction === undefined || isNaN(parseInt(subAction)) || parseInt(subAction) < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.subbonus.usage'));
|
||||
return;
|
||||
}
|
||||
subscriberBonus = parseInt(subAction);
|
||||
$.inidb.set('raffleSettings', 'subscriberBonusRaffle', subscriberBonus);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.subbonus.set', subscriberBonus));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle regularbonus [1-10] - Sets the bonus luck for regulars.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('regularbonus')) {
|
||||
if (subAction === undefined || isNaN(parseInt(subAction)) || parseInt(subAction) < 1) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.regbonus.usage'));
|
||||
return;
|
||||
}
|
||||
regularBonus = parseInt(subAction);
|
||||
$.inidb.set('raffleSettings', 'regularBonusRaffle', regularBonus);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.regbonus.set', regularBonus));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle whisperwinner - Toggles if the raffle winner gets a whisper from the bot saying he won.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('whisperwinner')) {
|
||||
whisperWinner = !whisperWinner;
|
||||
$.inidb.set('raffleSettings', 'raffleWhisperWinner', whisperWinner);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.whisper.winner.toggle', (whisperWinner ? '' : $.lang.get('rafflesystem.common.message'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle togglewarningmessages - Toggles the raffle warning messages when entering.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglewarningmessages')) {
|
||||
sendMessages = !sendMessages;
|
||||
$.inidb.set('raffleSettings', 'raffleMSGToggle', sendMessages);
|
||||
$.say($.whisperPrefix(sender) + 'Raffle warning messages have been ' + (sendMessages ? $.lang.get('common.enabled') : $.lang.get('common.disabled')) + '.');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle togglerepicks - Toggles if the same winner can be repicked more than one.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglerepicks')) {
|
||||
allowRepick = !allowRepick;
|
||||
$.inidb.set('raffleSettings', 'noRepickSame', allowRepick);
|
||||
$.say($.whisperPrefix(sender) + (allowRepick ? $.lang.get('rafflesystem.raffle.repick.toggle1') : $.lang.get('rafflesystem.raffle.repick.toggle2')));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle message [message] - Sets the raffle auto annouce messages saying that raffle is still active.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raffleMessage = arguments.substring(action.length() + 1);
|
||||
$.inidb.set('raffleSettings', 'raffleMessage', raffleMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.message.set', raffleMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath raffle messagetimer [minutes] - Sets the raffle auto annouce messages interval. 0 is disabled.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('messagetimer')) {
|
||||
if (subAction === undefined || isNaN(parseInt(subAction))) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.timer.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
messageInterval = parseInt(subAction);
|
||||
$.inidb.set('raffleSettings', 'raffleMessageInterval', messageInterval);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.timer.set', messageInterval));
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
* @info event sent to register commands
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/raffleSystem.js', 'raffle', 2);
|
||||
|
||||
$.registerChatSubcommand('raffle', 'open', 2);
|
||||
$.registerChatSubcommand('raffle', 'close', 2);
|
||||
$.registerChatSubcommand('raffle', 'draw', 2);
|
||||
$.registerChatSubcommand('raffle', 'reset', 2);
|
||||
$.registerChatSubcommand('raffle', 'results', 7);
|
||||
$.registerChatSubcommand('raffle', 'subscriberbonus', 1);
|
||||
$.registerChatSubcommand('raffle', 'regularbonus', 1);
|
||||
$.registerChatSubcommand('raffle', 'togglemessages', 1);
|
||||
$.registerChatSubcommand('raffle', 'togglerepicks', 1);
|
||||
$.registerChatSubcommand('raffle', 'message', 1);
|
||||
$.registerChatSubcommand('raffle', 'messagetimer', 1);
|
||||
|
||||
// Mark the raffle as off for the panel.
|
||||
$.inidb.set('raffleSettings', 'isActive', 'false');
|
||||
$.inidb.set('raffleresults', 'raffleEntries', 0);
|
||||
$.inidb.RemoveFile('raffleList');
|
||||
});
|
||||
|
||||
$.reloadRaffle = reloadRaffle;
|
||||
})();
|
||||
419
libs/phantombot/scripts/systems/ranksSystem.js
Normal file
419
libs/phantombot/scripts/systems/ranksSystem.js
Normal file
@@ -0,0 +1,419 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides for a configurable rank system with various different configurable ranks
|
||||
* based on time spent in the channel. This is just aesthetic but could, in theory,
|
||||
* be used for other purposes if really desired.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var rankEligableTime = $.getSetIniDbNumber('settings', 'rankEligableTime', 50),
|
||||
rankEligableCost = $.getSetIniDbNumber('settings', 'rankEligableCost', 200),
|
||||
time,
|
||||
ranksTimeTable;
|
||||
|
||||
/**
|
||||
* @function sortCompare
|
||||
* Callback function for sorting the ranksMapping table.
|
||||
*/
|
||||
function sortCompare(a, b) {
|
||||
var numA = parseInt(a),
|
||||
numB = parseInt(b);
|
||||
|
||||
if (numA > numB) {
|
||||
return 1;
|
||||
} else if (numA == numB) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadRanksTimeTable
|
||||
* Loads the time portion of the ranksMapping table into local memory and sorts it.
|
||||
* The table is then used to map to the rank that a person belongs to.
|
||||
*/
|
||||
function loadRanksTimeTable() {
|
||||
ranksTimeTable = $.inidb.GetKeyList('ranksMapping', '');
|
||||
ranksTimeTable.sort(sortCompare);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function hasRank
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {int} time (optional) Time for the user in seconds. If not set, read from the DB.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasRank(username) {
|
||||
var userTime;
|
||||
|
||||
username = username.toLowerCase();
|
||||
|
||||
// Has a custom rank.
|
||||
if ($.inidb.exists('viewerRanks', username.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Look for data in the ranksMapping table, if none, the user has no rank, else, has a rank.
|
||||
if (ranksTimeTable === undefined) {
|
||||
loadRanksTimeTable();
|
||||
}
|
||||
if (ranksTimeTable.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (time === undefined) {
|
||||
time = parseInt($.inidb.get('time', username));
|
||||
}
|
||||
userTime = parseInt(time / 3600);
|
||||
if (isNaN(userTime)) {
|
||||
userTime = 0;
|
||||
}
|
||||
for (var i = 0; i < ranksTimeTable.length; i++) {
|
||||
if (parseInt(userTime) >= parseInt(ranksTimeTable[i])) {
|
||||
return true;
|
||||
} else {
|
||||
i = ranksTimeTable.length;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getRank
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {int} time (optional) Time for the user in seconds. If not set, read from the DB.
|
||||
* @returns {string}
|
||||
*/
|
||||
function getRank(username, time) {
|
||||
var userTime,
|
||||
userLevel;
|
||||
|
||||
username = username.toLowerCase();
|
||||
|
||||
if (!hasRank(username, time)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Return Custom Rank
|
||||
if ($.inidb.exists('viewerRanks', username.toLowerCase())) {
|
||||
return $.inidb.get('viewerRanks', username.toLowerCase());
|
||||
}
|
||||
|
||||
// Return System Rank
|
||||
userLevel = -1;
|
||||
if (time === undefined) {
|
||||
time = parseInt($.inidb.get('time', username));
|
||||
}
|
||||
userTime = parseInt(time / 3600);
|
||||
if (isNaN(userTime)) {
|
||||
userTime = 0;
|
||||
}
|
||||
for (var i = 0; i < ranksTimeTable.length; i++) {
|
||||
if (parseInt(userTime) >= parseInt(ranksTimeTable[i])) {
|
||||
userLevel = i;
|
||||
} else {
|
||||
i = ranksTimeTable.length;
|
||||
}
|
||||
}
|
||||
if (userLevel != -1) {
|
||||
return $.inidb.get('ranksMapping', ranksTimeTable[userLevel].toString());
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @function resolveRank
|
||||
* @export $
|
||||
* @param {string} username
|
||||
* @param {boolean} resolveName
|
||||
* @returns {string}
|
||||
*/
|
||||
function resolveRank(username) {
|
||||
return (getRank(username.toLowerCase()) + ' ' + ($.username.hasUser(username) == true ? $.username.get(username) : username)).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
sender = event.getSender().toLowerCase(),
|
||||
username = $.username.resolve(sender),
|
||||
levelTime,
|
||||
levelName,
|
||||
userTime = parseInt(parseInt($.inidb.get('time', sender)) / 3600),
|
||||
rankEligableTime = $.getIniDbNumber('settings', 'rankEligableTime', 50),
|
||||
rankEligableCost = $.getIniDbNumber('settings', 'rankEligableCost', 200),
|
||||
userLevel,
|
||||
timeUntilNextRank,
|
||||
nextLevel,
|
||||
isReplace,
|
||||
customUser,
|
||||
customRank;
|
||||
|
||||
if (isNaN(userTime)) {
|
||||
userTime = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @commandpath rankedit - Displays the usage of rankedit.
|
||||
* @commandpath rankedit add [time] [rankname] - Add a new rank. Time is in hours.
|
||||
* @commandpath rankedit del [time] - Deletes the rank associated with the given time
|
||||
* @commandpath rankedit custom [user] [rankname] - Add a custom rank to a user.
|
||||
* @commandpath rankedit customdel [user] - Remove a custom rank from a user.
|
||||
* @commandpath rankedit settime [time] - Number of minimum hours before user can choose custom rank.
|
||||
* @commandpath rankedit setcost [points] - Cost of custom rank.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('rankedit')) {
|
||||
if (!args[0]) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.edit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('settime')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.settime.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.settime.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
rankEligableTime = parseInt(args[1]);
|
||||
$.inidb.set('settings', 'rankEligableTime', rankEligableTime);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.settime.success', rankEligableTime));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('setcost')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.setcost.usage', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.setcost.usage', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
rankEligableCost = parseInt(args[1]);
|
||||
$.inidb.set('settings', 'rankEligableCost', rankEligableCost);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.setcost.success', rankEligableCost, $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('custom')) {
|
||||
if (args.length < 3) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.custom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
customUser = args[1];
|
||||
customRank = args.splice(2).join(' ');
|
||||
|
||||
if (!$.inidb.exists('time', customUser.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.custom.404', customUser));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('viewerRanks', customUser.toLowerCase(), customRank);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.custom.success', $.username.resolve(customUser), customRank));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('customdel')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.customdel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
customUser = args[1];
|
||||
|
||||
if (!$.inidb.exists('viewerRanks', customUser.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.customdel.404', customUser));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('viewerRanks', customUser.toLowerCase());
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.customdel.success', $.username.resolve(customUser)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('add')) {
|
||||
if (args.length < 3) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.add.usage'));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
levelTime = args[1];
|
||||
levelName = args.splice(2).join(' ');
|
||||
|
||||
isReplace = $.inidb.exists('ranksMapping', levelTime);
|
||||
$.inidb.set('ranksMapping', levelTime, levelName);
|
||||
if (isReplace) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.add.success-update', levelTime, levelName));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.add.success-new', levelTime, levelName));
|
||||
}
|
||||
|
||||
if (!isReplace) {
|
||||
loadRanksTimeTable();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('del')) {
|
||||
if (args.length < 2) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.del.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('ranksMapping', args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.del.404', args[1]));
|
||||
} else {
|
||||
$.inidb.del('ranksMapping', args[1]);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.del.success', args[1]));
|
||||
loadRanksTimeTable();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath rank - Display current rank.
|
||||
* @commandpath rank set [rankname] - Set rank for self if enough hours and points, if applicable, available in chat.
|
||||
* @commandpath rank del - Deletes customized rank.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('rank')) {
|
||||
if (args[0]) {
|
||||
if (args[0].equalsIgnoreCase('del')) {
|
||||
if (inidb.exists('viewerRanks', sender.toLowerCase())) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.delself.success'));
|
||||
$.inidb.del('viewerRanks', sender.toLowerCase());
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.delself.404'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase('set')) {
|
||||
if (!args[1]) {
|
||||
if ($.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.set.usage', rankEligableTime, rankEligableCost, $.pointNameMultiple));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.set.usage.nopoints', rankEligableTime));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
customRank = args.splice(1).join(' ');
|
||||
|
||||
if (userTime >= rankEligableTime &&
|
||||
($.bot.isModuleEnabled('./systems/pointSystem.js') && $.getUserPoints(sender) > rankEligableCost) || !$.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.set.success', customRank));
|
||||
$.inidb.set('viewerRanks', sender.toLowerCase(), customRank);
|
||||
if ($.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
$.inidb.decr('points', sender.toLowerCase(), rankEligableCost);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.bot.isModuleEnabled('./systems/pointSystem.js')) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.set.failure', rankEligableTime, $.pointNameMultiple, rankEligableCost));
|
||||
} else {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.set.failure.nopoints', rankEligableTime));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($.inidb.exists('viewerRanks', username.toLowerCase())) {
|
||||
$.say($.lang.get('ranks.rank.customsuccess', username, $.inidb.get('viewerRanks', username.toLowerCase())));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ranksTimeTable === undefined) {
|
||||
loadRanksTimeTable();
|
||||
}
|
||||
if (ranksTimeTable.length == 0) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ranks.rank.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
userLevel = -1;
|
||||
for (var i = 0; i < ranksTimeTable.length; i++) {
|
||||
if (parseInt(userTime) >= parseInt(ranksTimeTable[i])) {
|
||||
userLevel = i;
|
||||
} else {
|
||||
i = ranksTimeTable.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (userLevel <= ranksTimeTable.length - 2) {
|
||||
nextLevel = parseInt(userLevel) + 1;
|
||||
timeUntilNextRank = parseInt(ranksTimeTable[nextLevel]) - userTime;
|
||||
if (userLevel == -1) {
|
||||
$.say($.lang.get('ranks.rank.norank.success', username, timeUntilNextRank, $.inidb.get('ranksMapping', ranksTimeTable[nextLevel].toString())));
|
||||
} else {
|
||||
$.say($.lang.get('ranks.rank.success', username, $.inidb.get('ranksMapping', ranksTimeTable[userLevel].toString()), timeUntilNextRank, $.inidb.get('ranksMapping', ranksTimeTable[nextLevel].toString())));
|
||||
}
|
||||
} else {
|
||||
$.say($.lang.get('ranks.rank.maxsuccess', username, $.inidb.get('ranksMapping', ranksTimeTable[userLevel].toString())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/ranksSystem.js', 'rank', 7);
|
||||
$.registerChatCommand('./systems/ranksSystem.js', 'rankedit', 1);
|
||||
|
||||
$.registerChatSubcommand('rankedit', 'add', 1);
|
||||
$.registerChatSubcommand('rankedit', 'del', 1);
|
||||
$.registerChatSubcommand('rankedit', 'custom', 1);
|
||||
$.registerChatSubcommand('rankedit', 'customdel', 1);
|
||||
|
||||
$.registerChatSubcommand('rank', 'set', 7);
|
||||
$.registerChatSubcommand('rank', 'del', 7);
|
||||
});
|
||||
|
||||
/**
|
||||
* Export functions to API
|
||||
*/
|
||||
$.resolveRank = resolveRank;
|
||||
$.getRank = getRank;
|
||||
$.hasRank = hasRank;
|
||||
$.loadRanksTimeTable = loadRanksTimeTable;
|
||||
})();
|
||||
346
libs/phantombot/scripts/systems/ticketraffleSystem.js
Normal file
346
libs/phantombot/scripts/systems/ticketraffleSystem.js
Normal file
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* 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 cost = 0,
|
||||
entries = [],
|
||||
subTMulti = 1,
|
||||
regTMulti = 1,
|
||||
maxEntries = 0,
|
||||
followers = false,
|
||||
raffleStatus = false,
|
||||
msgToggle = $.getSetIniDbBoolean('settings', 'tRaffleMSGToggle', false),
|
||||
raffleMessage = $.getSetIniDbString('settings', 'traffleMessage', 'A raffle is still opened! Type !tickets (amount) to enter. (entries) users have entered so far.'),
|
||||
messageInterval = $.getSetIniDbNumber('settings', 'traffleMessageInterval', 0),
|
||||
totalEntries = 0,
|
||||
lastTotalEntries = 0,
|
||||
totalTickets = 0,
|
||||
a = '',
|
||||
interval;
|
||||
|
||||
function reloadTRaffle() {
|
||||
msgToggle = $.getIniDbBoolean('settings', 'tRaffleMSGToggle');
|
||||
raffleMessage = $.getSetIniDbString('settings', 'traffleMessage');
|
||||
messageInterval = $.getSetIniDbNumber('settings', 'traffleMessageInterval');
|
||||
}
|
||||
|
||||
function checkArgs(user, max, regMulti, subMulti, price, followersOnly) {
|
||||
if (raffleStatus) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.err.raffle.opened'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!max) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.err.missing.syntax'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNaN(parseInt(max)) || isNaN(parseInt(price))) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (max) {
|
||||
maxEntries = parseInt(max);
|
||||
}
|
||||
|
||||
if (price) {
|
||||
cost = parseInt(price);
|
||||
}
|
||||
|
||||
if (regMulti) {
|
||||
regTMulti = (parseInt(regMulti) < 1 ? 1 : parseInt(regMulti));
|
||||
}
|
||||
|
||||
if (subMulti) {
|
||||
subTMulti = (parseInt(subMulti) < 1 ? 1 : parseInt(subMulti));
|
||||
}
|
||||
|
||||
if (followersOnly && followersOnly.equalsIgnoreCase('-followers')) {
|
||||
followers = true;
|
||||
a = $.lang.get('ticketrafflesystem.msg.need.to.be.follwing');
|
||||
}
|
||||
openRaffle(maxEntries, followers, cost, a, user);
|
||||
};
|
||||
|
||||
function openRaffle(maxEntries, followers, cost, a, user) {
|
||||
$.say($.lang.get('ticketrafflesystem.raffle.opened', maxEntries, $.getPointsString(cost), a));
|
||||
raffleStatus = true;
|
||||
$.inidb.RemoveFile('ticketsList');
|
||||
$.inidb.RemoveFile('entered');
|
||||
$.inidb.set('raffleresults', 'ticketRaffleEntries', 0);
|
||||
entries = "";
|
||||
entries = [];
|
||||
|
||||
if (messageInterval != 0) {
|
||||
interval = setInterval(function() {
|
||||
$.say(raffleMessage.replace('(entries)', String(totalEntries))); //can't use regex here. why? who knows.
|
||||
}, messageInterval * 6e4);
|
||||
}
|
||||
|
||||
$.log.event(user + ' opened a ticket raffle.');
|
||||
$.inidb.set('traffleSettings', 'isActive', 'true');
|
||||
};
|
||||
|
||||
function closeRaffle(user) {
|
||||
if (!raffleStatus) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.err.raffle.not.opened'));
|
||||
return;
|
||||
}
|
||||
|
||||
clear();
|
||||
|
||||
$.say($.lang.get('ticketrafflesystem.raffle.closed'));
|
||||
$.log.event(user + ' closed a ticket raffle.');
|
||||
};
|
||||
|
||||
function clear() {
|
||||
clearInterval(interval);
|
||||
|
||||
raffleStatus = false;
|
||||
followers = false;
|
||||
maxEntries = 0;
|
||||
cost = 0;
|
||||
a = '';
|
||||
totalEntries = 0;
|
||||
lastTotalEntries = 0;
|
||||
totalTickets = 0;
|
||||
regTMulti = 1;
|
||||
subTMulti = 1;
|
||||
$.inidb.set('traffleSettings', 'isActive', 'false');
|
||||
};
|
||||
|
||||
function winner(force) {
|
||||
if (entries.length == 0) {
|
||||
$.say($.lang.get('ticketrafflesystem.raffle.close.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
var Winner = $.randElement(entries),
|
||||
isFollowing = $.user.isFollower(Winner.toLowerCase()),
|
||||
followMsg = (isFollowing ? $.lang.get('rafflesystem.isfollowing') : $.lang.get('rafflesystem.isnotfollowing'));
|
||||
|
||||
$.say($.lang.get('ticketrafflesystem.winner', $.username.resolve(Winner), followMsg));
|
||||
$.inidb.set('traffleresults', 'winner', $.username.resolve(Winner) + ' ' + followMsg);
|
||||
$.log.event('Winner of the ticket raffle was ' + Winner);
|
||||
};
|
||||
|
||||
function enterRaffle(user, tags, times) {
|
||||
if (!raffleStatus) {
|
||||
if (msgToggle) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.err.raffle.not.opened'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var otimes = times;
|
||||
if (tags.getTags().containsKey('subscriber') && tags.getTags().get('subscriber').equals('1')) {
|
||||
times *= subTMulti;
|
||||
} else if ($.isReg(user)) {
|
||||
times *= regTMulti;
|
||||
}
|
||||
|
||||
if (times > maxEntries || times == 0 || times < 0) {
|
||||
if (msgToggle) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.only.buy.amount', maxEntries));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0, t = 0; i < entries.length; i++) {
|
||||
if (entries[i].equalsIgnoreCase(user)) {
|
||||
t++;
|
||||
if ((t + times) > maxEntries) {
|
||||
if (msgToggle) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.limit.hit', maxEntries));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cost > 0) {
|
||||
if ((otimes * cost) > $.getUserPoints(user)) {
|
||||
if (msgToggle) {
|
||||
$.say($.whisperPrefix(user) + $.lang.get('ticketrafflesystem.err.points', $.pointNameMultiple));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('entered', user.toLowerCase())) {
|
||||
totalEntries++;
|
||||
}
|
||||
|
||||
totalTickets += times;
|
||||
$.inidb.decr('points', user, (otimes * cost));
|
||||
incr(user.toLowerCase(), times);
|
||||
|
||||
for (var i = 0; i < times; i++) {
|
||||
entries.push(user);
|
||||
}
|
||||
};
|
||||
|
||||
function incr(user, times) {
|
||||
if (!$.inidb.exists('entered', user.toLowerCase())) {
|
||||
$.inidb.set('entered', user.toLowerCase(), 'true');
|
||||
$.inidb.incr('raffleresults', 'ticketRaffleEntries', 1);
|
||||
}
|
||||
$.inidb.incr('ticketsList', user.toLowerCase(), times);
|
||||
}
|
||||
|
||||
function getTickets(user) {
|
||||
if (!$.inidb.exists('ticketsList', user.toLowerCase())) {
|
||||
return 0;
|
||||
}
|
||||
return $.inidb.get('ticketsList', user.toLowerCase());
|
||||
};
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
argString = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath traffle [option] - Displays usage for the command
|
||||
*/
|
||||
if (command.equalsIgnoreCase('traffle')) {
|
||||
if (!action) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle open [max entries] [regular ticket multiplier (default = 1)] [subscriber ticket multiplier (default = 1)] [cost] [-followers] - Opens a ticket raffle. -followers is optional.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('open')) {
|
||||
if (args[4] === undefined) {
|
||||
checkArgs(sender, args[1], args[2], 1, 1, args[3]);
|
||||
} else {
|
||||
checkArgs(sender, args[1], args[2], args[3], args[4], args[5]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle close - Closes a ticket raffle.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('close')) {
|
||||
closeRaffle(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle draw - Picks a winner for the ticket raffle
|
||||
*/
|
||||
if (action.equalsIgnoreCase('draw')) {
|
||||
winner();
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle reset - Resets the raffle.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('reset')) {
|
||||
clear();
|
||||
$.inidb.RemoveFile('ticketsList');
|
||||
$.inidb.RemoveFile('entered');
|
||||
$.inidb.set('raffleresults', 'ticketRaffleEntries', 0);
|
||||
entries = [];
|
||||
if (sender != $.botName.toLowerCase()) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.reset'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle messagetoggle - Toggles on and off a message when entering a ticket raffle
|
||||
*/
|
||||
if (action.equalsIgnoreCase('messagetoggle')) {
|
||||
if (msgToggle) {
|
||||
msgToggle = false;
|
||||
$.inidb.set('settings', 'tRaffleMSGToggle', msgToggle);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.msg.disabled'));
|
||||
} else {
|
||||
msgToggle = true;
|
||||
$.inidb.set('settings', 'tRaffleMSGToggle', msgToggle);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.msg.enabled'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle autoannouncemessage [message] - Sets the auto annouce message for when a raffle is opened
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autoannouncemessage')) {
|
||||
if (!args[1]) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.auto.msg.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
raffleMessage = argString.replace(action, '').trim();
|
||||
$.inidb.set('settings', 'traffleMessage', raffleMessage);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.auto.msg.set', raffleMessage));
|
||||
$.log.event(sender + ' changed the auto annouce message to ' + raffleMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath traffle autoannounceinterval [minutes] - Sets the auto annouce message interval. Use 0 to disable it
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autoannounceinterval')) {
|
||||
if (!parseInt(args[1])) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('rafflesystem.auto.msginterval.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
messageInterval = parseInt(args[1]);
|
||||
$.inidb.set('settings', 'traffleMessageInterval', messageInterval);
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.auto.msginterval.set', messageInterval));
|
||||
$.log.event(sender + ' changed the auto annouce interval to ' + messageInterval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @commandpath tickets [amount] - Buy tickets to enter the ticket raffle.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('tickets') || command.equalsIgnoreCase('ticket')) {
|
||||
if (!action) {
|
||||
if (msgToggle && raffleStatus) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('ticketrafflesystem.ticket.usage', getTickets(sender)));
|
||||
}
|
||||
return;
|
||||
}
|
||||
enterRaffle(sender, event, parseInt(action));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.registerChatCommand('./systems/ticketraffleSystem.js', 'traffle', 2);
|
||||
$.registerChatCommand('./systems/ticketraffleSystem.js', 'tickets', 7);
|
||||
$.registerChatCommand('./systems/ticketraffleSystem.js', 'ticket', 7);
|
||||
|
||||
$.inidb.set('traffleSettings', 'isActive', 'false');
|
||||
$.inidb.set('raffleresults', 'ticketRaffleEntries', 0);
|
||||
$.inidb.RemoveFile('ticketsList');
|
||||
$.inidb.RemoveFile('entered');
|
||||
});
|
||||
|
||||
$.reloadTRaffle = reloadTRaffle;
|
||||
})();
|
||||
2105
libs/phantombot/scripts/systems/youtubePlayer.js
Normal file
2105
libs/phantombot/scripts/systems/youtubePlayer.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user