phantombot-plugins/twitch/customAlerts.js

93 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2022-02-05 13:00:32 +01:00
(function() {
2022-02-23 21:43:59 +01:00
2022-02-24 02:05:33 +01:00
function sendData(tpe, d) {
$.panelsocketserver.sendJSONToAll(JSON.stringify({
'eventFamily': 'calert',
'eventType': tpe,
'data': d
}));
}
$.bind('twitchFollow', function(event) {
sendData('follow',{ 'user': event.getFollower()});
});
$.bind('twitchSubscriber', function(event) {
sendData('subscribe', {
'user': event.getSubscriber(),
'isReSub': false,
'months': 0,
'tier': event.getPlan() / 1000,
'message': event.getMessage()
});
});
$.bind('twitchReSubscriber', function(event) {
sendData('subscribe', {
'user': event.getReSubscriber(),
'isReSub': true,
'months': event.getMonths(),
'tier': event.getPlan() / 1000,
'message': event.getMessage()
2022-02-05 13:00:32 +01:00
});
2022-02-24 02:05:33 +01:00
});
$.bind('twitchSubscriptionGift', function(event) {
sendData('gift', {
'recipient': event.getRecipient(),
'user': event.getUsername(),
'months': event.getMonths(),
'isReSub': (parseInt(event.getMonths()) > 1),
'tier': event.getPlan() / 1000
2022-02-05 13:00:32 +01:00
});
2022-02-24 02:05:33 +01:00
});
$.bind('twitchMassSubscriptionGifted', function(event) {
sendData('mgift', {
'user': event.getUsername(),
'amount': event.getAmount(),
'tier': event.getPlan() / 1000
});
});
2022-02-06 19:30:05 +01:00
2022-02-24 02:05:33 +01:00
$.bind('twitchRaid', function(event) {
sendData('raid',{
'user': event.getUsername(),
'viewers': event.getViewers(),
2022-02-06 19:59:23 +01:00
});
2022-02-24 02:05:33 +01:00
});
$.bind('twitchBits', function (event) {
sendData('bits', {
'user': event.getUsername(),
'amount': event.getBits(),
'message': event.getMessage()
});
});
$.bind('command', function(event) {
const sender = "" + event.getSender().toLowerCase(),
command = event.getCommand(),
args = event.getArgs(),
action = args[0];
if (command.equalsIgnoreCase('calert')) {
if (!action) {
$.say($.whisperPrefix(sender) + $.lang.get('calert.help', ' Use "!calert [follow | subsribe | donation] user" to trigger alert.'));
} else if (action.equalsIgnoreCase('follow')) {
2022-02-24 02:28:55 +01:00
sendData('follow',{ 'user': args[1]});
2022-02-24 02:05:33 +01:00
} else if (action.equalsIgnoreCase('subscribe')) {
2022-02-24 02:28:55 +01:00
sendData('subscribe',{ 'user': args[1]});
2022-02-24 02:05:33 +01:00
} else if (action.equalsIgnoreCase('donation')) {
2022-02-24 02:28:55 +01:00
sendData('bits',{ 'user': args[1], amount: args[2]});
2022-02-24 02:05:33 +01:00
} else {
$.say($.whisperPrefix(sender) + $.lang.get('calert.help', ' Use "!calert [follow | subsribe | donation] user" to trigger alert.'));
}
}
});
$.bind('initReady', function() {
$.registerChatCommand('./custom/custom/customAlerts.js', 'calert');
$.registerChatSubcommand('calert', 'follow', 2);
$.registerChatSubcommand('calert', 'subscribe', 2);
$.registerChatSubcommand('calert', 'donation', 2);
});
})();