This commit is contained in:
2022-02-05 13:00:32 +01:00
commit 9e95efc675
5 changed files with 108 additions and 0 deletions

26
twitch/Main.py Normal file
View File

@@ -0,0 +1,26 @@
import PIL.Image, PIL.ImageDraw, PIL.ImageFont
import os
import sys
font = PIL.ImageFont.truetype(os.path.join(os.path.dirname(__file__), 'IBMPlexMono.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')

18
twitch/customAlerts.js Normal file
View File

@@ -0,0 +1,18 @@
(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");
});
$.bind('twitchSubscriber', function(event) {
var subscriber = event.getSubscriber();
alert(subscriber.toUpperCase(), "NEW SUBSCRIBER", "subscribe");
});
})();