Skip to content

Commit

Permalink
WidgetListener: use message of widget instead of retrieving by id
Browse files Browse the repository at this point in the history
  • Loading branch information
robinfriedli committed Aug 17, 2019
1 parent 2e759ea commit d40bfe1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.robinfriedli.botify.command.widgets.actions.RewindAction;
import net.robinfriedli.botify.command.widgets.actions.SkipAction;
import net.robinfriedli.botify.discord.MessageService;
import net.robinfriedli.botify.exceptions.UserException;
import net.robinfriedli.botify.util.EmojiConstants;

public class QueueWidget extends AbstractWidget {
Expand Down Expand Up @@ -46,15 +45,15 @@ public List<AbstractWidgetAction> setupActions() {

@Override
public void reset() throws Exception {
setMessageDeleted(true);
MessageService messageService = new MessageService();
try {
getMessage().delete().queue();
setMessageDeleted(true);
} catch (InsufficientPermissionException e) {
throw new UserException("Bot is missing permission: " + e.getPermission().getName(), e);
messageService.sendError("Bot is missing permission: " + e.getPermission().getName(), getMessage().getChannel());
}

EmbedBuilder embedBuilder = audioPlayback.getAudioQueue().buildMessageEmbed(audioPlayback, getMessage().getGuild());
MessageService messageService = new MessageService();
CompletableFuture<Message> futureMessage = messageService.sendWithLogo(embedBuilder, getMessage().getChannel());
getCommandManager().registerWidget(new QueueWidget(getCommandManager(), futureMessage.get(), audioManager, audioPlayback));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.robinfriedli.botify.command.AbstractWidget;
import net.robinfriedli.botify.command.CommandContext;
import net.robinfriedli.botify.command.CommandManager;
import net.robinfriedli.botify.discord.CompletablePlaceholderMessage;
import net.robinfriedli.botify.discord.GuildContext;
import net.robinfriedli.botify.discord.MessageService;
import net.robinfriedli.botify.exceptions.CommandRuntimeException;
Expand Down Expand Up @@ -57,14 +56,11 @@ public void onGuildMessageDelete(GuildMessageDeleteEvent event) {

private void handleWidgetExecution(GuildMessageReactionAddEvent event, String messageId, AbstractWidget activeWidget) {
TextChannel channel = event.getChannel();
CompletablePlaceholderMessage message = new CompletablePlaceholderMessage();
channel.retrieveMessageById(messageId).queue(message::complete, message::completeExceptionally);

Guild guild = event.getGuild();
Botify botify = Botify.get();
SpotifyApi spotifyApi = botify.getSpotifyApiBuilder().build();
GuildContext guildContext = botify.getGuildManager().getContextForGuild(guild);
CommandContext commandContext = new CommandContext("", message, StaticSessionProvider.getSessionFactory(), spotifyApi, guildContext);
CommandContext commandContext = new CommandContext("", activeWidget.getMessage(), StaticSessionProvider.getSessionFactory(), spotifyApi, guildContext);

Thread widgetExecutionThread = new Thread(() -> {
CommandContext.Current.set(commandContext);
Expand Down

0 comments on commit d40bfe1

Please sign in to comment.