Skip to content

Commit

Permalink
add channel and group switches to dDiscordBot
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 3, 2019
1 parent 04082d7 commit b608ecc
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
Expand Up @@ -16,7 +16,7 @@ public abstract class DiscordScriptEvent extends ScriptEvent {

@Override
public boolean matches(ScriptPath path) {
return runBotIDCheck(path, "for");
return path.checkSwitch("for", botID);
}

@Override
Expand All @@ -39,14 +39,6 @@ public String stripMentions(String message, Flux<User> mentioned) {
return message;
}

public boolean runBotIDCheck(ScriptPath path, String label) {
String botLabel = path.switches.get(label);
if (botLabel == null) {
return true;
}
return botLabel.equalsIgnoreCase(botID);
}

public boolean enabled = false;

public boolean isProperEvent() {
Expand Down
Expand Up @@ -21,7 +21,10 @@ public class DiscordMessageDeletedScriptEvent extends DiscordScriptEvent {
// discord message deleted
//
// @Regex ^on discord message deleted$
//
// @Switch for <bot>
// @Switch channel <channel_id>
// @Switch group <group_id>
//
// @Triggers when a Discord user deletes a message.
//
Expand Down Expand Up @@ -55,6 +58,18 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord message deleted");
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", String.valueOf(getEvent().getChannelId().asLong()))) {
return false;
}
if (getEvent().getChannel().block() instanceof GuildChannel
&& !path.checkSwitch("group", String.valueOf(((GuildChannel) getEvent().getChannel().block()).getGuildId().asLong()))) {
return false;
}
return super.matches(path);
}

@Override
public dObject getContext(String name) {
if (name.equals("channel")) {
Expand Down
Expand Up @@ -20,7 +20,10 @@ public class DiscordMessageModifiedScriptEvent extends DiscordScriptEvent {
// discord message modified
//
// @Regex ^on discord message modified$
//
// @Switch for <bot>
// @Switch channel <channel_id>
// @Switch group <group_id>
//
// @Triggers when a Discord user modified a message.
//
Expand Down Expand Up @@ -58,6 +61,17 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord message modified");
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", String.valueOf(getEvent().getChannelId().asLong()))) {
return false;
}
if (getEvent().getGuildId().isPresent() && !path.checkSwitch("group", String.valueOf(getEvent().getGuildId().get().asLong()))) {
return false;
}
return super.matches(path);
}

@Override
public dObject getContext(String name) {
if (name.equals("channel")) {
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.event.domain.message.MessageUpdateEvent;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User;
Expand All @@ -22,7 +21,10 @@ public class DiscordMessageReceivedScriptEvent extends DiscordScriptEvent {
// discord message received
//
// @Regex ^on discord message received$
//
// @Switch for <bot>
// @Switch channel <channel_id>
// @Switch group <group_id>
//
// @Triggers when a Discord bot receives a message.
//
Expand Down Expand Up @@ -55,6 +57,17 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord message received");
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("channel", String.valueOf(getEvent().getMessage().getChannelId().asLong()))) {
return false;
}
if (getEvent().getGuildId().isPresent() && !path.checkSwitch("group", String.valueOf(getEvent().getGuildId().get().asLong()))) {
return false;
}
return super.matches(path);
}

@Override
public dObject getContext(String name) {
if (name.equals("channel")) {
Expand Down
Expand Up @@ -16,7 +16,9 @@ public class DiscordUserJoinsScriptEvent extends DiscordScriptEvent {
// discord user joins
//
// @Regex ^on discord user join$
//
// @Switch for <bot>
// @Switch group <group_id>
//
// @Triggers when a Discord user joins a guild.
//
Expand All @@ -35,6 +37,14 @@ public MemberJoinEvent getEvent() {
return (MemberJoinEvent) event;
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", String.valueOf(getEvent().getGuildId().asLong()))) {
return false;
}
return super.matches(path);
}

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord user joins");
Expand Down
Expand Up @@ -16,7 +16,9 @@ public class DiscordUserLeavesScriptEvent extends DiscordScriptEvent {
// discord user leaves
//
// @Regex ^on discord user leaves$
//
// @Switch for <bot>
// @Switch group <group_id>
//
// @Triggers when a Discord user leaves a guild.
//
Expand All @@ -35,6 +37,14 @@ public MemberLeaveEvent getEvent() {
return (MemberLeaveEvent) event;
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", String.valueOf(getEvent().getGuildId().asLong()))) {
return false;
}
return super.matches(path);
}

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord user leaves");
Expand Down
Expand Up @@ -20,7 +20,9 @@ public class DiscordUserRoleChangeScriptEvent extends DiscordScriptEvent {
// discord user role changes
//
// @Regex ^on discord role changes$
//
// @Switch for <bot>
// @Switch group <group_id>
//
// @Triggers when a Discord user's roles change.
//
Expand Down Expand Up @@ -48,6 +50,14 @@ public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("discord user role changes");
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("group", String.valueOf(getEvent().getGuildId().asLong()))) {
return false;
}
return super.matches(path);
}

public ArrayList<Long> getOldRoles() {
ArrayList<Long> oldRoles = new ArrayList<>();
for (Snowflake role : getEvent().getOld().get().getRoleIds()) {
Expand Down

0 comments on commit b608ecc

Please sign in to comment.