init commit

This commit is contained in:
zino
2021-02-16 23:07:41 +01:00
parent ec3fc78e0f
commit 12b4ef5db4
5000 changed files with 2596132 additions and 0 deletions

View 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);
});
})();