discord4j.core.object.presence.Activity Java Examples

The following examples show how to use discord4j.core.object.presence.Activity. 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: StatusChanger.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #2
Source File: StatusChanger.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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: DisCalClient.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 #4
Source File: ReadyListener.java    From KaellyBot with GNU General Public License v3.0 5 votes vote down vote up
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 #5
Source File: ShadbotUtils.java    From Shadbot with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @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 #6
Source File: DisCalClient.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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();
}