use of sx.blah.discord.handle.obj.IReaction in project DiscordSailv2 by Vaerys-Dawn.
the class ArtHandler method unPin.
public static void unPin(CommandObject command) {
IChannel channel = command.guild.getChannelByType(ChannelSetting.ART);
List<Long> pins = command.guild.channelData.getPinnedMessages();
// exit if channel is wrong
if (channel == null || !command.channel.get().equals(channel))
return;
// exit if message isn't pinned
if (!command.message.get().isPinned())
return;
for (long l : pins) {
if (command.message.longID == l && command.message.author.longID == command.user.longID) {
RequestBuffer.request(() -> channel.unpin(command.message.get()));
RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_REMOVE_PIN)));
IReaction reaction = command.message.getReationByName(Constants.EMOJI_ADD_PIN);
for (IUser user : reaction.getUsers()) {
RequestBuffer.request(() -> command.message.get().removeReaction(user, reaction));
}
checkList(command);
return;
}
}
}
use of sx.blah.discord.handle.obj.IReaction in project DiscordSailv2 by Vaerys-Dawn.
the class ArtHandler method pinMessage.
public static void pinMessage(CommandObject command, UserObject reacted, UserObject owner) {
IChannel channelIDS = command.guild.getChannelByType(ChannelSetting.ART);
List<TrackLikes> likes = command.guild.channelData.getLikes();
List<Long> pins = command.guild.channelData.getPinnedMessages();
// exit if not pinning art
if (!command.guild.config.artPinning)
return;
// exit if the art is already pinned
if (command.message.get().isPinned())
return;
// exit if message owner is a bot
if (owner.get().isBot())
return;
// exit if message has already been unpinned.
IReaction reaction = command.message.getReationByName(Constants.EMOJI_REMOVE_PIN);
if (reaction != null && reaction.getUserReacted(command.client.bot.get())) {
RequestBuffer.request(() -> command.message.get().removeReaction(reacted.get(), Utility.getReaction(Constants.EMOJI_ADD_PIN))).get();
return;
}
// exit if user has art pinning denied.
ProfileObject profile = reacted.getProfile(command.guild);
if (profile != null && profile.getSettings().contains(UserSetting.DENY_ART_PINNING))
return;
// exit if there is no art channel
if (channelIDS == null)
return;
// exit if this is not the art channel
if (channelIDS.getLongID() != command.channel.longID)
return;
// exit if there is no art to be found
if (!checkAttachments(command) && !checkMessage(command))
return;
try {
// pin message
RequestBuffer.request(() -> command.channel.get().pin(command.message.get())).get();
// debug builder
String name;
if (checkAttachments(command)) {
name = "ATTACHMENT_PIN";
} else {
name = "MESSAGE_PIN";
}
String args;
args = command.message.getContent();
for (IMessage.Attachment a : command.message.getAttachments()) {
args += " <" + a.getUrl() + ">";
}
if (command.message.getContent() == null || command.message.getContent().isEmpty()) {
args = args.replace(" ", "");
}
command.guild.sendDebugLog(command, "ART_PINNED", name, args);
// end debug
// add to ping
pins.add(command.message.longID);
// add pin response
RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_ADD_PIN)));
if (command.guild.config.likeArt && command.guild.config.modulePixels) {
// add heart
RequestBuffer.request(() -> command.message.get().addReaction(Utility.getReaction(Constants.EMOJI_LIKE_PIN)));
// add to list
likes.add(new TrackLikes(command.message.longID));
}
String response;
if (!command.guild.config.autoArtPinning) {
if (owner.longID == reacted.longID) {
response = "> **" + reacted.displayName + "** Has pinned their";
} else {
response = "> **" + reacted.displayName + "** Has pinned **" + owner.displayName + "'s**";
}
response += " art by reacting with the \uD83D\uDCCC emoji.";
} else {
response = "> I have pinned **" + owner.displayName + "'s** art.";
}
if (command.guild.config.likeArt && command.guild.config.modulePixels) {
response += "\nYou can now react with a \u2764 emoji to give the user some pixels.";
}
IMessage pinResponse = RequestHandler.sendMessage(response, command.channel).get();
Thread thread = new Thread(() -> {
try {
logger.trace("Deleting in 2 minutes.");
Thread.sleep(2 * 60 * 1000);
RequestHandler.deleteMessage(pinResponse);
} catch (InterruptedException e) {
// do nothing
}
});
checkList(command);
thread.start();
return;
} catch (DiscordException e) {
if (e.getErrorMessage().contains("already pinned")) {
return;
} else {
Utility.sendStack(e);
}
}
}
Aggregations