Skip to content

Commit

Permalink
Discord edit/delete message: update channel handling, deprecate old s…
Browse files Browse the repository at this point in the history
…ubcmds
  • Loading branch information
mcmonkey4eva committed Feb 5, 2022
1 parent dad43c7 commit 80913e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class DenizenDiscordBot extends JavaPlugin {
public static Warning oldMessageContexts = new SlowWarning("dDiscordBot contexts relating to message data are now provided by DiscordMessageTag.");
public static Warning oldMessageCommand = new SlowWarning("dDiscordBot's 'discord message' sub-command has been moved to a base 'discordmessage' command.");
public static Warning oldConnectCommand = new FutureWarning("dDiscordBot's 'discord connect' sub-command has been moved to a base 'discordconnect' command.");
public static Warning oldStopTyping = new FutureWarning("dDiscordBot's 'discord stop_typing' sub-command is deprecated as it does nothing.");
public static Warning oldDeleteMessage = new FutureWarning("dDiscordBot's 'discord delete_message' sub-command is deprecated in favor of 'adjust <[message]> delete'.");

public static DenizenDiscordBot instance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public class DiscordCommand extends AbstractDiscordCommand implements Holdable {

public DiscordCommand() {
setName("discord");
setSyntax("discord [id:<id>] [disconnect/add_role/start_typing/stop_typing/remove_role/status (status:<status>) (activity:<activity>)/rename/edit_message/delete_message] (<value>) (message_id:<id>) (channel:<channel>) (user:<user>) (group:<group>) (role:<role>) (url:<url>)");
setSyntax("discord [id:<id>] [disconnect/add_role/start_typing/remove_role/status (status:<status>) (activity:<activity>)/rename/edit_message] (<value>) (message_id:<id>) (channel:<channel>) (user:<user>) (group:<group>) (role:<role>) (url:<url>)");
setRequiredArguments(2, 12);
isProcedural = false;
}

// <--[command]
// @Name discord
// @Syntax discord [id:<id>] [disconnect/add_role/start_typing/stop_typing/remove_role/status (status:<status>) (activity:<activity>)/rename/edit_message/delete_message] (<value>) (message_id:<id>) (channel:<channel>) (user:<user>) (group:<group>) (role:<role>) (url:<url>)
// @Syntax discord [id:<id>] [disconnect/add_role/start_typing/remove_role/status (status:<status>) (activity:<activity>)/rename/edit_message] (<value>) (message_id:<id>) (channel:<channel>) (user:<user>) (group:<group>) (role:<role>) (url:<url>)
// @Required 2
// @Maximum 12
// @Short Interacts with Discord.
Expand Down Expand Up @@ -88,17 +88,9 @@ public DiscordCommand() {
// - ~discord id:mybot start_typing channel:<[channel]>
//
// @Usage
// Use to stop typing in a specific channel.
// - ~discord id:mybot stop_typing channel:<[channel]>
//
// @Usage
// Use to edit a message the bot has already sent.
// - ~discord id:mybot edit_message channel:<[channel]> message_id:<[msg]> "Wow! It got edited!"
//
// @Usage
// Use to delete a message the bot has already sent.
// - ~discord id:mybot delete_message channel:<[channel]> message_id:<[msg]>
//
// -->

public enum DiscordInstruction { CONNECT, DISCONNECT, MESSAGE, ADD_ROLE, REMOVE_ROLE, STATUS, RENAME, START_TYPING, STOP_TYPING, EDIT_MESSAGE, DELETE_MESSAGE }
Expand Down Expand Up @@ -375,11 +367,11 @@ public void execute(ScriptEntry scriptEntry) {
if (requireClientID.get() || requireChannel.get() || requireMessage.get() || requireMessageId.get()) {
return;
}
JDA client = DenizenDiscordBot.instance.connections.get(id.asString()).client;
if (requireClientObject.apply(client)) {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(id.asString());
if (requireClientObject.apply(connection == null ? null : connection.client)) {
return;
}
MessageChannel textChannel = client.getTextChannelById(channel.channel_id);
MessageChannel textChannel = (MessageChannel) connection.getChannel(channel.channel_id);
if (message.asString().startsWith("discordembed@")) {
MessageEmbed embed = DiscordEmbedTag.valueOf(message.asString(), scriptEntry.context).build(scriptEntry.context).build();
textChannel.editMessageEmbedsById(messageId.asLong(), embed).complete();
Expand All @@ -391,30 +383,33 @@ public void execute(ScriptEntry scriptEntry) {
break;
}
case DELETE_MESSAGE: {
DenizenDiscordBot.oldDeleteMessage.warn(scriptEntry);
if (requireClientID.get() || requireChannel.get() || requireMessageId.get()) {
return;
}
JDA client = DenizenDiscordBot.instance.connections.get(id.asString()).client;
if (requireClientObject.apply(client)) {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(id.asString());
if (requireClientObject.apply(connection == null ? null : connection.client)) {
return;
}
client.getTextChannelById(channel.channel_id).deleteMessageById(messageId.asLong()).complete();
((MessageChannel) connection.getChannel(channel.channel_id)).deleteMessageById(messageId.asLong()).complete();
scriptEntry.setFinished(true);
break;
}
case START_TYPING: {
if (requireClientID.get() || requireChannel.get()) {
return;
}
JDA client = DenizenDiscordBot.instance.connections.get(id.asString()).client;
if (requireClientObject.apply(client)) {
DiscordConnection connection = DenizenDiscordBot.instance.connections.get(id.asString());
if (requireClientObject.apply(connection == null ? null : connection.client)) {
return;
}
client.getTextChannelById(channel.channel_id).sendTyping().complete();
MessageChannel textChannel = (MessageChannel) connection.getChannel(channel.channel_id);
textChannel.sendTyping().complete();
scriptEntry.setFinished(true);
break;
}
case STOP_TYPING: {
DenizenDiscordBot.oldStopTyping.warn(scriptEntry);
if (requireClientID.get() || requireChannel.get()) {
return;
}
Expand Down

0 comments on commit 80913e2

Please sign in to comment.