Skip to content

Commit

Permalink
add DiscordUserTag contexts to events, fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 30, 2019
1 parent 8332454 commit 310c768
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.message.MessageDeleteEvent;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.MessageChannel;
Expand Down Expand Up @@ -37,8 +38,7 @@ public class DiscordMessageDeletedScriptEvent extends DiscordScriptEvent {
// <context.channel_name> returns the channel name.
// <context.group> returns the group ID.
// <context.group_name> returns the group name.
// <context.author_id> returns the author's internal ID.
// <context.author_name> returns the author's name.
// <context.author> returns the user that authored the message.
// <context.mentions> returns a list of all mentioned user IDs.
// <context.mention_names> returns a list of all mentioned user names.
// <context.is_direct> returns whether the message was sent directly to the bot (if false, the message was sent to a public channel).
Expand Down Expand Up @@ -110,12 +110,15 @@ else if (name.equals("formatted_message")) {
return new ElementTag(getEvent().getMessage().get().getContent().get());
}
}
else if (name.equals("author_id")) {
else if (name.equals("author")) {
return new DiscordUserTag(botID, getEvent().getMessage().get().getAuthor().get());
}
else if (name.equals("author_id")) { // Deprecated
if (getEvent().getMessage().isPresent()) {
return new ElementTag(getEvent().getMessage().get().getAuthor().get().getId().asLong());
}
}
else if (name.equals("author_name")) {
else if (name.equals("author_name")) { // Deprecated
if (getEvent().getMessage().isPresent()) {
return new ElementTag(getEvent().getMessage().get().getAuthor().get().getUsername());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.message.MessageUpdateEvent;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.MessageChannel;
Expand Down Expand Up @@ -36,8 +37,7 @@ public class DiscordMessageModifiedScriptEvent extends DiscordScriptEvent {
// <context.channel_name> returns the channel name.
// <context.group> returns the group ID.
// <context.group_name> returns the group name.
// <context.author_id> returns the author's internal ID.
// <context.author_name> returns the author's name.
// <context.author> returns the user that authored the message.
// <context.mentions> returns a list of all mentioned user IDs.
// <context.mention_names> returns a list of all mentioned user names.
// <context.is_direct> returns whether the message was sent directly to the bot (if false, the message was sent to a public channel).
Expand Down Expand Up @@ -122,10 +122,13 @@ else if (name.equals("no_mention_message")) {
else if (name.equals("formatted_message")) {
return new ElementTag(getEvent().getMessage().block().getContent().orElse(""));
}
else if (name.equals("author_id")) {
else if (name.equals("author")) {
return new DiscordUserTag(botID, getEvent().getMessage().block().getAuthor().get());
}
else if (name.equals("author_id")) { // Deprecated
return new ElementTag(getEvent().getMessage().block().getAuthor().get().getId().asLong());
}
else if (name.equals("author_name")) {
else if (name.equals("author_name")) { // Deprecated
return new ElementTag(getEvent().getMessage().block().getAuthor().get().getUsername());
}
else if (name.equals("mentions")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.MessageChannel;
Expand Down Expand Up @@ -40,8 +41,7 @@ public class DiscordMessageReceivedScriptEvent extends DiscordScriptEvent {
// <context.message> returns the message (raw).
// <context.no_mention_message> returns the message with all user mentions stripped.
// <context.formatted_message> returns the formatted message (mentions/etc. are written cleanly). CURRENTLY NON-FUNCTIONAL.
// <context.author_id> returns the author's internal ID.
// <context.author_name> returns the author's name.
// <context.author> returns the user that authored the message.
// <context.mentions> returns a list of all mentioned user IDs.
// <context.mention_names> returns a list of all mentioned user names.
// <context.is_direct> returns whether the message was sent directly to the bot (if false, the message was sent to a public channel).
Expand Down Expand Up @@ -99,10 +99,13 @@ else if (name.equals("no_mention_message")) {
else if (name.equals("formatted_message")) {
return new ElementTag(getEvent().getMessage().getContent().orElse(""));
}
else if (name.equals("author_id")) {
else if (name.equals("author")) {
return new DiscordUserTag(botID, getEvent().getMessage().getAuthor().get());
}
else if (name.equals("author_id")) { // Deprecated
return new ElementTag(getEvent().getMessage().getAuthor().get().getId().asLong());
}
else if (name.equals("author_name")) {
else if (name.equals("author_name")) { // Deprecated
return new ElementTag(getEvent().getMessage().getAuthor().get().getUsername());
}
else if (name.equals("mentions")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.guild.MemberJoinEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down Expand Up @@ -29,8 +30,7 @@ public class DiscordUserJoinsScriptEvent extends DiscordScriptEvent {
// <context.self> returns the bots own Discord user ID.
// <context.group> returns the group ID.
// <context.group_name> returns the group name.
// <context.user_id> returns the user's internal ID.
// <context.user_name> returns the user's name.
// <context.user> returns the user.
// -->

public MemberJoinEvent getEvent() {
Expand Down Expand Up @@ -58,10 +58,13 @@ public ObjectTag getContext(String name) {
else if (name.equals("group_name")) {
return new ElementTag(getEvent().getGuild().block().getName());
}
else if (name.equals("user_id")) {
else if (name.equals("user")) {
return new DiscordUserTag(botID, getEvent().getMember());
}
else if (name.equals("user_id")) { // Deprecated
return new ElementTag(getEvent().getMember().getId().asLong());
}
else if (name.equals("user_name")) {
else if (name.equals("user_name")) { // Deprecated
return new ElementTag(getEvent().getMember().getUsername());
}
return super.getContext(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.guild.MemberLeaveEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down Expand Up @@ -29,8 +30,7 @@ public class DiscordUserLeavesScriptEvent extends DiscordScriptEvent {
// <context.self> returns the bots own Discord user ID.
// <context.group> returns the group ID.
// <context.group_name> returns the group name.
// <context.user_id> returns the user's internal ID.
// <context.user_name> returns the user's name.
// <context.user> returns the user.
// -->

public MemberLeaveEvent getEvent() {
Expand Down Expand Up @@ -58,10 +58,13 @@ public ObjectTag getContext(String name) {
else if (name.equals("group_name")) {
return new ElementTag(getEvent().getGuild().block().getName());
}
else if (name.equals("user_id")) {
else if (name.equals("user")) {
return new DiscordUserTag(botID, getEvent().getMember().get());
}
else if (name.equals("user_id")) { // Deprecated
return new ElementTag(getEvent().getMember().get().getId().asLong());
}
else if (name.equals("user_name")) {
else if (name.equals("user_name")) { // Deprecated
return new ElementTag(getEvent().getMember().get().getUsername());
}
return super.getContext(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.denizenscript.ddiscordbot.events;

import com.denizenscript.ddiscordbot.DiscordScriptEvent;
import com.denizenscript.ddiscordbot.objects.DiscordUserTag;
import discord4j.core.event.domain.guild.MemberUpdateEvent;
import discord4j.core.object.util.Snowflake;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand Down Expand Up @@ -33,8 +34,7 @@ public class DiscordUserRoleChangeScriptEvent extends DiscordScriptEvent {
// <context.self> returns the bots own Discord user ID.
// <context.group> returns the group ID.
// <context.group_name> returns the group name.
// <context.user_id> returns the user's internal ID.
// <context.user_name> returns the user's name.
// <context.user> returns the user.
// <context.old_roles_ids> returns a list of the user's previous role set.
// <context.new_role_ids> returns a list of the user's new role set.
// <context.added_role_ids> returns a list of the user's added role set.
Expand Down Expand Up @@ -104,10 +104,13 @@ public ObjectTag getContext(String name) {
else if (name.equals("group_name")) {
return new ElementTag(getEvent().getGuild().block().getName());
}
else if (name.equals("user_id")) {
else if (name.equals("user")) {
return new DiscordUserTag(botID, getEvent().getMember().block());
}
else if (name.equals("user_id")) { // Deprecated
return new ElementTag(getEvent().getMember().block().getId().asLong());
}
else if (name.equals("user_name")) {
else if (name.equals("user_name")) { // Deprecated
return new ElementTag(getEvent().getMember().block().getUsername());
}
if (name.equals("old_role_ids")) {
Expand Down

0 comments on commit 310c768

Please sign in to comment.