phantombot-plugins/twitch/customEmoteWall.js
2022-02-23 19:42:53 +01:00

78 lines
3.0 KiB
JavaScript

(function() {
function getNoTwitchEmotes(event, message){
var emotes = event.getTags().get('emotes'),
str = message, i;
if (emotes.length() > 0) {
emotes = emotes.replaceAll('[0-9]+:', '').split('/');
for (i in emotes) {
str = str.replace(getWordAt(message, parseInt(emotes[i].split('-')[0])), '');
}
}
return str;
}
function sendData(tpe, te, ce) {
$.panelsocketserver.sendJSONToAll(JSON.stringify({
'eventFamily': 'emote',
'eventType': tpe,
'data': {
twitch: te,
custom: ce,
}
}));
}
$.bind('ircChannelMessage', function(event){
var sender = event.getSender(),
message = event.getMessage();
tags = event.getTags();
if(message.indexOf('!')!=0)
sendData('bounce',event.getTags().get('emotes'), getNoTwitchEmotes(event,message))
})
$.bind('command', function(event) {
const sender = "" + event.getSender().toLowerCase(),
command = event.getCommand(),
args = event.getArgs(),
action = args[0];
if (command.equalsIgnoreCase('ew')) {
if (!action) {
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
} else if (action.equalsIgnoreCase('rain')) {
sendData('rain',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage()))
} else if (action.equalsIgnoreCase('firework')) {
sendData('firework',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage()))
} else if (action.equalsIgnoreCase('volcano')) {
sendData('volcano',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage()))
} else if (action.equalsIgnoreCase('bomb')) {
sendData('bomb',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage()))
} else if (action.equalsIgnoreCase('explosion')) {
sendData('explosion',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage()))
} else {
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
}
}
});
$.bind('twitchFollow', function(event) {
sendData('firework', [],['AYAYA'])
});
$.bind('twitchSubscriber', function(event) {
sendData('volcano', [], ['AYAYA']);
});
$.bind('initReady', function() {
$.registerChatCommand('./custom/custom/customOverlay.js', 'ew');
$.registerChatSubcommand('ew', 'rain', 2);
$.registerChatSubcommand('ew', 'firework', 2);
$.registerChatSubcommand('ew', 'volcano', 2);
$.registerChatSubcommand('ew', 'bomb', 2);
$.registerChatSubcommand('ew', 'explosion', 2);
});
})();