phantombot-plugins/twitch/customEmoteWall.js

88 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-02-19 00:48:41 +01:00
(function() {
2022-02-23 20:03:44 +01:00
function getWordAt(str, pos) {
str = String(str);
pos = pos >>> 0;
var left = str.slice(0, pos + 2).search(/\S+$/),
right = str.slice(pos).search(/\s/);
if (right < 0)
return str.slice(left);
return str.slice(left, right + pos);
}
2022-02-23 19:38:39 +01:00
function getNoTwitchEmotes(event, message){
2022-02-19 00:48:41 +01:00
var emotes = event.getTags().get('emotes'),
2022-02-23 19:38:39 +01:00
str = message, i;
2022-02-19 00:48:41 +01:00
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;
}
2022-02-23 19:38:39 +01:00
function sendData(tpe, te, ce) {
2022-02-19 00:48:41 +01:00
$.panelsocketserver.sendJSONToAll(JSON.stringify({
'eventFamily': 'emote',
'eventType': tpe,
2022-02-23 19:38:39 +01:00
'data': {
twitch: te,
custom: ce,
}
2022-02-19 00:48:41 +01:00
}));
}
$.bind('ircChannelMessage', function(event){
var sender = event.getSender(),
2022-02-23 19:38:39 +01:00
message = event.getMessage();
2022-02-19 00:48:41 +01:00
tags = event.getTags();
2022-02-23 19:42:53 +01:00
if(message.indexOf('!')!=0)
2022-02-23 20:59:45 +01:00
sendData('bounce',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,message).split(' '))
2022-02-19 00:48:41 +01:00
})
$.bind('command', function(event) {
const sender = "" + event.getSender().toLowerCase(),
command = event.getCommand(),
args = event.getArgs(),
2022-02-23 19:38:39 +01:00
action = args[0];
2022-02-19 00:48:41 +01:00
2022-02-23 19:38:39 +01:00
if (command.equalsIgnoreCase('ew')) {
2022-02-19 00:48:41 +01:00
if (!action) {
2022-02-23 19:38:39 +01:00
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
} else if (action.equalsIgnoreCase('rain')) {
2022-02-23 20:59:45 +01:00
sendData('rain',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(' '))
2022-02-23 19:38:39 +01:00
} else if (action.equalsIgnoreCase('firework')) {
2022-02-23 20:59:45 +01:00
sendData('firework',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(' '))
2022-02-23 19:38:39 +01:00
} else if (action.equalsIgnoreCase('volcano')) {
2022-02-23 20:59:45 +01:00
sendData('volcano',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(' '))
2022-02-23 19:38:39 +01:00
} else if (action.equalsIgnoreCase('bomb')) {
2022-02-23 20:59:45 +01:00
sendData('bomb',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(' '))
2022-02-23 19:38:39 +01:00
} else if (action.equalsIgnoreCase('explosion')) {
2022-02-23 20:59:45 +01:00
sendData('explosion',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(' '))
2022-02-19 00:48:41 +01:00
} else {
2022-02-23 19:38:39 +01:00
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
2022-02-19 00:48:41 +01:00
}
}
});
$.bind('twitchFollow', function(event) {
2022-02-23 19:38:39 +01:00
sendData('firework', [],['AYAYA'])
2022-02-19 00:48:41 +01:00
});
$.bind('twitchSubscriber', function(event) {
2022-02-23 19:38:39 +01:00
sendData('volcano', [], ['AYAYA']);
2022-02-19 00:48:41 +01:00
});
$.bind('initReady', function() {
2022-02-23 20:41:12 +01:00
$.registerChatCommand('./custom/custom/customEmoteWall.js', 'ew');
2022-02-23 19:38:39 +01:00
$.registerChatSubcommand('ew', 'rain', 2);
$.registerChatSubcommand('ew', 'firework', 2);
$.registerChatSubcommand('ew', 'volcano', 2);
$.registerChatSubcommand('ew', 'bomb', 2);
$.registerChatSubcommand('ew', 'explosion', 2);
2022-02-19 00:48:41 +01:00
});
})();