@Override public RestAction<Message> getMessageById(String messageId) { checkPermission(Permission.MESSAGE_READ); checkPermission(Permission.MESSAGE_HISTORY); //Call MessageChannel's default method return TextChannel.super.getMessageById(messageId); }
/** * Handles the reaction * * @param channel TextChannel of the message * @param messageId id of the message * @param userId id of the user reacting * @param reaction the reaction */ public void handle(TextChannel channel, long messageId, long userId, MessageReaction reaction) { CommandReactionListener<?> listener = reactions.get(channel.getGuild().getIdLong()).get(messageId); if (!listener.isActive() || listener.getExpiresInTimestamp() < System.currentTimeMillis()) { reactions.get(channel.getGuild().getIdLong()).remove(messageId); } else if (listener.hasReaction(reaction.getReactionEmote().getName()) && listener.getUserId() == userId) { reactions.get(channel.getGuild().getIdLong()).get(messageId).updateLastAction(); Message message = channel.getMessageById(messageId).complete(); listener.react(reaction.getReactionEmote().getName(), message); } }
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { if (args.length == 1 && args[0].matches("[0-9]{18,22}")) { if (!guild.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) { MessageUtils.sendErrorMessage("I need the `Manage Messages` permission in order to pin!", channel); return; } Message msg = channel.getMessageById(args[0].trim()).complete(); if (msg == null) { MessageUtils.sendErrorMessage("That message could not be found!", channel); return; } msg.pin().complete(); channel.getHistory().retrievePast(1).complete().get(0).delete().queue(); } else if (args.length != 0) { if (!guild.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_MANAGE)) { MessageUtils.sendErrorMessage("I need the `Manage Messages` permission in order to pin!", channel); return; } Message msg = channel.sendMessage(new EmbedBuilder().setTitle(sender.getName(), null) .setThumbnail(MessageUtils.getAvatar(sender)).setDescription(MessageUtils.getMessage(args, 0)) .build()).complete(); msg.pin().complete(); channel.getHistory().retrievePast(1).complete().get(0).delete().queue(); } else { MessageUtils.sendUsage(this, channel, sender, args); } }
private String editReason(DiscordBot bot, Guild guild, Member moderator, MessageChannel feedbackChannel, String caseId, String reason) { OModerationCase oCase; if (caseId.equalsIgnoreCase("last")) { oCase = CModerationCase.findLastFor(CGuild.getCachedId(guild.getIdLong()), CUser.getCachedId(moderator.getUser().getIdLong())); } else { oCase = CModerationCase.findById(Misc.parseInt(caseId, -1)); } if (oCase.id == 0 || oCase.guildId != CGuild.getCachedId(guild.getIdLong())) { return Templates.command.case_not_found.formatGuild(guild.getIdLong(), oCase.id); } oCase.reason = reason; CModerationCase.update(oCase); TextChannel channel = guild.getTextChannelById(GuildSettings.get(guild).getOrDefault(GSetting.BOT_CHANNEL)); if (channel == null) { return Templates.config.modlog_not_found.formatGuild(guild.getIdLong()); } bot.queue.add(channel.getMessageById(oCase.messageId), msg -> { if (msg != null) { bot.queue.add(msg.editMessage(new MessageBuilder().setEmbed(CModerationCase.buildCase(guild, oCase)).build())); } else { bot.queue.add(feedbackChannel.sendMessage(Templates.command.case_reason_modified.formatGuild(channel))); } }); return ""; } }
.update(statement -> statement.set("reason", reason, true)); channel.getMessageById(first.getString("message_id")).queue(message -> { if (message.getEmbeds().isEmpty()) {