use of net.dv8tion.jda.api.entities.MessageReaction in project cds by iamysko.
the class ReactionListener method onMessageReactionAdd.
/**
* On message reaction add.
*
* @param event the event
*/
@Override
public void onMessageReactionAdd(final MessageReactionAddEvent event) {
final TextChannel commandChannel = event.getGuild().getTextChannelById(Properties.CHANNEL_COMMANDS_ID);
final MessageReaction reaction = event.getReaction();
final Member reactee = event.getMember();
final MessageChannel channel = event.getTextChannel();
final ReactionEmote emote = reaction.getReactionEmote();
final String emoteId = emote.isEmote() ? emote.getId() : "";
if (!emoteId.equals(ID_REACTION_ALERT_MODS) && !RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_SENIOR_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
// Do nothing.
return;
}
event.retrieveMessage().queue(message -> {
final String messageLink = message.getJumpUrl();
message.getJDA().getGuildById(message.getGuild().getIdLong()).retrieveMemberById(message.getAuthor().getId()).queue(messageAuthor -> {
if (emoteId.equals(ID_REACTION_ALERT_MODS)) {
if (existingAlertsMap.get(message.getIdLong()) == null) {
alertMods(event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
}
}
if (!RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_SENIOR_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
// Do nothing.
return;
}
final Action commandAction = new Action();
commandAction.setDate(Instant.now());
commandAction.setUser(reactee.getUser().getAsTag());
commandAction.setDiscordId(reactee.getIdLong());
switch(emoteId) {
case ID_REACTION_PURGE_MESSAGES:
if (!isStaffOnStaff(reactee, messageAuthor, commandChannel) && !isInStaffChannel(reactee, commandChannel, event.getChannel()) && RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR, RoleUtils.ROLE_BOT)) {
purgeMessagesInChannel(messageAuthor, channel);
commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
commandAction.setOffendingUserId(messageAuthor.getIdLong());
commandAction.setActionType("REACTION_PURGE_MESSAGES");
log.info("[Reaction Command] Message purge executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
}
break;
case ID_REACTION_QM_30:
if (reactee.getIdLong() != messageAuthor.getIdLong()) {
if (RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_BOT)) {
if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
quickMuteFromLogs(reactee, message, commandChannel, "30m");
log.info("[Reaction Command] 30m Quick-Mute executed by {} ({}) (message: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
} else if (event.getChannel().getIdLong() != Properties.CHANNEL_MOD_ALERTS_ID) {
if (!isStaffOnStaff(reactee, messageAuthor, commandChannel)) {
muteUser(reactee, messageAuthor, "30m", message, commandChannel);
purgeMessagesInChannel(messageAuthor, channel);
commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
commandAction.setOffendingUserId(messageAuthor.getIdLong());
commandAction.setActionType("REACTION_QM_30");
log.info("[Reaction Command] 30m Quick-Mute executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
deleteModAlert(messageLink, event);
}
} else {
final String rawMessage = message.getContentRaw();
final String channelId = rawMessage.split("/")[5];
final String messageId = rawMessage.split("/")[6];
final String authorId = rawMessage.split("`")[3];
event.getGuild().getTextChannelById(channelId).retrieveMessageById(messageId).queue(alertmessage -> {
event.getGuild().retrieveMemberById(authorId).queue((author) -> {
if (!isStaffOnStaff(reactee, author, commandChannel)) {
muteUser(reactee, author, "30m", alertmessage, commandChannel);
purgeMessagesInChannel(author, event.getGuild().getTextChannelById(channelId));
}
});
}, alertfailure -> {
commandChannel.sendMessage(new StringBuilder().append(reactee.getAsMention()).append(" the message does not exist or action has already been taken.")).queue();
});
if (reactee.getIdLong() != messageAuthor.getIdLong()) {
clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
commandAction.setActionType("REACTION_ALERT_DONE");
log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
}
}
}
break;
case ID_REACTION_QM_60:
if (reactee.getIdLong() != messageAuthor.getIdLong()) {
if (RoleUtils.isAnyRole(reactee, RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_BOT)) {
if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
quickMuteFromLogs(reactee, message, commandChannel, "1h");
log.info("[Reaction Command] 1h Quick-Mute executed by {} ({}) (message: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
} else if (event.getChannel().getIdLong() != Properties.CHANNEL_MOD_ALERTS_ID) {
if (!isStaffOnStaff(reactee, messageAuthor, commandChannel)) {
muteUser(reactee, messageAuthor, "1h", message, commandChannel);
purgeMessagesInChannel(messageAuthor, channel);
commandAction.setOffendingUser(messageAuthor.getUser().getAsTag());
commandAction.setOffendingUserId(messageAuthor.getIdLong());
commandAction.setActionType("REACTION_QM_60");
log.info("[Reaction Command] 1h Quick-Mute executed by {} on {}", reactee.getUser().getAsTag(), messageAuthor.getUser().getAsTag());
deleteModAlert(messageLink, event);
}
} else {
final String rawMessage = message.getContentRaw();
final String channelId = rawMessage.split("/")[5];
final String messageId = rawMessage.split("/")[6];
final String authorId = rawMessage.split("`")[3];
event.getGuild().getTextChannelById(channelId).retrieveMessageById(messageId).queue(alertmessage -> {
event.getGuild().retrieveMemberById(authorId).queue((author) -> {
if (!isStaffOnStaff(reactee, author, commandChannel)) {
muteUser(reactee, author, "60m", alertmessage, commandChannel);
purgeMessagesInChannel(author, event.getGuild().getTextChannelById(channelId));
}
});
}, alertfailure -> {
commandChannel.sendMessage(new StringBuilder().append(reactee.getAsMention()).append(" the message does not exist or action has already been taken.")).queue();
});
if (reactee.getIdLong() != messageAuthor.getIdLong()) {
clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
commandAction.setActionType("REACTION_ALERT_DONE");
log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
}
}
}
break;
case // Used for ban requests, filtered log bans, and mod alerts.
ID_REACTION_APPROVE:
if (RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_SENIOR_MODERATOR)) {
if (event.getChannel().getIdLong() == Properties.CHANNEL_MOD_ALERTS_ID) {
if (reactee.getIdLong() != messageAuthor.getIdLong()) {
clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
commandAction.setActionType("REACTION_ALERT_DONE");
log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
}
if (event.getChannel().getIdLong() == Properties.CHANNEL_BAN_REQUESTS_QUEUE_ID) {
approveBanRequest(reactee, message, commandChannel);
commandAction.setActionType("REACTION_APPROVE_BAN_REQUEST");
log.info("[Reaction Command] Ban request approved by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
} else if (event.getChannel().getIdLong() == Properties.CHANNEL_CENSORED_AND_SPAM_LOGS_ID || event.getChannel().getIdLong() == Properties.CHANNEL_MESSAGE_LOGS_ID) {
approveLogsBan(reactee, message, commandChannel);
commandAction.setActionType("REACTION_APPROVE_BAN_REQUEST");
log.info("[Reaction Command] Logs message ban approved by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
} else if (RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_MODERATOR, RoleUtils.ROLE_TRIAL_MODERATOR)) {
if (event.getChannel().getIdLong() == Properties.CHANNEL_MOD_ALERTS_ID) {
clearAlert(commandChannel, event.getGuild().getTextChannelById(Properties.CHANNEL_MOD_ALERTS_ID), reactee, message, messageAuthor, Instant.now());
commandAction.setActionType("REACTION_ALERT_DONE");
log.info("[Reaction Command] Mod alert marked done by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
}
break;
case ID_REACTION_REJECT:
if (event.getChannel().getIdLong() == Properties.CHANNEL_BAN_REQUESTS_QUEUE_ID && RoleUtils.isAnyRole(event.getMember(), RoleUtils.ROLE_SERVER_MANAGER, RoleUtils.ROLE_SENIOR_MODERATOR)) {
rejectBanRequest(reactee, message, commandChannel);
commandAction.setActionType("REACTION_REJECT_BAN_REQUEST");
log.info("[Reaction Command] Ban request rejected by {} ({}) (request: {})", reactee.getEffectiveName(), reactee.getId(), message.getJumpUrl());
}
break;
default:
// Do nothing.
return;
}
cdsData.insertAction(commandAction);
});
}, (failure) -> {
log.error("An error occurred obtaining a reaction event's message. Details: {}", failure.getMessage());
});
}
use of net.dv8tion.jda.api.entities.MessageReaction in project JDA by DV8FromTheWorld.
the class MessageReactionClearEmoteHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
long guildId = content.getUnsignedLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
Guild guild = getJDA().getGuildById(guildId);
if (guild == null) {
EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown guild {}", guildId);
getJDA().getEventCache().cache(EventCache.Type.GUILD, guildId, responseNumber, allContent, this::handle);
return null;
}
long channelId = content.getUnsignedLong("channel_id");
// TODO-v5-unified-channel-cache
GuildMessageChannel channel = guild.getTextChannelById(channelId);
if (channel == null)
channel = guild.getNewsChannelById(channelId);
if (channel == null)
channel = guild.getThreadChannelById(channelId);
if (channel == null) {
EventCache.LOG.debug("Caching MESSAGE_REACTION_REMOVE_EMOJI event for unknown channel {}", channelId);
getJDA().getEventCache().cache(EventCache.Type.CHANNEL, channelId, responseNumber, allContent, this::handle);
return null;
}
long messageId = content.getUnsignedLong("message_id");
DataObject emoji = content.getObject("emoji");
MessageReaction.ReactionEmote reactionEmote = null;
if (emoji.isNull("id")) {
reactionEmote = MessageReaction.ReactionEmote.fromUnicode(emoji.getString("name"), getJDA());
} else {
long emoteId = emoji.getUnsignedLong("id");
Emote emote = getJDA().getEmoteById(emoteId);
if (emote == null) {
emote = new EmoteImpl(emoteId, getJDA()).setAnimated(emoji.getBoolean("animated")).setName(emoji.getString("name", ""));
}
reactionEmote = MessageReaction.ReactionEmote.fromCustom(emote);
}
MessageReaction reaction = new MessageReaction(channel, reactionEmote, messageId, false, 0);
getJDA().handleEvent(new MessageReactionRemoveEmoteEvent(getJDA(), responseNumber, messageId, channel, reaction));
return null;
}
use of net.dv8tion.jda.api.entities.MessageReaction in project Sx4 by sx4-discord-bot.
the class GiveawayManager method endGiveawayBulk.
public CompletableFuture<UpdateOneModel<Document>> endGiveawayBulk(Document data, boolean forced) {
long guildId = data.getLong("guildId"), messageId = data.get("messageId", 0L);
Guild guild = this.bot.getShardManager().getGuildById(guildId);
if (guild == null) {
return CompletableFuture.completedFuture(null);
}
TextChannel channel = guild.getTextChannelById(data.getLong("channelId"));
if (channel == null) {
return CompletableFuture.completedFuture(null);
}
if (!guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_READ, Permission.MESSAGE_HISTORY, Permission.MESSAGE_EMBED_LINKS)) {
return CompletableFuture.completedFuture(null);
}
CompletableFuture<UpdateOneModel<Document>> future = new CompletableFuture<>();
channel.retrieveMessageById(messageId).queue(message -> {
MessageReaction reaction = message.getReactions().stream().filter(r -> r.getReactionEmote().getName().equals("🎉")).findFirst().orElse(null);
if (reaction == null) {
future.complete(null);
return;
}
List<Long> oldWinners = data.getList("winners", Long.class, Collections.emptyList());
List<Member> members = new ArrayList<>();
reaction.retrieveUsers().forEachAsync(user -> {
Member member = guild.getMember(user);
if (member != null && member.getIdLong() != guild.getSelfMember().getIdLong() && !oldWinners.contains(member.getIdLong())) {
members.add(member);
}
return true;
}).thenRun(() -> {
Bson update;
if (members.size() == 0) {
update = Updates.set("winners", Collections.EMPTY_LIST);
future.complete(new UpdateOneModel<>(Filters.eq("messageId", messageId), forced ? Updates.combine(Updates.set("endAt", Clock.systemUTC().instant().getEpochSecond()), update) : update));
channel.sendMessage("At least " + (oldWinners.isEmpty() ? "1 person needs" : oldWinners.size() == 1 ? "1 extra person needs" : oldWinners.size() + " extra people need") + " to have entered the giveaway to pick a winner " + this.bot.getConfig().getFailureEmote()).queue();
return;
}
Set<Member> winners = MathUtility.randomSample(members, Math.min(data.getInteger("winnersAmount"), members.size()));
List<Long> winnerIds = new ArrayList<>();
List<String> winnerTags = new ArrayList<>(), winnerMentions = new ArrayList<>();
for (Member winner : winners) {
winnerIds.add(winner.getIdLong());
winnerTags.add(winner.getUser().getAsTag());
winnerMentions.add(winner.getAsMention());
}
if (guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)) {
channel.sendMessage(String.join(", ", winnerMentions) + ", Congratulations you have won the giveaway for **" + data.getString("item") + "**").allowedMentions(EnumSet.of(MentionType.USER)).queue();
}
EmbedBuilder embed = new EmbedBuilder();
embed.setTitle("Giveaway");
embed.setDescription("**" + String.join(", ", winnerTags) + "** has won **" + data.getString("item") + "**");
embed.setTimestamp(Instant.now());
embed.setFooter("Giveaway Ended", null);
if (guild.getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE, Permission.MESSAGE_EMBED_LINKS)) {
message.editMessageEmbeds(embed.build()).queue();
}
update = Updates.set("winners", winnerIds);
future.complete(new UpdateOneModel<>(Filters.eq("messageId", messageId), forced ? Updates.combine(Updates.set("endAt", Clock.systemUTC().instant().getEpochSecond()), update) : update));
});
});
this.deleteExecutor(messageId);
return future;
}
use of net.dv8tion.jda.api.entities.MessageReaction in project Minecord by Tisawesomeness.
the class ReactListener method removeEmote.
/**
* Removes an emote, keeping stars for starboard purposes
* @param e The event received from a message reaction
*/
private void removeEmote(MessageReactionAddEvent e) {
if (!e.isFromGuild() || !hasManageMessagePerms(e)) {
return;
}
MessageReaction r = e.getReaction();
if (!isRemovableEmoji(r.getReactionEmote())) {
return;
}
User u = e.getUser();
if (u != null) {
r.removeReaction(u).queue();
}
}
use of net.dv8tion.jda.api.entities.MessageReaction in project LemBot by Leminee.
the class ReactionManager method registerReaction.
/**
* Registriert eine neue ReactionMessage
*
* @param channelId Die Discord Textchannel ID, in welcher die Nachricht sich befindet
* @param messageId Die Discord Message ID, auf die reagiert werden soll
* @param emoji Das Emoji als Codepoints ODER die Emote ID, nach dem gefiltert werden soll
* @param roleId Die Discord Role ID, die vergeben werden soll, wenn man auf die Nachricht reagiert
* @return Diesen ReactionManager für Chain Calls
*/
public ReactionManager registerReaction(String channelId, String messageId, String emoji, String roleId) {
try {
jda.awaitReady();
} catch (InterruptedException e) {
e.printStackTrace();
}
ReactionMessage m = new ReactionMessage(channelId, messageId, emoji, roleId);
Guild g = jda.getTextChannelById(channelId).getGuild();
if (!reactionMessages.stream().anyMatch(m::equals))
reactionMessages.add(m);
jda.getTextChannelById(channelId).retrieveMessageById(messageId).queue(message -> {
Optional<MessageReaction> optional;
if (Helpers.isNumeric(emoji)) {
Emote e = g.getEmoteById(emoji);
message.addReaction(e).queue();
optional = message.getReactions().stream().filter(r -> r.getReactionEmote().isEmote() && r.getReactionEmote().getEmote().getId().equals(emoji)).findFirst();
} else {
jda.getTextChannelById(channelId).addReactionById(messageId, emoji).queue();
optional = message.getReactions().stream().filter(r -> r.getReactionEmote().isEmoji() && r.getReactionEmote().getEmoji().equals(emoji)).findFirst();
}
optional.ifPresent(r -> r.retrieveUsers().queue(l -> l.forEach(u -> g.addRoleToMember(u.getId(), g.getRoleById(roleId)))));
});
return this;
}
Aggregations