use of sx.blah.discord.handle.impl.obj.ReactionEmoji in project DiscordSailv2 by Vaerys-Dawn.
the class PixelHandler method handleReactions.
/**
* Handler for attaching reactions to the message that leveled the user up.
*
* @param user the user that leveled up
* @param object the container for all relevant API content.
*/
private static void handleReactions(ProfileObject user, CommandObject object) {
if (user.getSettings().contains(UserSetting.NO_LEVEL_UP_REACTIONS))
return;
if (object.guild.config.levelUpReaction.equalsIgnoreCase("null"))
return;
ReactionEmoji emoji;
// get Emoji
try {
long emojiID = Long.parseUnsignedLong(object.guild.config.levelUpReaction);
emoji = ReactionEmoji.of(object.client.getEmojiByID(emojiID));
} catch (NumberFormatException e) {
emoji = ReactionEmoji.of(object.guild.config.levelUpReaction);
}
// send error if the reaction failed
if (emoji == null) {
IChannel adminChannel = object.guild.getChannelByType(ChannelSetting.ADMIN);
if (adminChannel == null)
adminChannel = object.channel.get();
RequestHandler.sendMessage("> The current emoji set to be used for level up reactions is invalid and needs to be updated.", adminChannel);
return;
}
// add the reaction
RequestHandler.addReaction(object.message, emoji);
}
use of sx.blah.discord.handle.impl.obj.ReactionEmoji in project DiscordSailv2 by Vaerys-Dawn.
the class QueueHandler method reactionAdded.
public static void reactionAdded(CommandObject object, IReaction reaction) {
ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
ReactionEmoji ok = Utility.getReaction("white_check_mark");
ReactionEmoji no = Utility.getReaction(Constants.EMOJI_REMOVE_PIN);
ArrayList<QueueObject> queuedMessages = Globals.getDailyMessages().getQueue();
IMessage message = object.message.get();
IUser owner = object.client.creator.get();
// exit if not the queue channel
if (object.channel.longID != Globals.queueChannelID) {
return;
}
// exit if not the owner.
if (reaction.getCount() == 0) {
return;
}
if (!reaction.getUserReacted(owner)) {
return;
}
// exit if no embeds
if (message.getEmbeds().size() == 0) {
return;
}
// exit if not enough reactions
if (message.getReactions().size() <= 1) {
return;
}
checkQueue();
for (QueueObject q : queuedMessages) {
if (q.getMessageId() == message.getLongID()) {
// getToggles the embed
IEmbed embed = message.getEmbeds().get(0);
RequestBuffer.request(() -> message.removeAllReactions()).get();
switch(q.getType()) {
// do if daily request
case Constants.QUEUE_DAILY:
try {
// getToggles the data
long userID = Long.parseLong(embed.getFooter().getText());
long uID = -1;
DayOfWeek day = null;
for (IEmbed.IEmbedField f : embed.getEmbedFields()) {
if (f.getName().equalsIgnoreCase(dowString)) {
day = DayOfWeek.valueOf(f.getValue());
} else if (f.getName().equalsIgnoreCase(uIDString)) {
uID = Long.parseLong(f.getValue());
}
}
UserObject user = new UserObject(object.client.getUserByID(userID), null);
// do if accepted
if (reaction.getEmoji().equals(thumbsUp)) {
user.sendDm("> A daily message you sent was approved. **[" + uID + "]**");
Globals.getDailyMessages().getMessages().add(new DailyMessage(embed.getDescription(), day, userID, uID));
RequestBuffer.request(() -> message.addReaction(ok)).get();
q.toggleMarkedForRemoval();
return;
// do if denied
} else if (reaction.getEmoji().equals(thumbsDown)) {
user.sendDm("> A daily message you sent was denied. **[" + uID + "]**");
q.toggleMarkedForRemoval();
RequestBuffer.request(() -> message.addReaction(no)).get();
return;
} else {
return;
}
} catch (NumberFormatException e) {
q.toggleMarkedForRemoval();
} catch (IllegalArgumentException e) {
q.toggleMarkedForRemoval();
}
default:
return;
}
}
}
}
use of sx.blah.discord.handle.impl.obj.ReactionEmoji in project DiscordSailv2 by Vaerys-Dawn.
the class AnnotationListener method onReactionAddEvent.
@EventSubscriber
public void onReactionAddEvent(ReactionAddEvent event) {
if (event.getUser().isBot()) {
return;
}
ReactionEmoji x = Utility.getReaction("x");
ReactionEmoji pin = Utility.getReaction(Constants.EMOJI_ADD_PIN);
ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
ReactionEmoji heart = Utility.getReaction(Constants.EMOJI_LIKE_PIN);
ReactionEmoji remove = Utility.getReaction(Constants.EMOJI_REMOVE_PIN);
ReactionEmoji emoji = event.getReaction().getEmoji();
if (emoji == null)
return;
IMessage message = event.getMessage();
if (message == null)
message = event.getChannel().getMessageByID(event.getMessageID());
CommandObject object = new CommandObject(message);
UserObject pinner = new UserObject(event.getUser(), object.guild);
UserObject owner = new UserObject(event.getAuthor(), object.guild);
// do only on server channels
if (!event.getChannel().isPrivate() && emoji.isUnicode()) {
// if is x and can bypass
if (emoji.equals(remove))
ArtHandler.unPin(object);
if (emoji.equals(x) && GuildHandler.testForPerms(object, Permissions.MANAGE_MESSAGES) && object.client.bot.longID == object.user.longID)
RequestHandler.deleteMessage(object.message);
// if is pushpin
if (emoji.equals(pin))
ArtHandler.pinMessage(object, pinner, owner);
// if is thumbsup or thumbs down and is creator.
if (emoji.equals(thumbsUp) || emoji.equals(thumbsDown))
QueueHandler.reactionAdded(object, event.getReaction());
// if is hear and is pinned then give xp
if (emoji.equals(heart))
ArtHandler.pinLiked(object, pinner, owner);
// do only within Direct messages
} else if (event.getChannel().isPrivate() && emoji.isUnicode()) {
// if anyone uses x
if (emoji.equals(x) && object.client.bot.longID == object.user.longID) {
RequestHandler.deleteMessage(message);
}
}
}
use of sx.blah.discord.handle.impl.obj.ReactionEmoji in project DiscordSailv2 by Vaerys-Dawn.
the class QueueHandler method addToQueue.
public static void addToQueue(CommandObject object, String content, DayOfWeek dayOfWeek, String type) {
ReactionEmoji thumbsUp = Utility.getReaction(Constants.EMOJI_APPROVE);
ReactionEmoji thumbsDown = Utility.getReaction(Constants.EMOJI_DISAPPROVE);
IChannel channel = object.client.get().getChannelByID(Globals.queueChannelID);
if (channel != null) {
switch(type) {
case Constants.QUEUE_DAILY:
long uID = Globals.getDailyMessages().newDailyMsgUID();
if (uID == -1) {
object.client.creator.sendDm("> Max limit of Daily messages hit.");
break;
}
XEmbedBuilder embedBuilder = new XEmbedBuilder(object);
embedBuilder.withAuthorName("New Daily Message - " + object.guild.get().getName());
embedBuilder.withFooterText(object.user.longID + "");
embedBuilder.withTitle(object.user.username);
embedBuilder.withDesc(content);
embedBuilder.appendField(dowString, dayOfWeek + "", true);
embedBuilder.appendField(uIDString, uID + "", true);
IMessage message = RequestHandler.sendEmbedMessage("", embedBuilder, channel).get();
RequestBuffer.request(() -> message.addReaction(thumbsUp)).get();
RequestBuffer.request(() -> message.addReaction(thumbsDown)).get();
Globals.getDailyMessages().getQueue().add(new QueueObject(message.getLongID(), uID, type));
checkQueue();
return;
default:
return;
}
}
}
Aggregations