msg reaction remove all & emoji gateway event

This commit is contained in:
TomatoCake 2024-08-25 18:36:30 +02:00
parent 1de4767c6d
commit b366381e53
2 changed files with 30 additions and 4 deletions

View file

@ -374,7 +374,7 @@ class Localuser{
}else{ }else{
thing={id:temp.d.user_id} thing={id:temp.d.user_id}
} }
message.makeReaction(temp.d.emoji,thing); message.reactionAdd(temp.d.emoji,thing);
} }
break; break;
case "MESSAGE_REACTION_REMOVE": case "MESSAGE_REACTION_REMOVE":
@ -382,9 +382,21 @@ class Localuser{
const message=SnowFlake.getSnowFlakeFromID(temp.d.message_id,Message).getObject(); const message=SnowFlake.getSnowFlakeFromID(temp.d.message_id,Message).getObject();
console.log("test"); console.log("test");
message.removeReaction(temp.d.emoji,temp.d.user_id); message.reactionRemove(temp.d.emoji,temp.d.user_id);
} }
break; break;
case "MESSAGE_REACTION_REMOVE_ALL":
if (SnowFlake.hasSnowFlakeFromID(temp.d.message_id, Message)) {
const messageReactionRemoveAll = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject()
messageReactionRemoveAll.reactionRemoveAll()
}
break
case "MESSAGE_REACTION_REMOVE_EMOJI":
if (SnowFlake.hasSnowFlakeFromID(temp.d.message_id, Message)) {
const messageReactionRemoveEmoji = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject()
messageReactionRemoveEmoji.reactionRemoveEmoji(temp.d.emoji)
}
break
case "GUILD_MEMBERS_CHUNK": case "GUILD_MEMBERS_CHUNK":
this.gotChunk(temp.d); this.gotChunk(temp.d);
break; break;

View file

@ -509,7 +509,7 @@ class Message{
} }
func(); func();
} }
makeReaction(data:{name:string},member:Member|{id:string}){ reactionAdd(data:{name:string},member:Member|{id:string}){
for(const thing of this.reactions){ for(const thing of this.reactions){
if(thing.emoji.name===data.name){ if(thing.emoji.name===data.name){
thing.count++; thing.count++;
@ -527,7 +527,7 @@ class Message{
}); });
this.updateReactions(); this.updateReactions();
} }
removeReaction(data:{name:string},id:string){ reactionRemove(data:{name:string},id:string){
console.log("test"); console.log("test");
for(const i in this.reactions){ for(const i in this.reactions){
const thing=this.reactions[i]; const thing=this.reactions[i];
@ -547,6 +547,20 @@ class Message{
} }
} }
} }
reactionRemoveAll() {
this.reactions = [];
this.updateReactions();
}
reactionRemoveEmoji(emoji:Emoji) {
for (const i in this.reactions) {
const reaction = this.reactions[i];
if ((reaction.emoji.id && reaction.emoji.id == emoji.id) || (!reaction.emoji.id && reaction.emoji.name == emoji.name)) {
this.reactions.splice(i, 1);
this.updateReactions();
break;
}
}
}
buildhtml(premessage:Message|undefined=undefined){ buildhtml(premessage:Message|undefined=undefined){
if(this.div){console.error(`HTML for ${this.snowflake} already exists, aborting`);return;} if(this.div){console.error(`HTML for ${this.snowflake} already exists, aborting`);return;}
try{ try{