diff --git a/twitch/Main.py b/twitch/Main.py deleted file mode 100644 index 03460f7..0000000 --- a/twitch/Main.py +++ /dev/null @@ -1,26 +0,0 @@ -import PIL.Image, PIL.ImageDraw, PIL.ImageFont -import os -import sys - - -font = PIL.ImageFont.truetype(os.path.join(os.path.dirname(__file__), './customAlertsMedia/ibmplex.ttf'), 20) -nFrames = 60 -width = 500 -height = 500 -if __name__ == "__main__": - tpe = sys.argv[1] - username = sys.argv[2] - description = sys.argv[3] - target = sys.argv[4] - - animated_gif = Image.open("./customAlertsMedia/"+tpe+".gif") - - frames = [] - for frame in ImageSequence.Iterator(animated_gif): - frame = frame.convert('RGB') - d = PIL.ImageDraw.Draw(frame) - d.text((0, 0), description, font=font, fill=(255, 255, 255)) - d.text((0, 100), username, font=font, fill=(255, 255, 255)) - frames.append(frame) - frames[0].save(target+tpe+".gif", save_all=True, append_images=frames[1:], duration=100, loop=0, optimize=0, comment="") - os.popen('cp ./customAlertsMedia/'+tpe+'.mp3 '+target+tpe+'.mp3') \ No newline at end of file diff --git a/twitch/customAlerts.js b/twitch/customAlerts.js index 7f2a8ae..7320f06 100644 --- a/twitch/customAlerts.js +++ b/twitch/customAlerts.js @@ -1,47 +1,92 @@ (function() { - function alert(username, desc, tpe) { - var pb = new java.lang.ProcessBuilder("/usr/bin/python3", "./Main.py", tpe, username, desc, "/opt/PhantomBot/config/gif-alerts/"); - var proc = pb.start(); - proc.waitFor(); - - $.panelsocketserver.alertImage(tpe+".gif?noise=" + Math.floor(Math.random() * 1000 + 1)); - } - $.bind('twitchFollow', function(event) { - var follower = event.getFollower(); - alert(follower.toUpperCase(), "NEW FOLLOWER", "follow"); + 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('twitchSubscriber', function(event) { - var subscriber = event.getSubscriber(); - alert(subscriber.toUpperCase(), "NEW SUBSCRIBER", "subscribe"); + }); + $.bind('twitchReSubscriber', function(event) { + sendData('subscribe', { + 'user': event.getReSubscriber(), + 'isReSub': true, + 'months': event.getMonths(), + 'tier': event.getPlan() / 1000, + 'message': event.getMessage() + }); + }); + $.bind('twitchSubscriptionGift', function(event) { + sendData('gift', { + 'recipient': event.getRecipient(), + 'user': event.getUsername(), + 'months': event.getMonths(), + 'isReSub': (parseInt(event.getMonths()) > 1), + 'tier': event.getPlan() / 1000 }); - - $.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')) { - alert(args[1].toUpperCase(), "NEW FOLLOWER", "follow"); - } else if (action.equalsIgnoreCase('subscribe')) { - alert(args[1].toUpperCase(), "NEW SUBSCRIBER", "subscribe"); - } else if (action.equalsIgnoreCase('donation')) { - alert(args[1].toUpperCase(), "NEW DONATION", "donation"); - } 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); + $.bind('twitchMassSubscriptionGifted', function(event) { + sendData('mgift', { + 'user': event.getUsername(), + 'amount': event.getAmount(), + 'tier': event.getPlan() / 1000 }); - })(); - \ No newline at end of file + }); + + $.bind('twitchRaid', function(event) { + sendData('raid',{ + 'user': event.getUsername(), + 'viewers': event.getViewers(), + }); + }); + + $.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')) { + alert(args[1].toUpperCase(), "NEW FOLLOWER", "follow"); + } else if (action.equalsIgnoreCase('subscribe')) { + alert(args[1].toUpperCase(), "NEW SUBSCRIBER", "subscribe"); + } else if (action.equalsIgnoreCase('donation')) { + alert(args[1].toUpperCase(), "NEW DONATION", "donation"); + } 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); + }); +})(); diff --git a/twitch/customAlertsMedia/subscribe.gif b/twitch/customAlertsMedia/subscribe.gif deleted file mode 100644 index d6ce6fe..0000000 Binary files a/twitch/customAlertsMedia/subscribe.gif and /dev/null differ diff --git a/web/alert/index.html b/web/alert/index.html new file mode 100644 index 0000000..f41510d --- /dev/null +++ b/web/alert/index.html @@ -0,0 +1,62 @@ + + + + + CustomAlerts + + + + + + + + +
+ + +
+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web/alert/index.js b/web/alert/index.js new file mode 100644 index 0000000..9a68d65 --- /dev/null +++ b/web/alert/index.js @@ -0,0 +1,157 @@ +const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + +const volume = parseInt((new URLSearchParams(window.location.search)).get('vol')) || 100 + +$(async function () { + const webSocket = window.socket; + const announceQueue = []; + + const playAudio = (src) =>{ + return new Promise(resolve =>{ + var audio = new Audio(); + $(audio).on("loadedmetadata", function() { + resolve(audio); + }); + audio.volume = volume/100.0; + audio.src = src; + audio.play().catch((err)=>{ + if(err.toString().startsWith('NotAllowedError')){ + $('body').append($('