Java Code Examples for net.dv8tion.jda.api.entities.Member#getUser()
The following examples show how to use
net.dv8tion.jda.api.entities.Member#getUser() .
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: TagCommand.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
private boolean isTagPatron(Member member) { final User u = member.getUser(); if (isUserTagPatron(u)) { return true; } if (member.getGuild().getIdLong() != Settings.SUPPORT_GUILD_ID) { return false; } final boolean hasRole = member.getRoles() .stream() .map(Role::getIdLong) .anyMatch((it) -> it == Settings.TAG_PATRONS_ROLE); if (hasRole) { tagPatrons.add(u.getIdLong()); } return hasRole; }
Example 2
Source File: ContextServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public void initContext(GenericEvent event) { Guild guild = null; User user = null; if (event instanceof GenericGuildMemberEvent) { GenericGuildMemberEvent memberEvent = (GenericGuildMemberEvent) event; guild = memberEvent.getMember().getGuild(); user = memberEvent.getMember().getUser(); } if (guild == null && event instanceof GenericGuildEvent) { guild = ((GenericGuildEvent) event).getGuild(); } if (guild == null || user == null) { Member member = resolverService.getMember(event); if (member != null) { guild = member.getGuild(); user = member.getUser(); } } if (guild == null) { guild = resolverService.getGuild(event); } if (user == null) { user = resolverService.getUser(event); } if (guild != null) { initContext(guild); } if (user != null) { initContext(user); } }
Example 3
Source File: BanCommand.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(@Nonnull CommandContext ctx) { final List<String> args = ctx.getArgs(); final List<Member> mentioned = ctx.getMentionedArg(0); if (mentioned.isEmpty()) { sendMsg(ctx, "I could not find any members with name " + args.get(0)); return; } final Member toBanMember = mentioned.get(0); if (!canInteract(ctx.getMember(), toBanMember, "ban", ctx.getChannel())) { return; } final User toBan = toBanMember.getUser(); if (toBan.equals(ctx.getAuthor()) && !ctx.getMember().canInteract(Objects.requireNonNull(ctx.getGuild().getMember(toBan)))) { sendMsg(ctx, "You are not permitted to perform this action."); return; } String reason = "No reason given"; final var flags = ctx.getParsedFlags(this); if (flags.containsKey("r")) { reason = String.join(" ", flags.get("r")); } final String fReason = reason; final int delDays = flags.containsKey("nodel") ? 0 : 1; ctx.getGuild().ban(toBan.getId(), delDays, reason) .reason(String.format("Ban by %#s: %s", ctx.getAuthor(), fReason)) .queue( (m) -> { modLog(ctx.getAuthor(), toBan, "banned", fReason, ctx.getGuild()); sendSuccess(ctx.getMessage()); } ); }
Example 4
Source File: SoftbanCommand.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(@Nonnull CommandContext ctx) { final List<String> args = ctx.getArgs(); if (args.size() < 2) { this.sendUsageInstructions(ctx); return; } final List<Member> mentioned = ctx.getMentionedArg(0); if (mentioned.isEmpty()) { sendMsg(ctx, "I could not find any members with name " + args.get(0)); return; } final Member toBanMember = mentioned.get(0); if (!canInteract(ctx.getMember(), toBanMember, "softban", ctx.getChannel())) { return; } try { final User toBan = toBanMember.getUser(); if (toBan.equals(ctx.getAuthor()) && !ctx.getMember().canInteract(toBanMember)) { sendMsg(ctx, "You are not permitted to perform this action."); return; } String reason = "No reason given"; final var flags = ctx.getParsedFlags(this); if (flags.containsKey("r")) { reason = String.join(" ", flags.get("r")); } final String fReason = reason; ctx.getGuild().ban(toBanMember, 1, fReason) .reason("Kicked by: " + ctx.getAuthor().getAsTag() + ": " + fReason).queue( nothing -> { ModerationUtils.modLog(ctx.getAuthor(), toBan, "kicked", fReason, ctx.getGuild()); MessageUtils.sendSuccess(ctx.getMessage()); ctx.getGuild().unban(toBan.getId()) .reason("(softban) Kicked by: " + ctx.getAuthor().getAsTag()).queue(); } ); } catch (HierarchyException ignored) { sendMsg(ctx, "I can't ban that member because his roles are above or equals to mine."); } }
Example 5
Source File: TempBanCommand.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(@Nonnull CommandContext ctx) { final List<String> args = ctx.getArgs(); final List<Member> mentioned = ctx.getMentionedArg(0); if (mentioned.isEmpty()) { sendMsg(ctx, "I could not find any members with name " + args.get(0)); return; } final Member toBanMember = mentioned.get(0); if (toBanMember.equals(ctx.getMember())) { sendMsg(ctx, "You cannot ban yourself"); return; } if (!canInteract(ctx.getMember(), toBanMember, "ban", ctx.getChannel())) { return; } String reason = "No reason given"; final var flags = ctx.getParsedFlags(this); if (flags.containsKey("r")) { reason = String.join(" ", flags.get("r")); } final Duration duration = getDuration(args.get(1), getName(), ctx.getEvent(), ctx.getPrefix()); if (duration == null) { return; } final String finalUnbanDate = AirUtils.getDatabaseDateFormat(duration); final String fReason = reason; final User toBan = toBanMember.getUser(); ctx.getGuild().ban(toBan.getId(), 1, fReason).queue( (__) -> { if (duration.getSeconds() > 0) { addBannedUserToDb(ctx.getDatabaseAdapter(), ctx.getAuthor().getIdLong(), toBan.getName(), toBan.getDiscriminator(), toBan.getIdLong(), finalUnbanDate, ctx.getGuild().getIdLong()); modLog(ctx.getAuthor(), toBan, "temporally banned", fReason, duration.toString(), ctx.getGuild()); } else { logger.error("Perm ban code in temp ban ran {}", args); modLog(ctx.getAuthor(), toBan, "banned", fReason, ctx.getGuild()); } } ); sendSuccess(ctx.getMessage()); }
Example 6
Source File: TempMuteCommand.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(@Nonnull CommandContext ctx) { final GuildMessageReceivedEvent event = ctx.getEvent(); final List<String> args = ctx.getArgs(); final GuildSettings settings = ctx.getGuildSettings(); final List<Member> mentioned = ctx.getMentionedArg(0); if (mentioned.isEmpty()) { sendMsg(ctx, "I could not find any members with name " + args.get(0)); return; } if (settings.getMuteRoleId() <= 0) { sendMsg(event, "No mute/spamrole is set, use `" + ctx.getPrefix() + "spamrole <Role>` to set it"); return; } final User author = event.getAuthor(); final Member mod = ctx.getMember(); final Member toMute = mentioned.get(0); final User mutee = toMute.getUser(); final Guild guild = event.getGuild(); final Role role = guild.getRoleById(settings.getMuteRoleId()); final Member self = ctx.getSelfMember(); if (canNotProceed(ctx, event, mod, toMute, role, self)) { return; } String reason = "No reason given"; final var flags = ctx.getParsedFlags(this); if (flags.containsKey("r")) { reason = String.join(" ", flags.get("r")); } final Duration duration = getDuration(args.get(1), getName(), event, ctx.getPrefix()); if (duration == null) { return; } final String fReason = reason; final String finalDate = AirUtils.getDatabaseDateFormat(duration); ctx.getDatabaseAdapter().createMute( author.getIdLong(), mutee.getIdLong(), mutee.getAsTag(), finalDate, guild.getIdLong(), (mute) -> { if (mute != null) { final String modId = mute.getModId(); final User oldMuteMod = guild.getJDA().getUserById(modId); String modName = "Unknown"; if (oldMuteMod != null) { modName = oldMuteMod.getAsTag(); } sendMsg(event, String.format( "Previously created muted for %#s removed, mute was created by %s", mutee, modName )); } return null; } ); guild.addRoleToMember(toMute, role) .reason("Muted by " + author.getAsTag() + ": " + fReason) .queue(success -> { ModerationUtils.modLog(author, mutee, "muted", fReason, duration.toString(), ctx.getGuild()); sendSuccess(event.getMessage()); } ); }
Example 7
Source File: PurgeUserCommand.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
@Override public void execute(@Nonnull CommandContext ctx) { final List<Member> mentionedMembers = ctx.getMentionedArg(0); if (mentionedMembers.isEmpty()) { sendMsg(ctx, "I could not find any members with that name"); return; } final Member targetMember = mentionedMembers.get(0); final User targetUser = targetMember.getUser(); final TextChannel channel = ctx.getChannel(); final Message message = ctx.getMessage(); channel.getIterableHistory() .takeAsync(DEL_COUNT) .thenApplyAsync( (msgs) -> msgs.stream() .filter((msg) -> msg.getAuthor().equals(targetUser)) .collect(Collectors.toList()) ) .thenApplyAsync((msgs) -> { final List<CompletableFuture<Void>> futures = channel.purgeMessages(msgs); sendSuccess(message); try { CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(); } catch (InterruptedException | ExecutionException e) { Sentry.capture(e); return 0; } return msgs.size(); }) .exceptionally((thr) -> { String cause = ""; if (thr.getCause() != null) { cause = " caused by: " + thr.getCause().getMessage(); } sendMsg(ctx, "ERROR: " + thr.getMessage() + cause); sendError(message); return 0; }) .whenCompleteAsync((count, thr) -> { sendMsgFormatAndDeleteAfter(ctx.getEvent(), 5, TimeUnit.SECONDS, "Removed %d messages! (this message will auto delete in 5 seconds)", count); channel.deleteMessageById(message.getIdLong()).queue(null, ignore(UNKNOWN_MESSAGE)); modLog(String.format("%d messages by %#s removed in %s by %#s", count, targetUser, channel, ctx.getAuthor()), ctx.getGuild()); }); }
Example 8
Source File: UserUpdateOnlineStatusEvent.java From JDA with Apache License 2.0 | 4 votes |
public UserUpdateOnlineStatusEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nonnull OnlineStatus oldOnlineStatus) { super(api, responseNumber, member.getUser(), oldOnlineStatus, member.getOnlineStatus(), IDENTIFIER); this.guild = member.getGuild(); this.member = member; }
Example 9
Source File: UserUpdateActivityOrderEvent.java From JDA with Apache License 2.0 | 4 votes |
public UserUpdateActivityOrderEvent(@Nonnull JDAImpl api, long responseNumber, @Nonnull List<Activity> previous, @Nonnull Member member) { super(api, responseNumber, member.getUser(), previous, member.getActivities(), IDENTIFIER); this.member = member; }
Example 10
Source File: UserActivityEndEvent.java From JDA with Apache License 2.0 | 4 votes |
public UserActivityEndEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nonnull Activity oldActivity) { super(api, responseNumber, member.getUser()); this.oldActivity = oldActivity; this.member = member; }
Example 11
Source File: UserActivityStartEvent.java From JDA with Apache License 2.0 | 4 votes |
public UserActivityStartEvent(@Nonnull JDA api, long responseNumber, @Nonnull Member member, @Nonnull Activity newActivity) { super(api, responseNumber, member.getUser()); this.newActivity = newActivity; this.member = member; }