Skip to content

Commit

Permalink
Remove 'context.self', rework 'context.bot', add 'discord.self_user'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 23, 2019
1 parent 7be5601 commit 6bfa117
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.denizenscript.ddiscordbot;

import com.denizenscript.ddiscordbot.objects.DiscordBotTag;
import discord4j.core.event.domain.Event;
import discord4j.core.object.entity.User;
import com.denizenscript.denizencore.events.ScriptEvent;
Expand All @@ -22,10 +23,7 @@ public boolean matches(ScriptPath path) {
@Override
public ObjectTag getContext(String name) {
if (name.equals("bot")) {
return new ElementTag(botID);
}
else if (name.equals("self")) {
return new ElementTag(event.getClient().getSelf().block().getId().asLong());
return new DiscordBotTag(botID);
}
return super.getContext(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class DiscordMessageDeletedScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.channel> returns the channel.
// <context.group> returns the group.
// <context.author> returns the user that authored the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public class DiscordMessageModifiedScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.channel> returns the channel.
// <context.group> returns the group.
// <context.author> returns the user that authored the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class DiscordMessageReceivedScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.channel> returns the channel.
// <context.group> returns the group.
// <context.message> returns the message (raw).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class DiscordUserJoinsScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.group> returns the group.
// <context.user> returns the user.
// -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class DiscordUserLeavesScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.group> returns the group.
// <context.user> returns the user.
// -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class DiscordUserRoleChangeScriptEvent extends DiscordScriptEvent {
// @Plugin dDiscordBot
//
// @Context
// <context.bot> returns the Denizen ID of the bot.
// <context.self> returns the bots own Discord user ID.
// <context.bot> returns the relevant Discord bot object.
// <context.group> returns the group.
// <context.user> returns the user.
// <context.old_roles> returns a list of the user's previous role set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
}
});

// <--[tag]
// @attribute <DiscordBotTag.self_user>
// @returns DiscordUserTag
// @plugin dDiscordBot
// @description
// Returns the bot's own Discord user object.
// -->
registerTag("self_user", new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(((DiscordBotTag) object).bot);
if (connection == null) {
return null;
}
return new DiscordUserTag(((DiscordBotTag) object).bot, connection.client.getSelf().block())
.getObjectAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <DiscordBotTag.groups>
// @returns ListTag(DiscordGroupTag)
Expand Down

0 comments on commit 6bfa117

Please sign in to comment.