-
Notifications
You must be signed in to change notification settings - Fork 13
/
DiscordScriptEvent.java
79 lines (68 loc) · 2.08 KB
/
DiscordScriptEvent.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
package com.denizenscript.ddiscordbot;
import com.denizenscript.ddiscordbot.objects.DiscordBotTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.events.Event;
public abstract class DiscordScriptEvent extends BukkitScriptEvent {
public String botID;
public Event event;
@Override
public boolean matches(ScriptPath path) {
if (!runGenericSwitchCheck(path, "for", botID)) {
return false;
}
return super.matches(path);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("bot")) {
return new DiscordBotTag(botID);
}
return super.getContext(name);
}
public boolean enabled = false;
@Override
public void init() {
enabled = true;
}
@Override
public void destroy() {
enabled = false;
}
public static boolean tryChannel(ScriptPath path, MessageChannel channel) {
String text = path.switches.get("channel");
if (text == null) {
return true;
}
if (channel == null) {
return false;
}
MatchHelper matcher = createMatcher(text);
if (matcher.doesMatch(channel.getId())) {
return true;
}
if (matcher.doesMatch(channel.getName())) {
return true;
}
return false;
}
public static boolean tryGuild(ScriptPath path, Guild guild) {
String text = path.switches.get("group");
if (text == null) {
return true;
}
if (guild == null) {
return false;
}
MatchHelper matcher = createMatcher(text);
if (matcher.doesMatch(guild.getId())) {
return true;
}
if (matcher.doesMatch(guild.getName())) {
return true;
}
return false;
}
}