Search in sources :

Example 1 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class PixelHandler method totalRanked.

public static long totalRanked(CommandObject command) {
    long totalRanked = 0;
    for (ProfileObject u : command.guild.users.getProfiles()) {
        boolean hideRank;
        UserObject object = new UserObject(command.guild.getUserByID(u.getUserID()), command.guild);
        hideRank = !object.showRank(command.guild);
        if (command.guild.getUserByID(u.getUserID()) != null) {
            if (u.getXP() != 0 && !hideRank) {
                totalRanked++;
            }
        }
    }
    return totalRanked;
}
Also used : UserObject(com.github.vaerys.masterobjects.UserObject) ProfileObject(com.github.vaerys.objects.ProfileObject)

Example 2 with UserObject

use of com.github.vaerys.masterobjects.UserObject 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;
            }
        }
    }
}
Also used : QueueObject(com.github.vaerys.objects.QueueObject) DayOfWeek(java.time.DayOfWeek) UserObject(com.github.vaerys.masterobjects.UserObject) DailyMessage(com.github.vaerys.objects.DailyMessage) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji)

Example 3 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class AnnotationListener method onUserJoinEvent.

@EventSubscriber
public void onUserJoinEvent(UserJoinEvent event) {
    GuildObject content = Globals.getGuildContent(event.getGuild().getLongID());
    UserObject user = new UserObject(event.getUser().getLongID(), content);
    if (content.config.welcomeMessages && !user.get().isBot()) {
        JoinHandler.sendWelcomeMessage(content, event, user);
    }
    if (content.config.checkNewUsers) {
        JoinHandler.checkNewUsers(content, event, user);
    }
    if (content.config.moduleJoinMessages && content.config.sendJoinMessages) {
        JoinHandler.customJoinMessages(content, event.getUser());
    }
    JoinHandler.autoReMute(event, content, user);
    if (!content.config.moduleLogging)
        return;
    LoggingHandler.doJoinLeaveLog(event, true);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) UserObject(com.github.vaerys.masterobjects.UserObject) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 4 with UserObject

use of com.github.vaerys.masterobjects.UserObject 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);
        }
    }
}
Also used : CommandObject(com.github.vaerys.commands.CommandObject) IMessage(sx.blah.discord.handle.obj.IMessage) UserObject(com.github.vaerys.masterobjects.UserObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Example 5 with UserObject

use of com.github.vaerys.masterobjects.UserObject in project DiscordSailv2 by Vaerys-Dawn.

the class Utility method getUser.

public static UserObject getUser(CommandObject command, String args, boolean doContains, boolean hasProfile) {
    if (args != null && !args.isEmpty()) {
        IUser user = null;
        IUser conUser = null;
        String toTest;
        if (args.split(" ").length != 1) {
            toTest = escapeRegex(args);
        } else {
            toTest = escapeRegex(args).replace("_", "[_| ]");
        }
        List<IUser> guildUsers = command.guild.getUsers();
        guildUsers.sort(Comparator.comparing(o -> o.getRolesForGuild(command.guild.get()).size()));
        Collections.reverse(guildUsers);
        for (IUser u : guildUsers) {
            if (user != null) {
                break;
            }
            try {
                UserObject object = new UserObject(u, command.guild, true);
                if (hasProfile) {
                    ProfileObject profile = object.getProfile(command.guild);
                    if (profile == null || profile.isEmpty())
                        continue;
                }
                if ((u.getName() + "#" + u.getDiscriminator()).matches("(?i)" + toTest)) {
                    user = u;
                }
                if (u.getName().matches("(?i)" + toTest) && user == null) {
                    user = u;
                }
                String displayName = u.getDisplayName(command.guild.get());
                if (displayName.matches("(?i)" + toTest) && user == null) {
                    user = u;
                }
                if (doContains && conUser == null) {
                    if (u.getName().matches("(?i).*" + toTest + ".*")) {
                        conUser = u;
                    }
                    if (displayName.matches("(?i).*" + toTest + ".*") && conUser == null) {
                        conUser = u;
                    }
                }
            } catch (PatternSyntaxException e) {
            // continue.
            }
        }
        UserObject userObject = null;
        try {
            long uID = Long.parseLong(args);
            return new UserObject(uID, command.guild);
        } catch (NumberFormatException e) {
            if (command.message.get().getMentions().size() > 0) {
                user = command.message.get().getMentions().get(0);
            }
        }
        if (user == null && doContains) {
            user = conUser;
        }
        if (user != null) {
            userObject = new UserObject(user, command.guild);
        }
        return userObject;
    }
    return null;
}
Also used : com.github.vaerys.objects(com.github.vaerys.objects) java.util(java.util) RequestHandler(com.github.vaerys.handlers.RequestHandler) GuildObject(com.github.vaerys.masterobjects.GuildObject) ReactionEmoji(sx.blah.discord.handle.impl.obj.ReactionEmoji) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) SAILType(com.github.vaerys.enums.SAILType) GuildHandler(com.github.vaerys.handlers.GuildHandler) StringUtils(org.apache.commons.lang3.StringUtils) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandObject(com.github.vaerys.commands.CommandObject) Logger(org.slf4j.Logger) PatternSyntaxException(java.util.regex.PatternSyntaxException) MalformedURLException(java.net.MalformedURLException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) EmojiManager(com.vdurmont.emoji.EmojiManager) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) Stream(java.util.stream.Stream) StringHandler(com.github.vaerys.handlers.StringHandler) UserObject(com.github.vaerys.masterobjects.UserObject) Command(com.github.vaerys.templates.Command) Emoji(com.vdurmont.emoji.Emoji) Pattern(java.util.regex.Pattern) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) UserObject(com.github.vaerys.masterobjects.UserObject) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

UserObject (com.github.vaerys.masterobjects.UserObject)28 ProfileObject (com.github.vaerys.objects.ProfileObject)13 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)10 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)8 IRole (sx.blah.discord.handle.obj.IRole)5 CommandObject (com.github.vaerys.commands.CommandObject)4 ChannelSetting (com.github.vaerys.enums.ChannelSetting)4 SAILType (com.github.vaerys.enums.SAILType)4 ArrayList (java.util.ArrayList)4 UserSetting (com.github.vaerys.enums.UserSetting)3 RequestHandler (com.github.vaerys.handlers.RequestHandler)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 GuildObject (com.github.vaerys.masterobjects.GuildObject)3 Command (com.github.vaerys.templates.Command)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ReactionEmoji (sx.blah.discord.handle.impl.obj.ReactionEmoji)3 IChannel (sx.blah.discord.handle.obj.IChannel)3 IMessage (sx.blah.discord.handle.obj.IMessage)3 GuildHandler (com.github.vaerys.handlers.GuildHandler)2