use of net.robinfriedli.aiode.discord.GuildContext in project aiode by robinfriedli.
the class WidgetListener method handleWidgetExecution.
private void handleWidgetExecution(GuildMessageReactionAddEvent event, AbstractWidget activeWidget) {
TextChannel channel = event.getChannel();
Guild guild = event.getGuild();
Aiode aiode = Aiode.get();
SpotifyApi.Builder spotifyApiBuilder = aiode.getSpotifyApiBuilder();
GuildContext guildContext = aiode.getGuildManager().getContextForGuild(guild);
String emojiUnicode = event.getReaction().getReactionEmote().getName();
try {
Message message = activeWidget.getMessage().retrieve();
if (message == null) {
throw new IllegalStateException("Message of widget could not be retrieved.");
}
CommandContext commandContext = new CommandContext(event, guildContext, message, hibernateComponent.getSessionFactory(), spotifyApiBuilder, emojiUnicode);
activeWidget.handleReaction(event, commandContext);
} catch (UserException e) {
messageService.sendError(e.getMessage(), channel);
} catch (InsufficientPermissionException e) {
Permission permission = e.getPermission();
messageService.send("Bot is missing permission: " + permission.getName(), channel);
logger.warn(String.format("Missing permission %s on guild %s", permission, guild));
} catch (Exception e) {
logger.error("Exception while handling WidgetAction execution.", e);
}
}
use of net.robinfriedli.aiode.discord.GuildContext in project aiode by robinfriedli.
the class RequestInterceptorHandler method setupExecutionContext.
private ExecutionContext setupExecutionContext(ClientSession clientSession) {
SessionFactory sessionFactory = hibernateComponent.getSessionFactory();
Guild guild = shardManager.getGuildById(clientSession.getGuildId());
if (guild == null) {
return null;
}
Member member = guild.getMemberById(clientSession.getUserId());
if (member == null) {
return null;
}
TextChannel textChannel = guild.getTextChannelById(clientSession.getTextChannelId());
if (textChannel == null) {
textChannel = guildManager.getDefaultTextChannelForGuild(guild);
TextChannel finalTextChannel = textChannel;
hibernateComponent.consumeSession(session -> {
clientSession.setTextChannelId(finalTextChannel.getIdLong());
session.update(clientSession);
});
}
JDA jda = guild.getJDA();
GuildContext guildContext = guildManager.getContextForGuild(guild);
return new ExecutionContext(guild, guildContext, jda, member, sessionFactory, spotifyApiBuilder, textChannel);
}
Aggregations