From 9e95efc675424e1ccf6aa22a859eee4267df4c4e Mon Sep 17 00:00:00 2001 From: choelzl Date: Sat, 5 Feb 2022 13:00:32 +0100 Subject: [PATCH] reimport --- discord/PhantomDiscRole.js | 64 ++++++++++++++++++++++++++++++++ twitch/Main.py | 26 +++++++++++++ twitch/customAlerts.js | 18 +++++++++ web/overlay/follow/index.html | 0 web/overlay/subscribe/index.html | 0 5 files changed, 108 insertions(+) create mode 100644 discord/PhantomDiscRole.js create mode 100644 twitch/Main.py create mode 100644 twitch/customAlerts.js create mode 100644 web/overlay/follow/index.html create mode 100644 web/overlay/subscribe/index.html diff --git a/discord/PhantomDiscRole.js b/discord/PhantomDiscRole.js new file mode 100644 index 0000000..3530584 --- /dev/null +++ b/discord/PhantomDiscRole.js @@ -0,0 +1,64 @@ +/* + * Made By Helcel + */ + +/** + * Script : PhantomDiscRole.js + * Purpose : Gives roles based on reactions.... + */ + (function() { + var messageId = $.getSetIniDbString('discordSettings', 'selectRole', '! Select your Role !'), + channelName = $.getSetIniDbString('discordSettings', 'roleChannel', ''), + notInit = false; + + var Snowflake = Packages.discord4j.common.util.Snowflake, + ReactionEmoji = Packages.discord4j.core.object.reaction.ReactionEmoji, + Permission = Packages.discord4j.rest.util.Permission; //core.object.util.Permission; + + $.bind('webPanelSocketUpdate', function(event) { + if (event.getScript().equalsIgnoreCase('./discord/custom/phantomDiscRoles.js')) { + messageId = $.getIniDbString('discordSettings', 'selectRole', '! Select your Role !'); + channelName = $.getIniDbString('discordSettings', 'roleChannel', ''); + } + }); + + $.bind('discordMessageReaction', function(event) { + var reactionEvent = event.getEvent(); + var reactionChannel = reactionEvent.getChannel().block(); + var reactionEmoji = reactionEvent.emoji; + var reactionMessage = reactionEvent.getMessage().block(); + var reactionMessageText = reactionMessage.getContent(); + var reactionUser = reactionEvent.getUserId(); + + if(!reactionMessage.getAuthorAsMember().block().getHighestRole().block().getPermissions().contains(Permission.ADMINISTRATOR)) return; + if(reactionMessageText.indexOf(messageId)!=0) return; + + var mapping = reactionMessageText.replace(messageId,"").split("\n") + var mojirole = {} + for(var i = 0; i < mapping.length; ++i){ + var map = mapping[i] + if(map.length()<3) continue; + var mape = map.split(" "); + if(mape.length!=2) continue; + var clean = mape[0].substring(mape[0].lastIndexOf(':')+1).replace('>',''); + mojirole[clean] = mape[1].replace("<@&",'').replace(">",''); + + if(notInit){ + reactionMessage.addReaction(ReactionEmoji.unicode(clean)).block(); + } + } + notInit = false; + var mojiid = reactionEmoji.asUnicodeEmoji().isPresent()? (reactionEmoji.asUnicodeEmoji().get().getRaw()) : (reactionEmoji.asCustomEmoji().get().getId().asString()); + if(mojirole[mojiid]){ + var roleid = Snowflake.of(mojirole[mojiid]) + if(event.type.ordinal()) + reactionEvent.getUser().block().asMember(reactionEvent.getGuildId().get()).block().removeRole(roleid).block() + else + reactionEvent.getUser().block().asMember(reactionEvent.getGuildId().get()).block().addRole(roleid).block() + }else{ + reactionMessage.removeReaction(reactionEmoji,reactionUser).block(); + } + }); + + $.bind('initReady', function() {}); +})(); diff --git a/twitch/Main.py b/twitch/Main.py new file mode 100644 index 0000000..7251a36 --- /dev/null +++ b/twitch/Main.py @@ -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') \ No newline at end of file diff --git a/twitch/customAlerts.js b/twitch/customAlerts.js new file mode 100644 index 0000000..cb691fc --- /dev/null +++ b/twitch/customAlerts.js @@ -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"); + }); + })(); + \ No newline at end of file diff --git a/web/overlay/follow/index.html b/web/overlay/follow/index.html new file mode 100644 index 0000000..e69de29 diff --git a/web/overlay/subscribe/index.html b/web/overlay/subscribe/index.html new file mode 100644 index 0000000..e69de29