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,201 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
(function() {
var joinToggle = $.getSetIniDbBoolean('discordSettings', 'joinToggle', false),
partToggle = $.getSetIniDbBoolean('discordSettings', 'partToggle', false),
joinMessage = $.getSetIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!'),
partMessage = $.getSetIniDbString('discordSettings', 'partMessage', '(name) just left the server!'),
channelName = $.getSetIniDbString('discordSettings', 'greetingsChannel', ''),
joinGroup = $.getSetIniDbString('discordSettings', 'greetingsDefaultGroup', '');
/**
* @event webPanelSocketUpdate
*/
$.bind('webPanelSocketUpdate', function(event) {
if (event.getScript().equalsIgnoreCase('./discord/systems/greetingsSystem.js')) {
joinToggle = $.getIniDbBoolean('discordSettings', 'joinToggle', false);
partToggle = $.getIniDbBoolean('discordSettings', 'partToggle', false);
joinMessage = $.getIniDbString('discordSettings', 'joinMessage', '(name) just joined the server!');
partMessage = $.getIniDbString('discordSettings', 'partMessage', '(name) just left the server!');
channelName = $.getIniDbString('discordSettings', 'greetingsChannel', '');
joinGroup = $.getIniDbString('discordSettings', 'greetingsDefaultGroup', '');
}
});
/**
* @event discordChannelJoin
*/
$.bind('discordChannelJoin', function(event) {
// Add the join group if there's one.
if (joinGroup !== '' && joinGroup != null && joinGroup.length > 0) {
$.discord.setRole(joinGroup, event.getDiscordUser());
}
// Check for the toggle.
if (joinToggle === false || channelName == '') {
return;
}
var username = event.getUsername(),
mention = event.getMention(),
s = joinMessage;
if (s.match(/\(@name\)/)) {
s = $.replace(s, '(@name)', mention);
}
if (s.match(/\(name\)/)) {
s = $.replace(s, '(name)', username);
}
if (s.match(/\(role\)/)) {
s = $.replace(s, '(role)', joinGroup);
}
$.discord.say(channelName, s);
});
/**
* @event discordChannelPart
*/
$.bind('discordChannelPart', function(event) {
if (partToggle === false || channelName == '') {
return;
}
var username = event.getUsername(),
mention = event.getMention(),
s = partMessage;
if (s.match(/\(@name\)/)) {
s = $.replace(s, '(@name)', mention);
}
if (s.match(/\(name\)/)) {
s = $.replace(s, '(name)', username);
}
$.discord.say(channelName, s);
});
/**
* @event discordChannelCommand
*/
$.bind('discordChannelCommand', function(event) {
var sender = event.getSender(),
command = event.getCommand(),
channel = event.getDiscordChannel(),
mention = event.getMention(),
args = event.getArgs(),
action = args[0],
subAction = args[1];
if (command.equalsIgnoreCase('greetingssystem')) {
if (action === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.usage'));
return;
}
/**
* @discordcommandpath greetingssystem jointoggle - Toggles the announcement for when someone joins the server.
*/
if (action.equalsIgnoreCase('jointoggle')) {
joinToggle = !joinToggle;
$.setIniDbBoolean('discordSettings', 'joinToggle', joinToggle);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.toggle', (joinToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
}
/**
* @discordcommandpath greetingssystem parttoggle - Toggles the announcement for when someone leaves the server.
*/
if (action.equalsIgnoreCase('parttoggle')) {
partToggle = !partToggle;
$.setIniDbBoolean('discordSettings', 'partToggle', partToggle);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.toggle', (partToggle === true ? $.lang.get('common.enabled') : $.lang.get('common.disabled'))));
}
/**
* @discordcommandpath greetingssystem joinmessage [message] - Sets the message for when a user joins your server.
*/
if (action.equalsIgnoreCase('joinmessage')) {
if (subAction === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.usage'));
return;
}
joinMessage = args.slice(1).join(' ');
$.setIniDbString('discordSettings', 'joinMessage', joinMessage);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.join.message.set', joinMessage));
}
/**
* @discordcommandpath greetingssystem partmessage [message] - Sets the message for when a user leaves your server.
*/
if (action.equalsIgnoreCase('partmessage')) {
if (subAction === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.usage'));
return;
}
partMessage = args.slice(1).join(' ');
$.setIniDbString('discordSettings', 'partMessage', partMessage);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.part.message.set', partMessage));
}
/**
* @discordcommandpath greetingssystem channel [channel] - Sets the channel messages from this modules will be made in.
*/
if (action.equalsIgnoreCase('channel')) {
if (subAction === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.usage'));
return;
}
channelName = $.discord.sanitizeChannelName(subAction);
$.setIniDbString('discordSettings', 'greetingsChannel', channelName);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.channel.set', subAction));
}
/**
* @discordcommandpath greetingssystem joinrole [role name] - Sets the default role users will get when joining.
*/
if (action.equalsIgnoreCase('joinrole')) {
if (subAction === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.usage'));
return;
}
joinGroup = subAction;
$.setIniDbString('discordSettings', 'greetingsDefaultGroup', joinGroup);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.greetingssystem.joinrole.set', joinGroup));
}
}
});
/**
* @event initReady
*/
$.bind('initReady', function() {
$.discord.registerCommand('./discord/systems/greetingsSystem.js', 'greetingssystem', 1);
$.discord.registerSubCommand('greetingssystem', 'jointoggle', 1);
$.discord.registerSubCommand('greetingssystem', 'partoggle', 1);
$.discord.registerSubCommand('greetingssystem', 'joinmessage', 1);
$.discord.registerSubCommand('greetingssystem', 'partmessage', 1);
$.discord.registerSubCommand('greetingssystem', 'channel', 1);
});
})();

View File

@@ -0,0 +1,93 @@
/*
* Copyright (C) 2016-2020 phantombot.github.io/PhantomBot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
(function() {
/*
* @function getUserPoints
*
* @param {Number} id
* @return {Number}
*/
function getUserPoints(id) {
var username = $.discord.resolveTwitchName(id);
if (username === null) {
return 0;
}
username = username.toLowerCase();
return ($.inidb.exists('points', username) ? parseInt($.inidb.get('points', username)) : 0);
}
/*
* @function decrUserPoints
*
* @param {Number} id
* @param {Number} amount
*/
function decrUserPoints(id, amount) {
var username = $.discord.resolveTwitchName(id);
if (username !== null) {
$.inidb.decr('points', username.toLowerCase(), amount);
}
}
/**
* @event discordChannelCommand
*/
$.bind('discordChannelCommand', function(event) {
var sender = event.getSender(),
command = event.getCommand(),
channel = event.getDiscordChannel(),
mention = event.getMention(),
args = event.getArgs(),
action = args[0],
twitchName = $.discord.resolveTwitchName(event.getSenderId());
/**
* @discordcommandpath points - Tells you how many points you have if you linked in you Twitch account.
*/
if (command.equalsIgnoreCase('points')) {
if (action === undefined) {
if (twitchName !== null) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.self.points', $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
} else {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.linkrequired'));
}
} else if ($.user.isKnown(action.toLowerCase())) {
twitchName = action.replace('@', '').toLowerCase();
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.other.points', twitchName, $.getPointsString($.getUserPoints(twitchName)), $.getTimeString($.getUserTime(twitchName)), $.resolveRank(twitchName)));
} else {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.pointsystem.no.points.other', $.pointNameMultiple));
}
}
});
/**
* @event initReady
*/
$.bind('initReady', function() {
$.discord.registerCommand('./discord/systems/pointSystem.js', 'points', 0);
});
/* Export to the API */
$.discord.getUserPoints = getUserPoints;
$.discord.decrUserPoints = decrUserPoints;
})();

View File

@@ -0,0 +1,469 @@
/**
* promoteSystem.js
*
* TODO:
* - Add controls to the Beta Panel once that is the formal release.
*
*/
(function() {
var showStats = $.getSetIniDbBoolean('promotesettings', 'showstats', true);
var showBanner = $.getSetIniDbBoolean('promotesettings', 'showbanner', true);
var promoteChannel = $.getSetIniDbString('promotesettings', 'channel', '');
var streamChannel = $.getSetIniDbString('promotesettings', 'streamchannel', '');
var allowSelfManage = $.getSetIniDbBoolean('promotesettings', 'allowselfmanage', true);
var lastIdx = $.getSetIniDbNumber('promotesettings', 'lastidx', 0);
var promoteInterval = $.getSetIniDbNumber('promotesettings', 'promoteinterval', 120);
var promoteIntervalID = -1;
/**
* @event discordChannelCommand
*/
$.bind('discordChannelCommand', function(event) {
var channel = event.getDiscordChannel(),
command = event.getCommand(),
sender = event.getSender(),
mention = event.getMention(),
args = event.getArgs(),
action = args[0];
/*
* @discordcommandpath promoteadm channel discord_channel - Channel to send promotion messages to.
* @discordcommandpath promoteadm streamchannel discord_channel - Channel to send go-live messages to.
* @discordcommandpath promoteadm toggleselfmanage - If you do not want people to add themselves.
* @discordcommandpath promoteadm setinterval - Change the interval for promotion messages from 120 minutes to something else.
* @discordcommandpath promoteadm togglestats - Show follow and view stats or not.
* @discordcommandpath promoteadm togglebanner - Display the channel banner or not.
* @discordcommandpath promoteadm so - Shout out a user.
* @discordcommandpath promoteadm add - Add a user based on their Twitch channel.
* @discordcommandpath promoteadm delete - Delete a user based on their Twitch channel.
* @discordcommandpath promoteadm revoke - Revoke the privilege of a user to be able to promote themselves.
* @discordcommandpath promoteadm allow - Allow a user to be able to promote themselves.
* @discordcommandpath promoteadm list - List the users currently configured.
* @discordcommandpath promote add - Add yourself if permitted to do so.
* @discordcommandpath promote delete - Delete yourself if permitted to do so.
*/
if (command.equalsIgnoreCase('promote')) {
if (action === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.usage'));
return;
}
if (action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) {
if (!allowSelfManage) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.noselfmanage'));
return;
}
if (promoteChannel.length === 0 && streamChannel.length === 0) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.nochannels'));
return;
}
var twitchName = $.discord.resolveTwitchName(event.getSenderId());
if (twitchName === null || twitchName === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.accountlink.usage.nolink'));
return;
}
var twitchID = $.username.getID(twitchName);
if ($.inidb.exists('promoterevoke', twitchID)) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.revoked'));
return;
}
}
if (action.equalsIgnoreCase('add')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.nobio'));
return;
}
var biography = args.splice(1).join(' ');
if (biography.equalsIgnoreCase('none')) {
biography = '';
}
$.inidb.set('promotebio', twitchID, biography);
$.inidb.set('promoteids', twitchID, twitchName.toLowerCase());
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.add.success', twitchName.toLowerCase()));
return;
}
if (action.equalsIgnoreCase('delete')) {
$.inidb.del('promotebio', twitchID);
$.inidb.del('promoteids', twitchID);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promote.del.success', twitchName.toLowerCase()));
return;
}
}
if (command.equalsIgnoreCase('promoteadm')) {
if (action === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.usage'));
return;
}
if ((action.equalsIgnoreCase('add') || action.equalsIgnoreCase('delete')) && (promoteChannel.length === 0 && streamChannel.length === 0)) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.nochannels'));
return;
}
if (action.equalsIgnoreCase('add')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nouser'));
return;
}
var twitchID = $.username.getID(args[1]);
if (twitchID.equals('0')) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
return;
}
if (args[2] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.nobio'));
return;
}
var biography = args.splice(2).join(' ');
if (biography.equalsIgnoreCase('none')) {
biography = '';
}
$.inidb.set('promotebio', twitchID, biography);
$.inidb.set('promoteids', twitchID, args[1].toLowerCase());
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.add.success', args[1].toLowerCase()));
return;
}
if (action.equalsIgnoreCase('delete')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.nouser'));
return;
}
var twitchID = $.username.getID(args[1]);
if (twitchID.equals('0')) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct'));
return;
}
$.inidb.del('promotebio', twitchID);
$.inidb.del('promoteids', twitchID);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.del.success', args[1].toLowerCase()));
return;
}
if (action.equalsIgnoreCase('channel')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.nochannel'));
return;
}
promoteChannel = $.discord.sanitizeChannelName(args[1]);
if (promoteChannel.equals('clear')) {
$.inidb.set('promotesettings', 'channel', '');
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.cleared'));
} else {
$.inidb.set('promotesettings', 'channel', promoteChannel);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.channel.success', args[1]));
}
return;
}
if (action.equalsIgnoreCase('streamchannel')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.nochannel'));
return;
}
streamChannel = $.discord.sanitizeChannelName(args[1]);
if (streamChannel.equals('clear')) {
streamChannel = '';
$.inidb.set('promotesettings', 'streamchannel', '');
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.cleared'));
} else {
$.inidb.set('promotesettings', 'streamchannel', streamChannel);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.streamchannel.success', args[1]));
}
return;
}
if (action.equalsIgnoreCase('revoke')) {
if (args[1] == undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.nouser'));
return;
}
var twitchID = $.username.getID(args[1]);
if (twitchID.equals('0')) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
return;
}
$.inidb.del('promotebio', twitchID);
$.inidb.del('promoteids', twitchID);
$.inidb.set('promoterevoke', twitchID);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.revoke.success', args[1].toLowerCase()));
return;
}
if (action.equalsIgnoreCase('allow')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.nouser'));
return;
}
var twitchID = $.username.getID(args[1]);
if (twitchID.equals('0')) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.noacct', args[1]));
return;
}
$.inidb.del('promoterevoke', twitchID);
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.allow.success', args[1].toLowerCase()));
return;
}
if (action.equalsIgnoreCase('toggleselfmanage')) {
if (allowSelfManage) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.off'));
} else {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.toggleselfmanage.on'));
}
allowSelfManage = !allowSelfManage;
$.setIniDbBoolean('promotesettings', 'allowselfmanage', allowSelfManage);
return;
}
if (action.equalsIgnoreCase('togglestats')) {
if (showStats) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.off'));
} else {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglestats.on'));
}
showStats = !showStats;
$.setIniDbBoolean('promotesettings', 'showstats', showStats);
return;
}
if (action.equalsIgnoreCase('togglebanner')) {
if (showBanner) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.off'));
} else {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.togglebanner.on'));
}
showBanner = !showBanner;
$.setIniDbBoolean('promotesettings', 'showbanner', showBanner);
return;
}
if (action.equalsIgnoreCase('list')) {
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
if (twitchIDs.length === 0) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.empty'));
return;
}
var twitchNames = [];
for (var i = 0; i < twitchIDs.length; i++) {
twitchNames.push($.inidb.get('promoteids', twitchIDs[i]));
}
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.list.success', twitchNames.join(', ')));
return;
}
if (action.equalsIgnoreCase('setinterval')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
return;
}
if (isNaN(args[1])) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.nominutes'));
return;
}
var newPromoteInterval = parseInt(args[1]);
if (newPromoteInterval < 15) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.toolow'));
return;
}
$.setIniDbNumber('promotesettings', 'promoteinterval', newPromoteInterval);
promoteInterval = newPromoteInterval;
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.promoteadm.setinterval.success', promoteInterval));
startPromote();
return;
}
if (action.equalsIgnoreCase('so')) {
if (args[1] === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.nouser'));
return;
}
var twitchID = $.inidb.GetKeyByValue('promoteids', '', args[1].toLowerCase());
if (twitchID === null || twitchID === undefined) {
$.discord.say(channel, $.discord.userPrefix(mention) + $.lang.get('discord.promotesystem.cmd.so.noexist'));
return;
}
var twitchName = $.inidb.get('promoteids', twitchID);
var biography = $.inidb.get('promotebio', twitchID);
if (biography.equals('')) {
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
}
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
.withTitle('https://twitch.tv/' + twitchName)
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
.withColor(31, 158, 242)
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
.withUrl('https://twitch.tv/' + twitchName).build());
}
}
});
/**
* Check for online status of channels every minute.
*/
setInterval(function() {
if ($.inidb.get('promotesettings', 'streamchannel').equals('')) {
return;
}
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
if (twitchIDs.length === 0) {
return;
}
var start = 0;
var end = 100;
var total = twitchIDs.length;
do {
var queryString = twitchIDs.slice(start, end).join(',') + '&stream_type=live';
var jsonObject = $.twitch.GetStreams(queryString);
start += 100;
end += 100;
if (!jsonObject.has('streams')) {
return;
}
var liveStreamers = [];
var jsonStreams = jsonObject.getJSONArray('streams');
for (var i = 0; i < jsonStreams.length(); i++) {
var twitchID = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('_id').toString();
var logoUrl = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('logo');
var url = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('url');
var game = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('game');
var title = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('status');
var twitchName = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('display_name');
var followers = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('followers');
var views = jsonStreams.getJSONObject(i).getJSONObject('channel').getInt('views');
var banner = null;
if (jsonStreams.getJSONObject(i).getJSONObject('channel').has('profile_banner')) {
if (jsonStreams.getJSONObject(i).getJSONObject('channel').isNull('profile_banner')) {
banner = null;
} else {
banner = jsonStreams.getJSONObject(i).getJSONObject('channel').getString('profile_banner');
}
}
liveStreamers.push(twitchID);
if (title === null) {
title = $.lang.get('discord.promotesystem.livemsg.missingtitle');
}
if (game === null) {
game = $.lang.get('discord.promotesystem.livemsg.missinggame');
}
if (!$.inidb.exists('promoteonline', twitchID)) {
if ($.systemTime() - $.getIniDbNumber('promoteonlinetime', twitchID, 0) >= (6e4 * 5)) {
$.inidb.set('promoteonlinetime', twitchID, $.systemTime());
var embedBuilder = new Packages.tv.phantombot.discord.util.EmbedBuilder();
embedBuilder.withThumbnail(logoUrl)
.withTitle($.lang.get('discord.promotesystem.livemsg.title', $.username.resolve(twitchName), twitchName))
.withColor(100, 65, 164)
.withTimestamp(Date.now())
.appendField($.lang.get('discord.promotesystem.livemsg.nowplaying'), game, true)
.appendField($.lang.get('discord.promotesystem.livemsg.streamtitle'), title, true);
if (showStats) {
embedBuilder.appendField($.lang.get('discord.promotesystem.livemsg.followers'), followers, true)
.appendField($.lang.get('discord.promotesystem.livemsg.views'), views, true);
}
if (banner !== null && showBanner) {
embedBuilder.withImage(banner)
}
embedBuilder.withFooterText($.inidb.get('promotebio', twitchID))
.withUrl('https://twitch.tv/' + twitchName);
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'streamchannel'), embedBuilder.build());
}
}
}
$.inidb.RemoveFile('promoteonline');
for (var i = 0; i < liveStreamers.length; i++) {
$.inidb.set('promoteonline', liveStreamers[i], $.inidb.get('promoteids', liveStreamers[i]));
}
} while (start < total);
}, 6e4, 'scripts::promote.js::checkstreams');
/**
* Send out biography information every so often.
*/
function startPromote() {
if (promoteIntervalID != -1) {
$.consoleLn('Restarting the Promotion Interval Handler');
clearInterval(promoteIntervalID);
}
promoteIntervalID = setInterval(function() {
if ($.inidb.get('promotesettings', 'channel').equals('')) {
return;
}
var twitchIDs = $.inidb.GetKeyList('promoteids', '');
if (twitchIDs.length === 0) {
return;
}
if (++lastIdx >= twitchIDs.length) {
lastIdx = 0;
}
$.setIniDbNumber('promotesettings', 'lastidx', lastIdx);
var twitchName = $.inidb.get('promoteids', twitchIDs[lastIdx]);
var biography = $.inidb.get('promotebio', twitchIDs[lastIdx]);
if (biography.equals('')) {
biography = $.lang.get('discord.promotesystem.promotemsg.nobio');
}
$.discordAPI.sendMessageEmbed($.inidb.get('promotesettings', 'channel'), new Packages.tv.phantombot.discord.util.EmbedBuilder()
.withThumbnail('http://iotv.me/i/followontwitch.jpg')
.withTitle('https://twitch.tv/' + twitchName)
.withDesc($.lang.get('discord.promotesystem.promotemsg.description', $.username.resolve(twitchName)))
.withColor(31, 158, 242)
.appendField($.lang.get('discord.promotesystem.promotemsg.biography'), biography, true)
.withUrl('https://twitch.tv/' + twitchName).build());
}, promoteInterval * 6e4, 'scripts::promote.js::biography');
}
/**
* @event initReady
*/
$.bind('initReady', function() {
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promote', 0);
$.discord.registerCommand('./discord/systems/promoteSystem.js', 'promoteadm', 1);
$.discord.registerSubCommand('promote', 'add', 0);
$.discord.registerSubCommand('promote', 'delete', 0);
$.discord.registerSubCommand('promoteadm', 'add', 1);
$.discord.registerSubCommand('promoteadm', 'delete', 1);
$.discord.registerSubCommand('promoteadm', 'channel', 1);
$.discord.registerSubCommand('promoteadm', 'streamchannel', 1);
$.discord.registerSubCommand('promoteadm', 'revoke', 1);
$.discord.registerSubCommand('promoteadm', 'allow', 1);
$.discord.registerSubCommand('promoteadm', 'toggleselfmanage', 1);
$.discord.registerSubCommand('promoteadm', 'list', 1);
$.discord.registerSubCommand('promoteadm', 'setinterval', 1);
$.discord.registerSubCommand('promoteadm', 'togglestats', 1);
$.discord.registerSubCommand('promoteadm', 'togglebanner', 1);
$.discord.registerSubCommand('promoteadm', 'so', 1);
startPromote();
});
})();