init commit
This commit is contained in:
615
libs/phantombot/scripts/discord/commands/customCommands.js
Normal file
615
libs/phantombot/scripts/discord/commands/customCommands.js
Normal file
@@ -0,0 +1,615 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle custom commands for discord.
|
||||
*/
|
||||
(function() {
|
||||
var reCustomAPI = new RegExp(/\(customapi\s([\w\W:\/\$\=\?\&]+)\)/),
|
||||
reCustomAPIJson = new RegExp(/\(customapijson ([\w\.:\/\$=\?\&]+)\s([\w\W]+)\)/),
|
||||
reCustomArg = new RegExp(/\(([1-9])=([a-zA-Z1-9\)\(]+)\)/),
|
||||
reCustomToUserArg = new RegExp(/\(touser=([a-zA-Z1-9]+)\)/),
|
||||
reCustomAPITextTag = new RegExp(/{([\w\W]+)}/);
|
||||
|
||||
/**
|
||||
* @function getCustomAPIValue
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} url
|
||||
* @return {object}
|
||||
*/
|
||||
function getCustomAPIValue(url) {
|
||||
var HttpResponse = Packages.com.gmt2001.HttpResponse,
|
||||
HttpRequest = Packages.com.gmt2001.HttpRequest,
|
||||
HashMap = Packages.java.util.HashMap,
|
||||
responseData = HttpRequest.getData(HttpRequest.RequestType.GET, url, '', new HashMap());
|
||||
|
||||
return responseData.content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function tags
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {object} event
|
||||
* @param {string} s
|
||||
* @return {string}
|
||||
*/
|
||||
function tags(event, s) {
|
||||
if (s.match(reCustomArg)) {
|
||||
s = $.replace(s, s.match(reCustomArg)[0], (event.getArgs()[parseInt(s.match(reCustomArg)[1]) - 1] === undefined ? s.match(reCustomArg)[2] : $.discord.resolve.global(event.getArgs()[parseInt(s.match(reCustomArg)[1]) - 1])));
|
||||
}
|
||||
|
||||
if (s.match(/\(1\)/g)) {
|
||||
for (var i = 1; i < 10; i++) {
|
||||
if (s.includes('(' + i + ')')) {
|
||||
s = $.replace(s, '(' + i + ')', (event.getArgs()[i - 1] !== undefined ? event.getArgs()[i - 1] : ''));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(reCustomToUserArg)) {
|
||||
s = $.replace(s, s.match(reCustomToUserArg)[0], (event.getArgs()[0] ? $.discord.username.resolve(event.getArgs().join(' ')) : s.match(reCustomToUserArg)[1]));
|
||||
}
|
||||
|
||||
if (s.match(/\(sender\)/)) {
|
||||
s = $.replace(s, '(sender)', event.getUsername());
|
||||
}
|
||||
|
||||
if (s.match(/\(@sender\)/)) {
|
||||
s = $.replace(s, '(@sender)', event.getMention());
|
||||
}
|
||||
|
||||
if (s.match(/\(touser\)/)) {
|
||||
s = $.replace(s, '(touser)', (event.getArgs()[0] ? $.discord.username.resolve(event.getArgs().join(' ')) : event.getMention()));
|
||||
}
|
||||
|
||||
if (s.match(/\(random\)/)) {
|
||||
s = $.replace(s, '(random)', $.discord.username.random());
|
||||
}
|
||||
|
||||
if (s.match(/\(#\)/)) {
|
||||
s = $.replace(s, '(#)', $.randRange(1, 100).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(# (\d+),(\d+)\)/g)) {
|
||||
var mat = s.match(/\(# (\d+),(\d+)\)/);
|
||||
s = $.replace(s, mat[0], $.randRange(parseInt(mat[1]), parseInt(mat[2])).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(status\)/)) {
|
||||
s = $.replace(s, '(status)', $.getStatus($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(game\)/)) {
|
||||
s = $.replace(s, '(game)', $.getGame($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(uptime\)/)) {
|
||||
s = $.replace(s, '(uptime)', $.getStreamUptime($.channelName));
|
||||
}
|
||||
|
||||
if (s.match(/\(echo\)/)) {
|
||||
s = $.replace(s, '(echo)', (event.getArgs()[0] ? event.getArguments() : ''));
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', $.getViewers($.channelName).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(follows\)/g)) {
|
||||
s = $.replace(s, '(follows)', $.getFollows($.channelName).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(readfile/)) {
|
||||
if (s.search(/\((readfile ([^)]+)\))/g) >= 0) {
|
||||
s = $.replace(s, '(' + RegExp.$1, $.readFile('./addons/' + $.replace(RegExp.$2, '..', ''))[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(readfilerand/)) {
|
||||
if (s.search(/\((readfilerand ([^)]+)\))/g) >= 0) {
|
||||
var results = $.readFile('./addons/' + RegExp.$2);
|
||||
s = $.replace(s, '(' + RegExp.$1, $.randElement(results));
|
||||
}
|
||||
}
|
||||
|
||||
if (s.match(/\(count\)/g)) {
|
||||
$.inidb.incr('discordCommandCount', event.getCommand(), 1);
|
||||
s = $.replace(s, '(count)', $.inidb.get('discordCommandCount', event.getCommand()));
|
||||
}
|
||||
|
||||
if (s.match(/\(writefile ([\w\W^,]+), ([\w^,]+), ([\w\W^,]+)\)/)) {
|
||||
var file = s.match(/\(writefile (.+), (.+), (.+)\)/)[1],
|
||||
append = (s.match(/\(writefile (.+), (.+), (.+)\)/)[2] == 'true' ? true : false),
|
||||
string = s.match(/\(writefile (.+), (.+), (.+)\)/)[3];
|
||||
$.writeToFile(string, './addons/' + $.replace(file, '..', ''), append);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (s.match(/\(lasttip\)/g)) {
|
||||
s = $.replace(s, '(lasttip)', ($.inidb.exists('donations', 'last_donation_message') ? $.inidb.get('donations', 'last_donation_message') : 'No donations found.'));
|
||||
}
|
||||
|
||||
if (s.match(/\(encodeurl ([\w\W]+)\)/)) {
|
||||
var m = s.match(/\(encodeurl ([\w\W]+)\)/);
|
||||
s = $.replace(s, m[0], encodeURI(m[1]));
|
||||
}
|
||||
|
||||
if (s.match(reCustomAPIJson) || s.match(reCustomAPI)) {
|
||||
s = api(event, s);
|
||||
}
|
||||
|
||||
if (s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)/)) {
|
||||
$.discord.setRole(s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[2], s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[1]);
|
||||
|
||||
s = $.replace(s, s.match(/\(setrole ([\w\W\s]+), ([\w\W\s]+)\)/)[0], '');
|
||||
if (s.length === 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function api
|
||||
*
|
||||
* @param {object} event
|
||||
* @param {string} message
|
||||
* @return {string}
|
||||
*/
|
||||
function api(event, message) {
|
||||
var JSONObject = Packages.org.json.JSONObject,
|
||||
JSONArray = Packages.org.json.JSONArray,
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
origCustomAPIResponse = '',
|
||||
customAPIReturnString = '',
|
||||
message = message + '',
|
||||
customAPIResponse = '',
|
||||
customJSONStringTag = '',
|
||||
commandToExec = 0,
|
||||
jsonObject,
|
||||
regExCheck,
|
||||
jsonItems,
|
||||
jsonCheckList;
|
||||
|
||||
// Get the URL for a customapi, if applicable, and process $1 - $9. See below about that.
|
||||
if ((regExCheck = message.match(reCustomAPI))) {
|
||||
if (regExCheck[1].indexOf('$1') != -1) {
|
||||
for (var i = 1; i <= 9; i++) {
|
||||
if (regExCheck[1].indexOf('$' + i) != -1) {
|
||||
if (!args[i - 1]) {
|
||||
return $.lang.get('customcommands.customapi.404', command);
|
||||
}
|
||||
regExCheck[1] = regExCheck[1].replace('$' + i, args[i - 1]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
customAPIReturnString = getCustomAPIValue(regExCheck[1]);
|
||||
}
|
||||
|
||||
// Design Note. As of this comment, this parser only supports parsing out of objects, it does not
|
||||
// support parsing of arrays, especially walking arrays. If that needs to be done, please write
|
||||
// a custom JavaScript. We limit $1 - $9 as well; 10 or more arguments being passed by users to an
|
||||
// API seems like overkill. Even 9 does, to be honest.
|
||||
if ((regExCheck = message.match(reCustomAPIJson))) {
|
||||
if (regExCheck[1].indexOf('$1') != -1) {
|
||||
for (var i = 1; i <= 9; i++) {
|
||||
if (regExCheck[1].indexOf('$' + i) != -1) {
|
||||
if (!args[i - 1]) {
|
||||
return $.lang.get('customcommands.customapi.404', command);
|
||||
}
|
||||
regExCheck[1] = regExCheck[1].replace('$' + i, args[i - 1]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
origCustomAPIResponse = getCustomAPIValue(regExCheck[1]);
|
||||
jsonItems = regExCheck[2].split(' ');
|
||||
for (var j = 0; j < jsonItems.length; j++) {
|
||||
if (jsonItems[j].startsWith('{') && jsonItems[j].endsWith('}')) {
|
||||
customAPIReturnString += " " + jsonItems[j].match(reCustomAPITextTag)[1];
|
||||
} else if (jsonItems[j].startsWith('{') && !jsonItems[j].endsWith('}')) {
|
||||
customJSONStringTag = '';
|
||||
while (!jsonItems[j].endsWith('}')) {
|
||||
customJSONStringTag += jsonItems[j++] + " ";
|
||||
}
|
||||
customJSONStringTag += jsonItems[j];
|
||||
customAPIReturnString += " " + customJSONStringTag.match(reCustomAPITextTag)[1];
|
||||
} else {
|
||||
jsonCheckList = jsonItems[j].split('.');
|
||||
if (jsonCheckList.length == 1) {
|
||||
try {
|
||||
customAPIResponse = new JSONObject(origCustomAPIResponse).get(jsonCheckList[0]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
customAPIReturnString += " " + customAPIResponse;
|
||||
} else {
|
||||
for (var i = 0; i < jsonCheckList.length - 1; i++) {
|
||||
if (i == 0) {
|
||||
try {
|
||||
jsonObject = new JSONObject(origCustomAPIResponse).get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
} else if (!isNaN(jsonCheckList[i + 1])) {
|
||||
try {
|
||||
jsonObject = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
jsonObject = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
customAPIResponse = jsonObject.get(jsonCheckList[i]);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to get data from API: ' + ex.message);
|
||||
return $.lang.get('discord.customcommands.customapijson.err', command);
|
||||
}
|
||||
customAPIReturnString += " " + customAPIResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return message.replace(reCustomAPI, customAPIReturnString).replace(reCustomAPIJson, customAPIReturnString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function permCom
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {int}
|
||||
*/
|
||||
function permCom(command, subCommand) {
|
||||
if (subCommand === '') {
|
||||
return $.discord.getCommandPermission(command);
|
||||
} else {
|
||||
return $.discord.getSubCommandPermission(command, subCommand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadCustomCommands
|
||||
*
|
||||
* @export $.discord
|
||||
*/
|
||||
function loadCustomCommands() {
|
||||
if ($.bot.isModuleEnabled('./discord/commands/customCommands.js')) {
|
||||
var keys = $.inidb.GetKeyList('discordCommands', ''),
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', keys[i], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* Checks for custom commands, no command path needed here.
|
||||
*/
|
||||
if ($.inidb.exists('discordCommands', command)) {
|
||||
var tag = tags(event, $.inidb.get('discordCommands', command));
|
||||
if (tag !== null) {
|
||||
$.discord.say(channel, tag);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath addcom [command] [response] - Adds a custom command to be used in your Discord server.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('addcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if ($.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.err'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordCommands', action, args.slice(1).join(' '));
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', action, 0);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.addcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath editcom [command] [response] - Edits an existing command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('editcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordCommands', action, args.slice(1).join(' '));
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', action, 0);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.editcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath delcom [command] - Deletes a custom command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delcom')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('discordCommands', action);
|
||||
$.discord.unregisterCommand(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delcom.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath channelcom [command] [channel / --global / --list] - Makes a command only work in that channel, separate the channels with commas (no spaces) for multiple, use --global as the channel to make the command global again.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('channelcom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('--global') || subAction.equalsIgnoreCase('-g')) {
|
||||
$.inidb.del('discordChannelcom', action);
|
||||
$.discord.updateCommandChannel(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.global', action));
|
||||
return;
|
||||
} else if (subAction.equalsIgnoreCase('--list') || subAction.equalsIgnoreCase('-l')) {
|
||||
var keys = ($.inidb.exists('discordChannelcom', action) ? $.inidb.get('discordChannelcom', action).split(',') : []),
|
||||
key = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
key.push('#' + keys[i]);
|
||||
}
|
||||
|
||||
if (key.length !== 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + key.join(', '));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.404'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = subAction.split(','),
|
||||
key = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
key.push($.discord.sanitizeChannelName(keys[i]));
|
||||
}
|
||||
|
||||
$.inidb.set('discordChannelcom', action, key.join(','));
|
||||
$.discord.updateCommandChannel(action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.channelcom.success', action, subAction.replace(',', ', ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath pricecom [command] [amount] - Sets a cost for that command, users must of their Twitch accounts linked for this to work.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('pricecom')) {
|
||||
if (action === undefined || (subAction === undefined || isNaN(parseInt(subAction)))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.pricecom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordPricecom', action, subAction);
|
||||
$.discord.setCommandCost(action, subAction);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.pricecom.success', action, $.getPointsString(subAction)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath aliascom [alias] [command] - Alias a command to another command, this only works with commands that have a single command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('aliascom')) {
|
||||
if (action === undefined || subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.aliascom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = subAction.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.commandExists(subAction)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordAliascom', subAction, action);
|
||||
$.discord.setCommandAlias(subAction, action);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.aliascom.success', action, subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath delalias [alias] - Removes the alias of that command.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('delalias')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delalias.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
|
||||
if (!$.discord.aliasExists(action)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.alias.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = $.inidb.GetKeyList('discordAliascom', ''),
|
||||
i;
|
||||
for (i in keys) {
|
||||
if ($.inidb.get('discordAliascom', keys[i]).equalsIgnoreCase(action)) {
|
||||
$.inidb.del('discordAliascom', keys[i]);
|
||||
$.discord.removeAlias(keys[i], '');
|
||||
}
|
||||
}
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.customcommands.delalias.success', action));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath commands - Shows all of the custom commands you created.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('commands')) {
|
||||
var keys = $.inidb.GetKeyList('discordCommands', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('!' + keys[i]);
|
||||
}
|
||||
|
||||
$.paginateArrayDiscord(temp, 'discord.customcommands.commands', ', ', channel, mention);
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath botcommands - Gives you a list of commands that you are allowed to use.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('botcommands')) {
|
||||
var keys = $.inidb.GetKeyList('discordPermcom', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
if (keys[i].indexOf(' ') === -1) {
|
||||
temp.push('!' + keys[i]);
|
||||
}
|
||||
}
|
||||
$.paginateArrayDiscord(temp, 'discord.customcommands.bot.commands', ', ', channel, mention);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'addcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'delcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'editcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'coolcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'channelcom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'pricecom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'aliascom', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'delalias', 1);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'commands', 0);
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', 'botcommands', 1);
|
||||
|
||||
loadCustomCommands();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/commands/customCommands.js')) {
|
||||
if (event.getArguments().length() === 0) {
|
||||
if (!$.discord.commandExists(event.getArgs()[0])) {
|
||||
$.discord.registerCommand('./discord/commands/customCommands.js', event.getArgs()[0], event.getArgs()[1]);
|
||||
} else {
|
||||
$.discord.setCommandPermission(event.getArgs()[0], event.getArgs()[1]);
|
||||
$.discord.setCommandCost(event.getArgs()[0], (event.getArgs()[4].length() === 0 ? '' : event.getArgs()[4]));
|
||||
if (event.getArgs()[3].length() === 0) {
|
||||
$.discord.removeAlias(event.getArgs()[0], $.inidb.get('discordAliascom', event.getArgs()[0]));
|
||||
} else {
|
||||
$.discord.setCommandAlias(event.getArgs()[0], (event.getArgs()[3].length() === 0 ? '' : event.getArgs()[3]));
|
||||
}
|
||||
|
||||
if (event.getArgs()[2].length() === 0) {
|
||||
$.inidb.del('discordChannelcom', event.getArgs()[0]);
|
||||
} else {
|
||||
$.inidb.set('discordChannelcom', event.getArgs()[0], String(event.getArgs()[2]).replace(/#/g, '').toLowerCase());
|
||||
}
|
||||
|
||||
$.discord.updateCommandChannel(event.getArgs()[0]);
|
||||
}
|
||||
} else {
|
||||
$.discord.unregisterCommand(event.getArgs()[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.loadCustomCommands = loadCustomCommands;
|
||||
$.discord.tags = tags;
|
||||
$.discord.permCom = permCom;
|
||||
})();
|
||||
161
libs/phantombot/scripts/discord/core/accountLink.js
Normal file
161
libs/phantombot/scripts/discord/core/accountLink.js
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles linking of a Discord account to a Twitch account.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var accounts = {},
|
||||
interval;
|
||||
|
||||
/**
|
||||
* @function resolveTwitchName
|
||||
* @function discordToTwitch
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} userId (snowflake)
|
||||
* @return {string or null}
|
||||
*/
|
||||
function resolveTwitchName(userId) {
|
||||
return ($.inidb.exists('discordToTwitch', userId) ? $.inidb.get('discordToTwitch', userId) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
user = event.getDiscordUser(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath account - Checks the current account linking status of the sender.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('account')) {
|
||||
var userId = event.getSenderId(),
|
||||
islinked = $.inidb.exists('discordToTwitch', userId);
|
||||
|
||||
if (action === undefined) {
|
||||
if (islinked) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.link', $.inidb.get('discordToTwitch', userId)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath account link - Starts the process of linking an account. Completing this will overwrite existing links
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('link')) {
|
||||
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+',
|
||||
text = '',
|
||||
i;
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
text += code.charAt(Math.floor(Math.random() * code.length));
|
||||
}
|
||||
|
||||
accounts[userId] = {
|
||||
userObj: user,
|
||||
time: $.systemTime(),
|
||||
code: text
|
||||
};
|
||||
|
||||
if (islinked) {
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link.relink', $.channelName, text));
|
||||
} else {
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link', $.channelName, text));
|
||||
}
|
||||
/**
|
||||
* @discordcommandpath account remove - Removes account links from the sender.
|
||||
*/
|
||||
} else if (action.equalsIgnoreCase('remove')) {
|
||||
$.inidb.del('discordToTwitch', userId);
|
||||
$.discordAPI.sendPrivateMessage(user, $.lang.get('discord.accountlink.link.remove'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event command
|
||||
*/
|
||||
$.bind('command', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @commandpath account link [code] - Completes an account link for Discord.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('account')) {
|
||||
if (action !== undefined && action.equalsIgnoreCase('link')) {
|
||||
var code = args[1];
|
||||
if (code === undefined || code.length() < 10) {
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('discord.accountlink.link.fail'));
|
||||
return;
|
||||
}
|
||||
|
||||
var keys = Object.keys(accounts),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (accounts[keys[i]].code == code && (accounts[keys[i]].time + 6e5) > $.systemTime()) {
|
||||
$.inidb.set('discordToTwitch', keys[i], sender.toLowerCase());
|
||||
|
||||
$.discordAPI.sendPrivateMessage(accounts[keys[i]].userObj, $.lang.get('discord.accountlink.link.success', sender.toLowerCase()));
|
||||
delete accounts[keys[i]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$.say($.whisperPrefix(sender) + $.lang.get('discord.accountlink.link.fail'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/accountLink.js', 'account', 0);
|
||||
$.discord.registerSubCommand('accountlink', 'link', 0);
|
||||
$.discord.registerSubCommand('accountlink', 'remove', 0);
|
||||
// This is used to verify your account from Twitch. Do not remove it.
|
||||
$.registerChatCommand('./discord/core/accountLink.js', 'account', 7);
|
||||
|
||||
|
||||
// Interval to clear our old codes that have not yet been registered.
|
||||
interval = setInterval(function() {
|
||||
var keys = Object.keys(accounts),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if ((accounts[keys[i]].time + 6e5) < $.systemTime()) {
|
||||
delete accounts[keys[i]];
|
||||
}
|
||||
}
|
||||
}, 6e4, 'scripts::discord::core::accountLink.js');
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.resolveTwitchName = resolveTwitchName;
|
||||
})();
|
||||
259
libs/phantombot/scripts/discord/core/commandCooldown.js
Normal file
259
libs/phantombot/scripts/discord/core/commandCooldown.js
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* this module is made to handle command cooldowns for discord.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var defaultCooldownTime = $.getSetIniDbNumber('discordCooldownSettings', 'defaultCooldownTime', 5),
|
||||
defaultCooldowns = [],
|
||||
cooldowns = [];
|
||||
|
||||
/*
|
||||
* @class Cooldown
|
||||
*
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function Cooldown(command, seconds, isGlobal) {
|
||||
this.isGlobal = isGlobal;
|
||||
this.command = command;
|
||||
this.seconds = seconds;
|
||||
this.cooldowns = [];
|
||||
this.time = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function loadCooldowns
|
||||
*/
|
||||
function loadCooldowns() {
|
||||
var commands = $.inidb.GetKeyList('discordCooldown', ''),
|
||||
json,
|
||||
i;
|
||||
|
||||
for (i in commands) {
|
||||
json = JSON.parse($.inidb.get('discordCooldown', commands[i]));
|
||||
|
||||
cooldowns[commands[i]] = new Cooldown(json.command, json.seconds, (json.isGlobal == true));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function get
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function get(command, username) {
|
||||
var cooldown = cooldowns[command];
|
||||
|
||||
if (cooldown !== undefined) {
|
||||
if (cooldown.isGlobal) {
|
||||
if (cooldown.time > $.systemTime()) {
|
||||
return cooldown.time;
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds);
|
||||
}
|
||||
} else {
|
||||
if (cooldown.cooldowns[username] !== undefined && cooldown.cooldowns[username] > $.systemTime()) {
|
||||
return cooldown.cooldowns[username];
|
||||
} else {
|
||||
return set(command, true, cooldown.seconds, username);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (defaultCooldowns[command] !== undefined && defaultCooldowns[command] > $.systemTime()) {
|
||||
return defaultCooldowns[command];
|
||||
} else {
|
||||
return set(command, false, defaultCooldownTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function set
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Boolean} hasCooldown
|
||||
* @param {Number} seconds
|
||||
* @param {String} username
|
||||
* @return {Number}
|
||||
*/
|
||||
function set(command, hasCooldown, seconds, username) {
|
||||
seconds = ((parseInt(seconds) * 1e3) + $.systemTime());
|
||||
|
||||
if (hasCooldown) {
|
||||
if (username === undefined) {
|
||||
cooldowns[command].time = seconds;
|
||||
} else {
|
||||
cooldowns[command].cooldowns[username] = seconds;
|
||||
}
|
||||
} else {
|
||||
defaultCooldowns[command] = seconds;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function add
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
* @param {Number} seconds
|
||||
* @param {Boolean} isGlobal
|
||||
*/
|
||||
function add(command, seconds, isGlobal) {
|
||||
if (cooldowns[command] === undefined) {
|
||||
cooldowns[command] = new Cooldown(command, seconds, isGlobal);
|
||||
$.inidb.set('discordCooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
} else {
|
||||
cooldowns[command].isGlobal = isGlobal;
|
||||
cooldowns[command].seconds = seconds;
|
||||
$.inidb.set('discordCooldown', command, JSON.stringify({
|
||||
command: String(command),
|
||||
seconds: String(seconds),
|
||||
isGlobal: String(isGlobal)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function remove
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function remove(command) {
|
||||
$.inidb.del('discordCooldown', command);
|
||||
if (cooldowns[command] !== undefined) {
|
||||
delete cooldowns[command];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function clear
|
||||
*
|
||||
* @export $.coolDown
|
||||
* @param {String} command
|
||||
*/
|
||||
function clear(command) {
|
||||
if (cooldowns[command] !== undefined) {
|
||||
cooldowns[command].time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
/*
|
||||
* @commandpath coolcom [command] [seconds] [type (global / user)] - Sets a cooldown for a command, default is global. Using -1 for the seconds removes the cooldown.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('coolcom')) {
|
||||
if (action === undefined || isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = (actionArgs !== undefined && actionArgs == 'user' ? false : true);
|
||||
action = action.replace('!', '').toLowerCase();
|
||||
subAction = parseInt(subAction);
|
||||
|
||||
if (subAction > -1) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.set', action, subAction));
|
||||
add(action, subAction, actionArgs);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.coolcom.remove', action));
|
||||
remove(action);
|
||||
}
|
||||
clear(command);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('cooldown')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.cooldown.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath cooldown setdefault [seconds] - Sets a default global cooldown for commands without a cooldown.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setdefault')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.default.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
defaultCooldownTime = parseInt(subAction);
|
||||
$.setIniDbNumber('discordCooldownSettings', 'defaultCooldownTime', defaultCooldownTime);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cooldown.default.set', defaultCooldownTime));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/commandCoolDown.js', 'coolcom', 1);
|
||||
|
||||
$.discord.registerCommand('./discord/core/commandCoolDown.js', 'cooldown', 1);
|
||||
$.discord.registerSubCommand('cooldown', 'setdefault', 1);
|
||||
loadCooldowns();
|
||||
});
|
||||
|
||||
/*
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/core/commandCoolDown.js')) {
|
||||
if (event.getArgs()[0] == 'add') {
|
||||
add(event.getArgs()[1], event.getArgs()[2], event.getArgs()[3].equals('true'));
|
||||
} else {
|
||||
remove(event.getArgs()[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* Export to the $. API */
|
||||
$.discord.cooldown = {
|
||||
remove: remove,
|
||||
clear: clear,
|
||||
get: get,
|
||||
set: set,
|
||||
add: add
|
||||
};
|
||||
})();
|
||||
432
libs/phantombot/scripts/discord/core/misc.js
Normal file
432
libs/phantombot/scripts/discord/core/misc.js
Normal file
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles the main things for the Discord modules. This is like the core if you would like to call it that.
|
||||
*
|
||||
* Command permissions for the registerCommand function:
|
||||
* - 1 means only administrators can access the command.
|
||||
* - 0 means everyone can access the command.
|
||||
*
|
||||
* Guidelines for merging thing on our repo for this module:
|
||||
* - Please try not to call the $.discordAPI function out of this script, move all the main functions here and export the function to the $.discord API.
|
||||
* - To register command to our command list please add a comment starting with @discordcommandpath before the command info.
|
||||
* - Make sure to comment on every function what their name is and the parameters they require and if they return something.
|
||||
*/
|
||||
(function() {
|
||||
var embedReg = new RegExp(/\(embed\s([\s\d\w]+),\s([\w\W]+)\)/),
|
||||
fileRegMsg = new RegExp(/\(file\s([\w\W]+),\s?([\r\n\w\W]*)\)/),
|
||||
fileReg = new RegExp(/\(file\s([\w\W]+)\)/),
|
||||
messageDeleteArray = [];
|
||||
|
||||
/**
|
||||
* @function userPrefix
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} username
|
||||
* @return {String}
|
||||
*/
|
||||
function userPrefix(username) {
|
||||
return (username + ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isConnected
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isConnected() {
|
||||
return $.discordAPI.isLoggedIn() &&
|
||||
$.discordAPI.checkConnectionStatus() == Packages.tv.phantombot.discord.DiscordAPI.ConnectionState.CONNECTED
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserMention
|
||||
*
|
||||
* @export $.discord.username
|
||||
* @param {string} username
|
||||
* @return {string}
|
||||
*/
|
||||
function getUserMention(username) {
|
||||
return ($.discordAPI.getUser(username) != null ? $.discordAPI.getUser(username).getMention() : username);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getUserMentionOrChannel
|
||||
*
|
||||
* @export $.discord.resolve
|
||||
* @param {string} argument
|
||||
* @return {string}
|
||||
*/
|
||||
function getUserMentionOrChannel(argument) {
|
||||
if ($.discordAPI.getUser(username) != null) {
|
||||
return $.discordAPI.getUser(argument).getMention();
|
||||
} else if ($.discordAPI.getChannel(argument) != null) {
|
||||
return $.discordAPI.getChannel(argument).getMention();
|
||||
} else {
|
||||
return argument;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getRandomUser
|
||||
*
|
||||
* @export $.discord.username
|
||||
* @return {string}
|
||||
*/
|
||||
function getRandomUser() {
|
||||
return ($.discordAPI.getUsers().get($.randRange(0, $.discordAPI.getUsers().size() - 1)).getMention()());
|
||||
}
|
||||
|
||||
/**
|
||||
* @function say
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} channel
|
||||
* @param {string} message
|
||||
*/
|
||||
function say(channel, message) {
|
||||
if (embedReg.test(message)) {
|
||||
return $.discordAPI.sendMessageEmbed(channel, message.match(embedReg)[1], message.match(embedReg)[2]);
|
||||
} else if (fileRegMsg.test(message)) {
|
||||
return $.discordAPI.sendFile(channel, message.match(fileRegMsg)[2], message.match(fileRegMsg)[1]);
|
||||
} else if (fileReg.test(message)) {
|
||||
return $.discordAPI.sendFile(channel, message.match(fileReg)[1]);
|
||||
} else {
|
||||
return $.discordAPI.sendMessage(channel, message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setGame
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} game
|
||||
*/
|
||||
function setGame(game) {
|
||||
$.discordAPI.setGame(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setGame
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} game
|
||||
* @param {string} url
|
||||
*/
|
||||
function setStream(game, url) {
|
||||
$.discordAPI.setStream(game, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function removeGame
|
||||
*
|
||||
* @export $.discord
|
||||
*/
|
||||
function removeGame() {
|
||||
$.discordAPI.removeGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setRole
|
||||
*
|
||||
* @param {string} role
|
||||
* @param {string} username
|
||||
* @export $.discord
|
||||
*/
|
||||
function setRole(role, username) {
|
||||
return $.discordAPI.addRole(role, username);
|
||||
}
|
||||
|
||||
function sanitizeChannelName(channel) {
|
||||
channel = channel.trim();
|
||||
|
||||
if (channel.substr(0, 1) === '<') {
|
||||
channel = channel.substr(1);
|
||||
}
|
||||
|
||||
if (channel.substr(0, 1) === '#') {
|
||||
channel = channel.substr(1);
|
||||
}
|
||||
|
||||
if (channel.substr(channel.length - 1, 1) === '>') {
|
||||
channel = channel.substr(0, channel.length - 1);
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function handleDeleteReaction
|
||||
*
|
||||
* @param {object} user
|
||||
* @param {object} message
|
||||
* @param {object} commandMessage
|
||||
* @export $.discord
|
||||
*/
|
||||
function handleDeleteReaction(user, message, commandMessage) {
|
||||
var xEmoji = Packages.discord4j.core.object.reaction.ReactionEmoji.unicode('❌');
|
||||
message.addReaction(xEmoji);
|
||||
|
||||
messageDeleteArray[message.getId().asString()] = {
|
||||
lastMessage: message,
|
||||
lastCommandMessage: commandMessage,
|
||||
lastUser: user,
|
||||
timeout: setTimeout(function() {
|
||||
messageDeleteArray[message.getId().asString()].lastMessage.delete().subscribe();
|
||||
messageDeleteArray[message.getId().asString()].lastCommandMessage.delete().subscribe();
|
||||
delete messageDeleteArray[message.getId().asString()];
|
||||
}, 3e4)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @discordcommandpath module enable [path] - Enables any modules in the bot, it should only be used to enable discord modules though.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('module')) {
|
||||
if (action === undefined || (subAction === undefined && !action.equalsIgnoreCase('list'))) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('enable')) {
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, true);
|
||||
$.bot.loadScript(module.scriptName);
|
||||
$.bot.modules[module.scriptName].isEnabled = true;
|
||||
|
||||
var hookIndex = $.bot.getHookIndex(module.scriptName, 'initReady');
|
||||
|
||||
try {
|
||||
if (hookIndex !== -1) {
|
||||
$.bot.getHook(module.scriptName, 'initReady').handler();
|
||||
}
|
||||
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.enabled', module.getModuleName()));
|
||||
} catch (ex) {
|
||||
$.log.error('[DISCORD] Unable to call initReady for enabled module (' + module.scriptName + '): ' + ex.message);
|
||||
$.consoleLn("Sending stack trace to error log...");
|
||||
Packages.com.gmt2001.Console.err.printStackTrace(ex.javaException);
|
||||
}
|
||||
} else {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.404', subAction));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath module disable [path] - Disables any modules in the bot, it should only be used to enable discord modules though.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('disable')) {
|
||||
var module = $.bot.getModule(subAction);
|
||||
|
||||
if (module !== undefined) {
|
||||
$.setIniDbBoolean('modules', module.scriptName, false);
|
||||
$.bot.modules[module.scriptName].isEnabled = false;
|
||||
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.disabled', module.getModuleName()));
|
||||
} else {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.404', subAction));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath module list - Lists all of the discord modules.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('list')) {
|
||||
var keys = Object.keys($.bot.modules),
|
||||
modules = $.bot.modules,
|
||||
list = [],
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (!modules[keys[i]].scriptName.startsWith('./discord/core/') && modules[keys[i]].scriptName.startsWith('./discord/')) {
|
||||
list.push(modules[keys[i]].scriptName + ' [' + (modules[keys[i]].isEnabled === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled')) + ']');
|
||||
}
|
||||
}
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.module.list', list.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath setgame [game name] - Sets the bot game.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setgame')) {
|
||||
if (action === undefined) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
setGame(args.join(' '));
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.set', args.join(' ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath setstream [twitch url] [game name] - Sets the bot game and marks it as streaming.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('setstream')) {
|
||||
if (action === undefined) {
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.stream.set.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
setStream(args.slice(1).join(' '), action);
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.stream.set', action, args.slice(1).join(' ')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath removegame - Removes the bot's game and streaming status if set.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('removegame')) {
|
||||
removeGame();
|
||||
say(channel, userPrefix(mention) + $.lang.get('discord.misc.game.removed'));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleCreated
|
||||
*/
|
||||
$.bind('discordRoleCreated', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
|
||||
permObj.roles.push({
|
||||
'name': event.getDiscordRole().getName() + '',
|
||||
'_id': event.getRoleID() + '',
|
||||
'selected': 'false'
|
||||
});
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleUpdated
|
||||
*/
|
||||
$.bind('discordRoleUpdated', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
|
||||
for (var i = 0; i < permObj.roles.length; i++) {
|
||||
if (permObj.roles[i]._id.equals(event.getRoleID() + '')) {
|
||||
permObj.roles[i].name = event.getDiscordRole().getName() + '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordRoleDeleted
|
||||
*/
|
||||
$.bind('discordRoleDeleted', function(event) {
|
||||
var permObj = JSON.parse($.inidb.get('discordPermsObj', 'obj'));
|
||||
var commands = $.inidb.GetKeyList('discordPermcom', '');
|
||||
|
||||
for (var i = 0; i < permObj.roles.length; i++) {
|
||||
if (permObj.roles[i]._id.equals(event.getRoleID() + '')) {
|
||||
permObj.roles.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < commands.length; i++) {
|
||||
var perms = JSON.parse($.inidb.get('discordPermcom', commands[i]));
|
||||
|
||||
if (perms.roles.indexOf((event.getRoleID() + '')) > -1) {
|
||||
perms.roles.splice(perms.roles.indexOf((event.getRoleID() + '')), 1);
|
||||
$.discord.setCommandPermission(commands[i], perms);
|
||||
$.inidb.set('discordPermcom', commands[i], JSON.stringify(perms));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.set('discordPermsObj', 'obj', JSON.stringify(permObj));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordMessageReaction
|
||||
*/
|
||||
$.bind('discordMessageReaction', function (event) {
|
||||
var reactionEvent = event.getEvent(),
|
||||
reactionUser = event.getSenderId();
|
||||
|
||||
if (event.getReactionEmoji().asUnicodeEmoji().equals(Packages.discord4j.core.object.reaction.ReactionEmoji.unicode('❌'))) {
|
||||
var messageID = reactionEvent.getMessage().block().getId().asString(),
|
||||
messageInArray = messageDeleteArray[messageID];
|
||||
if (messageInArray !== undefined) {
|
||||
if (messageInArray.lastUser.getId().asString().equals(reactionUser) &&
|
||||
messageInArray.lastMessage.getId().asString().equals(messageID)) {
|
||||
reactionEvent.getMessage().block().delete().subscribe();
|
||||
messageInArray.lastCommandMessage.delete().subscribe();
|
||||
clearTimeout(messageInArray.timeout);
|
||||
delete messageDeleteArray[messageID];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'module', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'setgame', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'setstream', 1);
|
||||
$.discord.registerCommand('./discord/core/misc.js', 'removegame', 1);
|
||||
$.discord.registerSubCommand('module', 'list', 1);
|
||||
$.discord.registerSubCommand('module', 'enable', 1);
|
||||
$.discord.registerSubCommand('module', 'disable', 1);
|
||||
});
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
/* There are the same functions twice in here - that's normal and wanted. */
|
||||
$.discord = {
|
||||
isConnected: isConnected,
|
||||
getUserMention: getUserMention,
|
||||
userMention: getUserMention,
|
||||
removeGame: removeGame,
|
||||
userPrefix: userPrefix,
|
||||
setStream: setStream,
|
||||
setGame: setGame,
|
||||
setRole: setRole,
|
||||
say: say,
|
||||
handleDeleteReaction: handleDeleteReaction,
|
||||
sanitizeChannelName: sanitizeChannelName,
|
||||
resolve: {
|
||||
global: getUserMentionOrChannel,
|
||||
getUserMentionOrChannel: getUserMentionOrChannel
|
||||
},
|
||||
username: {
|
||||
resolve: getUserMention,
|
||||
random: getRandomUser,
|
||||
getUserMention: getUserMention,
|
||||
getRandomUser: getRandomUser
|
||||
}
|
||||
};
|
||||
})();
|
||||
722
libs/phantombot/scripts/discord/core/moderation.js
Normal file
722
libs/phantombot/scripts/discord/core/moderation.js
Normal file
@@ -0,0 +1,722 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var blacklist = [],
|
||||
whitelist = [],
|
||||
permitList = {},
|
||||
timeout = {},
|
||||
spam = {},
|
||||
lastMessage = 0,
|
||||
|
||||
linkToggle = $.getSetIniDbBoolean('discordSettings', 'linkToggle', false),
|
||||
linkPermit = $.getSetIniDbNumber('discordSettings', 'linkPermit', 60),
|
||||
|
||||
capsToggle = $.getSetIniDbBoolean('discordSettings', 'capToggle', false),
|
||||
capsLimitPercent = $.getSetIniDbNumber('discordSettings', 'capsLimitPercent', 50),
|
||||
capsTriggerLength = $.getSetIniDbNumber('discordSettings', 'capsTriggerLength', 15),
|
||||
|
||||
longMessageToggle = $.getSetIniDbBoolean('discordSettings', 'longMessageToggle', false),
|
||||
longMessageLimit = $.getSetIniDbNumber('discordSettings', 'longMessageLimit', 600),
|
||||
|
||||
spamToggle = $.getSetIniDbBoolean('discordSettings', 'spamToggle', false),
|
||||
spamLimit = $.getSetIniDbNumber('discordSettings', 'spamLimit', 5),
|
||||
|
||||
modLogs = $.getSetIniDbBoolean('discordSettings', 'modLogs', false),
|
||||
modLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
|
||||
/**
|
||||
* @function reload
|
||||
*/
|
||||
function reload() {
|
||||
linkToggle = $.getSetIniDbBoolean('discordSettings', 'linkToggle', false),
|
||||
linkPermit = $.getSetIniDbNumber('discordSettings', 'linkPermit', 60);
|
||||
capsToggle = $.getSetIniDbBoolean('discordSettings', 'capToggle', false);
|
||||
capsLimitPercent = $.getSetIniDbNumber('discordSettings', 'capsLimitPercent', 50);
|
||||
capsTriggerLength = $.getSetIniDbNumber('discordSettings', 'capsTriggerLength', 15);
|
||||
longMessageToggle = $.getSetIniDbBoolean('discordSettings', 'longMessageToggle', false);
|
||||
longMessageLimit = $.getSetIniDbNumber('discordSettings', 'longMessageLimit', 600);
|
||||
spamToggle = $.getSetIniDbBoolean('discordSettings', 'spamToggle', false);
|
||||
spamLimit = $.getSetIniDbNumber('discordSettings', 'spamLimit', 5);
|
||||
modLogs = $.getSetIniDbBoolean('discordSettings', 'modLogs', false);
|
||||
modLogChannel = $.getSetIniDbString('discordSettings', 'modLogChannel', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadBlackList
|
||||
*/
|
||||
function loadBlackList() {
|
||||
var keys = $.inidb.GetKeyList('discordBlacklist', ''),
|
||||
i;
|
||||
|
||||
blacklist = [];
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
blacklist.push(keys[i].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadWhitelist
|
||||
*/
|
||||
function loadWhitelist() {
|
||||
var keys = $.inidb.GetKeyList('discordWhitelist', ''),
|
||||
i;
|
||||
|
||||
whitelist = []
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
whitelist.push(keys[i].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function hasPermit
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function hasPermit(username) {
|
||||
if (permitList[username] !== undefined && (permitList[username] + linkPermit) >= $.systemTime()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} message
|
||||
*/
|
||||
function isWhiteList(username, message) {
|
||||
for (var i in whitelist) {
|
||||
if (message.includes(whitelist[i]) || username == whitelist[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hasBlackList
|
||||
*
|
||||
* @param {String} message
|
||||
*/
|
||||
function hasBlackList(message) {
|
||||
for (var i in blacklist) {
|
||||
if (message.includes(blacklist[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function username
|
||||
*
|
||||
* @param {String} username
|
||||
*/
|
||||
function bulkDelete(username, channel) {
|
||||
$.discordAPI.bulkDeleteMessages(channel, spam[username].messages);
|
||||
delete spam[username];
|
||||
}
|
||||
|
||||
/**
|
||||
* function timeoutUser
|
||||
*
|
||||
* @param {Object} message
|
||||
*/
|
||||
function timeoutUser(message) {
|
||||
$.discordAPI.deleteMessage(message);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedDelete
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedDelete(username, creator, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Deleted_message_of:**'] = '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'blue', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedTimeout
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} reason
|
||||
* @param {String} time
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedTimeout(username, creator, reason, time, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Timeout_placed_on:**'] = '[' + username + '](https://www.twitch.tv/popout/' + $.channelName + '/viewercard/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Reason:**'] = reason;
|
||||
obj['**Time:**'] = time + ' seconds.';
|
||||
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'yellow', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function embedBanned
|
||||
*
|
||||
* @param {String} username
|
||||
* @param {String} creator
|
||||
* @param {String} reason
|
||||
* @param {String} message
|
||||
*/
|
||||
function embedBanned(username, creator, reason, message) {
|
||||
var toSend = '',
|
||||
obj = {},
|
||||
i;
|
||||
|
||||
obj['**Ban_placed_on:**'] = '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')';
|
||||
obj['**Creator:**'] = creator;
|
||||
obj['**Reason:**'] = reason;
|
||||
obj['**Last_message:**'] = (message.length() > 50 ? message.substring(0, 50) + '...' : message);
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i in keys) {
|
||||
if (obj[keys[i]] != '') {
|
||||
toSend += keys[i].replace(/_/g, ' ') + ' ' + obj[keys[i]] + '\r\n\r\n';
|
||||
}
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'red', toSend);
|
||||
}
|
||||
|
||||
/*
|
||||
* @event PubSubModerationDelete
|
||||
*/
|
||||
$.bind('PubSubModerationDelete', function (event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedDelete(username, creator, message);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationTimeout
|
||||
*/
|
||||
$.bind('PubSubModerationTimeout', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage(),
|
||||
reason = event.getReason(),
|
||||
time = parseInt(event.getTime());
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedTimeout(username, creator, reason, time, message);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationUnTimeout
|
||||
*/
|
||||
$.bind('PubSubModerationUnTimeout', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'green', '**Timeout removed from:** ' + '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')' + ' \r\n\r\n **Creator:** ' + creator);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationUnBan
|
||||
*/
|
||||
$.bind('PubSubModerationUnBan', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(modLogChannel, 'green', '**Ban removed from:** ' + '[' + username + '](https://twitch.tv/' + username.toLowerCase() + ')' + ' \r\n\r\n **Creator:** ' + creator);
|
||||
});
|
||||
|
||||
/*
|
||||
* @event PubSubModerationBan
|
||||
*/
|
||||
$.bind('PubSubModerationBan', function(event) {
|
||||
var username = event.getUsername(),
|
||||
creator = event.getCreator(),
|
||||
message = event.getMessage(),
|
||||
reason = event.getReason();
|
||||
|
||||
if (modLogs === false || modLogChannel === '' || $.getIniDbBoolean('chatModerator', 'moderationLogs', false) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
embedBanned(username, creator, reason, message);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelMessage
|
||||
*/
|
||||
$.bind('discordChannelMessage', function(event) {
|
||||
var sender = event.getSenderId(),
|
||||
channel = event.getDiscordChannel(),
|
||||
message = event.getMessage().toLowerCase(),
|
||||
messageLength = message.length();
|
||||
|
||||
if (event.isAdmin() == false && !hasPermit(sender) && !isWhiteList(sender, message)) {
|
||||
if (linkToggle && $.discord.pattern.hasLink(message)) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (longMessageToggle && messageLength > longMessageLimit) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (capsToggle && messageLength > capsTriggerLength && (($.discord.pattern.getCapsCount(event.getMessage()) / messageLength) * 100) > capsLimitPercent) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (spamToggle) {
|
||||
if (spam[sender] !== undefined) {
|
||||
if (spam[sender].time + 5000 > $.systemTime() && (spam[sender].total + 1) <= spamLimit) {
|
||||
spam[sender].total++; spam[sender].messages.push(event.getDiscordMessage());
|
||||
} else if (spam[sender].time + 5000 < $.systemTime() && (spam[sender].total + 1) <= spamLimit) {
|
||||
spam[sender] = { total: 1, time: $.systemTime(), messages: [event.getDiscordMessage()] };
|
||||
} else {
|
||||
spam[sender].messages.push(event.getDiscordMessage());
|
||||
bulkDelete(sender, channel);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
spam[sender] = { total: 1, time: $.systemTime(), messages: [event.getDiscordMessage()] };
|
||||
}
|
||||
}
|
||||
|
||||
if (hasBlackList(message)) {
|
||||
timeoutUser(event.getDiscordMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastMessage = $.systemTime();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
if (command.equalsIgnoreCase('moderation')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('links')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation links toggle - Toggles the link filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
linkToggle = !linkToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'linkToggle', linkToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.toggle', (linkToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation links permittime [seconds] - Sets the amount a time a permit lasts for.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('permittime')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.permit.time.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
linkPermit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'linkPermit', linkPermit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.links.permit.time.set', linkPermit));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('caps')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps toggle - Toggle the caps filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
capsToggle = !capsToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'capsToggle', capsToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.toggle', (capsToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps triggerlength [characters] - Sets the amount of characters needed a message before checking for caps.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('triggerlength')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.trigger.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
capsTriggerLength = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'capsTriggerLength', capsTriggerLength);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.trigger.set', capsTriggerLength));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation caps limitpercent [percent] - Sets the amount in percent of caps are allowed in a message.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limitpercent')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
capsLimitPercent = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'capsLimitPercent', capsLimitPercent);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.caps.limit.set', capsLimitPercent));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('longmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation longmessage toggle - Toggles the long message filter
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
longMessageToggle = !longMessageToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'longMessageToggle', longMessageToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.toggle', (longMessageToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation longmessage limit [characters] - Sets the amount of characters allowed in a message.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limit')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
longMessageLimit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'longMessageLimit', longMessageLimit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.long.message.limit.set', longMessageLimit));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('spam')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation spam toggle - Toggles the spam filter.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
spamToggle = !spamToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'spamToggle', spamToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.toggle', (spamToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation limit [messages] - Sets the amount of messages users are allowed to send in 5 seconds.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('limit')) {
|
||||
if (isNaN(parseInt(actionArgs))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.limit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
spamLimit = parseInt(actionArgs);
|
||||
$.setIniDbNumber('discordSettings', 'spamLimit', spamLimit);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.spam.limit.set', spamLimit));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (action.equalsIgnoreCase('blacklist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist add [phrase] - Adds a word or phrase to the blacklist which will be deleted if said in any channel.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('discordBlacklist', actionArgs, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.add.success'));
|
||||
loadBlackList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist remove [phrase] - Removes a word or phrase to the blacklist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('discordBlacklist', args.splice(2).join(' ').toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('discordBlacklist', actionArgs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.remove.success'));
|
||||
loadBlackList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation blacklist list - Gives you a list of everything in the blacklist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('list')) {
|
||||
var keys = $.inidb.GetKeyList('discordBlacklist', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('#' + i + ': ' + keys[i]);
|
||||
}
|
||||
|
||||
if (temp.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.list.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.blacklist.list', temp.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('whitelist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist add [phrase or username#discriminator] - Adds a phrase, word or username that will not get checked by the moderation system.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('discordWhitelist', actionArgs, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.add.success'));
|
||||
loadWhitelist();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist add [phrase or username#discriminator] - Removes that phrase, word or username from the whitelist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.usage'));
|
||||
return;
|
||||
} else if (!$.inidb.exists('discordWhitelist', args.splice(2).join(' ').toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
actionArgs = args.splice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('discordWhitelist', actionArgs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.remove.success'));
|
||||
loadWhitelist();
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation whitelist list - Gives you a list of everything in the whitelist.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('list')) {
|
||||
var keys = $.inidb.GetKeyList('discordWhitelist', ''),
|
||||
temp = [],
|
||||
i;
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
temp.push('#' + i + ': ' + keys[i]);
|
||||
}
|
||||
|
||||
if (temp.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.list.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.whitelist.list', temp.join('\r\n')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation cleanup [channel] [amount] - Will delete that amount of messages for that channel.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('cleanup')) {
|
||||
var resolvedChannel = null;
|
||||
if (subAction === undefined || (actionArgs == undefined || isNaN(parseInt(actionArgs)))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.usage'));
|
||||
return;
|
||||
} else if (parseInt(actionArgs) > 10000 || parseInt(actionArgs) < 2) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.err.amount'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.match(/<#\d+>/)) {
|
||||
resolvedChannel = $.discordAPI.getChannelByID(subAction.match(/<#(\d+)>/)[1]);
|
||||
}
|
||||
if (resolvedChannel == null) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.err.unknownchannel', subAction));
|
||||
return;
|
||||
}
|
||||
|
||||
$.discordAPI.bulkDelete(resolvedChannel, parseInt(actionArgs));
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.cleanup.done', actionArgs));
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('logs')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.toggle.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation logs toggle - Will toggle if Twitch moderation logs are to be said in Discord. Requires a bot restart.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('toggle')) {
|
||||
modLogs = !modLogs;
|
||||
$.setIniDbBoolean('discordSettings', 'modLogs', modLogs);
|
||||
$.setIniDbBoolean('chatModerator', 'moderationLogs', modLogs);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.toggle', (modLogs ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath moderation logs channel [channel name] - Will make Twitch moderator action be announced in that channel.
|
||||
*/
|
||||
if (subAction.equalsIgnoreCase('channel')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
modLogChannel = $.discord.sanitizeChannelName(args.splice(2).join(' '));
|
||||
$.setIniDbString('discordSettings', 'modLogChannel', modLogChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('moderation.logs.channel.set', args.splice(2).join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/core/moderation.js')) {
|
||||
reload();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
if ($.bot.isModuleEnabled('./discord/core/moderation.js')) {
|
||||
$.discord.registerCommand('./discord/core/moderation.js', 'moderation', 1);
|
||||
$.discord.registerSubCommand('moderation', 'links', 1);
|
||||
$.discord.registerSubCommand('moderation', 'caps', 1);
|
||||
$.discord.registerSubCommand('moderation', 'longmessage', 1);
|
||||
$.discord.registerSubCommand('moderation', 'spam', 1);
|
||||
$.discord.registerSubCommand('moderation', 'blacklist', 1);
|
||||
$.discord.registerSubCommand('moderation', 'whitelist', 1);
|
||||
$.discord.registerSubCommand('moderation', 'cleanup', 1);
|
||||
$.discord.registerSubCommand('moderation', 'logs', 1);
|
||||
|
||||
loadWhitelist();
|
||||
loadBlackList();
|
||||
setInterval(function() {
|
||||
if (spam.length !== 0 && lastMessage - $.systemTime() <= 0) {
|
||||
spam = {};
|
||||
if (permitList.length !== 0) {
|
||||
permitList = {};
|
||||
}
|
||||
}
|
||||
}, 6e4, 'scripts::discord::core::moderation');
|
||||
}
|
||||
});
|
||||
})();
|
||||
57
libs/phantombot/scripts/discord/core/patternDetector.js
Normal file
57
libs/phantombot/scripts/discord/core/patternDetector.js
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var link = new RegExp('((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-z0-9\\$\\-\\_\\.\\+\\!\\*\\\'\\(\\)' + '\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-z0-9\\$\\-\\_' + '\\.\\+\\!\\*\\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?' + '((?:(?:[a-z0-9][a-z0-9\\-]{0,64}\\.)+' + '(?:' + '(?:aero|arpa|app|a[cdefgilmnoqrstuwxz])' + '|(?:biz|bar|best|bingo|bot|b[abdefghijmnorstvwyz])' + '|(?:cat|com|coop|cash|chat|codes|cool|c[acdfghiklmnoruvxyz])' + '|d[ejkmoz]' + '|(?:edu|e[cegrstu])' + '|(?:fyi|f[ijkmor])' + '|(?:gov|g[abdefghilmnpqrstuwy])' + '|(?:how|h[kmnrtu])' + '|(?:info|int|i[delmnoqrst])' + '|(?:jobs|j[emop])' + '|k[eghimnrwyz]' + '|l[abcikrstuvy]' + '|(?:mil|mobi|moe|m[acdeghklmnopqrstuvwxyz])' + '|(?:name|net|n[acefgilopruz])' + '|(?:org|om)' + '|(?:pro|p[aefghklmnrstwy])' + '|qa' + '|(?:rodeo|rocks|r[eouw])' + '|(?:stream|support|sale|s[abcdeghijklmnortuvyz])' + '|(?:tel|travel|top|t[cdfghjklmnoprtvwz])' + '|u[agkmsyz]' + '|(?:vote|video|v[aceginu])' + '|(?:xxx)' + '|(?:watch|w[fs])' + '|y[etu]' + '|z[amw]))' + '|(?:(?:25[0-5]|2[0-4]' + '[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]' + '|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]' + '[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}' + '|[1-9][0-9]|[0-9])))' + '(?:\\:\\d{1,5})?)' + '(\\/(?:(?:[a-z0-9\\;\\/\\?\\:\\@\\&\\=\\#\\~' + '\\-\\.\\+\\!\\*\\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?' + '(?:\\b|$)' + '|(\\.[a-z]+\\/|magnet:\/\/|mailto:\/\/|ed2k:\/\/|irc:\/\/|ircs:\/\/|skype:\/\/|ymsgr:\/\/|xfire:\/\/|steam:\/\/|aim:\/\/|spotify:\/\/)', 'i'),
|
||||
caps = /([A-Z])/g,
|
||||
lastLink = '';
|
||||
|
||||
/**
|
||||
* @function hasLink
|
||||
*
|
||||
* @export $.discord.pattern
|
||||
* @param {String} message
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasLink(message) {
|
||||
try {
|
||||
lastLink = link.exec(message)[0];
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCapsCount
|
||||
*
|
||||
* @export $.discord.pattern
|
||||
* @param {String} message
|
||||
* @return {Number}
|
||||
*/
|
||||
function getCapsCount(message) {
|
||||
var sequences = message.match(caps);
|
||||
|
||||
return (sequences === null ? 0 : sequences.length);
|
||||
}
|
||||
|
||||
/* Export to the $. API. */
|
||||
$.discord.pattern = {
|
||||
getCapsCount: getCapsCount,
|
||||
hasLink: hasLink
|
||||
};
|
||||
})();
|
||||
355
libs/phantombot/scripts/discord/core/registerCommand.js
Normal file
355
libs/phantombot/scripts/discord/core/registerCommand.js
Normal file
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This script is made to register discord commands.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var commands = {},
|
||||
aliases = {};
|
||||
|
||||
/**
|
||||
* @function commandExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {boolean}
|
||||
*/
|
||||
function commandExists(command) {
|
||||
return (commands[command] !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function aliasExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {boolean}
|
||||
*/
|
||||
function aliasExists(command) {
|
||||
return (aliases[command] !== undefined && aliases[command] !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function subCommandExists
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {boolean}
|
||||
*/
|
||||
function subCommandExists(command, subCommand) {
|
||||
return (commands[command] !== undefined && commands[command].subCommand[subCommand] !== undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {JSON} permission
|
||||
*/
|
||||
function setCommandPermission(command, permission) {
|
||||
if (command.includes(' ')) {
|
||||
if (subCommandExists(command.split(' ')[0], command.split(' ')[1])) {
|
||||
commands[command.split(' ')[0]].subCommand[command.split(' ')[1]].permission = getJSONCommandPermission(command, permission);
|
||||
}
|
||||
} else {
|
||||
if (commandExists(command)) {
|
||||
commands[command].permission = getJSONCommandPermission(command, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @info Gets the json for the command permission
|
||||
*/
|
||||
function getJSONCommandPermission(commandStr, permission) {
|
||||
// Already JSON return.
|
||||
if (permission.toString().startsWith('{')) {
|
||||
return permission;
|
||||
}
|
||||
|
||||
// The script sometimes load before discord, so add this.
|
||||
while (!$.inidb.exists('discordPermsObj', 'obj')) {
|
||||
try {
|
||||
java.lang.Thread.sleep(1000);
|
||||
} catch (ex) {
|
||||
$.log.error('Failed to set permission on Discord command as Discord is not connected. Please restart PhantomBot.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Build a new json object for the permissions of this command.
|
||||
var everyoneRoleID = 0;
|
||||
var discordRoles = $.discordAPI.getGuildRoles();
|
||||
var permissionsObj = {
|
||||
'roles': [],
|
||||
'permissions': []
|
||||
};
|
||||
|
||||
for (var i = 0; i < discordRoles.size(); i++) {
|
||||
if (discordRoles.get(i).getName().equalsIgnoreCase('@everyone')) {
|
||||
everyoneRoleID = discordRoles.get(i).getId().asString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((permission + '').equals('0')) {
|
||||
permissionsObj.roles.push(everyoneRoleID + '');
|
||||
}
|
||||
|
||||
permissionsObj.permissions.push({
|
||||
'name': 'Administrator',
|
||||
'selected': ((permission + '').equals('1') + '')
|
||||
});
|
||||
|
||||
return JSON.stringify(permissionsObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandCost
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {int} cost
|
||||
*/
|
||||
function setCommandCost(command, cost) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].cost = parseInt(cost);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function setCommandAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} alias
|
||||
*/
|
||||
function setCommandAlias(command, alias) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].alias = alias.toLowerCase();
|
||||
aliases[commands[command].alias] = command.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function removeAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} alias
|
||||
*/
|
||||
function removeAlias(command, alias) {
|
||||
if (commandExists(command)) {
|
||||
delete aliases[commands[command].alias];
|
||||
commands[command].alias = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandCost
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {int}
|
||||
*/
|
||||
function getCommandCost(command) {
|
||||
if (commandExists(command)) {
|
||||
return commands[command].cost;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {int}
|
||||
*/
|
||||
function getCommandPermission(command) {
|
||||
if (commandExists(command)) {
|
||||
return JSON.parse(commands[command].permission);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandPermission
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @return {int}
|
||||
*/
|
||||
function getSubCommandPermission(command, subCommand) {
|
||||
if (commandExists(command) && subCommandExists(command, subCommand)) {
|
||||
return JSON.parse(commands[command].subCommand[subCommand].permission);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function updateCommandChannel(command) {
|
||||
if (commandExists(command)) {
|
||||
commands[command].channels = ($.inidb.exists('discordChannelcom', command) ? $.inidb.get('discordChannelcom', command) : '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandChannelAllowed
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} channelName
|
||||
* @param {string} channelId
|
||||
* @return {string}
|
||||
*/
|
||||
function getCommandChannelAllowed(command, channelName, channelId) {
|
||||
if (commandExists(command) && commands[command].channels !== '') {
|
||||
var channels = commands[command].channels;
|
||||
var found = channels.indexOf(channelName + ',') === 0 || channels.indexOf(',' + channelName + ',') >= 0
|
||||
|| (channels.indexOf(channelName) === channels.lastIndexOf(',') + 1 && channels.endsWith(channelName))
|
||||
|| channels.indexOf(channelId + ',') === 0 || channels.indexOf(',' + channelId + ',') >= 0
|
||||
|| (channels.indexOf(channelId) === channels.lastIndexOf(',') + 1 && channels.endsWith(channelId));
|
||||
return found;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getCommandAlias
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @return {string}
|
||||
*/
|
||||
function getCommandAlias(command) {
|
||||
if (aliasExists(command)) {
|
||||
return aliases[command];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @function registerCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} scriptFile
|
||||
* @param {string} command
|
||||
* @param {int} permission
|
||||
*/
|
||||
function registerCommand(scriptFile, command, permission) {
|
||||
if (!commandExists(command)) {
|
||||
if ($.inidb.exists('discordPermcom', command)) {
|
||||
permission = $.getIniDbString('discordPermcom', command);
|
||||
} else {
|
||||
permission = $.getSetIniDbString('discordPermcom', command, getJSONCommandPermission(command, permission));
|
||||
}
|
||||
|
||||
commands[command] = {
|
||||
permission: getJSONCommandPermission(command, permission),
|
||||
cost: ($.inidb.exists('discordPricecom', command) ? $.inidb.get('discordPricecom', command) : 0),
|
||||
alias: ($.inidb.exists('discordAliascom', command) ? $.inidb.get('discordAliascom', command) : ''),
|
||||
channels: ($.inidb.exists('discordChannelcom', command) ? $.inidb.get('discordChannelcom', command) : ''),
|
||||
scriptFile: scriptFile,
|
||||
subCommand: {}
|
||||
};
|
||||
|
||||
|
||||
if (commands[command].alias !== '') {
|
||||
aliases[commands[command].alias] = command;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function registerSubCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
* @param {int} permission
|
||||
*/
|
||||
function registerSubCommand(command, subCommand, permission) {
|
||||
if (commandExists(command) && !subCommandExists(command, subCommand)) {
|
||||
if ($.inidb.exists('discordPermcom', command)) {
|
||||
permission = $.getIniDbString('discordPermcom', command);
|
||||
} else {
|
||||
permission = $.getSetIniDbString('discordPermcom', command, getJSONCommandPermission(command, permission));
|
||||
}
|
||||
|
||||
commands[command].subCommand[subCommand] = {
|
||||
permission: getJSONCommandPermission((command + ' ' + subCommand), permission)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function unregisterSubCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
* @param {string} subCommand
|
||||
*/
|
||||
function unregisterSubCommand(command, subCommand) {
|
||||
if (commandExists(command) && subCommandExists(command, subCommand)) {
|
||||
delete commands[command].subCommand[subCommand];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function unregisterCommand
|
||||
*
|
||||
* @export $.discord
|
||||
* @param {string} command
|
||||
*/
|
||||
function unregisterCommand(command) {
|
||||
if (commandExists(command)) {
|
||||
if (commands[command].alias !== '') {
|
||||
delete aliases[commands[command].alias];
|
||||
}
|
||||
delete commands[command];
|
||||
}
|
||||
}
|
||||
|
||||
/* Export the function to the $.discord api. */
|
||||
$.discord.commands = commands;
|
||||
$.discord.commandExists = commandExists;
|
||||
$.discord.subCommandExists = subCommandExists;
|
||||
$.discord.getCommandPermission = getCommandPermission;
|
||||
$.discord.getSubCommandPermission = getSubCommandPermission;
|
||||
$.discord.registerCommand = registerCommand;
|
||||
$.discord.registerSubCommand = registerSubCommand;
|
||||
$.discord.unregisterCommand = unregisterCommand;
|
||||
$.discord.unregisterSubCommand = unregisterSubCommand;
|
||||
$.discord.setCommandPermission = setCommandPermission;
|
||||
$.discord.getCommandChannelAllowed = getCommandChannelAllowed;
|
||||
$.discord.updateCommandChannel = updateCommandChannel;
|
||||
$.discord.setCommandCost = setCommandCost;
|
||||
$.discord.getCommandCost = getCommandCost;
|
||||
$.discord.getCommandAlias = getCommandAlias;
|
||||
$.discord.setCommandAlias = setCommandAlias;
|
||||
$.discord.aliasExists = aliasExists;
|
||||
$.discord.removeAlias = removeAlias;
|
||||
})();
|
||||
303
libs/phantombot/scripts/discord/core/roleManager.js
Normal file
303
libs/phantombot/scripts/discord/core/roleManager.js
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var autoSetPermissions = $.getSetIniDbBoolean('discordSettings', 'autoSetPermissions', false),
|
||||
autoSetRanks = $.getSetIniDbBoolean('discordSettings', 'autoSetRanks', false);
|
||||
|
||||
/*
|
||||
* updateRoleManager
|
||||
*/
|
||||
function updateRoleManager() {
|
||||
autoSetPermissions = $.getIniDbBoolean('discordSettings', 'autoSetPermissions');
|
||||
autoSetRanks = $.getIniDbBoolean('discordSettings', 'autoSetRanks');
|
||||
}
|
||||
|
||||
/*
|
||||
* @function roleUpdateCheck
|
||||
*/
|
||||
function roleUpdateCheck() {
|
||||
if ($.discord.isConnected()) {
|
||||
var users = $.inidb.GetKeyList('discordToTwitch', ''),
|
||||
i;
|
||||
|
||||
// If both options are disabled, stop here.
|
||||
if (autoSetPermissions === false && autoSetRanks === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create our default roles.
|
||||
createRoles();
|
||||
|
||||
// Wait a bit to create the roles.
|
||||
setTimeout(function() {
|
||||
for (i in users) {
|
||||
try {
|
||||
if (hasRankOrPermission($.getIniDbString('discordToTwitch', users[i]))) {
|
||||
updateRoles(users[i], getRanksAndPermissions($.getIniDbString('discordToTwitch', users[i])));
|
||||
}
|
||||
} catch (e){
|
||||
$.log.error(e);
|
||||
}
|
||||
}
|
||||
}, 5e3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function updateRoles
|
||||
*
|
||||
* @param {Number} id
|
||||
* @param {Array} roles
|
||||
*/
|
||||
function updateRoles(id, roles) {
|
||||
var oldRoles = $.getIniDbString('discordRoles', id, ',').split(','),
|
||||
currentRoles = $.discordAPI.getUserRoles(id),
|
||||
newRoles = roles.join(','),
|
||||
idx,
|
||||
i;
|
||||
|
||||
// Build our roles list.
|
||||
for (i in currentRoles) {
|
||||
// If the user's current Discord role list contains an old role, and the new list does not have it, don't add it to the list.
|
||||
if ((oldRoles.length > 0 && hasRole(oldRoles, currentRoles[i].getName())) && newRoles.indexOf(currentRoles[i].getName()) === -1) {
|
||||
continue;
|
||||
} else {
|
||||
if (!hasRole(roles, currentRoles[i].getName())) {
|
||||
roles.push(currentRoles[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only update the user's role if there's a new one.
|
||||
for (i in roles) {
|
||||
if (!hasRole(currentRoles, roles[i], true)) {
|
||||
var roleObjs = $.discordAPI.getRoleObjects(roles);
|
||||
$.discordAPI.editUserRoles(id, roleObjs);
|
||||
$.setIniDbString('discordRoles', id, newRoles);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function createRoles
|
||||
*/
|
||||
function createRoles() {
|
||||
if (autoSetPermissions === true) {
|
||||
var keys = $.inidb.GetKeyList('groups', ''),
|
||||
group = '',
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
group = $.getIniDbString('groups', keys[i]).trim();
|
||||
|
||||
var hasTheRole = false;
|
||||
|
||||
try {
|
||||
hasTheRole = $.discordAPI.getRole(group) != null;
|
||||
} catch(e){}
|
||||
|
||||
if (!$.inidb.exists('blacklistedDiscordRoles', group.toLowerCase()) && !hasTheRole) {
|
||||
$.discordAPI.createRole(group);
|
||||
} else if (hasTheRole && $.inidb.exists('blacklistedDiscordRoles', group.toLowerCase())) {
|
||||
$.discordAPI.deleteRole(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (autoSetRanks === true) {
|
||||
var keys = $.inidb.GetKeyList('ranksMapping', ''),
|
||||
rank = '',
|
||||
i;
|
||||
|
||||
// Remove old ranks.
|
||||
cleanOldRanks();
|
||||
|
||||
for (i in keys) {
|
||||
rank = $.getIniDbString('ranksMapping', keys[i]).trim();
|
||||
|
||||
var hasTheRole = false;
|
||||
|
||||
try {
|
||||
hasTheRole = $.discordAPI.getRole(rank) != null;
|
||||
} catch(e){}
|
||||
|
||||
if (!$.inidb.exists('blacklistedDiscordRoles', rank.toLowerCase()) && !hasTheRole) {
|
||||
$.discordAPI.createRole(rank);
|
||||
$.setIniDbString('discordRanks', rank, keys[i]);
|
||||
} else if (hasTheRole && $.inidb.exists('blacklistedDiscordRoles', rank.toLowerCase())) {
|
||||
$.discordAPI.deleteRole(rank);
|
||||
$.inidb.del('discordRanks', rank);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function hasRole
|
||||
*
|
||||
* @param {Array} array
|
||||
* @param {String} role
|
||||
* @param {Boolean} getName
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasRole(array, role, getName) {
|
||||
for (var i in array) {
|
||||
if (!getName) {
|
||||
if (array[i].equalsIgnoreCase(role)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (array[i].getName().equalsIgnoreCase(role)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @function cleanOldRanks
|
||||
*/
|
||||
function cleanOldRanks() {
|
||||
var keys = $.inidb.GetKeyList('discordRanks', ''),
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
if (!$.getIniDbString('ranksMapping', $.getIniDbNumber('discordRanks', keys[i]), '').equalsIgnoreCase(keys[i])) {
|
||||
$.discordAPI.deleteRole(keys[i]);
|
||||
$.inidb.del('discordRanks', keys[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function hasRankOrPermission
|
||||
*
|
||||
* @param {String} username
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function hasRankOrPermission(username) {
|
||||
return (getRanksAndPermissions(username).length > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getRanksAndPermissions
|
||||
*
|
||||
* @param {String} username
|
||||
* @return {Array}
|
||||
*/
|
||||
function getRanksAndPermissions(username) {
|
||||
var roles = [],
|
||||
role;
|
||||
|
||||
if (autoSetPermissions === true) {
|
||||
if ($.inidb.exists('group', username) && !$.inidb.exists('blacklistedDiscordRoles', $.getIniDbString('group', username).toLowerCase())) {
|
||||
roles.push($.getIniDbString('groups', $.getIniDbString('group', username)));
|
||||
}
|
||||
}
|
||||
|
||||
if (autoSetRanks === true) {
|
||||
if ($.hasRank(username) && !$.inidb.exists('blacklistedDiscordRoles', $.getRank(username).toLowerCase())) {
|
||||
roles.push($.getRank(username));
|
||||
}
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
/*
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1],
|
||||
actionArgs = args[2];
|
||||
|
||||
if (command.equalsIgnoreCase('rolemanager')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager togglesyncpermissions - Makes the bot sync default permissions with those who have their accounts linked.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglesyncpermissions')) {
|
||||
autoSetPermissions = !autoSetPermissions;
|
||||
$.setIniDbBoolean('discordSettings', 'autoSetPermissions', autoSetPermissions);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (autoSetPermissions ? $.lang.get('discord.rolemanager.permission.sync.on') : $.lang.get('discord.rolemanager.permission.sync.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager togglesyncranks - Makes the bot sync ranks with those who have their accounts linked.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglesyncranks')) {
|
||||
autoSetRanks = !autoSetRanks;
|
||||
$.setIniDbBoolean('discordSettings', 'autoSetRanks', autoSetRanks);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (autoSetRanks ? $.lang.get('discord.rolemanager.ranks.sync.on') : $.lang.get('discord.rolemanager.ranks.sync.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath rolemanager blacklist [add / remove] [permission or rank] - Blacklist a rank or permission from being used.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('blacklist')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('add')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var blacklist = args.slice(2).join(' ').toLowerCase();
|
||||
$.setIniDbString('blacklistedDiscordRoles', blacklist, 'true');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.add.success', blacklist));
|
||||
}
|
||||
|
||||
if (subAction.equalsIgnoreCase('remove')) {
|
||||
if (actionArgs === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.remove.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var blacklist = args.slice(2).join(' ').toLowerCase();
|
||||
$.inidb.del('blacklistedDiscordRoles', blacklist);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.rolemanager.blacklist.remove.success', blacklist));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/core/roleManager.js', 'rolemanager', 1);
|
||||
|
||||
setInterval(roleUpdateCheck, 3e4);
|
||||
});
|
||||
})();
|
||||
1
libs/phantombot/scripts/discord/custom/README.txt
Normal file
1
libs/phantombot/scripts/discord/custom/README.txt
Normal file
@@ -0,0 +1 @@
|
||||
Place custom scripts in this directory.
|
||||
74
libs/phantombot/scripts/discord/games/8ball.js
Normal file
74
libs/phantombot/scripts/discord/games/8ball.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the 8ball game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('8ball.answer.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath 8ball [question] - Ask the magic 8ball a question.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('8ball')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('8ball.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('8ball.discord.response', $.lang.get('8ball.answer.' + random)));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/8ball.js', '8ball', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
182
libs/phantombot/scripts/discord/games/gambling.js
Normal file
182
libs/phantombot/scripts/discord/games/gambling.js
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var winGainPercent = $.getSetIniDbNumber('discordGambling', 'winGainPercent', 30),
|
||||
winRange = $.getSetIniDbNumber('discordGambling', 'winRange', 50),
|
||||
max = $.getSetIniDbNumber('discordGambling', 'max', 100),
|
||||
min = $.getSetIniDbNumber('discordGambling', 'min', 5),
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
|
||||
/**
|
||||
* @function reloadGamble
|
||||
*/
|
||||
function reloadGamble() {
|
||||
winGainPercent = $.getIniDbNumber('discordGambling', 'winGainPercent');
|
||||
winRange = $.getIniDbNumber('discordGambling', 'winRange');
|
||||
max = $.getIniDbNumber('discordGambling', 'max');
|
||||
min = $.getIniDbNumber('discordGambling', 'min');
|
||||
gain = Math.abs(winGainPercent / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function gamble
|
||||
*
|
||||
* @param {int amout}
|
||||
* @param {string} sender
|
||||
*/
|
||||
function gamble(channel, sender, mention, username, amount) {
|
||||
var winnings = 0,
|
||||
winSpot = 0,
|
||||
range = $.randRange(1, 100);
|
||||
|
||||
if ($.getUserPoints(sender) < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.need.points', $.pointNameMultiple));
|
||||
return;
|
||||
}
|
||||
|
||||
if (max < amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.max', $.getPointsString(max)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (min > amount) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.error.min', $.getPointsString(min)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (range <= winRange) {
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.lost', $.discord.userPrefix(mention), range, $.getPointsString(amount), $.getPointsString($.getUserPoints(sender) - amount), $.gameMessages.getLose(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
} else {
|
||||
winSpot = (range - winRange + 1);
|
||||
winnings = Math.floor(amount + ((amount + winSpot) * gain));
|
||||
$.discord.say(channel, $.lang.get('discord.gambling.won', $.discord.userPrefix(mention), range, $.getPointsString(winnings), $.getPointsString($.getUserPoints(sender) + (winnings - amount)), $.gameMessages.getWin(username, 'gamble')));
|
||||
$.inidb.decr('points', sender, amount);
|
||||
$.inidb.incr('points', sender, winnings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
/**
|
||||
* @discordcommandpath gamble [amount] - Gamble your points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('gamble')) {
|
||||
if (isNaN(parseInt(action))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.usage'));
|
||||
} else {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
gamble(channel, twitchName, mention, sender, parseInt(action));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('gambling')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.main.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmax [amount] - Set how many points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmax')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max.usage'));
|
||||
return;
|
||||
}
|
||||
max = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'max', max);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.max', $.getPointsString(max)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setmin [amount] - Set the minimum amount of points people can gamble.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setmin')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min.usage'));
|
||||
return;
|
||||
}
|
||||
min = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'min', min);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.set.min', $.getPointsString(min)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setwinningrange [range] - Set the winning range from 0-100. The higher the less of a chance people have at winning.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setwinningrange')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range.usage'));
|
||||
return;
|
||||
}
|
||||
winRange = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winRange', winRange);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.win.range', parseInt(winRange) + 1, winRange));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath gambling setgainpercent [amount in percent] - Set the winning gain percent.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('setgainpercent')) {
|
||||
if (isNaN(parseInt(subAction))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent.usage'));
|
||||
return;
|
||||
}
|
||||
winGainPercent = parseInt(subAction);
|
||||
$.inidb.set('discordGambling', 'winGainPercent', winGainPercent);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.gambling.percent', winGainPercent));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./games/gambling.js', 'gamble', 0);
|
||||
$.discord.registerCommand('./games/gambling.js', 'gambling', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmax', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setmin', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setwinningrange', 1);
|
||||
$.discord.registerSubCommand('gambling', 'setgainpercent', 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/gambling.js')) {
|
||||
reloadGamble();
|
||||
}
|
||||
});
|
||||
})();
|
||||
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
103
libs/phantombot/scripts/discord/games/kill.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var selfMessageCount = 0,
|
||||
otherMessageCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('killcommand.self.' + i); i++) {
|
||||
selfMessageCount++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('killcommand.other.' + i); i++) {
|
||||
otherMessageCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function selfKill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} channel
|
||||
*/
|
||||
function selfKill(sender, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, selfMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.self.' + random, sender));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function kill
|
||||
*
|
||||
* @param {String} sender
|
||||
* @param {String} username
|
||||
* @param {String} channel
|
||||
*/
|
||||
function kill(sender, username, channel) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, otherMessageCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.lang.get('killcommand.other.' + random, sender, username, $.getIniDbNumber('settings', 'killTimeoutTime', 60), $.botName).replace('(jail)', ''));
|
||||
lastRandom = random;
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
args = event.getArgs();
|
||||
|
||||
/**
|
||||
* @discordcommandpath kill [username] - Kill a fellow viewer (not for real!).
|
||||
*/
|
||||
if (command.equalsIgnoreCase('kill')) {
|
||||
if (args.length === 0) {
|
||||
selfKill(sender, channel);
|
||||
} else {
|
||||
kill(sender, args[0], channel);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/kill.js', 'kill', 0);
|
||||
|
||||
if (otherMessageCount === 0 && selfMessageCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
65
libs/phantombot/scripts/discord/games/random.js
Normal file
65
libs/phantombot/scripts/discord/games/random.js
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCount = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('randomcommand.' + i); i++) {
|
||||
responseCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath random - Will display something really random.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('random')) {
|
||||
var random;
|
||||
do {
|
||||
random = $.randRange(1, responseCount);
|
||||
} while (random == lastRandom);
|
||||
|
||||
$.discord.say(channel, $.tags(event, $.lang.get('randomcommand.' + random), false));
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/random.js', 'random', 0);
|
||||
|
||||
if (responseCount === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
134
libs/phantombot/scripts/discord/games/roll.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var rewards = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordRollReward', 'rewards_0', 4);
|
||||
rewards[1] = $.getSetIniDbNumber('discordRollReward', 'rewards_1', 16);
|
||||
rewards[2] = $.getSetIniDbNumber('discordRollReward', 'rewards_2', 36);
|
||||
rewards[3] = $.getSetIniDbNumber('discordRollReward', 'rewards_3', 64);
|
||||
rewards[4] = $.getSetIniDbNumber('discordRollReward', 'rewards_4', 100);
|
||||
rewards[5] = $.getSetIniDbNumber('discordRollReward', 'rewards_5', 144);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function roll
|
||||
*
|
||||
* @param {String} channel
|
||||
* @param {String} sender
|
||||
* @param {String} twitchName
|
||||
* @param {String} mention
|
||||
*/
|
||||
function roll(channel, sender, twitchName, mention) {
|
||||
var dice1 = $.randRange(1, 6),
|
||||
dice2 = $.randRange(1, 6),
|
||||
resultMessage = $.lang.get('discord.roll.rolled', $.discord.userPrefix(mention), dice1, dice2);
|
||||
|
||||
if (dice1 == dice2) {
|
||||
switch (dice1) {
|
||||
case 1:
|
||||
resultMessage += $.lang.get('discord.roll.doubleone', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 2:
|
||||
resultMessage += $.lang.get('discord.roll.doubletwo', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 3:
|
||||
resultMessage += $.lang.get('discord.roll.doublethree', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 4:
|
||||
resultMessage += $.lang.get('discord.roll.doublefour', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 5:
|
||||
resultMessage += $.lang.get('discord.roll.doublefive', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
case 6:
|
||||
resultMessage += $.lang.get('discord.roll.doublesix', $.getPointsString(rewards[dice1 - 1]));
|
||||
break;
|
||||
}
|
||||
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getWin(sender, 'roll'));
|
||||
$.inidb.incr('points', twitchName, rewards[dice1 - 1]);
|
||||
} else {
|
||||
$.discord.say(channel, resultMessage + $.gameMessages.getLose(sender, 'roll'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
if (command.equalsIgnoreCase('roll')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
roll(channel, sender, twitchName, mention);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath roll rewards [rewards] - Sets the rewards for the dice roll
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 7 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5])) && !isNaN(parseInt(args[6]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.success'));
|
||||
$.inidb.set('discordRollReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordRollReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordRollReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordRollReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordRollReward', 'reward_4', args[5]);
|
||||
$.inidb.set('discordRollReward', 'reward_5', args[6]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.roll.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roll.js', 'roll', 0);
|
||||
$.discord.registerSubCommand('roll', 'rewards', 1);
|
||||
loadRewards();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/roll.js')) {
|
||||
loadRewards();
|
||||
}
|
||||
});
|
||||
})();
|
||||
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
80
libs/phantombot/scripts/discord/games/roulette.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handles the random game.
|
||||
*/
|
||||
(function() {
|
||||
var responseCountWin = 0,
|
||||
responseCountLost = 0,
|
||||
lastRandom = 0;
|
||||
|
||||
/**
|
||||
* @function loadResponses
|
||||
*/
|
||||
function loadResponses() {
|
||||
for (var i = 1; $.lang.exists('roulette.win.' + i); i++) {
|
||||
responseCountWin++;
|
||||
}
|
||||
|
||||
for (var i = 1; $.lang.exists('roulette.lost.' + i); i++) {
|
||||
responseCountLost++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getUsername(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand();
|
||||
|
||||
/**
|
||||
* @discordcommandpath roulette - Pull the trigger and find out if there's a bullet in the chamber
|
||||
*/
|
||||
if (command.equalsIgnoreCase('roulette')) {
|
||||
var r1 = $.randRange(1, 2),
|
||||
r2 = $.randRange(1, 2),
|
||||
random;
|
||||
|
||||
if (r1 == r2) {
|
||||
do {
|
||||
random = $.randRange(1, responseCountWin);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.win.' + random, sender));
|
||||
} else {
|
||||
do {
|
||||
random = $.randRange(1, responseCountLost);
|
||||
} while (random == lastRandom);
|
||||
$.discord.say(channel, $.lang.get('roulette.lost.' + random, sender));
|
||||
}
|
||||
lastRandom = random;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/roulette.js', 'roulette', 0);
|
||||
|
||||
if (responseCountWin === 0 && responseCountLost === 0) {
|
||||
loadResponses();
|
||||
}
|
||||
});
|
||||
})();
|
||||
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
153
libs/phantombot/scripts/discord/games/slotMachine.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var rewards = [],
|
||||
emojis = [];
|
||||
|
||||
/**
|
||||
* @function loadRewards
|
||||
*/
|
||||
function loadRewards() {
|
||||
rewards[0] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_0', 75);
|
||||
rewards[1] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_1', 150);
|
||||
rewards[2] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_2', 300);
|
||||
rewards[3] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_3', 450);
|
||||
rewards[4] = $.getSetIniDbNumber('discordSlotMachineReward', 'reward_4', 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function loadEmojis
|
||||
*/
|
||||
function loadEmojis() {
|
||||
emojis[0] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_0', ':cherries:');
|
||||
emojis[1] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_1', ':strawberry:');
|
||||
emojis[2] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_2', ':tangerine:');
|
||||
emojis[3] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_3', ':spades:');
|
||||
emojis[4] = $.getSetIniDbString('discordSlotMachineEmojis', 'emoji_4', ':hearts:');
|
||||
}
|
||||
|
||||
/**
|
||||
* @function getEmoteKey
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
function getEmoteKey() {
|
||||
var rand = $.randRange(1, 1000);
|
||||
|
||||
if (rand <= 75) {
|
||||
return 4;
|
||||
} else if (rand > 75 && rand <= 200) {
|
||||
return 3;
|
||||
} else if (rand > 200 && rand <= 450) {
|
||||
return 2;
|
||||
} else if (rand > 450 && rand <= 700) {
|
||||
return 1;
|
||||
} else if (rand > 700) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function calculate
|
||||
*
|
||||
* @param {string} channel
|
||||
* @param {string} username
|
||||
* @param {string} mention
|
||||
* @param {string} twitchName
|
||||
*/
|
||||
function calculate(channel, username, mention, twitchName) {
|
||||
var e1 = getEmoteKey(),
|
||||
e2 = getEmoteKey(),
|
||||
e3 = getEmoteKey(),
|
||||
message = $.lang.get('discord.slotmachine.result.start', $.discord.userPrefix(mention).replace(', ', ''), emojis[e1], emojis[e2], emojis[e3]);
|
||||
|
||||
if (e1 == e2 && e2 == e3) {
|
||||
$.discord.say(channel, message + $.lang.get('discord.slotmachine.result.win', ($.getPointsString(rewards[e1]) + '.')) + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, rewards[e1]);
|
||||
} else if (e1 == e2 || (e2 == e3 && e3 == e1)) {
|
||||
$.discord.say(channel, message + $.lang.get('slotmachine.result.win', (e1 == e2 ? $.getPointsString(Math.floor(rewards[e1] * 0.3)) : $.getPointsString(Math.floor(rewards[e3] * 0.3))) + '.') + $.gameMessages.getWin(username, 'slot'));
|
||||
$.inidb.incr('points', twitchName, (e1 == e2 ? (Math.floor(rewards[e1] * 0.3)) : (Math.floor(rewards[e3] * 0.3))));
|
||||
} else {
|
||||
$.discord.say(channel, message + $.gameMessages.getLose(username, 'slot'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/**
|
||||
* @discordcommandpath slot - Play the slot machines for some points.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('slot')) {
|
||||
if (action === undefined) {
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName !== null) {
|
||||
calculate(channel, sender, mention, twitchName);
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* @discordcommandpath slot rewards [rewards] - Sets the rewards for the slot machine
|
||||
*/
|
||||
if (action.equalsIgnoreCase('rewards')) {
|
||||
if (args.length === 6 && !isNaN(parseInt(args[1])) && !isNaN(parseInt(args[2])) && !isNaN(parseInt(args[3])) && !isNaN(parseInt(args[4])) && !isNaN(parseInt(args[5]))) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.success'));
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_0', args[1]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_1', args[2]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_2', args[3]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_3', args[4]);
|
||||
$.inidb.set('discordSlotMachineReward', 'reward_4', args[5]);
|
||||
loadRewards();
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.slotmachine.rewards.usage', rewards.join(' ')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/games/slotMachine.js', 'slot', 0);
|
||||
$.discord.registerSubCommand('slot', 'rewards', 1);
|
||||
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
});
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/games/slotMachine.js')) {
|
||||
loadRewards();
|
||||
loadEmojis();
|
||||
}
|
||||
})
|
||||
})();
|
||||
211
libs/phantombot/scripts/discord/handlers/bitsHandler.js
Normal file
211
libs/phantombot/scripts/discord/handlers/bitsHandler.js
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle bits notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'bitsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'bitsMessage', '(name) just cheered (amount) bits!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'bitsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/bitsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'bitsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'bitsMessage', '(name) just cheered (amount) bits!');
|
||||
channelName = $.getIniDbString('discordSettings', 'bitsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @function getCheerAmount
|
||||
*
|
||||
* @param {String} bits
|
||||
*/
|
||||
function getCheerAmount(bits) {
|
||||
bits = parseInt(bits);
|
||||
|
||||
switch (true) {
|
||||
case bits < 100:
|
||||
return '1';
|
||||
case bits >= 100 && bits < 1000:
|
||||
return '100';
|
||||
case bits >= 1000 && bits < 5000:
|
||||
return '1000';
|
||||
case bits >= 5000 && bits < 10000:
|
||||
return '5000';
|
||||
case bits >= 10000 && bits < 100000:
|
||||
return '10000';
|
||||
case bits >= 100000:
|
||||
return '100000';
|
||||
default:
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @function getBitsColor
|
||||
*
|
||||
* @param {String} bits
|
||||
*/
|
||||
function getBitsColor(bits) {
|
||||
bits = parseInt(bits);
|
||||
|
||||
switch (true) {
|
||||
case bits < 100:
|
||||
return 0xa1a1a1;
|
||||
case bits >= 100 && bits < 1000:
|
||||
return 0x8618fc;
|
||||
case bits >= 1000 && bits < 5000:
|
||||
return 0x00f7db;
|
||||
case bits >= 5000 && bits < 10000:
|
||||
return 0x2845bc;
|
||||
case bits >= 10000 && bits < 100000:
|
||||
return 0xd41818;
|
||||
case bits >= 100000:
|
||||
return 0xfffa34;
|
||||
default:
|
||||
return 0xa1a1a1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event twitchBits
|
||||
*/
|
||||
$.bind('twitchBits', function(event) {
|
||||
var username = event.getUsername(),
|
||||
bits = event.getBits(),
|
||||
ircMessage = event.getMessage(),
|
||||
emoteRegexStr = $.twitch.GetCheerEmotesRegex(),
|
||||
s = message;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/g)) {
|
||||
s = $.replace(s, '(amount)', bits);
|
||||
}
|
||||
|
||||
if ((ircMessage + '').length > 0) {
|
||||
if (emoteRegexStr.length() > 0) {
|
||||
emoteRegex = new RegExp(emoteRegexStr, 'gi');
|
||||
ircMessage = String(ircMessage).valueOf();
|
||||
ircMessage = ircMessage.replace(emoteRegex, '').trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (ircMessage.length > 0) {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(getBitsColor(bits))
|
||||
.withThumbnail('https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/' + getCheerAmount(bits) + '/1.gif')
|
||||
.withTitle($.lang.get('discord.bitshandler.bits.embed.title'))
|
||||
.appendDescription(s)
|
||||
.appendField($.lang.get('discord.bitsHandler.bits.embed.messagetitle'), ircMessage, true)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
} else {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(getBitsColor(bits))
|
||||
.withThumbnail('https://d3aqoihi2n8ty8.cloudfront.net/actions/cheer/dark/animated/' + getCheerAmount(bits) + '/1.gif')
|
||||
.withTitle($.lang.get('discord.bitshandler.bits.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('bitshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler toggle - Toggles bit announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'bitsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler message [message] - Sets the bit announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'bitsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath bitshandler channel [channel name] - Sets the channel bit announcements will be made in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'bitsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.bitshandler.bits.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/bitsHandler.js', 'bitshandler', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('bitshandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
164
libs/phantombot/scripts/discord/handlers/clipHandler.js
Normal file
164
libs/phantombot/scripts/discord/handlers/clipHandler.js
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Script : clipHandler.js
|
||||
* Purpose : Configures the automatic display of clips in chat and captures the events from Twitch.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'clipsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'clipsMessage', '(name) created a new clip!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'clipsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/clipHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'clipsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'clipsMessage', '(name) created a new clip!');
|
||||
channelName = $.getIniDbString('discordSettings', 'clipsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchClip
|
||||
*/
|
||||
$.bind('twitchClip', function(event) {
|
||||
var creator = event.getCreator(),
|
||||
url = event.getClipURL(),
|
||||
title = event.getClipTitle(),
|
||||
clipThumbnail = event.getThumbnailObject().getString("medium"),
|
||||
s = message;
|
||||
|
||||
/* Even though the Core won't even query the API if this is false, we still check here. */
|
||||
if (announce === false || toggle === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', creator);
|
||||
}
|
||||
|
||||
if (s.match(/\(url\)/g)) {
|
||||
s = $.replace(s, '(url)', url);
|
||||
}
|
||||
|
||||
if (s.match(/\(title\)/g)) {
|
||||
s = $.replace(s, '(title)', title);
|
||||
}
|
||||
|
||||
if (s.match(/\(embedurl\)/g)) {
|
||||
s = $.replace(s, '(embedurl)', url);
|
||||
}
|
||||
|
||||
if (message.indexOf('(embedurl)') !== -1) {
|
||||
$.discord.say(channelName, s);
|
||||
} else {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/clip-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.cliphandler.clip.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withUrl(url)
|
||||
.withImage(clipThumbnail)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event command
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
argsString = event.getArguments(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipstoggle - Toggles the clips announcements.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipstoggle')) {
|
||||
toggle = !toggle;
|
||||
$.setIniDbBoolean('discordSettings', 'clipsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + (toggle ? $.lang.get('discord.cliphandler.toggle.on') : $.lang.get('discord.cliphandler.toggle.off')));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipsmessage [message] - Sets a message for when someone creates a clip.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipsmessage')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = argsString;
|
||||
$.setIniDbString('discordSettings', 'clipsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.message.set', message));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath clipschannel [channel] - Sets the channel to send a message to for when someone creates a clip.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('clipschannel')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.channel.usage', channelName));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(action);
|
||||
$.setIniDbString('discordSettings', 'clipsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.channel.set', action));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath lastclip - Displays information about the last clip captured.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('lastclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'last_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.lastclip', url));
|
||||
}
|
||||
|
||||
/*
|
||||
* @discordcommandpath topclip - Displays the top clip from the past day.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('topclip')) {
|
||||
var url = $.getIniDbString('streamInfo', 'most_viewed_clip_url', $.lang.get('cliphandler.noclip'));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.cliphandler.topclip', url));
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipstoggle', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipsmessage', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'clipschannel', 1);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'lastclip', 0);
|
||||
$.discord.registerCommand('./discord/handlers/clipHandler.js', 'topclip', 0);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
137
libs/phantombot/scripts/discord/handlers/followHandler.js
Normal file
137
libs/phantombot/scripts/discord/handlers/followHandler.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle follower announcements.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'followToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'followMessage', '(name) just followed!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'followChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/followHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'followToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'followMessage', '(name) just followed!');
|
||||
channelName = $.getIniDbString('discordSettings', 'followChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchFollowsInitialized
|
||||
*/
|
||||
$.bind('twitchFollowsInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchFollow
|
||||
*/
|
||||
$.bind('twitchFollow', function(event) {
|
||||
var follower = event.getFollower(),
|
||||
s = message;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', follower);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(20, 184, 102)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/follow-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.followhandler.follow.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('followhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler toggle - Toggles the follower announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'followToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler message [message] - Sets the follower announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'followMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath followhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'followChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.followhandler.follow.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/followHandler.js', 'followhandler', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'message', 1);
|
||||
$.discord.registerSubCommand('followhandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
212
libs/phantombot/scripts/discord/handlers/hostHandler.js
Normal file
212
libs/phantombot/scripts/discord/handlers/hostHandler.js
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle hosts notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'hostToggle', false),
|
||||
hostMessage = $.getSetIniDbString('discordSettings', 'hostMessage', '(name) just hosted for (viewers) viewers!'),
|
||||
autoHostMessage = $.getSetIniDbString('discordSettings', 'autohostMessage', '(name) just auto-hosted!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'hostChannel', ''),
|
||||
hosters = {},
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/hostHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'hostToggle', false);
|
||||
hostMessage = $.getIniDbString('discordSettings', 'hostMessage', '(name) just hosted for (viewers) viewers!');
|
||||
autoHostMessage = $.getIniDbString('discordSettings', 'autohostMessage', '(name) just auto-hosted!');
|
||||
channelName = $.getIniDbString('discordSettings', 'hostChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchHostsInitialized
|
||||
*/
|
||||
$.bind('twitchHostsInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchAutoHosted
|
||||
*/
|
||||
$.bind('twitchAutoHosted', function(event) {
|
||||
var hoster = event.getHoster(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
now = $.systemTime(),
|
||||
s = autoHostMessage;
|
||||
|
||||
if (toggle === false || announce === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hosters[hoster] !== undefined) {
|
||||
if (hosters[hoster].time > now) {
|
||||
return;
|
||||
}
|
||||
hosters[hoster].time = now + 216e5;
|
||||
} else {
|
||||
hosters[hoster] = {};
|
||||
hosters[hoster].time = now + 216e5;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', hoster);
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', String(viewers));
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(255, 0, 0)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/host-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.hosthandler.auto.host.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchHosted
|
||||
*/
|
||||
$.bind('twitchHosted', function(event) {
|
||||
var hoster = event.getHoster(),
|
||||
viewers = parseInt(event.getUsers()),
|
||||
now = $.systemTime(),
|
||||
s = hostMessage;
|
||||
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hosters[hoster] !== undefined) {
|
||||
if (hosters[hoster].time > now) {
|
||||
return;
|
||||
}
|
||||
hosters[hoster].time = now + 216e5;
|
||||
} else {
|
||||
hosters[hoster] = {};
|
||||
hosters[hoster].time = now + 216e5;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', hoster);
|
||||
}
|
||||
|
||||
if (s.match(/\(viewers\)/g)) {
|
||||
s = $.replace(s, '(viewers)', String(viewers));
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(255, 0, 0)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/host-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.hosthandler.host.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('hosthandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler toggle - Toggles the hosts announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'hostToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler hostmessage [message] - Sets the host announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('hostmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
hostMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'hostMessage', hostMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.host.message.set', hostMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler hostmessage [message] - Sets the auto-host announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('autohostmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.autohost.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
autoHostMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'autohostMessage', autohostMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.autohost.message.set', autoHostMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath hosthandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'hostChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.hosthandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/hostHandler.js', 'hosthandler', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'hostmessage', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'autohostmessage', 1);
|
||||
$.discord.registerSubCommand('hosthandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
140
libs/phantombot/scripts/discord/handlers/keywordHandler.js
Normal file
140
libs/phantombot/scripts/discord/handlers/keywordHandler.js
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle custom keywords in discord.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
/**
|
||||
* @event discordChannelMessage
|
||||
*/
|
||||
$.bind('discordChannelMessage', function(event) {
|
||||
var message = event.getMessage().toLowerCase(),
|
||||
channel = event.getDiscordChannel(),
|
||||
keys = $.inidb.GetKeyList('discordKeywords', ''),
|
||||
keyword,
|
||||
i;
|
||||
|
||||
for (i in keys) {
|
||||
// Some users use special symbols that may break regex so this will fix that.
|
||||
try {
|
||||
if (message.match('\\b' + keys[i] + '\\b') && !message.includes('!keyword')) {
|
||||
keyword = $.inidb.get('discordKeywords', keys[i]);
|
||||
$.discord.say(channel, $.discord.tags(event, keyword));
|
||||
break;
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex.message.toLowerCase().includes('invalid quantifier') || ex.message.toLowerCase().includes('syntax')) {
|
||||
if (message.includes(keys[i]) && !message.includes('!keyword')) {
|
||||
keyword = $.inidb.get('discordKeywords', keys[i]);
|
||||
$.discord.say(channel, $.discord.tags(event, keyword));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$.log.error('Failed to send keyword "' + keys[i] + '": ' + ex.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('keyword')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword add [keyword] [response] - Adds a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (subAction === undefined || args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.error'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordKeywords', subAction.toLowerCase(), args.slice(2).join(' '));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.add.success', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword edit [keyword] [response] - Edits a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('edit')) {
|
||||
if (subAction === undefined || args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.edit.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.set('discordKeywords', subAction.toLowerCase(), args.slice(2).join(' '));
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.edit.success', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath keyword remove [keyword] - Removes a custom keyword.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('remove')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.remove.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('discordKeywords', subAction.toLowerCase())) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.404'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('discordKeywords', subAction.toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.keywordhandler.remove.success', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/keywordHandler.js', 'keyword', 1);
|
||||
$.discord.registerSubCommand('keyword', 'add', 1);
|
||||
$.discord.registerSubCommand('keyword', 'edit', 1);
|
||||
$.discord.registerSubCommand('keyword', 'remove', 1);
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle streamelements notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'streamelementsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'streamelementsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'streamelementsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamElementsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'streamelementsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'streamelementsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'streamelementsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamElementsDonationInitialized
|
||||
*/
|
||||
$.bind('streamElementsDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamElementsDonation
|
||||
*/
|
||||
$.bind('streamElementsDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getString('_id'),
|
||||
paramObj = donationObj.getJSONObject('donation'),
|
||||
donationUsername = paramObj.getJSONObject('user').getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'streamelements' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'streamelements' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', String(parseInt(donationAmount.toFixed(2))));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', String(parseInt(donationAmount.toFixed(0))));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(87, 113, 220)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/streamelements-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.streamelementshandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamelementshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler toggle - Toggles the streamelements donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'streamelementsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler message [message] - Sets the streamelements donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'streamelementsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamelementshandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'streamelementsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamelementshandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamElementsHandler.js', 'streamelementshandler', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('streamelementshandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
402
libs/phantombot/scripts/discord/handlers/streamHandler.js
Normal file
402
libs/phantombot/scripts/discord/handlers/streamHandler.js
Normal file
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle online and offline events from Twitch.
|
||||
*/
|
||||
(function() {
|
||||
var onlineToggle = $.getSetIniDbBoolean('discordSettings', 'onlineToggle', false),
|
||||
onlineMessage = $.getSetIniDbString('discordSettings', 'onlineMessage', '(name) just went online on Twitch!'),
|
||||
offlineToggle = $.getSetIniDbBoolean('discordSettings', 'offlineToggle', false),
|
||||
offlineMessage = $.getSetIniDbString('discordSettings', 'offlineMessage', '(name) is now offline.'),
|
||||
gameToggle = $.getSetIniDbBoolean('discordSettings', 'gameToggle', false),
|
||||
gameMessage = $.getSetIniDbString('discordSettings', 'gameMessage', '(name) just changed game on Twitch!'),
|
||||
botGameToggle = $.getSetIniDbBoolean('discordSettings', 'botGameToggle', true),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'onlineChannel', ''),
|
||||
deleteMessageToggle = $.getSetIniDbBoolean('discordSettings', 'deleteMessageToggle', true),
|
||||
timeout = (6e4 * 5), // 5 minutes.
|
||||
lastEvent = 0,
|
||||
msg,
|
||||
liveMessages = [],
|
||||
offlineMessages = [];
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamHandler.js')) {
|
||||
onlineToggle = $.getIniDbBoolean('discordSettings', 'onlineToggle', false);
|
||||
onlineMessage = $.getIniDbString('discordSettings', 'onlineMessage', '(name) just went online on Twitch!');
|
||||
offlineToggle = $.getIniDbBoolean('discordSettings', 'offlineToggle', false);
|
||||
offlineMessage = $.getIniDbString('discordSettings', 'offlineMessage', '(name) is now offline.');
|
||||
gameToggle = $.getIniDbBoolean('discordSettings', 'gameToggle', false);
|
||||
gameMessage = $.getIniDbString('discordSettings', 'gameMessage', '(name) just changed game on Twitch!');
|
||||
botGameToggle = $.getIniDbBoolean('discordSettings', 'botGameToggle', true);
|
||||
channelName = $.getIniDbString('discordSettings', 'onlineChannel', '');
|
||||
deleteMessageToggle = $.getSetIniDbBoolean('discordSettings', 'deleteMessageToggle', true);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* @function getTrimmedGameName
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
function getTrimmedGameName() {
|
||||
var game = $.getGame($.channelName) + '';
|
||||
|
||||
return (game.length > 15 ? game.substr(0, 15) + '...' : game);
|
||||
}
|
||||
|
||||
/**
|
||||
* @event twitchOffline
|
||||
*/
|
||||
$.bind('twitchOffline', function(event) {
|
||||
// Make sure the channel is really offline before deleting and posting the data. Wait a minute and do another check.
|
||||
setTimeout(function() {
|
||||
// Delete live messages if any.
|
||||
if (deleteMessageToggle && liveMessages.length > 0) {
|
||||
while (liveMessages.length > 0) {
|
||||
$.discordAPI.deleteMessage(liveMessages.shift());
|
||||
}
|
||||
}
|
||||
|
||||
if (botGameToggle === true) {
|
||||
$.discord.removeGame();
|
||||
}
|
||||
|
||||
if (!$.isOnline($.channelName) && offlineToggle === true) {
|
||||
var keys = $.inidb.GetKeyList('discordStreamStats', ''),
|
||||
chatters = [],
|
||||
viewers = [],
|
||||
i;
|
||||
|
||||
// Get our data.
|
||||
for (i in keys) {
|
||||
switch (true) {
|
||||
case keys[i].indexOf('chatters_') !== -1:
|
||||
chatters.push($.getIniDbNumber('discordStreamStats', keys[i]));
|
||||
case keys[i].indexOf('viewers_') !== -1:
|
||||
viewers.push($.getIniDbNumber('discordStreamStats', keys[i]));
|
||||
}
|
||||
}
|
||||
|
||||
// Get average viewers.
|
||||
var avgViewers = 1;
|
||||
if (viewers.length > 0) {
|
||||
avgViewers = Math.round(viewers.reduce(function(a, b) {
|
||||
return (a + b);
|
||||
}) / (viewers.length < 1 ? 1 : viewers.length));
|
||||
} else {
|
||||
viewers = [0];
|
||||
}
|
||||
|
||||
// Get average chatters.
|
||||
var avgChatters = 1;
|
||||
if (chatters.length > 0) {
|
||||
avgChatters = Math.round(chatters.reduce(function(a, b) {
|
||||
return (a + b);
|
||||
}) / (chatters.length < 1 ? 1 : chatters.length));
|
||||
} else {
|
||||
chatters = [0];
|
||||
}
|
||||
|
||||
// Get new follows.
|
||||
var followersNow = $.getFollows($.channelName),
|
||||
follows = (followersNow - $.getIniDbNumber('discordStreamStats', 'followers', followersNow));
|
||||
|
||||
// Get max viewers.
|
||||
var maxViewers = Math.max.apply(null, viewers);
|
||||
|
||||
// Get max chatters.
|
||||
var maxChatters = Math.max.apply(null, chatters);
|
||||
|
||||
var s = offlineMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
msg = $.discord.say(channelName, s);
|
||||
if (deleteMessageToggle) {
|
||||
offlineMessages.push(msg)
|
||||
}
|
||||
}
|
||||
|
||||
// Send the message as an embed.
|
||||
msg = $.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.offline.game'), getTrimmedGameName(), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.viewers'), $.lang.get('discord.streamhandler.offline.viewers.stat', avgViewers, maxViewers), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.chatters'), $.lang.get('discord.streamhandler.offline.chatters.stat', avgChatters, maxChatters), true)
|
||||
.appendField($.lang.get('discord.streamhandler.offline.followers'), $.lang.get('discord.streamhandler.offline.followers.stat', follows, followersNow), true)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withUrl('https://twitch.tv/' + $.channelName).build());
|
||||
if (deleteMessageToggle) {
|
||||
offlineMessages.push(msg);
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('discordStreamStats');
|
||||
}
|
||||
}, 6e4);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchOnline
|
||||
*/
|
||||
$.bind('twitchOnline', function(event) {
|
||||
// Wait a minute for Twitch to generate a real thumbnail and make sure again that we are online.
|
||||
setTimeout(function() {
|
||||
if ($.isOnline($.channelName) && ($.systemTime() - $.getIniDbNumber('discordSettings', 'lastOnlineEvent', 0) >= timeout)) {
|
||||
// Remove old stats, if any.
|
||||
$.inidb.RemoveFile('discordStreamStats');
|
||||
|
||||
// Delete offline messages if any.
|
||||
if (deleteMessageToggle && offlineMessages.length > 0) {
|
||||
while (offlineMessages.length > 0) {
|
||||
$.discordAPI.deleteMessage(offlineMessages.shift());
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineToggle === true && channelName !== '') {
|
||||
var s = onlineMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
msg = $.discord.say(channelName, s);
|
||||
if(deleteMessageToggle) {
|
||||
liveMessages.push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Send the message as an embed.
|
||||
msg = $.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.common.game'), getTrimmedGameName(), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.title'), $.getStatus($.channelName), false)
|
||||
.withUrl('https://twitch.tv/' + $.channelName)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withImage($.twitchcache.getPreviewLink() + '?=' + $.randRange(1, 99999)).build());
|
||||
if (deleteMessageToggle) {
|
||||
liveMessages.push(msg);
|
||||
}
|
||||
|
||||
$.setIniDbNumber('discordSettings', 'lastOnlineEvent', $.systemTime());
|
||||
}
|
||||
if (botGameToggle === true) {
|
||||
$.discord.setStream($.getStatus($.channelName), ('https://twitch.tv/' + $.channelName));
|
||||
}
|
||||
}
|
||||
}, 6e4);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchGameChange
|
||||
*/
|
||||
$.bind('twitchGameChange', function(event) {
|
||||
if (gameToggle === false || channelName == '' || $.isOnline($.channelName) == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
var s = gameMessage;
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', $.username.resolve($.channelName));
|
||||
}
|
||||
|
||||
// Only say this when there is a mention.
|
||||
if (s.indexOf('@') !== -1) {
|
||||
liveMessages.push($.discord.say(channelName, s));
|
||||
}
|
||||
liveMessages.push($.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail($.twitchcache.getLogoLink())
|
||||
.withTitle(s.replace(/(\@everyone|\@here)/ig, ''))
|
||||
.appendField($.lang.get('discord.streamhandler.common.game'), getTrimmedGameName(), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.title'), $.getStatus($.channelName), false)
|
||||
.appendField($.lang.get('discord.streamhandler.common.uptime'), $.getStreamUptime($.channelName).toString(), false)
|
||||
.withUrl('https://twitch.tv/' + $.channelName)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink())
|
||||
.withImage($.twitchcache.getPreviewLink() + '?=' + $.randRange(1, 99999)).build()));
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggleonline - Toggles the stream online announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggleonline')) {
|
||||
onlineToggle = !onlineToggle;
|
||||
$.inidb.set('discordSettings', 'onlineToggle', onlineToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.toggle', (onlineToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler onlinemessage [message] - Sets the stream online announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('onlinemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
onlineMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'onlineMessage', onlineMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.online.message.set', onlineMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggleoffline - Toggles the stream offline announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggleoffline')) {
|
||||
offlineToggle = !offlineToggle;
|
||||
$.inidb.set('discordSettings', 'offlineToggle', offlineToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.toggle', (offlineToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler offlinemessage [message] - Sets the stream offline announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('offlinemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
offlineMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'offlineMessage', offlineMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.offline.message.set', offlineMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler togglegame - Toggles the stream game change announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglegame')) {
|
||||
gameToggle = !gameToggle;
|
||||
$.inidb.set('discordSettings', 'gameToggle', gameToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.toggle', (gameToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler gamemessage [message] - Sets the stream game change announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('gamemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
gameMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'gameMessage', gameMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.game.message.set', gameMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler togglebotstatus - If enabled the bot will be marked as streaming with your Twitch title when you go live.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('togglebotstatus')) {
|
||||
botGameToggle = !botGameToggle;
|
||||
$.inidb.set('discordSettings', 'botGameToggle', botGameToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.bot.game.toggle', (botGameToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'onlineChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.channel.set', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamhandler toggledeletemessage - Toggles if online announcements get deleted after stream.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggledeletemessage')) {
|
||||
deleteMessageToggle = !deleteMessageToggle;
|
||||
$.inidb.set('discordSettings', 'deleteMessageToggle', deleteMessageToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamhandler.delete.toggle', (deleteMessageToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamHandler.js', 'streamhandler', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'toggleonline', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'onlinemessage', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'togglegame', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'gamemessage', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'channel', 1);
|
||||
$.discord.registerSubCommand('streamhandler', 'toggledeletemessage', 1);
|
||||
|
||||
// Get our viewer and follower count every 30 minutes.
|
||||
// Not the most accurate way, but it will work.
|
||||
var interval = setInterval(function() {
|
||||
if ($.isOnline($.channelName)) {
|
||||
var now = $.systemTime();
|
||||
|
||||
// Save this every time to make an average.
|
||||
$.setIniDbNumber('discordStreamStats', 'chatters_' + now, $.users.length);
|
||||
// Save this every time to make an average.
|
||||
$.setIniDbNumber('discordStreamStats', 'viewers_' + now, $.getViewers($.channelName));
|
||||
// Only set this one to get the difference at the end.
|
||||
$.getSetIniDbNumber('discordStreamStats', 'followers', $.getFollows($.channelName));
|
||||
}
|
||||
}, 18e5);
|
||||
});
|
||||
})();
|
||||
166
libs/phantombot/scripts/discord/handlers/streamlabsHandler.js
Normal file
166
libs/phantombot/scripts/discord/handlers/streamlabsHandler.js
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle StreamLabs notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'streamlabsToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'streamlabsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'streamlabsChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/streamlabsHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'streamlabsToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'streamlabsMessage', 'Thank you very much (name) for the tip of $(amount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'streamlabsChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamLabsDonationInitialized
|
||||
*/
|
||||
$.bind('streamLabsDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event streamLabsDonation
|
||||
*/
|
||||
$.bind('streamLabsDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var donationJsonStr = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationJson = new JSONObject(donationJsonStr),
|
||||
donationID = donationJson.get("donation_id"),
|
||||
donationCurrency = donationJson.getString("currency"),
|
||||
donationAmount = donationJson.getString("amount"),
|
||||
donationUsername = donationJson.getString("name"),
|
||||
donationMsg = donationJson.getString("message"),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'streamlabs' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'streamlabs' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/g)) {
|
||||
s = $.replace(s, '(amount)', parseInt(donationAmount).toFixed(2).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', parseInt(donationAmount).toFixed(0).toString());
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/g)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/g)) {
|
||||
s = $.replace(s, '(message)', donationMsg);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(49, 196, 162)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/streamlabs-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.streamlabshandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('streamlabshandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler toggle - Toggles the StreamLabs donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'streamlabsToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler message [message] - Sets the StreamLabs donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'streamlabsMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath streamlabshandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'streamlabsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.streamlabshandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/streamlabsHandler.js', 'streamlabshandler', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'message', 1);
|
||||
$.discord.registerSubCommand('streamlabshandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
310
libs/phantombot/scripts/discord/handlers/subscribeHandler.js
Normal file
310
libs/phantombot/scripts/discord/handlers/subscribeHandler.js
Normal file
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle subscriber notifications.
|
||||
*/
|
||||
(function() {
|
||||
var subMessage = $.getSetIniDbString('discordSettings', 'subMessage', '(name) just subscribed!'),
|
||||
primeMessage = $.getSetIniDbString('discordSettings', 'primeMessage', '(name) just subscribed with Twitch Prime!'),
|
||||
resubMessage = $.getSetIniDbString('discordSettings', 'resubMessage', '(name) just subscribed for (months) months in a row!'),
|
||||
giftsubMessage = $.getSetIniDbString('discordSettings', 'giftsubMessage', '(name) just gifted (recipient) a subscription!'),
|
||||
subToggle = $.getSetIniDbBoolean('discordSettings', 'subToggle', false),
|
||||
primeToggle = $.getSetIniDbBoolean('discordSettings', 'primeToggle', false),
|
||||
resubToggle = $.getSetIniDbBoolean('discordSettings', 'resubToggle', false),
|
||||
giftsubToggle = $.getSetIniDbBoolean('discordSettings', 'giftsubToggle', false),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'subChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/subscribeHandler.js')) {
|
||||
subMessage = $.getIniDbString('discordSettings', 'subMessage', '(name) just subscribed!');
|
||||
primeMessage = $.getIniDbString('discordSettings', 'primeMessage', '(name) just subscribed with Twitch Prime!');
|
||||
resubMessage = $.getIniDbString('discordSettings', 'resubMessage', '(name) just subscribed for (months) months in a row!');
|
||||
giftsubMessage = $.getSetIniDbString('discordSettings', 'giftsubMessage', '(name) just gifted (recipient) a subscription!');
|
||||
subToggle = $.getIniDbBoolean('discordSettings', 'subToggle', false);
|
||||
primeToggle = $.getIniDbBoolean('discordSettings', 'primeToggle', false);
|
||||
resubToggle = $.getIniDbBoolean('discordSettings', 'resubToggle', false);
|
||||
giftsubToggle = $.getSetIniDbBoolean('discordSettings', 'giftsubToggle', false);
|
||||
channelName = $.getIniDbString('discordSettings', 'subChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchSubscriber
|
||||
*/
|
||||
$.bind('twitchSubscriber', function(event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
s = subMessage;
|
||||
|
||||
if (announce === false || subToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.subscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/*
|
||||
* @event twitchSubscriptionGift
|
||||
*/
|
||||
$.bind('twitchSubscriptionGift', function(event) {
|
||||
var gifter = event.getUsername(),
|
||||
recipient = event.getRecipient(),
|
||||
months = event.getMonths(),
|
||||
s = giftsubMessage;
|
||||
|
||||
if (announce === false || giftsubToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', gifter);
|
||||
}
|
||||
|
||||
if (s.match(/\(recipient\)/g)) {
|
||||
s = $.replace(s, '(recipient)', recipient);
|
||||
}
|
||||
|
||||
if (s.match(/\(months\)/g)) {
|
||||
s = $.replace(s, '(months)', months);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.giftsubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchPrimeSubscriber
|
||||
*/
|
||||
$.bind('twitchPrimeSubscriber', function(event) {
|
||||
var subscriber = event.getSubscriber(),
|
||||
s = primeMessage;
|
||||
|
||||
if (announce === false || primeToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.primesubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitchReSubscriber
|
||||
*/
|
||||
$.bind('twitchReSubscriber', function(event) {
|
||||
var subscriber = event.getReSubscriber(),
|
||||
months = event.getMonths(),
|
||||
s = resubMessage;
|
||||
|
||||
if (announce === false || resubToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/g)) {
|
||||
s = $.replace(s, '(name)', subscriber);
|
||||
}
|
||||
|
||||
if (s.match(/\(months\)/g)) {
|
||||
s = $.replace(s, '(months)', months);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(100, 65, 164)
|
||||
.withThumbnail('https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/2')
|
||||
.withTitle($.lang.get('discord.subscribehandler.resubscriber.embedtitle'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('subscribehandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler subtoggle - Toggles subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('subtoggle')) {
|
||||
subToggle = !subToggle;
|
||||
$.inidb.set('discordSettings', 'subToggle', subToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.toggle', (subToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler giftsubtoggle - Toggles gifted subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('giftsubtoggle')) {
|
||||
giftsubToggle = !giftsubToggle;
|
||||
$.inidb.set('discordSettings', 'giftsubToggle', giftsubToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.toggle', (giftsubToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler primetoggle - Toggles Twitch Prime subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('primetoggle')) {
|
||||
primeToggle = !primeToggle;
|
||||
$.inidb.set('discordSettings', 'primeToggle', primeToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.toggle', (primeToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler resubtoggle - Toggles re-subscriber announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('resubtoggle')) {
|
||||
resubToggle = !resubToggle;
|
||||
$.inidb.set('discordSettings', 'resubToggle', resubToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.toggle', (resubToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler submessage [message] - Sets the subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('submessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
subMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'subMessage', subMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.sub.message.set', subMessage));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler giftsubmessage [message] - Sets the gift subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('giftsubmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
giftsubMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'giftsubMessage', giftsubMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.giftsub.message.set', giftsubMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler primemessage [message] - Sets the Twitch Prime subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('primemessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.sub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
primeMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'primeMessage', primeMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.prime.sub.message.set', primeMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler resubmessage [message] - Sets the re-subscriber announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('resubmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
resubMessage = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'resubMessage', resubMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.resub.message.set', resubMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath subscribehandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'subChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.subscribehandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/subscribeHandler.js', 'subscribehandler', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'subtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'giftsubtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'primetoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'resubtoggle', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'submessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'giftsubmessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'primemessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'resubmessage', 1);
|
||||
$.discord.registerSubCommand('subscribehandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
172
libs/phantombot/scripts/discord/handlers/tipeeeStreamHandler.js
Normal file
172
libs/phantombot/scripts/discord/handlers/tipeeeStreamHandler.js
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle tipeeestream notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'tipeeestreamToggle', false),
|
||||
message = $.getSetIniDbString('discordSettings', 'tipeeestreamMessage', 'Thank you very much (name) for the tip of (formattedamount) (currency)!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'tipeeestreamChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/tipeeeStreamHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'tipeeestreamToggle', false);
|
||||
message = $.getIniDbString('discordSettings', 'tipeeestreamMessage', 'Thank you very much (name) for the tip of (formattedamount) (currency)!');
|
||||
channelName = $.getIniDbString('discordSettings', 'tipeeestreamChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event tipeeeStreamDonationInitialized
|
||||
*/
|
||||
$.bind('tipeeeStreamDonationInitialized', function(event) {
|
||||
announce = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* @event tipeeeStreamDonation
|
||||
*/
|
||||
$.bind('tipeeeStreamDonation', function(event) {
|
||||
if (announce === false || toggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonString = event.getJsonString(),
|
||||
JSONObject = Packages.org.json.JSONObject,
|
||||
donationObj = new JSONObject(jsonString),
|
||||
donationID = donationObj.getInt('id'),
|
||||
paramObj = donationObj.getJSONObject('parameters'),
|
||||
donationUsername = paramObj.getString('username'),
|
||||
donationCurrency = paramObj.getString('currency'),
|
||||
donationMessage = (paramObj.has('message') ? paramObj.getString('message') : ''),
|
||||
donationAmount = paramObj.getInt('amount'),
|
||||
donationFormattedAmount = donationObj.getString('formattedAmount'),
|
||||
s = message;
|
||||
|
||||
if ($.inidb.exists('discordDonations', 'tipeeestream' + donationID)) {
|
||||
return;
|
||||
} else {
|
||||
$.inidb.set('discordDonations', 'tipeeestream' + donationID, 'true');
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', donationUsername);
|
||||
}
|
||||
|
||||
if (s.match(/\(currency\)/)) {
|
||||
s = $.replace(s, '(currency)', donationCurrency);
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\)/)) {
|
||||
s = $.replace(s, '(amount)', parseInt(donationAmount.toFixed(2)));
|
||||
}
|
||||
|
||||
if (s.match(/\(amount\.toFixed\(0\)\)/)) {
|
||||
s = $.replace(s, '(amount.toFixed(0))', parseInt(donationAmount.toFixed(0)));
|
||||
}
|
||||
|
||||
if (s.match(/\(message\)/)) {
|
||||
s = $.replace(s, '(message)', donationMessage);
|
||||
}
|
||||
|
||||
if (s.match(/\(formattedamount\)/)) {
|
||||
s = $.replace(s, '(formattedamount)', donationFormattedAmount);
|
||||
}
|
||||
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withColor(216, 67, 89)
|
||||
.withThumbnail('https://raw.githubusercontent.com/PhantomBot/Miscellaneous/master/Discord-Embed-Icons/tipeeestream-embed-icon.png')
|
||||
.withTitle($.lang.get('discord.tipeeestreamhandler.embed.title'))
|
||||
.appendDescription(s)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitch')
|
||||
.withFooterIcon($.twitchcache.getLogoLink()).build());
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('tipeeestreamhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler toggle - Toggles the TipeeeStream donation announcements.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'tipeeestreamToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler message [message] - Sets the TipeeeStream donation announcement message.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('message')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
message = args.slice(1).join(' ');
|
||||
$.inidb.set('discordSettings', 'tipeeestreamMessage', message);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.message.set', message));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath tipeeestreamhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'tipeeestreamChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.tipeeestreamhandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/tipeeeStreamHandler.js', 'tipeeestreamhandler', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'message', 1);
|
||||
$.discord.registerSubCommand('tipeeestreamhandler', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
124
libs/phantombot/scripts/discord/handlers/twitterHandler.js
Normal file
124
libs/phantombot/scripts/discord/handlers/twitterHandler.js
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This module is to handle Twitter notifications.
|
||||
*/
|
||||
(function() {
|
||||
var toggle = $.getSetIniDbBoolean('discordSettings', 'twitterToggle', false),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'twitterChannel', ''),
|
||||
announce = false;
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/handlers/twitterHandler.js')) {
|
||||
toggle = $.getIniDbBoolean('discordSettings', 'twitterToggle', false);
|
||||
channelName = $.getIniDbString('discordSettings', 'twitterChannel', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event twitter
|
||||
*/
|
||||
$.bind('twitter', function(event) {
|
||||
if (toggle === false || announce === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getMentionUser() != null) {
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withTitle($.twitter.getUsername())
|
||||
.withUrl('https://twitter.com/' + $.twitter.getUsername())
|
||||
.withColor(31, 158, 242)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitter')
|
||||
.withFooterIcon('https://abs.twimg.com/icons/apple-touch-icon-192x192.png')
|
||||
.withAuthorName($.lang.get('discord.twitterhandler.tweet'))
|
||||
.withDesc('[' + event.getMentionUser() + '](https://twitter.com/' + event.getMentionUser() + '): ' + event.getTweet())
|
||||
.build());
|
||||
} else {
|
||||
// Send the message as an embed.
|
||||
$.discordAPI.sendMessageEmbed(channelName, new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withTitle($.twitter.getUsername())
|
||||
.withUrl('https://twitter.com/' + $.twitter.getUsername())
|
||||
.withColor(31, 158, 242)
|
||||
.withTimestamp(Date.now())
|
||||
.withFooterText('Twitter')
|
||||
.withFooterIcon('https://abs.twimg.com/icons/apple-touch-icon-192x192.png')
|
||||
.withAuthorName($.lang.get('discord.twitterhandler.tweet'))
|
||||
.withDesc(event.getTweet())
|
||||
.build());
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
mention = event.getMention(),
|
||||
arguments = event.getArguments(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('twitterhandler')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath twitterhandler toggle - Toggles Twitter announcements. Note this module will use settings from the main Twitter module.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('toggle')) {
|
||||
toggle = !toggle;
|
||||
$.inidb.set('discordSettings', 'twitterToggle', toggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.toggle', (toggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath twitterhandler channel [channel name] - Sets the channel that announcements from this module will be said in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.inidb.set('discordSettings', 'twitterChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.twitterhandler.channel.set', subAction));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/handlers/twitterHandler.js', 'twitterhandler', 1);
|
||||
$.discord.registerSubCommand('twitterhandler', 'toggle', 1);
|
||||
$.discord.registerSubCommand('twitterhandler', 'channel', 1);
|
||||
|
||||
announce = true;
|
||||
});
|
||||
})();
|
||||
201
libs/phantombot/scripts/discord/systems/greetingsSystem.js
Normal file
201
libs/phantombot/scripts/discord/systems/greetingsSystem.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var joinToggle = $.getSetIniDbBoolean('discordSettings', 'joinToggle', false),
|
||||
partToggle = $.getSetIniDbBoolean('discordSettings', 'partToggle', false),
|
||||
joinMessage = $.getSetIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!'),
|
||||
partMessage = $.getSetIniDbString('discordSettings', 'partMessage', '(name) just left the server!'),
|
||||
channelName = $.getSetIniDbString('discordSettings', 'greetingsChannel', ''),
|
||||
joinGroup = $.getSetIniDbString('discordSettings', 'greetingsDefaultGroup', '');
|
||||
|
||||
/**
|
||||
* @event webPanelSocketUpdate
|
||||
*/
|
||||
$.bind('webPanelSocketUpdate', function(event) {
|
||||
if (event.getScript().equalsIgnoreCase('./discord/systems/greetingsSystem.js')) {
|
||||
joinToggle = $.getIniDbBoolean('discordSettings', 'joinToggle', false);
|
||||
partToggle = $.getIniDbBoolean('discordSettings', 'partToggle', false);
|
||||
joinMessage = $.getIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!');
|
||||
partMessage = $.getIniDbString('discordSettings', 'partMessage', '(name) just left the server!');
|
||||
channelName = $.getIniDbString('discordSettings', 'greetingsChannel', '');
|
||||
joinGroup = $.getIniDbString('discordSettings', 'greetingsDefaultGroup', '');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelJoin
|
||||
*/
|
||||
$.bind('discordChannelJoin', function(event) {
|
||||
// Add the join group if there's one.
|
||||
if (joinGroup !== '' && joinGroup != null && joinGroup.length > 0) {
|
||||
$.discord.setRole(joinGroup, event.getDiscordUser());
|
||||
}
|
||||
|
||||
// Check for the toggle.
|
||||
if (joinToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var username = event.getUsername(),
|
||||
mention = event.getMention(),
|
||||
s = joinMessage;
|
||||
|
||||
if (s.match(/\(@name\)/)) {
|
||||
s = $.replace(s, '(@name)', mention);
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
if (s.match(/\(role\)/)) {
|
||||
s = $.replace(s, '(role)', joinGroup);
|
||||
}
|
||||
|
||||
$.discord.say(channelName, s);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelPart
|
||||
*/
|
||||
$.bind('discordChannelPart', function(event) {
|
||||
if (partToggle === false || channelName == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var username = event.getUsername(),
|
||||
mention = event.getMention(),
|
||||
s = partMessage;
|
||||
|
||||
if (s.match(/\(@name\)/)) {
|
||||
s = $.replace(s, '(@name)', mention);
|
||||
}
|
||||
|
||||
if (s.match(/\(name\)/)) {
|
||||
s = $.replace(s, '(name)', username);
|
||||
}
|
||||
|
||||
$.discord.say(channelName, s);
|
||||
});
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
subAction = args[1];
|
||||
|
||||
if (command.equalsIgnoreCase('greetingssystem')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem jointoggle - Toggles the announcement for when someone joins the server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('jointoggle')) {
|
||||
joinToggle = !joinToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'joinToggle', joinToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.toggle', (joinToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem parttoggle - Toggles the announcement for when someone leaves the server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('parttoggle')) {
|
||||
partToggle = !partToggle;
|
||||
$.setIniDbBoolean('discordSettings', 'partToggle', partToggle);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.toggle', (partToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem joinmessage [message] - Sets the message for when a user joins your server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('joinmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
joinMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('discordSettings', 'joinMessage', joinMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.set', joinMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem partmessage [message] - Sets the message for when a user leaves your server.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('partmessage')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
partMessage = args.slice(1).join(' ');
|
||||
$.setIniDbString('discordSettings', 'partMessage', partMessage);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.set', partMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem channel [channel] - Sets the channel messages from this modules will be made in.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
channelName = $.discord.sanitizeChannelName(subAction);
|
||||
$.setIniDbString('discordSettings', 'greetingsChannel', channelName);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.set', subAction));
|
||||
}
|
||||
|
||||
/**
|
||||
* @discordcommandpath greetingssystem joinrole [role name] - Sets the default role users will get when joining.
|
||||
*/
|
||||
if (action.equalsIgnoreCase('joinrole')) {
|
||||
if (subAction === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
joinGroup = subAction;
|
||||
$.setIniDbString('discordSettings', 'greetingsDefaultGroup', joinGroup);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.set', joinGroup));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/greetingsSystem.js', 'greetingssystem', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'jointoggle', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'partoggle', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'joinmessage', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'partmessage', 1);
|
||||
$.discord.registerSubCommand('greetingssystem', 'channel', 1);
|
||||
});
|
||||
})();
|
||||
93
libs/phantombot/scripts/discord/systems/pointSystem.js
Normal file
93
libs/phantombot/scripts/discord/systems/pointSystem.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
/*
|
||||
* @function getUserPoints
|
||||
*
|
||||
* @param {Number} id
|
||||
* @return {Number}
|
||||
*/
|
||||
function getUserPoints(id) {
|
||||
var username = $.discord.resolveTwitchName(id);
|
||||
|
||||
if (username === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
username = username.toLowerCase();
|
||||
|
||||
return ($.inidb.exists('points', username) ? parseInt($.inidb.get('points', username)) : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* @function decrUserPoints
|
||||
*
|
||||
* @param {Number} id
|
||||
* @param {Number} amount
|
||||
*/
|
||||
function decrUserPoints(id, amount) {
|
||||
var username = $.discord.resolveTwitchName(id);
|
||||
|
||||
if (username !== null) {
|
||||
$.inidb.decr('points', username.toLowerCase(), amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var sender = event.getSender(),
|
||||
command = event.getCommand(),
|
||||
channel = event.getDiscordChannel(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0],
|
||||
twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
|
||||
/**
|
||||
* @discordcommandpath points - Tells you how many points you have if you linked in you Twitch account.
|
||||
*/
|
||||
if (command.equalsIgnoreCase('points')) {
|
||||
if (action === undefined) {
|
||||
if (twitchName !== null) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.self.points', $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.linkrequired'));
|
||||
}
|
||||
} else if ($.user.isKnown(action.toLowerCase())) {
|
||||
twitchName = action.replace('@', '').toLowerCase();
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.other.points', twitchName, $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.no.points.other', $.pointNameMultiple));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/pointSystem.js', 'points', 0);
|
||||
});
|
||||
|
||||
/* Export to the API */
|
||||
$.discord.getUserPoints = getUserPoints;
|
||||
$.discord.decrUserPoints = decrUserPoints;
|
||||
})();
|
||||
469
libs/phantombot/scripts/discord/systems/promoteSystem.js
Normal file
469
libs/phantombot/scripts/discord/systems/promoteSystem.js
Normal file
@@ -0,0 +1,469 @@
|
||||
/**
|
||||
* promoteSystem.js
|
||||
*
|
||||
* TODO:
|
||||
* - Add controls to the Beta Panel once that is the formal release.
|
||||
*
|
||||
*/
|
||||
(function() {
|
||||
var showStats = $.getSetIniDbBoolean('promotesettings', 'showstats', true);
|
||||
var showBanner = $.getSetIniDbBoolean('promotesettings', 'showbanner', true);
|
||||
var promoteChannel = $.getSetIniDbString('promotesettings', 'channel', '');
|
||||
var streamChannel = $.getSetIniDbString('promotesettings', 'streamchannel', '');
|
||||
var allowSelfManage = $.getSetIniDbBoolean('promotesettings', 'allowselfmanage', true);
|
||||
var lastIdx = $.getSetIniDbNumber('promotesettings', 'lastidx', 0);
|
||||
var promoteInterval = $.getSetIniDbNumber('promotesettings', 'promoteinterval', 120);
|
||||
var promoteIntervalID = -1;
|
||||
|
||||
/**
|
||||
* @event discordChannelCommand
|
||||
*/
|
||||
$.bind('discordChannelCommand', function(event) {
|
||||
var channel = event.getDiscordChannel(),
|
||||
command = event.getCommand(),
|
||||
sender = event.getSender(),
|
||||
mention = event.getMention(),
|
||||
args = event.getArgs(),
|
||||
action = args[0];
|
||||
|
||||
/*
|
||||
* @discordcommandpath promoteadm channel discord_channel - Channel to send promotion messages to.
|
||||
* @discordcommandpath promoteadm streamchannel discord_channel - Channel to send go-live messages to.
|
||||
* @discordcommandpath promoteadm toggleselfmanage - If you do not want people to add themselves.
|
||||
* @discordcommandpath promoteadm setinterval - Change the interval for promotion messages from 120 minutes to something else.
|
||||
* @discordcommandpath promoteadm togglestats - Show follow and view stats or not.
|
||||
* @discordcommandpath promoteadm togglebanner - Display the channel banner or not.
|
||||
* @discordcommandpath promoteadm so - Shout out a user.
|
||||
* @discordcommandpath promoteadm add - Add a user based on their Twitch channel.
|
||||
* @discordcommandpath promoteadm delete - Delete a user based on their Twitch channel.
|
||||
* @discordcommandpath promoteadm revoke - Revoke the privilege of a user to be able to promote themselves.
|
||||
* @discordcommandpath promoteadm allow - Allow a user to be able to promote themselves.
|
||||
* @discordcommandpath promoteadm list - List the users currently configured.
|
||||
* @discordcommandpath promote add - Add yourself if permitted to do so.
|
||||
* @discordcommandpath promote delete - Delete yourself if permitted to do so.
|
||||
*/
|
||||
|
||||
if (command.equalsIgnoreCase('promote')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) {
|
||||
if (!allowSelfManage) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.noselfmanage'));
|
||||
return;
|
||||
}
|
||||
if (promoteChannel.length === 0 && streamChannel.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.nochannels'));
|
||||
return;
|
||||
}
|
||||
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
|
||||
if (twitchName === null || twitchName === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
|
||||
return;
|
||||
}
|
||||
var twitchID = $.username.getID(twitchName);
|
||||
if ($.inidb.exists('promoterevoke', twitchID)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.revoked'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.nobio'));
|
||||
return;
|
||||
}
|
||||
var biography = args.splice(1).join(' ');
|
||||
if (biography.equalsIgnoreCase('none')) {
|
||||
biography = '';
|
||||
}
|
||||
$.inidb.set('promotebio', twitchID, biography);
|
||||
$.inidb.set('promoteids', twitchID, twitchName.toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.success', twitchName.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('delete')) {
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.del.success', twitchName.toLowerCase()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (command.equalsIgnoreCase('promoteadm')) {
|
||||
if (action === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.usage'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) && (promoteChannel.length === 0 && streamChannel.length === 0)) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.nochannels'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('add')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
if (args[2] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nobio'));
|
||||
return;
|
||||
}
|
||||
var biography = args.splice(2).join(' ');
|
||||
if (biography.equalsIgnoreCase('none')) {
|
||||
biography = '';
|
||||
}
|
||||
$.inidb.set('promotebio', twitchID, biography);
|
||||
$.inidb.set('promoteids', twitchID, args[1].toLowerCase());
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('delete')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct'));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('channel')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.nochannel'));
|
||||
return;
|
||||
}
|
||||
|
||||
promoteChannel = $.discord.sanitizeChannelName(args[1]);
|
||||
if (promoteChannel.equals('clear')) {
|
||||
$.inidb.set('promotesettings', 'channel', '');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.cleared'));
|
||||
} else {
|
||||
$.inidb.set('promotesettings', 'channel', promoteChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.success', args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('streamchannel')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.nochannel'));
|
||||
return;
|
||||
}
|
||||
|
||||
streamChannel = $.discord.sanitizeChannelName(args[1]);
|
||||
if (streamChannel.equals('clear')) {
|
||||
streamChannel = '';
|
||||
$.inidb.set('promotesettings', 'streamchannel', '');
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.cleared'));
|
||||
} else {
|
||||
$.inidb.set('promotesettings', 'streamchannel', streamChannel);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.success', args[1]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('revoke')) {
|
||||
if (args[1] == undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promotebio', twitchID);
|
||||
$.inidb.del('promoteids', twitchID);
|
||||
$.inidb.set('promoterevoke', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('allow')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.nouser'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchID = $.username.getID(args[1]);
|
||||
if (twitchID.equals('0')) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
$.inidb.del('promoterevoke', twitchID);
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.success', args[1].toLowerCase()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('toggleselfmanage')) {
|
||||
if (allowSelfManage) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.on'));
|
||||
}
|
||||
allowSelfManage = !allowSelfManage;
|
||||
$.setIniDbBoolean('promotesettings', 'allowselfmanage', allowSelfManage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('togglestats')) {
|
||||
if (showStats) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.on'));
|
||||
}
|
||||
showStats = !showStats;
|
||||
$.setIniDbBoolean('promotesettings', 'showstats', showStats);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('togglebanner')) {
|
||||
if (showBanner) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.off'));
|
||||
} else {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.on'));
|
||||
}
|
||||
showBanner = !showBanner;
|
||||
$.setIniDbBoolean('promotesettings', 'showbanner', showBanner);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (action.equalsIgnoreCase('list')) {
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.empty'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchNames = [];
|
||||
for (var i = 0; i < twitchIDs.length; i++) {
|
||||
twitchNames.push($.inidb.get('promoteids', twitchIDs[i]));
|
||||
}
|
||||
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.success', twitchNames.join(', ')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('setinterval')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
|
||||
return;
|
||||
}
|
||||
if (isNaN(args[1])) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
|
||||
return;
|
||||
}
|
||||
var newPromoteInterval = parseInt(args[1]);
|
||||
if (newPromoteInterval < 15) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.toolow'));
|
||||
return;
|
||||
}
|
||||
$.setIniDbNumber('promotesettings', 'promoteinterval', newPromoteInterval);
|
||||
promoteInterval = newPromoteInterval;
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.success', promoteInterval));
|
||||
startPromote();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action.equalsIgnoreCase('so')) {
|
||||
if (args[1] === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.nouser'));
|
||||
return;
|
||||
}
|
||||
var twitchID = $.inidb.GetKeyByValue('promoteids', '', args[1].toLowerCase());
|
||||
if (twitchID === null || twitchID === undefined) {
|
||||
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.noexist'));
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchName = $.inidb.get('promoteids', twitchID);
|
||||
var biography = $.inidb.get('promotebio', twitchID);
|
||||
if (biography.equals('')) {
|
||||
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
|
||||
.withTitle('https://twitch.tv/' + twitchName)
|
||||
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
|
||||
.withColor(31, 158, 242)
|
||||
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
|
||||
.withUrl('https://twitch.tv/' + twitchName).build());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Check for online status of channels every minute.
|
||||
*/
|
||||
setInterval(function() {
|
||||
if ($.inidb.get('promotesettings', 'streamchannel').equals('')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
var start = 0;
|
||||
var end = 100;
|
||||
var total = twitchIDs.length;
|
||||
|
||||
do {
|
||||
var queryString = twitchIDs.slice(start, end).join(',') + '&stream_type=live';
|
||||
var jsonObject = $.twitch.GetStreams(queryString);
|
||||
|
||||
start += 100;
|
||||
end += 100;
|
||||
|
||||
if (!jsonObject.has('streams')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var liveStreamers = [];
|
||||
var jsonStreams = jsonObject.getJSONArray('streams');
|
||||
for (var i = 0; i < jsonStreams.length(); i++) {
|
||||
var twitchID = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('_id').toString();
|
||||
var logoUrl = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('logo');
|
||||
var url = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('url');
|
||||
var game = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('game');
|
||||
var title = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('status');
|
||||
var twitchName = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('display_name');
|
||||
var followers = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('followers');
|
||||
var views = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('views');
|
||||
var banner = null;
|
||||
if (jsonStreams.getJSONObject(i).getJSONObject('channel').has('profile_banner')) {
|
||||
if (jsonStreams.getJSONObject(i).getJSONObject('channel').isNull('profile_banner')) {
|
||||
banner = null;
|
||||
} else {
|
||||
banner = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('profile_banner');
|
||||
}
|
||||
}
|
||||
liveStreamers.push(twitchID);
|
||||
|
||||
if (title === null) {
|
||||
title = $.lang.get('discord.promotesystem.livemsg.missingtitle');
|
||||
}
|
||||
if (game === null) {
|
||||
game = $.lang.get('discord.promotesystem.livemsg.missinggame');
|
||||
}
|
||||
|
||||
if (!$.inidb.exists('promoteonline', twitchID)) {
|
||||
if ($.systemTime() - $.getIniDbNumber('promoteonlinetime', twitchID, 0) >= (6e4 * 5)) {
|
||||
$.inidb.set('promoteonlinetime', twitchID, $.systemTime());
|
||||
var embedBuilder = new Packages.tv.phantombot.discord.util.EmbedBuilder();
|
||||
embedBuilder.withThumbnail(logoUrl)
|
||||
.withTitle($.lang.get('discord.promotesystem.livemsg.title', $.username.resolve(twitchName), twitchName))
|
||||
.withColor(100, 65, 164)
|
||||
.withTimestamp(Date.now())
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.nowplaying'), game, true)
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.streamtitle'), title, true);
|
||||
|
||||
if (showStats) {
|
||||
embedBuilder.appendField($.lang.get('discord.promotesystem.livemsg.followers'), followers, true)
|
||||
.appendField($.lang.get('discord.promotesystem.livemsg.views'), views, true);
|
||||
}
|
||||
if (banner !== null && showBanner) {
|
||||
embedBuilder.withImage(banner)
|
||||
}
|
||||
|
||||
embedBuilder.withFooterText($.inidb.get('promotebio', twitchID))
|
||||
.withUrl('https://twitch.tv/' + twitchName);
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'streamchannel'), embedBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.inidb.RemoveFile('promoteonline');
|
||||
for (var i = 0; i < liveStreamers.length; i++) {
|
||||
$.inidb.set('promoteonline', liveStreamers[i], $.inidb.get('promoteids', liveStreamers[i]));
|
||||
}
|
||||
} while (start < total);
|
||||
}, 6e4, 'scripts::promote.js::checkstreams');
|
||||
|
||||
/**
|
||||
* Send out biography information every so often.
|
||||
*/
|
||||
function startPromote() {
|
||||
if (promoteIntervalID != -1) {
|
||||
$.consoleLn('Restarting the Promotion Interval Handler');
|
||||
clearInterval(promoteIntervalID);
|
||||
}
|
||||
|
||||
promoteIntervalID = setInterval(function() {
|
||||
if ($.inidb.get('promotesettings', 'channel').equals('')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
|
||||
if (twitchIDs.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (++lastIdx >= twitchIDs.length) {
|
||||
lastIdx = 0;
|
||||
}
|
||||
$.setIniDbNumber('promotesettings', 'lastidx', lastIdx);
|
||||
|
||||
var twitchName = $.inidb.get('promoteids', twitchIDs[lastIdx]);
|
||||
var biography = $.inidb.get('promotebio', twitchIDs[lastIdx]);
|
||||
if (biography.equals('')) {
|
||||
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
|
||||
}
|
||||
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
|
||||
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
|
||||
.withTitle('https://twitch.tv/' + twitchName)
|
||||
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
|
||||
.withColor(31, 158, 242)
|
||||
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
|
||||
.withUrl('https://twitch.tv/' + twitchName).build());
|
||||
}, promoteInterval * 6e4, 'scripts::promote.js::biography');
|
||||
}
|
||||
|
||||
/**
|
||||
* @event initReady
|
||||
*/
|
||||
$.bind('initReady', function() {
|
||||
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promote', 0);
|
||||
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promoteadm', 1);
|
||||
$.discord.registerSubCommand('promote', 'add', 0);
|
||||
$.discord.registerSubCommand('promote', 'delete', 0);
|
||||
$.discord.registerSubCommand('promoteadm', 'add', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'delete', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'channel', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'streamchannel', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'revoke', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'allow', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'toggleselfmanage', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'list', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'setinterval', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'togglestats', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'togglebanner', 1);
|
||||
$.discord.registerSubCommand('promoteadm', 'so', 1);
|
||||
|
||||
startPromote();
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user