net.dv8tion.jda.api.entities.User Java Examples

The following examples show how to use net.dv8tion.jda.api.entities.User. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LeaderboardCmd.java    From MantaroBot with GNU General Public License v3.0 6 votes vote down vote up
private EmbedBuilder generateLeaderboardEmbed(Context ctx, String description, String leaderboardKey, List<Map<String, Object>> lb, Function<Map<?, ?>, Pair<User, String>> mapFunction, String format, boolean isSeasonal) {
    I18nContext languageContext = ctx.getLanguageContext();
    return new EmbedBuilder()
            .setAuthor(isSeasonal ?
                    String.format(languageContext.get("commands.leaderboard.header_seasonal"),
                    config.getCurrentSeason().getDisplay()) : languageContext.get("commands.leaderboard.header"), null, ctx.getSelfUser().getEffectiveAvatarUrl()
            ).setDescription(description)
            .addField(languageContext.get(leaderboardKey), lb.stream()
                    .map(mapFunction)
                    .filter(p -> Objects.nonNull(p.getKey()))
                    .map(p -> {
                        //This is... an interesting place to do it lol
                        if(p.getKey().getIdLong() == ctx.getAuthor().getIdLong()) {
                            var player = MantaroData.db().getPlayer(ctx.getAuthor());
                            if(player.getData().addBadgeIfAbsent(Badge.CHAMPION))
                                player.saveAsync();
                        }

                        return String.format(
                                format, EmoteReference.BLUE_SMALL_MARKER, p.getKey().getName(), p.getKey().getDiscriminator(),
                                StringUtils.isNumeric(p.getValue()) ? Long.parseLong(p.getValue()) : p.getValue()
                        );
                    }).collect(Collectors.joining("\n")), false)
            .setFooter(String.format(languageContext.get("general.requested_by"), ctx.getAuthor().getName()), null)
            .setThumbnail(ctx.getAuthor().getEffectiveAvatarUrl());
}
 
Example #2
Source File: ReactionPaginationActionImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleSuccess(Response response, Request<List<User>> request)
{
    final EntityBuilder builder = api.getEntityBuilder();
    final DataArray array = response.getArray();
    final List<User> users = new LinkedList<>();
    for (int i = 0; i < array.length(); i++)
    {
        try
        {
            final User user = builder.createFakeUser(array.getObject(i));
            users.add(user);
            if (useCache)
                cached.add(user);
            last = user;
            lastKey = last.getIdLong();
        }
        catch (ParsingException | NullPointerException e)
        {
            LOG.warn("Encountered exception in ReactionPagination", e);
        }
    }

    request.onSuccess(users);
}
 
Example #3
Source File: ChoosingHandler.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onStart(User user, MafiaInstance instance) {
    instance.tick();
    String delayText = getEndTimeText(instance, CHOOSING_DELAY);
    EmbedBuilder builder = getBaseEmbed("mafia.start.message");

    GuildConfig config = configService.get(instance.getGuild());
    String nextCommand = messageService.getMessageByLocale("discord.command.mafia.done.key", config.getCommandLocale());

    builder.setFooter(messageService.getMessage("mafia.start.message.footer", delayText, instance.getPrefix(), nextCommand), null);

    TextChannel channel = instance.getChannel();
    if (channel == null) {
        return true; // end for non existent channel instantly
    }

    channel.sendMessage(builder.build()).queue(message -> {
        message.addReaction(CHOOSE).queue();
        instance.getListenedMessages().add(message.getId());
        reactionsListener.onReaction(message.getId(), (event, add) -> {
            if (!instance.isInState(MafiaState.CHOOSING)) {
                return true;
            }
            String emote = event.getReaction().getReactionEmote().getName();
            if (!event.getUser().equals(event.getJDA().getSelfUser()) && !event.getUser().isBot() && CHOOSE.equals(emote)) {
                instance.tick();
                if (add && instance.getPlayers().size() < 10) {
                    instance.getPlayers().add(new MafiaPlayer(event.getMember()));
                }
                if (!add) {
                    instance.getPlayers().removeIf(e -> event.getMember().getUser().getIdLong() == e.getMemberId());
                }
            }
            return false;
        });
    });
    return scheduleEnd(instance, CHOOSING_DELAY);
}
 
Example #4
Source File: InvestigateCmd.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
private static void investigateUser(GuildMessageReceivedEvent event, User user, boolean file) {
    if (user == null) {
        event.getChannel().sendMessage("Unknown user").queue();
        return;
    }
    EmbedBuilder eb = new EmbedBuilder()
            .setTitle("Please pick a guild")
            .setColor(Color.PINK);
    DiscordUtils.selectList(event, user.getMutualGuilds(), Guild::toString, s -> eb.setDescription(s).build(), g -> investigateGuild(event, g, file));
}
 
Example #5
Source File: ModLog.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static void log(Member author, User target, String reason, String channel, ModAction action, long caseNumber, int messagesDeleted) {
    DBGuild guildDB = db.getGuild(author.getGuild());
    Player player = db.getPlayer(author);
    PlayerData playerData = player.getData();
    EmbedBuilder embedBuilder = new EmbedBuilder();

    embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);

    if (target != null) {
        embedBuilder.addField("Member", target.getName(), true);
        embedBuilder.setThumbnail(target.getEffectiveAvatarUrl());
    } else {
        embedBuilder.setThumbnail(author.getUser().getEffectiveAvatarUrl());
    }

    embedBuilder.addField("Reason", reason, false);
    embedBuilder.addField("Channel", channel, true);

    if (action == ModAction.PRUNE) {
        embedBuilder.addField("Messages Deleted", String.valueOf(messagesDeleted), true);
    }

    //Why was this a giant switch statement?
    embedBuilder.setAuthor(String.format("%s | Case #%s", Utils.capitalize(action.name()), caseNumber),
            null, author.getUser().getEffectiveAvatarUrl());

    if (!playerData.hasBadge(Badge.POWER_USER)) {
        playerData.addBadgeIfAbsent(Badge.POWER_USER);
        player.saveAsync();
    }

    if (guildDB.getData().getGuildLogChannel() != null) {
        TextChannel logChannel = MantaroBot.getInstance().getShardManager().getTextChannelById(guildDB.getData().getGuildLogChannel());
        if (logChannel != null) {
            logChannel.sendMessage(embedBuilder.build()).queue();
        }
    }
}
 
Example #6
Source File: MafiaInstance.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
public boolean done(User user) {
    if (scheduledStep != null) {
        if (scheduledStep.isDone() || scheduledStep.isCancelled()) {
            return false;
        } else {
            scheduledStep.cancel(false);
            scheduledStep = null;
        }
    }
    return handler == null || handler.onEnd(user, this);
}
 
Example #7
Source File: GenericPrivateMessageReactionEvent.java    From JDA with Apache License 2.0 5 votes vote down vote up
public GenericPrivateMessageReactionEvent(@Nonnull JDA api, long responseNumber, @Nullable User user, @Nonnull MessageReaction reaction, long userId)
{
    super(api, responseNumber, reaction.getMessageIdLong(), (PrivateChannel) reaction.getChannel());
    this.userId = userId;
    this.issuer = user;
    this.reaction = reaction;
}
 
Example #8
Source File: AudioWebSocket.java    From JDA with Apache License 2.0 5 votes vote down vote up
private User getUser(final long userId)
{
    JDAImpl api = getJDA();
    User user = api.getUserById(userId);
    if (user != null)
        return user;
    return api.getFakeUserMap().get(userId);
}
 
Example #9
Source File: ImageCmd.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void call(Context ctx, String content) {
    String random;
    String id = "";
    if (images.size() == 1) {
        if (type != null) {
            Pair<String, String> result = weebapi.getRandomImageByType(type, false, null);
            images = Collections.singletonList(result.getKey());
            id = result.getValue();
        }

        random = images.get(0); //Guaranteed random selection :^).
    } else {
        random = images.get(rand.nextInt(images.size()));
    }

    String extension = random.substring(random.lastIndexOf("."));
    MessageBuilder builder = new MessageBuilder();
    builder.append(EmoteReference.TALKING);

    if (!noMentions) {
        List<User> users = ctx.getMentionedUsers();
        var names = users.stream().distinct().map(user -> {
            var member = ctx.getGuild().getMember(user);
            if (member == null) {
                return "unknown";
            }

            return member.getEffectiveName();
        }).collect(Collectors.joining(", "));
        if (!names.isEmpty())
            builder.append("**").append(names).append("**, ");
    }

    builder.append(ctx.getLanguageContext().get(toSend));
    ctx.getChannel().sendMessage(builder.build()).addFile(CACHE.getInput(random), imageName + "-" + id + "." + extension).queue();
}
 
Example #10
Source File: DayHandler.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEnd(User user, MafiaInstance instance) {
    MafiaPlayer toExile = getChoiceResult(instance);
    if (toExile != null) {
        instance.getDailyActions().put(MafiaActionType.EXILE, toExile);
    }
    unpinMessage(instance);
    return goonHandler.onStart(user, instance);
}
 
Example #11
Source File: CommandUtils.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
private static boolean isPatron(@Nonnull User u, @Nullable TextChannel tc) {
    // Developers have access to paton features
    if (isDev(u) || patrons.contains(u.getIdLong())) {
        return true;
    }

    //noinspection ConstantConditions
    final Guild supportGuild = u.getJDA().getShardManager().getGuildById(Settings.SUPPORT_GUILD_ID);

    // If the guild is not in cache (cuz discord) ignore the rest of the checks
    if (supportGuild == null) {
        return false;
    }

    final Member m = supportGuild.getMember(u);

    // If the member is not in our guild we tell them to join it
    if (m == null) {
        sendEmbed(tc, EmbedUtils.embedMessage("This command is a patron only command and is locked for you because you " +
            "are not one of our patrons.\n" +
            "For only $1 per month you can have access to this and many other commands [click here link to get started](https://www.patreon.com/DuncteBot).\n" +
            "You will also need to join our discord server [here](https://dunctebot.link/server)"));
        return false;
    }

    // If the member is not a patron tell them to become one
    if (!m.getRoles().contains(supportGuild.getRoleById(Settings.PATRONS_ROLE))) {
        sendEmbed(tc, EmbedUtils.embedMessage("This command is a patron only command and is locked for you because you " +
            "are not one of our patrons.\n" +
            "For only $1 per month you can have access to this and many other commands [click here link to get started](https://www.patreon.com/DuncteBot)."));
        return false;
    }

    patrons.add(u.getIdLong());

    return true;
}
 
Example #12
Source File: GenericMessageReactionEvent.java    From JDA with Apache License 2.0 5 votes vote down vote up
public GenericMessageReactionEvent(@Nonnull JDA api, long responseNumber, @Nonnull User user,
                                   @Nullable Member member, @Nonnull MessageReaction reaction, long userId)
{
    super(api, responseNumber, reaction.getMessageIdLong(), reaction.getChannel());
    this.userId = userId;
    this.issuer = user;
    this.member = member;
    this.reaction = reaction;
}
 
Example #13
Source File: ProfileComponent.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public Holder(User user, Player player, SeasonPlayer seasonalPlayer, DBUser dbUser, List<Badge> badges) {
    this.user = user;
    this.player = player;
    this.seasonalPlayer = seasonalPlayer;
    this.dbUser = dbUser;
    this.badges = badges;
}
 
Example #14
Source File: FlagCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    final GuildMessageReceivedEvent event = ctx.getEvent();

    if (!passes(event, false)) {
        return;
    }

    final List<String> args = ctx.getArgs();
    final String flag = args.get(0).toLowerCase();

    if (flag.equalsIgnoreCase("list")) {
        sendMsg(event, "A list of flags can be found at https://dunctebot.com/flags");

        return;
    }

    if (!flags.contains(flag)) {
        sendMsg(event, "I do not know what this flag is, visit <https://dunctebot.com/flags> for a list of available flags.");

        return;
    }

    User user = ctx.getAuthor();

    if (args.size() > 1) {
        final String search = String.join(" ", args.subList(1, args.size()));
        final List<User> foundUsers = FinderUtils.searchUsers(search, ctx);

        if (!foundUsers.isEmpty()) {
            user = foundUsers.get(0);
        }
    }

    final String imageUrl = UserKt.getStaticAvatarUrl(user) + "?size=512";
    final byte[] image = ctx.getApis().getFlag(flag, imageUrl);

    handleBasicImage(event, image);

}
 
Example #15
Source File: ApplicationInfoImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
public ApplicationInfoImpl(JDA api, String description, boolean doesBotRequireCodeGrant, String iconId, long id,
        boolean isBotPublic, String name, User owner, ApplicationTeam team)
{
    this.api = api;
    this.description = description;
    this.doesBotRequireCodeGrant = doesBotRequireCodeGrant;
    this.iconId = iconId;
    this.id = id;
    this.isBotPublic = isBotPublic;
    this.name = name;
    this.owner = owner;
    this.team = team;
}
 
Example #16
Source File: AudioUtils.java    From MantaroBot with GNU General Public License v3.0 5 votes vote down vote up
public static String getQueueList(ConcurrentLinkedDeque<AudioTrack> queue) {
    StringBuilder sb = new StringBuilder();
    int n = 1;
    for (AudioTrack audioTrack : queue) {
        long aDuration = audioTrack.getDuration();
        String duration = String.format("%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(aDuration),
                TimeUnit.MILLISECONDS.toSeconds(aDuration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(aDuration))
        );

        User dj = audioTrack.getUserData() != null ? MantaroBot.getInstance().getShardManager()
                .getUserById(String.valueOf(audioTrack.getUserData())) : null;

        sb.append("**")
                .append(n)
                .append(". [")
                .append(StringUtils.limit(audioTrack.getInfo().title, 30))
                .append("](")
                .append(audioTrack.getInfo().uri)
                .append(")** (")
                .append(duration)
                .append(")")
                .append(dj != null ? " **[" + dj.getName() + "]**" : "")
                .append("\n");
        n++;
    }
    return sb.toString();
}
 
Example #17
Source File: UnwarnCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<Member> mentioned = ctx.getMentionedArg(0);

    if (mentioned.isEmpty()) {
        sendMsg(ctx, "No users found for query");

        return;
    }

    final DunctebotGuild guild = ctx.getGuild();
    final User target = mentioned.get(0).getUser();

    ctx.getDatabaseAdapter().deleteLatestWarningForUser(
        target.getIdLong(),
        guild.getIdLong(),
        (latestWarning) -> {
            if (latestWarning == null) {
                sendMsg(ctx, "This user has no active warnings");

                return null;
            }

            sendMsgFormat(ctx, "Latest warning for _%s_ removed\nReason was: %s", target.getAsTag(), latestWarning.getReason());
            modLog(String.format(
                "**%s** removed the latest warning for **%s**\nReason was: %s",
                ctx.getAuthor().getAsTag(),
                target.getAsTag(),
                latestWarning.getReason()
            ), guild);

            return null;
        });
}
 
Example #18
Source File: SourceResolverServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
private Object getAuthor(GenericEvent event) {
    if (event == null) {
        return null;
    }
    Class<? extends GenericEvent> clazz = event.getClass();
    Method method;
    if (!userAccessors.containsKey(clazz)) {
        method = ReflectionUtils.findMethod(clazz, "getUser");
        if (method == null) {
            method = ReflectionUtils.findMethod(clazz, "getAuthor");
        }
        userAccessors.put(clazz, method);
    } else {
        method = userAccessors.get(clazz);
    }
    if (method != null) {
        try {
            Object result = ReflectionUtils.invokeMethod(method, event);
            if (result instanceof User) {
                return result;
            }
        } catch (Exception e) {
            // we don't care
        }
    }
    return null;
}
 
Example #19
Source File: GuildMessageReactionAddEvent.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@SuppressWarnings("ConstantConditions")
public User getUser()
{
    return super.getUser();
}
 
Example #20
Source File: PrettyUtil.java    From DiscordSRV with GNU General Public License v3.0 5 votes vote down vote up
public static String beautify(User user) {
    if (user == null) return "<Unknown>";

    Member member = DiscordSRV.getPlugin().getMainGuild().getMember(user);

    return member != null
            ? member.getEffectiveName() + " (#" + user.getId() + ")"
            : user.getName() + " (#" + user.getId() + ")";
}
 
Example #21
Source File: BotinfoCommand.java    From SkyBot with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(@Nonnull CommandContext ctx) {
    if ("support".equals(ctx.getInvoke())) {
        MessageUtils.sendMsg(ctx, "You can join my support server here: <https://dunctebot.link/server>");
        return;
    }

    final User u = ctx.getJDA().getSelfUser();
    final String duncte = " <@191231307290771456> (duncte123#1245)";

    final MessageEmbed eb = EmbedUtils.defaultEmbed()
        .setDescription("Here is some information about me \uD83D\uDE09")
        .setThumbnail(u.getEffectiveAvatarUrl())
        .addField("About me", "Hello there, my name is DuncteBot and I’m currently being developed by " +
            duncte + ".\n" +
            "If you want to add me to your server you can do that by [clicking here](https://bots.discord.pw/bots/210363111729790977).\n" +
            "\n**[Support server](https://dunctebot.link/server)** \u2022 **[Website](https://dunctebot.com/)** \u2022 " +
            "**[Invite me](https://dunctebot.link/invite)**" +
            " \u2022 **[Twitter](https://twitter.com/DuncteBot)**  \u2022 **[Cheap hosting](https://billing.oxide.host/aff.php?aff=6)**" +
            "\n\u200B", true)
        .addField("Lang & lib info", "**Coded in:** Java (version " + System.getProperty("java.version") +
            ") and Kotlin (version " + KotlinVersion.CURRENT + ")\n\n" +
            "**JDA version:** " + JDAInfo.VERSION + "" +
            "\n**LavaPlayer version:** " + this.lavaplayerVersion + "\n" +
            "**Weeb.java version:** " + WeebInfo.VERSION + "\n\u200B", false)
        .addField("Support", "If you want to help keep the bot up 24/7, please consider " +
            "[becoming a patron](https://www.patreon.com/DuncteBot).", false)
        .build();

    sendEmbed(ctx, eb);
}
 
Example #22
Source File: MemberServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Transactional(readOnly = true)
public LocalMember get(Guild guild, User user) {
    return get(guild.getIdLong(), user.getId());
}
 
Example #23
Source File: ServerInfoCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
protected MessageEmbed.Field getMemberListField(Guild guild) {
    List<Member> memberList = guild.getMembers();
    class Info {
        private long userCount = 0;
        private long botCount = 0;
        private long online = 0;
        private long offline = 0;
        private long dnd = 0;
        private long idle = 0;
    }
    Info memberInfo = new Info();
    guild.getMembers().forEach(member -> {
        User user = member.getUser();
        if (user.isBot()) {
            memberInfo.botCount++;
        } else {
            memberInfo.userCount++;
        }
        switch (member.getOnlineStatus()) {
            case ONLINE:
                memberInfo.online++;
                break;
            case OFFLINE:
            case INVISIBLE:
                memberInfo.offline++;
                break;
            case IDLE:
                memberInfo.idle++;
                break;
            case DO_NOT_DISTURB:
                memberInfo.dnd++;
                break;
        }
    });
    StringBuilder memberBuilder = new StringBuilder();
    if (memberInfo.userCount > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.users", memberInfo.userCount))
                .append("\n");
    }
    if (memberInfo.botCount > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.bots", memberInfo.botCount))
                .append("\n");
    }
    if (memberInfo.online > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.status.online", memberInfo.online))
                .append("\n");
    }
    if (memberInfo.idle > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.status.idle", memberInfo.idle))
                .append("\n");
    }
    if (memberInfo.dnd > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.status.dnd", memberInfo.dnd))
                .append("\n");
    }
    if (memberInfo.offline > 0) {
        memberBuilder.append(messageService.getMessage("discord.command.server.members.status.offline", memberInfo.offline))
                .append("\n");
    }
    return new MessageEmbed.Field(messageService.getMessage("discord.command.server.members", memberList.size()),
            memberBuilder.toString(), true);
}
 
Example #24
Source File: UserServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Transactional(readOnly = true)
public LocalUser get(User user) {
    return getById(user.getId());
}
 
Example #25
Source File: UserUpdateNameEvent.java    From JDA with Apache License 2.0 4 votes vote down vote up
public UserUpdateNameEvent(@Nonnull JDA api, long responseNumber, @Nonnull User user, @Nonnull String oldName)
{
    super(api, responseNumber, user, oldName, user.getName(), IDENTIFIER);
}
 
Example #26
Source File: ReminderTask.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
public static void handle() {
    log.debug("Checking reminder data...");
    try (Jedis j = MantaroData.getDefaultJedisPool().getResource()) {
        Set<String> reminders = j.zrange("zreminder", 0, 14);
        MantaroBot bot = MantaroBot.getInstance();

        log.debug("Reminder check - remainder is: {}", reminders.size());

        for (String rem : reminders) {
            try {
                JSONObject data = new JSONObject(rem);

                long fireAt = data.getLong("at");
                //If the time has passed...
                //System.out.println("time: " + System.currentTimeMillis() + ", expected: " + fireAt);

                if (System.currentTimeMillis() >= fireAt) {
                    log.debug("Reminder date has passed, remind accordingly.");
                    String userId = data.getString("user");
                    String fullId = data.getString("id") + ":" + userId;
                    String guildId = data.getString("guild");
                    long scheduledAt = data.getLong("scheduledAt");

                    //1 day passed already, assuming it's a stale reminder: Done because ReminderTask wasn't working.
                    if(System.currentTimeMillis() - fireAt > TimeUnit.DAYS.toMillis(1)) {
                        Reminder.cancel(userId, fullId);
                        return;
                    }

                    String reminder = data.getString("reminder"); //The actual reminder data
                    Guild guild = bot.getShardManager().getGuildById(guildId);

                    bot.getShardManager().retrieveUserById(userId)
                            .flatMap(User::openPrivateChannel)
                            .flatMap(privateChannel -> privateChannel.sendMessage(
                                        EmoteReference.POPPER + "**Reminder!**\n" + "You asked me to remind you of: " + reminder +
                                                "\nAt: " + new Date(scheduledAt) + (guild != null ? "\n*Asked on: " + guild.getName() + "*" : "")
                                    )
                            ).queue(success -> {
                                //FYI: This only logs on debug the id data, no personal stuff. We don't see your personal data. I don't wanna see it either, lmao.
                                log.debug("Reminded {}. Removing from remind database", fullId);
                                //Remove reminder from our database.
                                Reminder.cancel(userId, fullId);
                            }, err -> Reminder.cancel(userId, fullId)
                    );
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example #27
Source File: GulagServiceImpl.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Transactional(readOnly = true)
public Gulag getGulag(@NonNull User user) {
    return repository.findBySnowflake(user.getIdLong());
}
 
Example #28
Source File: GulagCommand.java    From JuniperBot with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String content) {
    TextChannel channel = event.getChannel();

    if (StringUtils.isBlank(content)) {
        showHelp(event, context);
        return false;
    }

    Member targetMember = reference.getMember();
    if (targetMember != null && supportService.isModerator(targetMember)) {
        return fail(event);
    }

    User targetUser = reference.getUser();
    if (targetUser != null && discordService.isSuperUser(targetUser)) {
        return fail(event);
    }

    String id = reference.getId();

    String targetName = targetUser != null
            ? String.format("%s#%s (%s)", targetUser.getName(), targetUser.getDiscriminator(), id)
            : id;

    boolean success = gulagService.send(event.getMember(), Long.valueOf(reference.getId()), content);
    if (!success) {
        messageService.onEmbedMessage(channel, "discord.command.gulag.exists", targetName);
        return false;
    }

    messageService.onEmbedMessage(channel, "discord.command.gulag.success", targetName);

    if (targetMember != null) {
        targetMember.ban(1, content).queueAfter(30, TimeUnit.SECONDS);
    } else if (targetUser != null) {
        event.getGuild().ban(targetUser, 1, content).queue();
    }

    if (targetUser != null) {
        discordService.getShardManager().getGuildCache()
                .stream()
                .filter(e -> e.getOwner() != null && targetUser.equals(e.getOwner().getUser()))
                .forEach(e -> e.leave().queue());
    }

    Guild guild = discordService.getShardManager().getGuildById(id);
    if (guild != null) {
        guild.leave().queue();
    }
    return true;
}
 
Example #29
Source File: DiscordBotServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
public void addController(User author) {
	controllers.add(author.getId());
}
 
Example #30
Source File: ProfileComponent.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
public User getUser() {
    return this.user;
}