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