This commit is contained in:
choelzl 2022-02-05 13:00:32 +01:00
commit 9e95efc675
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
5 changed files with 108 additions and 0 deletions

View File

@ -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() {});
})();

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");
});
})();

View File

View File