init commit
This commit is contained in:
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);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user