Skip to content

Commit

Permalink
proper matches for guilds channels
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 4, 2021
1 parent ecca95b commit 72046a3
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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 {
Expand Down Expand Up @@ -38,4 +40,40 @@ public void init() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
if (!path.checkSwitch("id", getEvent().getButton().getId())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
return super.matches(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
return super.matches(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
return super.matches(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
return super.matches(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
if (!runGenericSwitchCheck(path, "message", getEvent().getMessage().getContentRaw())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
if (!path.checkSwitch("id", getEvent().getSelectionMenu().getId())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,11 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", getEvent().getChannel().getId())) {
if (!tryChannel(path, getEvent().getChannel())) {
return false;
}
if (path.switches.containsKey("group")) {
if (!getEvent().isFromGuild()) {
return false;
}
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
return false;
}
if (!tryGuild(path, getEvent().isFromGuild() ? getEvent().getGuild() : null)) {
return false;
}
if (!path.checkSwitch("name", getEvent().getName())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GuildMemberJoinEvent getEvent() {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GuildMemberRemoveEvent getEvent() {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", getEvent().getGuild().getId())) {
if (!tryGuild(path, getEvent().getGuild())) {
return false;
}
return super.matches(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", getGenericEvent().getGuild().getId())) {
if (!tryGuild(path, getGenericEvent().getGuild())) {
return false;
}
return super.matches(path);
Expand Down

0 comments on commit 72046a3

Please sign in to comment.