-
Notifications
You must be signed in to change notification settings - Fork 13
/
DiscordMessageReactionAddScriptEvent.java
81 lines (73 loc) · 2.92 KB
/
DiscordMessageReactionAddScriptEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.denizenscript.ddiscordbot.events;
import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.*;
import com.denizenscript.denizencore.objects.ObjectTag;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
public class DiscordMessageReactionAddScriptEvent extends DiscordScriptEvent {
public static DiscordMessageReactionAddScriptEvent instance;
// <--[event]
// @Events
// discord message reaction added
//
// @Regex ^on discord message reaction added$
//
// @Switch for:<bot> to only process the event for a specified Discord bot.
// @Switch channel:<channel_id> to only process the event when it occurs in a specified Discord channel.
// @Switch group:<group_id> to only process the event for a specified Discord group.
//
// @Triggers when a Discord user added a reaction to a message.
//
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the relevant Discord bot object.
// <context.channel> returns the channel.
// <context.group> returns the group.
// <context.message> returns the message.
// <context.user> returns the user that added the reaction.
// <context.reaction> returns the new reaction.
//
// -->
public MessageReactionAddEvent getEvent() {
return (MessageReactionAddEvent) event;
}
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("discord message reaction added");
}
@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
return false;
}
if (getEvent().isFromGuild() && !path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
return super.matches(path);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("channel")) {
return new DiscordChannelTag(botID, getEvent().getChannel());
}
else if (name.equals("group")) {
if (getEvent().isFromGuild()) {
return new DiscordGroupTag(botID, getEvent().getGuild());
}
}
else if (name.equals("message")) {
return new DiscordMessageTag(botID, getEvent().getChannel().getIdLong(), getEvent().getMessageIdLong());
}
else if (name.equals("reaction")) {
return new DiscordReactionTag(botID, getEvent().getChannel().getIdLong(), getEvent().getMessageIdLong(), getEvent().getReaction());
}
else if (name.equals("user")) {
return new DiscordUserTag(botID, getEvent().getUserIdLong());
}
return super.getContext(name);
}
@Override
public String getName() {
return "DiscordMessageReactionAdded";
}
}