Search in sources :

Example 1 with PlayerCache

use of stream.flarebot.flarebot.objects.PlayerCache in project FlareBot by FlareBot.

the class UserInfoCommand method onCommand.

@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
    User user;
    if (args.length == 0)
        user = sender;
    else {
        if (getPermissions(channel).hasPermission(member, Permission.USERINFO_OTHER))
            user = GuildUtils.getUser(MessageUtils.getMessage(args, 0), true);
        else {
            MessageUtils.sendErrorMessage("You need the " + Permission.USERINFO_OTHER + " permission to userinfo other users!", channel);
            return;
        }
    }
    if (user == null) {
        MessageUtils.sendErrorMessage("We cannot find that user!", channel);
        return;
    }
    String id = user.getId();
    Member targetMember = null;
    if (channel.getGuild().getMember(user) != null)
        targetMember = channel.getGuild().getMember(user);
    PlayerCache cache = flareBot.getPlayerCache(id);
    channel.sendMessage(MessageUtils.getEmbed(sender).addField("User Info", "User: " + user.getName() + "#" + user.getDiscriminator() + "\nID: " + user.getId() + "\n" + "Avatar: " + (user.getEffectiveAvatarUrl() != null ? "[`link`](" + user.getEffectiveAvatarUrl() + ')' : "None") + "\n" + "Default Avatar: [`link`](" + MessageUtils.getDefaultAvatar(sender) + ')', true).addField("General Info", "Servers: " + Getters.getGuildCache().stream().filter(g -> g.getMemberById(id) != null).count() + " shared\n" + "Roles: " + (targetMember == null ? "The user is not in this server." : targetMember.getRoles().stream().map(Role::getName).collect(Collectors.joining(", "))) + (targetMember != null && targetMember.getGame() != null ? "\nStatus" + (targetMember.getUser().isBot() ? " (Current Shard)" : "") + ": " + (targetMember.getGame().getUrl() == null ? "`" + targetMember.getGame().getName() + "`" : String.format("[`%s`](%s)", targetMember.getGame().getName(), targetMember.getGame().getUrl())) : ""), true).addField("Time Data", "Created: " + FormatUtils.formatTime(LocalDateTime.from(user.getCreationTime())) + "\n" + "Joined: " + (targetMember == null ? "The user is not in this server." : FormatUtils.formatTime(LocalDateTime.from(channel.getGuild().getMember(user).getJoinDate()))) + "\n" + "Last Seen: " + (cache.getLastSeen() == null ? "Unknown" : FormatUtils.formatTime(cache.getLastSeen())) + "\n" + "Last Spoke: " + (cache.getLastMessage() == null ? "Unknown" : FormatUtils.formatTime(cache.getLastMessage())), false).setThumbnail(MessageUtils.getAvatar(user)).build()).queue();
}
Also used : PlayerCache(stream.flarebot.flarebot.objects.PlayerCache)

Example 2 with PlayerCache

use of stream.flarebot.flarebot.objects.PlayerCache in project FlareBot by FlareBot.

the class Events method onGuildMessageReceived.

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
    PlayerCache cache = flareBot.getPlayerCache(event.getAuthor().getId());
    cache.setLastMessage(LocalDateTime.from(event.getMessage().getCreationTime()));
    cache.setLastSeen(LocalDateTime.now());
    cache.setLastSpokeGuild(event.getGuild().getId());
    if (event.getAuthor().isBot())
        return;
    String message = multiSpace.matcher(event.getMessage().getContentRaw()).replaceAll(" ");
    if (message.startsWith("" + FlareBotManager.instance().getGuild(getGuildId(event)).getPrefix())) {
        List<Permission> perms = event.getChannel().getGuild().getSelfMember().getPermissions(event.getChannel());
        if (!perms.contains(Permission.ADMINISTRATOR)) {
            if (!perms.contains(Permission.MESSAGE_WRITE)) {
                return;
            }
            if (!perms.contains(Permission.MESSAGE_EMBED_LINKS)) {
                event.getChannel().sendMessage("Hey! I can't be used here." + "\nI do not have the `Embed Links` permission! Please go to your permissions and give me Embed Links." + "\nThanks :D").queue();
                return;
            }
        }
        String command = message.substring(1);
        String[] args = new String[0];
        if (message.contains(" ")) {
            command = command.substring(0, message.indexOf(" ") - 1);
            args = message.substring(message.indexOf(" ") + 1).split(" ");
        }
        Command cmd = FlareBot.getCommandManager().getCommand(command, event.getAuthor());
        if (cmd != null)
            handleCommand(event, cmd, args);
    } else {
        if (FlareBotManager.instance().getGuild(getGuildId(event)).getPrefix() != Constants.COMMAND_CHAR && (message.startsWith("_prefix")) || message.startsWith(event.getGuild().getSelfMember().getAsMention())) {
            event.getChannel().sendMessage(MessageUtils.getEmbed(event.getAuthor()).setDescription("The server prefix is `" + FlareBotManager.instance().getGuild(getGuildId(event)).getPrefix() + "`").build()).queue();
        }
        if (!message.isEmpty()) {
            RedisController.set(event.getMessageId(), GeneralUtils.getRedisMessageJson(event.getMessage()), "nx", "ex", 86400);
        }
        // Random fun stuff
        if (event.getGuild().getIdLong() == Constants.OFFICIAL_GUILD) {
            if (rip.matcher(message).find()) {
                // F
                event.getMessage().addReaction("\uD83C\uDDEB").queue();
            } else if (message.toLowerCase().startsWith("i cri")) {
                // Cry
                event.getMessage().addReaction("\uD83D\uDE22").queue();
            } else if ((message.toLowerCase().contains("bellend") || message.toLowerCase().contains("bollocks")) && RandomUtils.getInt(0, 20) == 20) {
                // GB flag
                event.getMessage().addReaction("\uD83C\uDDEC\uD83C\uDDE7").queue();
                // #
                event.getMessage().addReaction("\u0023\u20E3").queue();
                // 1
                event.getMessage().addReaction("\u0031\u20E3").queue();
                Constants.logEG("UK#1", null, event.getGuild(), event.getAuthor());
            } else if (message.toLowerCase().equalsIgnoreCase("fuck") && RandomUtils.getInt(0, 100) == 100) {
                GeneralUtils.sendImage("https://flarebot.stream/img/pissed-off-thats-why.gif", "pissed-off-thats-why.gif", event.getAuthor());
                Constants.logEG("Pissed Off", null, event.getGuild(), event.getAuthor());
            }
        }
    }
}
Also used : SkipCommand(stream.flarebot.flarebot.commands.music.SkipCommand) UpdateCommand(stream.flarebot.flarebot.commands.secret.update.UpdateCommand) Permission(net.dv8tion.jda.core.Permission) PlayerCache(stream.flarebot.flarebot.objects.PlayerCache)

Example 3 with PlayerCache

use of stream.flarebot.flarebot.objects.PlayerCache in project FlareBot by FlareBot.

the class Events method onGuildMemberJoin.

@Override
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    if (event.getMember().getUser().isBot() || event.getMember().getUser().isFake())
        return;
    PlayerCache cache = flareBot.getPlayerCache(event.getMember().getUser().getId());
    cache.setLastSeen(LocalDateTime.now());
    GuildWrapper wrapper = FlareBotManager.instance().getGuild(event.getGuild().getId());
    if (wrapper == null)
        return;
    if (wrapper.isBlocked())
        return;
    if (flareBot.getManager().getGuild(event.getGuild().getId()).getWelcome() != null) {
        Welcome welcome = wrapper.getWelcome();
        if ((welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null) || welcome.isDmEnabled()) {
            if (welcome.getChannelId() != null && Getters.getChannelById(welcome.getChannelId()) != null && welcome.isGuildEnabled()) {
                TextChannel channel = Getters.getChannelById(welcome.getChannelId());
                if (channel == null || !channel.canTalk()) {
                    welcome.setGuildEnabled(false);
                    MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Cannot send welcome messages in " + (channel == null ? welcome.getChannelId() : channel.getAsMention()) + " due to this, welcomes have been disabled!");
                    return;
                }
                if (welcome.isGuildEnabled()) {
                    String guildMsg = VariableUtils.parseVariables(welcome.getRandomGuildMessage(), wrapper, null, event.getUser());
                    // Deprecated values
                    guildMsg = guildMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
                    channel.sendMessage(guildMsg).queue();
                    if (guildMsg.contains("%user%") || guildMsg.contains("%guild%") || guildMsg.contains("%mention%")) {
                        MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your guild welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
                    }
                }
            }
            if (welcome.isDmEnabled()) {
                // We can't DM other bots.
                if (event.getMember().getUser().isBot())
                    return;
                String dmMsg = VariableUtils.parseVariables(welcome.getRandomDmMessage(), wrapper, null, event.getUser());
                // Deprecated values
                dmMsg = dmMsg.replace("%user%", event.getMember().getUser().getName()).replace("%guild%", event.getGuild().getName()).replace("%mention%", event.getMember().getUser().getAsMention());
                MessageUtils.sendPM(event.getMember().getUser(), dmMsg);
                if (dmMsg.contains("%user%") || dmMsg.contains("%guild%") || dmMsg.contains("%mention%")) {
                    MessageUtils.sendPM(event.getGuild().getOwner().getUser(), "Your DM welcome message contains deprecated variables! " + "Please check the docs at the link below for a list of all the " + "variables you can use!\n" + "https://docs.flarebot.stream/variables");
                }
            }
        } else
            welcome.setGuildEnabled(false);
    }
    if (event.getMember().getUser().isBot())
        return;
    if (!wrapper.getAutoAssignRoles().isEmpty()) {
        Set<String> autoAssignRoles = wrapper.getAutoAssignRoles();
        List<Role> roles = new ArrayList<>();
        for (String s : autoAssignRoles) {
            Role role = event.getGuild().getRoleById(s);
            if (role != null) {
                roles.add(role);
            } else
                autoAssignRoles.remove(s);
        }
        try {
            event.getGuild().getController().addRolesToMember(event.getMember(), roles).queue((n) -> {
            }, e1 -> handle(e1, event, roles));
            StringBuilder sb = new StringBuilder("```\n");
            for (Role role : roles) {
                sb.append(role.getName()).append(" (").append(role.getId()).append(")\n");
            }
            sb.append("```");
            ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.FLAREBOT_AUTOASSIGN_ROLE, event.getUser(), new MessageEmbed.Field("Roles", sb.toString(), false));
        } catch (Exception e1) {
            handle(e1, event, roles);
        }
    }
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) ArrayList(java.util.ArrayList) PlayerCache(stream.flarebot.flarebot.objects.PlayerCache) InsufficientPermissionException(net.dv8tion.jda.core.exceptions.InsufficientPermissionException) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) Role(net.dv8tion.jda.core.entities.Role) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Welcome(stream.flarebot.flarebot.objects.Welcome)

Aggregations

PlayerCache (stream.flarebot.flarebot.objects.PlayerCache)3 ArrayList (java.util.ArrayList)1 Permission (net.dv8tion.jda.core.Permission)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 Role (net.dv8tion.jda.core.entities.Role)1 TextChannel (net.dv8tion.jda.core.entities.TextChannel)1 InsufficientPermissionException (net.dv8tion.jda.core.exceptions.InsufficientPermissionException)1 SkipCommand (stream.flarebot.flarebot.commands.music.SkipCommand)1 UpdateCommand (stream.flarebot.flarebot.commands.secret.update.UpdateCommand)1 GuildWrapper (stream.flarebot.flarebot.objects.GuildWrapper)1 Welcome (stream.flarebot.flarebot.objects.Welcome)1