discord4j.core.object.presence.Presence Java Examples
The following examples show how to use
discord4j.core.object.presence.Presence.
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: BotSupport.java From Discord4J with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Mono<Void> onMessageCreate(MessageCreateEvent event) { Message message = event.getMessage(); return Mono.justOrEmpty(message.getContent()) .filter(content -> content.startsWith("!status ")) .map(content -> { String status = content.substring("!status ".length()); if (status.equalsIgnoreCase("online")) { return Presence.online(); } else if (status.equalsIgnoreCase("dnd")) { return Presence.doNotDisturb(); } else if (status.equalsIgnoreCase("idle")) { return Presence.idle(); } else if (status.equalsIgnoreCase("invisible")) { return Presence.invisible(); } else { throw new IllegalArgumentException("Invalid argument"); } }) .flatMap(presence -> event.getClient().updatePresence(presence)) .then(); }
Example #2
Source File: StatusChanger.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void run() { String status = statuses.get(index); status = status.replace("%guCount%", DisCalClient.getClient().getGuilds().count().block() + ""); status = status.replace("%calCount%", DatabaseManager.getManager().getCalendarCount() + ""); status = status.replace("%annCount%", DatabaseManager.getManager().getAnnouncementCount() + ""); status = status.replace("%shards%", BotSettings.SHARD_COUNT.get()); DisCalClient.getClient().updatePresence(Presence.online(Activity.playing(status))).subscribe(); //Set new index. if (index + 1 >= statuses.size()) index = 0; else index++; }
Example #3
Source File: StatusChanger.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void run() { String status = statuses.get(index); status = status.replace("%guCount%", DisCalClient.getClient().getGuilds().count().block() + ""); status = status.replace("%calCount%", DatabaseManager.getManager().getCalendarCount() + ""); status = status.replace("%annCount%", DatabaseManager.getManager().getAnnouncementCount() + ""); status = status.replace("%shards%", BotSettings.SHARD_COUNT.get()); DisCalClient.getClient().updatePresence(Presence.online(Activity.playing(status))).subscribe(); //Set new index. if (index + 1 >= statuses.size()) index = 0; else index++; }
Example #4
Source File: DisCalClient.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates the DisCal bot client. * * @return The client if successful, otherwise <code>null</code>. */ private static DiscordClient createClient() { DiscordClientBuilder clientBuilder = new DiscordClientBuilder(BotSettings.TOKEN.get()); //Handle shard count and index for multiple java instances clientBuilder.setShardIndex(Integer.valueOf(BotSettings.SHARD_INDEX.get())); clientBuilder.setShardCount(Integer.valueOf(BotSettings.SHARD_COUNT.get())); clientBuilder.setInitialPresence(Presence.online(Activity.playing("Booting Up!"))); //Redis info + store service for caching if (BotSettings.USE_REDIS_STORES.get().equalsIgnoreCase("true")) { RedisURI uri = RedisURI.Builder .redis(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get())) .withPassword(BotSettings.REDIS_PASSWORD.get()) .build(); RedisStoreService rss = new RedisStoreService(RedisClient.create(uri)); MappingStoreService mss = MappingStoreService.create() .setMappings(rss, GuildBean.class, MessageBean.class) .setFallback(new JdkStoreService()); clientBuilder.setStoreService(mss); } else { clientBuilder.setStoreService(new JdkStoreService()); } return clientBuilder.build(); }
Example #5
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 #6
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 #7
Source File: ReadyListener.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
public void onReady(DiscordClient client) { if (!isReadyOnce.containsKey(client)) { long time = System.currentTimeMillis(); LOG.info("Ajout des différents listeners..."); client.getEventDispatcher().on(GuildCreateEvent.class) .subscribe(guildCreateEvent -> guildCreateListener.onReady(client, guildCreateEvent)); client.getEventDispatcher().on(GuildDeleteEvent.class) .subscribe(guildDeleteEvent -> guildLeaveListener.onReady(guildDeleteEvent)); client.getEventDispatcher().on(GuildUpdateEvent.class) .subscribe(guildUpdateEvent -> guildUpdateListener.onReady(guildUpdateEvent)); client.getEventDispatcher().on(TextChannelDeleteEvent.class) .subscribe(textChannelDeleteEvent -> channelDeleteListener.onReady(textChannelDeleteEvent)); LOG.info("Présence mise à jour..."); // Joue à... client.updatePresence(Presence.online(Activity.watching(Constants.discordInvite))).subscribe(); LOG.info("Ecoute des flux RSS du site Dofus..."); RSSFinder.start(); LOG.info("Lancement du calendrier Almanax..."); AlmanaxCalendar.start(); LOG.info("Connexion à l'API Twitter..."); TwitterFinder.start(); LOG.info("Ecoute des messages..."); client.getEventDispatcher().on(MessageCreateEvent.class) .subscribe(event -> messageListener.onReady(event)); isReadyOnce.put(client, true); LOG.info("Mise en place des ressources en " + (System.currentTimeMillis() - time) + "ms"); } }
Example #8
Source File: PresenceUpdateEvent.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
public PresenceUpdateEvent(GatewayDiscordClient gateway, ShardInfo shardInfo, long guildId, @Nullable User oldUser, PartialUserData user, Presence current, @Nullable Presence old) { super(gateway, shardInfo); this.guildId = guildId; this.oldUser = oldUser; this.user = user; this.current = current; this.old = old; }
Example #9
Source File: Guild.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
/** * Requests to retrieve the presences of the guild. * * @return A {@link Flux} that continually emits the {@link Presence presences} of the guild. If an error is * received, it is emitted through the {@code Flux}. */ public Flux<Presence> getPresences() { return gateway.getGatewayResources().getStateView().getPresenceStore() .findInRange(LongLongTuple2.of(getId().asLong(), Long.MIN_VALUE), LongLongTuple2.of(getId().asLong(), Long.MAX_VALUE)) .map(Presence::new); }
Example #10
Source File: ExampleWithGateway.java From Discord4J with GNU Lesser General Public License v3.0 | 5 votes |
public static void main(String[] args) { DiscordClient.create(System.getenv("token")) .gateway() .setInitialStatus(s -> Presence.invisible()) .withGateway(client -> client.on(ReadyEvent.class) .doOnNext(ready -> log.info("Logged in as {}", ready.getSelf().getUsername())) .then()) .block(); }
Example #11
Source File: ShadbotUtils.java From Shadbot with GNU General Public License v3.0 | 4 votes |
/** * @return A random status update showing "Playing {prefix}help | {tip}" */ public static StatusUpdate getRandomStatus() { final String presence = String.format("%shelp | %s", Config.DEFAULT_PREFIX, TIPS.getRandomTextFormatted()); return Presence.online(Activity.playing(presence)); }
Example #12
Source File: DisCalClient.java From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates the DisCal bot client. * * @return The client if successful, otherwise <code>null</code>. */ private static DiscordClient createClient() { DiscordClientBuilder clientBuilder = new DiscordClientBuilder(BotSettings.TOKEN.get()); //Handle shard count and index for multiple java instances clientBuilder.setShardIndex(Integer.valueOf(BotSettings.SHARD_INDEX.get())); clientBuilder.setShardCount(Integer.valueOf(BotSettings.SHARD_COUNT.get())); clientBuilder.setInitialPresence(Presence.online(Activity.playing("Booting Up!"))); //Redis info + store service for caching if (BotSettings.USE_REDIS_STORES.get().equalsIgnoreCase("true")) { RedisURI uri = RedisURI.Builder .redis(BotSettings.REDIS_HOSTNAME.get(), Integer.valueOf(BotSettings.REDIS_PORT.get())) .withPassword(BotSettings.REDIS_PASSWORD.get()) .build(); RedisStoreService rss = new RedisStoreService(RedisClient.create(uri)); MappingStoreService mss = MappingStoreService.create() .setMappings(rss, GuildBean.class, MessageBean.class) .setFallback(new JdkStoreService()); clientBuilder.setStoreService(mss); } else { clientBuilder.setStoreService(new JdkStoreService()); } return clientBuilder.build(); }
Example #13
Source File: DispatchHandlers.java From Discord4J with GNU Lesser General Public License v3.0 | 4 votes |
private static Mono<PresenceUpdateEvent> presenceUpdate(DispatchContext<PresenceUpdate> context) { GatewayDiscordClient gateway = context.getGateway(); long guildId = Snowflake.asLong(context.getDispatch().guildId()); PartialUserData userData = context.getDispatch().user(); long userId = Snowflake.asLong(userData.id()); LongLongTuple2 key = LongLongTuple2.of(guildId, userId); PresenceData presenceData = createPresence(context.getDispatch()); Presence current = new Presence(presenceData); Mono<Void> saveNew = context.getStateHolder().getPresenceStore().save(key, presenceData); Mono<Optional<User>> saveUser = context.getStateHolder().getUserStore() .find(userId) .map(oldUserData -> { UserData newUserData = UserData.builder() .from(oldUserData) .username(userData.username().toOptional() .orElse(oldUserData.username())) .discriminator(userData.discriminator().toOptional() .orElse(oldUserData.discriminator())) .avatar(or(Possible.flatOpt(userData.avatar()), oldUserData::avatar)) .build(); return Tuples.of(oldUserData, newUserData); }) .flatMap(tuple -> context.getStateHolder().getUserStore() .save(userId, tuple.getT2()) .thenReturn(tuple.getT1())) .map(userBean -> new User(gateway, userBean)) .map(Optional::of) .defaultIfEmpty(Optional.empty()); return saveUser.flatMap(oldUser -> context.getStateHolder().getPresenceStore() .find(key) .flatMap(saveNew::thenReturn) .map(old -> new PresenceUpdateEvent(gateway, context.getShardInfo(), guildId, oldUser.orElse(null), userData, current, new Presence(old))) .switchIfEmpty(saveNew.thenReturn(new PresenceUpdateEvent(gateway, context.getShardInfo(), guildId, oldUser.orElse(null), userData, current, null)))); }
Example #14
Source File: PresenceUpdateEvent.java From Discord4J with GNU Lesser General Public License v3.0 | 2 votes |
/** * Gets the current, new version of the {@link Presence}. * * @return The current, new version of the {@link Presence}. */ public Presence getCurrent() { return current; }
Example #15
Source File: PresenceUpdateEvent.java From Discord4J with GNU Lesser General Public License v3.0 | 2 votes |
/** * Gets the old version of the {@link Presence} that was changed, if present. * This may not be available if {@code Presence} are not stored. * * @return The old version of the {@link Presence}, if present. */ public Optional<Presence> getOld() { return Optional.ofNullable(old); }
Example #16
Source File: Member.java From Discord4J with GNU Lesser General Public License v3.0 | 2 votes |
/** * Requests to retrieve the presence for this user for this guild. * * @return A {@link Mono} where, upon successful completion, emits a {@link Presence presence} for this user for * this guild. If an error is received, it is emitted through the {@code Mono}. */ public Mono<Presence> getPresence() { return getClient().getGatewayResources().getStateView().getPresenceStore() .find(LongLongTuple2.of(getGuildId().asLong(), getId().asLong())) .map(Presence::new); }