discord4j.core.object.entity.Member Java Examples
The following examples show how to use
discord4j.core.object.entity.Member.
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: OrderUser.java From KaellyBot with GNU General Public License v3.0 | 6 votes |
/** * @param user Joueur de la guilde * @param server Serveur dofus * @return Liste des résultats de la recherche */ public static List<Consumer<EmbedCreateSpec>> getOrdersFromUser(Member user, ServerDofus server, Language lg){ List<OrderUser> result = getOrders().get(user.getId().asLong(), server, null, null); result.sort(OrderUser::compare); List<Consumer<EmbedCreateSpec>> embed = new ArrayList<>(); embed.add(spec -> { spec.setTitle(Translator.getLabel(lg, "align.user").replace("{user}", user.getDisplayName())) .setThumbnail(user.getAvatarUrl()) .setColor(Color.GRAY); if (! result.isEmpty()) { StringBuilder st = new StringBuilder(); for (OrderUser orderUser : result) st.append(orderUser.city.getLogo()).append(orderUser.order.getLabel(lg)).append(" : ") .append(orderUser.level).append("\n"); spec.addField(Translator.getLabel(lg, "align.aligns"), st.toString(), true); } else spec.setDescription(Translator.getLabel(lg, "align.empty")); spec.setFooter(server.getLabel(lg), null); }); return embed; }
Example #2
Source File: DiscordUtils.java From Shadbot with GNU General Public License v3.0 | 6 votes |
public static Mono<Member> extractMemberOrAuthor(Guild guild, Message message) { final String[] args = message.getContent().split(" "); if (args.length == 1) { return message.getAuthorAsMember(); } if (args.length > 2) { return Mono.error(new CommandException("You can't specify more than one user.")); } return message.getUserMentions() .switchIfEmpty(DiscordUtils.extractMembers(guild, message.getContent())) .next() .flatMap(user -> user.asMember(guild.getId())) .switchIfEmpty(Mono.error(new CommandException(String.format("User **%s** not found.", args[1])))); }
Example #3
Source File: DisCalCommand.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
private void moduleDmAnnouncements(MessageCreateEvent event, GuildSettings settings) { if (settings.isDevGuild()) { Member user = event.getMember().get(); if (settings.getDmAnnouncements().contains(user.getId().asString())) { settings.getDmAnnouncements().remove(user.getId().asString()); DatabaseManager.getManager().updateSettings(settings); MessageManager.sendMessageAsync(MessageManager.getMessage("DisCal.DmAnnouncements.Off", settings), event); } else { settings.getDmAnnouncements().add(user.getId().asString()); DatabaseManager.getManager().updateSettings(settings); MessageManager.sendMessageAsync(MessageManager.getMessage("DisCal.DmAnnouncements.On", settings), event); } } else { MessageManager.sendMessageAsync(MessageManager.getMessage("Notification.Disabled", settings), event); } }
Example #4
Source File: GuildUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
public static List<WebGuild> getGuilds(JSONArray ids, String userId, DiscordClient client) { List<WebGuild> guilds = new ArrayList<>(); for (int i = 0; i < ids.length(); i++) { Guild g = client.getGuildById(Snowflake.of(ids.getLong(i))).onErrorResume(e -> Mono.empty()).block(); if (g != null) { Member m = g.getMemberById(Snowflake.of(userId)).block(); WebGuild wg = new WebGuild().fromGuild(g); wg.setManageServer(PermissionChecker.hasManageServerRole(m)); wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, m)); guilds.add(wg); } } return guilds; }
Example #5
Source File: UserUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
/** * Grabs a user from a string * * @param toLookFor The String to look with * @param guild The guild * @return The user if found, null otherwise */ public static Snowflake getUser(String toLookFor, Guild guild) { toLookFor = GeneralUtils.trim(toLookFor); final String lower = toLookFor.toLowerCase(); if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) { Member exists = guild.getMemberById(Snowflake.of(Long.parseLong(toLookFor.replaceAll("[<@!>]", "")))).onErrorResume(e -> Mono.empty()).block(); if (exists != null) return exists.getId(); } List<Member> users = new ArrayList<>(); users.addAll(guild.getMembers().filter(m -> m.getUsername().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getUsername().toLowerCase().contains(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> (m.getUsername() + "#" + m.getDiscriminator()).equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDiscriminator().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDisplayName().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDisplayName().toLowerCase().contains(lower)).collectList().block()); if (!users.isEmpty()) return users.get(0).getId(); return null; }
Example #6
Source File: RateLimiter.java From Shadbot with GNU General Public License v3.0 | 6 votes |
public boolean isLimitedAndWarn(Snowflake channelId, Member member) { final LimitedUser limitedUser = this.guildsLimitedMap.computeIfAbsent(member.getGuildId(), ignored -> new LimitedGuild(this.bandwidth)) .getUser(member.getId()); // The token could not been consumed, the user is limited if (!limitedUser.getBucket().tryConsume(1)) { // The user has not yet been warned if (!limitedUser.isWarned()) { this.sendWarningMessage(member.getClient(), channelId, member.getId()); limitedUser.warn(); } return true; } limitedUser.unwarn(); return false; }
Example #7
Source File: UserUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
/** * Grabs a user from a string * * @param toLookFor The String to look with * @param guild The guild * @return The user if found, null otherwise */ public static Snowflake getUser(String toLookFor, Guild guild) { toLookFor = GeneralUtils.trim(toLookFor); final String lower = toLookFor.toLowerCase(); if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) { Member exists = guild.getMemberById(Snowflake.of(Long.parseLong(toLookFor.replaceAll("[<@!>]", "")))).onErrorResume(e -> Mono.empty()).block(); if (exists != null) return exists.getId(); } List<Member> users = new ArrayList<>(); users.addAll(guild.getMembers().filter(m -> m.getUsername().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getUsername().toLowerCase().contains(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> (m.getUsername() + "#" + m.getDiscriminator()).equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDiscriminator().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDisplayName().equalsIgnoreCase(lower)).collectList().block()); users.addAll(guild.getMembers().filter(m -> m.getDisplayName().toLowerCase().contains(lower)).collectList().block()); if (!users.isEmpty()) return users.get(0).getId(); return null; }
Example #8
Source File: ServerInfoCmd.java From Shadbot with GNU General Public License v3.0 | 6 votes |
private Consumer<EmbedCreateSpec> getEmbed(Guild guild, List<GuildChannel> channels, Member owner, Region region, String avatarUrl) { final LocalDateTime creationTime = TimeUtils.toLocalDateTime(guild.getId().getTimestamp()); final String creationDate = String.format("%s%n(%s)", creationTime.format(this.dateFormatter), FormatUtils.formatLongDuration(creationTime)); final long voiceChannels = channels.stream().filter(VoiceChannel.class::isInstance).count(); final long textChannels = channels.stream().filter(TextChannel.class::isInstance).count(); return ShadbotUtils.getDefaultEmbed() .andThen(embed -> embed.setAuthor(String.format("Server Info: %s", guild.getName()), null, avatarUrl) .setThumbnail(guild.getIconUrl(Format.JPEG).orElse("")) .addField("Owner", owner.getUsername(), false) .addField("Server ID", guild.getId().asString(), false) .addField("Creation date", creationDate, false) .addField("Region", region.getName(), false) .addField("Channels", String.format("**Voice:** %d%n**Text:** %d", voiceChannels, textChannels), false) .addField("Members", Integer.toString(guild.getMemberCount()), false)); }
Example #9
Source File: BaseGuildChannel.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Mono<PermissionSet> getEffectivePermissions(Snowflake memberId) { Mono<Member> getMember = getClient().getMemberById(getGuildId(), memberId); Mono<PermissionSet> getBasePerms = getMember.flatMap(Member::getBasePermissions); return Mono.zip(getMember, getBasePerms, (member, basePerms) -> { PermissionOverwrite everyoneOverwrite = getOverwriteForRole(getGuildId()).orElse(null); List<PermissionOverwrite> roleOverwrites = member.getRoleIds().stream() .map(this::getOverwriteForRole) .flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)) // jdk 9 Optional#stream .collect(Collectors.toList()); PermissionOverwrite memberOverwrite = getOverwriteForMember(member.getId()).orElse(null); return PermissionUtil.computePermissions(basePerms, everyoneOverwrite, roleOverwrites, memberOverwrite); }); }
Example #10
Source File: RemoveMemberCmd.java From Shadbot with GNU General Public License v3.0 | 6 votes |
private Mono<Boolean> canInteract(MessageChannel channel, Member self, Member author, Member memberToRemove) { return Mono.zip(self.isHigher(memberToRemove), author.isHigher(memberToRemove)) .flatMap(TupleUtils.function((isSelfHigher, isAuthorHigher) -> { if (!isSelfHigher) { return DiscordUtils.sendMessage( String.format(Emoji.WARNING + " (**%s**) I cannot %s **%s** because he is higher in " + "the role hierarchy than me.", author.getUsername(), this.getName(), memberToRemove.getUsername()), channel) .thenReturn(false); } if (!isAuthorHigher) { return DiscordUtils.sendMessage( String.format(Emoji.WARNING + " (**%s**) You cannot %s **%s** because he is higher " + "in the role hierarchy than you.", author.getUsername(), this.getName(), memberToRemove.getUsername()), channel) .thenReturn(false); } return Mono.just(true); })); }
Example #11
Source File: JobUser.java From KaellyBot with GNU General Public License v3.0 | 6 votes |
/** * @param users Joueurs de la guilde * @param server Serveur dofus * @param jobs Métiers * @param level Niveau; si ingérieur à 0, filtre ignoré * @return Liste des résultats de la recherche */ public static List<Consumer<EmbedCreateSpec>> getJobsFromFilters(List<Member> users, ServerDofus server, Set<Job> jobs, int level, discord4j.core.object.entity.Guild guild, Language lg){ List<JobUser> result = new ArrayList<>(); for(Member user : users) if (! user.isBot()){ for(Job job : jobs) { List<JobUser> potentials = getJobs().get(user.getId().asLong(), server, job); if (level > 0) { for (JobUser potential : potentials) if (potential.getLevel() >= level) result.add(potential); } else result.addAll(potentials); } } result.sort(JobUser::compare); return getPlayersList(result, guild, server, lg, JOB_PREFIX); }
Example #12
Source File: JobUser.java From KaellyBot with GNU General Public License v3.0 | 6 votes |
/** * @param user Joueur de la guilde * @param server Serveur dofus * @return Liste des résultats de la recherche */ public static List<Consumer<EmbedCreateSpec>> getJobsFromUser(Member user, ServerDofus server, Language lg){ List<JobUser> result = getJobs().get(user.getId().asLong(), server, null); result.sort(JobUser::compare); List<Consumer<EmbedCreateSpec>> embed = new ArrayList<>(); embed.add(spec -> { spec.setTitle(Translator.getLabel(lg, "job.user").replace("{user}", user.getDisplayName())) .setThumbnail(user.getAvatarUrl()) .setColor(Color.GRAY); if (! result.isEmpty()) { StringBuilder st = new StringBuilder(); for (JobUser jobUser : result) st.append(jobUser.job.getLabel(lg)).append(" : ").append(jobUser.level).append("\n"); spec.addField(Translator.getLabel(lg, "job.jobs"), st.toString(), true); } else spec.setDescription(Translator.getLabel(lg, "job.empty")); spec.setFooter(server.getLabel(lg), null); }); return embed; }
Example #13
Source File: GuildUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 6 votes |
public static List<WebGuild> getGuilds(JSONArray ids, String userId, DiscordClient client) { List<WebGuild> guilds = new ArrayList<>(); for (int i = 0; i < ids.length(); i++) { Guild g = client.getGuildById(Snowflake.of(ids.getLong(i))).onErrorResume(e -> Mono.empty()).block(); if (g != null) { Member m = g.getMemberById(Snowflake.of(userId)).block(); WebGuild wg = new WebGuild().fromGuild(g); wg.setManageServer(PermissionChecker.hasManageServerRole(m)); wg.setDiscalRole(PermissionChecker.hasSufficientRole(g, m)); guilds.add(wg); } } return guilds; }
Example #14
Source File: ComHandler.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
@PostMapping(value = "/website/dashboard/guild", produces = "application/json") public static String getWebsiteDashboardGuild(HttpServletRequest request, HttpServletResponse response, @RequestBody String requestBody) { //Requires us to grab data for guild and return a response containing the WebGuild with needed info JSONObject jsonRequest = new JSONObject(requestBody); JSONObject jsonResponse = new JSONObject(); Optional<Guild> guild = GuildFinder.findGuild(Snowflake.of(jsonRequest.getLong("guild_id"))); if (guild.isPresent()) { Member member = guild.get().getMemberById(Snowflake.of(jsonRequest.getLong("member_id"))).block(); if (member != null) { WebGuild wg = new WebGuild().fromGuild(guild.get()); wg.setDiscalRole(PermissionChecker.hasSufficientRole(guild.get(), member)); wg.setManageServer(PermissionChecker.hasManageServerRole(member)); jsonResponse.put("guild", new WebGuild().fromGuild(guild.get()).toJson()); response.setStatus(200); response.setContentType("application/json"); return jsonResponse.toString(); } else { jsonResponse.put("message", "Member not Found"); response.setStatus(404); response.setContentType("application/json"); return jsonResponse.toString(); } } else { jsonResponse.put("message", "Guild not Found"); response.setStatus(404); response.setContentType("application/json"); return jsonResponse.toString(); } }
Example #15
Source File: UserInfoCmd.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@Override public Mono<Void> execute(Context context) { final Mono<Member> getMemberOrAuthor = context.getGuild() .flatMap(guild -> DiscordUtils.extractMemberOrAuthor(guild, context.getMessage())) .cache(); return Mono.zip(getMemberOrAuthor, getMemberOrAuthor.flatMapMany(Member::getRoles).collectList()) .map(TupleUtils.function((user, roles) -> this.getEmbed(user, roles, context.getAvatarUrl()))) .flatMap(embed -> context.getChannel() .flatMap(channel -> DiscordUtils.sendMessage(embed, channel))) .then(); }
Example #16
Source File: DispatchHandlers.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
private static Mono<TypingStartEvent> typingStart(DispatchContext<TypingStart> context) { long channelId = Snowflake.asLong(context.getDispatch().channelId()); Long guildId = context.getDispatch().guildId().toOptional().map(Snowflake::asLong).orElse(null); long userId = Snowflake.asLong(context.getDispatch().userId()); Instant startTime = Instant.ofEpochSecond(context.getDispatch().timestamp()); Member member = context.getDispatch().member().toOptional() .filter(__ -> guildId != null) .map(memberData -> new Member(context.getGateway(), memberData, guildId)) .orElse(null); return Mono.just(new TypingStartEvent(context.getGateway(), context.getShardInfo(), channelId, guildId, userId, startTime, member)); }
Example #17
Source File: RemoveMemberCmd.java From Shadbot with GNU General Public License v3.0 | 5 votes |
private Mono<Message> sendMessage(Guild guild, MessageChannel channel, Member author, Member memberToRemove, String reason) { return memberToRemove.getPrivateChannel() .flatMap(privateChannel -> DiscordUtils.sendMessage( String.format(Emoji.WARNING + " You were %s from the server **%s** by **%s**. Reason: `%s`", this.conjugatedVerb, guild.getName(), author.getUsername(), reason), privateChannel) .switchIfEmpty(DiscordUtils.sendMessage( String.format(Emoji.WARNING + " (**%s**) I could not send a message to **%s**.", author.getUsername(), memberToRemove.getUsername()), channel))); }
Example #18
Source File: DiceInputs.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@Override public Mono<Void> processEvent(MessageCreateEvent event) { return Mono.justOrEmpty(event.getMember()) .map(Member::getUsername) .filterWhen(username -> this.game.isCancelMessage(event.getMessage())) .flatMap(username -> Flux.fromIterable(this.game.getPlayers().values()) .flatMap(DicePlayer::cancelBet) .then() .thenReturn(username)) .map(username -> String.format(Emoji.CHECK_MARK + " Dice game cancelled by **%s**.", username)) .flatMap(text -> event.getMessage().getChannel() .flatMap(channel -> DiscordUtils.sendMessage(text, channel)) .then(Mono.fromRunnable(this.game::stop))); }
Example #19
Source File: UserInfoCmd.java From Shadbot with GNU General Public License v3.0 | 5 votes |
private Consumer<EmbedCreateSpec> getEmbed(Member member, List<Role> roles, String avatarUrl) { final LocalDateTime createTime = TimeUtils.toLocalDateTime(member.getId().getTimestamp()); final String creationDate = String.format("%s%n(%s)", createTime.format(this.dateFormatter), FormatUtils.formatLongDuration(createTime)); final LocalDateTime joinTime = TimeUtils.toLocalDateTime(member.getJoinTime()); final String joinDate = String.format("%s%n(%s)", joinTime.format(this.dateFormatter), FormatUtils.formatLongDuration(joinTime)); final StringBuilder usernameBuilder = new StringBuilder(member.getUsername()); if (member.isBot()) { usernameBuilder.append(" (Bot)"); } if (member.getPremiumTime().isPresent()) { usernameBuilder.append(" (Booster)"); } return ShadbotUtils.getDefaultEmbed() .andThen(embed -> { embed.setAuthor(String.format("User Info: %s", usernameBuilder), null, avatarUrl) .setThumbnail(member.getAvatarUrl()) .addField("Display name", member.getDisplayName(), false) .addField("User ID", member.getId().asString(), false) .addField("Creation date", creationDate, false) .addField("Join date", joinDate, false); if (!roles.isEmpty()) { embed.addField("Roles", FormatUtils.format(roles, Role::getMention, "\n"), true); } }); }
Example #20
Source File: BaseGuildMessageChannel.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
/** * Returns all members in the guild which have access to <b>view</b> this channel. * * @return A {@link Flux} that continually emits all members from {@link Guild#getMembers()} which have access to * view this channel {@link discord4j.rest.util.Permission#VIEW_CHANNEL} */ @Override public Flux<Member> getMembers() { return getGuild() .flatMapMany(Guild::getMembers) .filterWhen(member -> getEffectivePermissions(member.getId()) .map(permissions -> permissions.contains(Permission.VIEW_CHANNEL))); }
Example #21
Source File: OrderUser.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
/** * @param users Joueurs de la guilde * @param server Serveur dofus * @param city Cité (Brakmar ou Bonta) * @param order Ordre (coeur, oeil, esprit) * @return Liste des résultats de la recherche */ public static List<Consumer<EmbedCreateSpec>> getOrdersFromCityOrOrder(List<Member> users, ServerDofus server, City city, Order order, discord4j.core.object.entity.Guild guild, Language lg){ List<OrderUser> result = new ArrayList<>(); for(Member user : users) if (! user.isBot()){ List<OrderUser> potentials = getOrders().get(user.getId().asLong(), server, city, order); result.addAll(potentials); } result.sort(OrderUser::compare); return getPlayersList(result, guild, server, lg, ORDER_PREFIX); }
Example #22
Source File: JobUser.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
@Override protected String displayLine(discord4j.core.object.entity.Guild guild, Language lg) { Optional<Member> member = guild.getMemberById(Snowflake.of(idUser)).blockOptional(); if (member.isPresent()) { Status status = member.get().getPresence().blockOptional().map(Presence::getStatus).orElse(Status.OFFLINE); return EmojiManager.getEmojiForPresence(status) + " " + job.getLabel(lg) + ", " + level + " : **" + member.get().getDisplayName() + "**\n"; } return ""; }
Example #23
Source File: UserUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private static Member getUserFromID(String id, Guild guild) { try { return guild.getMemberById(Snowflake.of(Long.parseUnsignedLong(id))).block(); } catch (Exception e) { //Ignore. Probably invalid ID. return null; } }
Example #24
Source File: ComHandler.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
@PostMapping(value = "/website/dashboard/guild", produces = "application/json") public static String getWebsiteDashboardGuild(HttpServletRequest request, HttpServletResponse response, @RequestBody String requestBody) { //Requires us to grab data for guild and return a response containing the WebGuild with needed info JSONObject jsonRequest = new JSONObject(requestBody); JSONObject jsonResponse = new JSONObject(); Optional<Guild> guild = GuildFinder.findGuild(Snowflake.of(jsonRequest.getLong("guild_id"))); if (guild.isPresent()) { Member member = guild.get().getMemberById(Snowflake.of(jsonRequest.getLong("member_id"))).block(); if (member != null) { WebGuild wg = new WebGuild().fromGuild(guild.get()); wg.setDiscalRole(PermissionChecker.hasSufficientRole(guild.get(), member)); wg.setManageServer(PermissionChecker.hasManageServerRole(member)); jsonResponse.put("guild", new WebGuild().fromGuild(guild.get()).toJson()); response.setStatus(200); response.setContentType("application/json"); return jsonResponse.toString(); } else { jsonResponse.put("message", "Member not Found"); response.setStatus(404); response.setContentType("application/json"); return jsonResponse.toString(); } } else { jsonResponse.put("message", "Guild not Found"); response.setStatus(404); response.setContentType("application/json"); return jsonResponse.toString(); } }
Example #25
Source File: MessageUpdateListener.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@Override public Mono<Void> execute(MessageUpdateEvent event) { if (!event.isContentChanged()) { return Mono.empty(); } final Mono<Message> getMessage = event.getMessage() .onErrorResume(ClientException.isStatusCode(HttpResponseStatus.FORBIDDEN.code()), err -> Mono.empty()) .cache(); // The member can be empty if the message has been edited in a private channel final Mono<Optional<Member>> getMember = getMessage .flatMap(Message::getAuthorAsMember) .map(Optional::of) .defaultIfEmpty(Optional.empty()); // The guild ID can be null if the message has been edited in a private channel final Long guildId = event.getGuildId() .map(Snowflake::asLong) .orElse(null); return Mono.zip(getMessage, getMember) .doOnNext(TupleUtils.consumer((message, member) -> event.getClient() .getEventDispatcher() .publish(new MessageCreateEvent(event.getClient(), event.getShardInfo(), message, guildId, member.orElse(null))))) .then(); }
Example #26
Source File: ExampleIntents.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) { List<Member> members = DiscordClient.create(System.getenv("token")) .gateway() .setEnabledIntents(IntentSet.of(Intent.GUILD_MEMBERS)) .login() .flatMapMany(gateway -> gateway.requestMembers(Snowflake.of(System.getenv("guild"))) ) .collectList() .block(); }
Example #27
Source File: UserUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
private static Member getUserFromID(String id, Guild guild) { try { return guild.getMemberById(Snowflake.of(Long.parseUnsignedLong(id))).block(); } catch (Exception e) { //Ignore. Probably invalid ID. return null; } }
Example #28
Source File: UserUtils.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
public static ArrayList<Member> getUsers(ArrayList<String> userIds, Guild guild) { ArrayList<Member> users = new ArrayList<>(); for (String u : userIds) { Member user = getUserFromID(u, guild); if (user != null) users.add(user); } return users; }
Example #29
Source File: OrderUser.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
@Override protected String displayLine(discord4j.core.object.entity.Guild guild, Language lg) { Optional<Member> member = guild.getMemberById(Snowflake.of(idUser)).blockOptional(); if (member.isPresent()) { Status status = member.get().getPresence().blockOptional().map(Presence::getStatus).orElse(Status.OFFLINE); return EmojiManager.getEmojiForPresence(status) + " " + city.getLogo() + " " + order.getLabel(lg) + ", " + level + " : **" + member.get().getDisplayName() + "**\n"; } return ""; }
Example #30
Source File: OrderUser.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
/** * @param users Joueurs de la guilde * @param server Serveur dofus * @param level Niveau pallier * @return Liste des résultats de la recherche */ public static List<Consumer<EmbedCreateSpec>> getOrdersFromLevel(List<Member> users, ServerDofus server, int level, discord4j.core.object.entity.Guild guild, Language lg){ List<OrderUser> result = new ArrayList<>(); for(Member user : users) if (! user.isBot()){ List<OrderUser> potentials = getOrders().get(user.getId().asLong(), server, null, null); for(OrderUser order : potentials) if (order.getLevel() >= level) result.add(order); } result.sort(OrderUser::compare); return getPlayersList(result, guild, server, lg, ORDER_PREFIX); }