/** * Sets the provider that decides for all shards whether they should be marked as afk or not. * * <p>This will also change the provider for shards that are created in the future. * * @param idleProvider * boolean */ default void setIdleProvider(final IntFunction<Boolean> idleProvider) { this.getShardCache().forEach(jda -> jda.getPresence().setIdle(idleProvider.apply(jda.getShardInfo().getShardId()))); }
/** * Sets the provider that provides the {@link net.dv8tion.jda.core.OnlineStatus OnlineStatus} for all shards. * * <p>This will also change the provider for shards that are created in the future. * * @throws IllegalArgumentException * if the provided OnlineStatus is {@link net.dv8tion.jda.core.OnlineStatus#UNKNOWN UNKNOWN} * * @param statusProvider * the {@link net.dv8tion.jda.core.OnlineStatus OnlineStatus} * to be used (OFFLINE/null {@literal ->} INVISIBLE) */ default void setStatusProvider(final IntFunction<OnlineStatus> statusProvider) { this.getShardCache().forEach(jda -> jda.getPresence().setStatus(statusProvider.apply(jda.getShardInfo().getShardId()))); }
/** * Sets provider that provider the {@link net.dv8tion.jda.core.entities.Game Game} for all shards. * <br>A Game can be retrieved via {@link net.dv8tion.jda.core.entities.Game#playing(String)}. * For streams you provide a valid streaming url as second parameter. * * <p>This will also change the provider for shards that are created in the future. * * @param gameProvider * A {@link net.dv8tion.jda.core.entities.Game Game} instance or null to reset * * @see net.dv8tion.jda.core.entities.Game#playing(String) * @see net.dv8tion.jda.core.entities.Game#streaming(String, String) */ default void setGameProvider(final IntFunction<? extends Game> gameProvider) { this.getShardCache().forEach(jda -> jda.getPresence().setGame(gameProvider.apply(jda.getShardInfo().getShardId()))); }
public void resetGame() { Game game = config.getGame()==null || config.getGame().getName().equalsIgnoreCase("none") ? null : config.getGame(); if(!Objects.equals(jda.getPresence().getGame(), game)) jda.getPresence().setGame(game); }
/** * Updates the Bot's playing status * * @param status The game (you lost) */ public void setBotStatus(String status) { getJDA().getPresence().setGame(Game.playing(status)); }
private void setGameOnShards(BotContainer container, String status) { for (DiscordBot shard : container.getShards()) { shard.getJda().getPresence().setGame(Game.of(Game.GameType.DEFAULT, String.format(status, shard.getShardId()))); } }
@Override protected void execute(CommandEvent event) { String title = event.getArgs().toLowerCase().startsWith("playing") ? event.getArgs().substring(7).trim() : event.getArgs(); try { event.getJDA().getPresence().setGame(title.isEmpty() ? null : Game.playing(title)); event.reply(event.getClient().getSuccess()+" **"+event.getSelfUser().getName() +"** is "+(title.isEmpty() ? "no longer playing anything." : "now playing `"+title+"`")); } catch(Exception e) { event.reply(event.getClient().getError()+" The game could not be set!"); } }
@Override public void handle(AvaIre avaire) { if (hasCustomStatus || !avaire.areWeReadyYet()) { return; } if (index >= avaire.getConfig().getStringList("playing").size()) { index = 0; } String playing = avaire.getConfig().getStringList("playing").get(index); if (playing.trim().length() != 0) { for (JDA shard : avaire.getShardManager().getShards()) { shard.getPresence().setGame(getGameFromType(avaire, playing, shard)); } } else { avaire.getShardManager().setGame(null); } index++; }
public void onTrackUpdate(long guildId, AudioTrack track, AudioHandler handler) { // update bot status if applicable if(bot.getConfig().getSongInStatus()) { if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()<=1) bot.getJDA().getPresence().setGame(Game.listening(track.getInfo().title)); else bot.resetGame(); } // update channel topic if applicable updateTopic(guildId, handler, false); }
@Override protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { event.replyError("Please include a title to listen to!"); return; } String title = event.getArgs().toLowerCase().startsWith("to") ? event.getArgs().substring(2).trim() : event.getArgs(); try { event.getJDA().getPresence().setGame(Game.listening(title)); event.replySuccess("**"+event.getSelfUser().getName()+"** is now listening to `"+title+"`"); } catch(Exception e) { event.reply(event.getClient().getError()+" The game could not be set!"); } } }
@Override protected void execute(CommandEvent event) { try { OnlineStatus status = OnlineStatus.fromKey(event.getArgs()); if(status==OnlineStatus.UNKNOWN) { event.replyError("Please include one of the following statuses: `ONLINE`, `IDLE`, `DND`, `INVISIBLE`"); } else { event.getJDA().getPresence().setStatus(status); event.replySuccess("Set the status to `"+status.getKey().toUpperCase()+"`"); } } catch(Exception e) { event.reply(event.getClient().getError()+" The status could not be set!"); } } }
@Override protected void execute(CommandEvent event) { String[] parts = event.getArgs().split("\\s+", 2); if(parts.length<2) { event.replyError("Please include a twitch username and the name of the game to 'stream'"); return; } try { event.getJDA().getPresence().setGame(Game.streaming(parts[1], "https://twitch.tv/"+parts[0])); event.replySuccess("**"+event.getSelfUser().getName() +"** is now streaming `"+parts[1]+"`"); } catch(Exception e) { event.reply(event.getClient().getError()+" The game could not be set!"); } } }
@Override protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { event.replyError("Please include a title to watch!"); return; } String title = event.getArgs(); try { event.getJDA().getPresence().setGame(Game.watching(title)); event.replySuccess("**"+event.getSelfUser().getName()+"** is now watching `"+title+"`"); } catch(Exception e) { event.reply(event.getClient().getError()+" The game could not be set!"); } } }
public void initStuff(Boolean fake) { logger.info("MagiBridge is starting!"); Config = new ConfigManager(instance).loadConfig(); Task.builder().async().execute(() -> { this.initJDA(); Task.builder().execute(() -> { this.registerListeners(); if (!Config.MESSAGES.BOT_GAME_STATUS.isEmpty()) { jda.getPresence().setGame(Game.playing(Config.MESSAGES.BOT_GAME_STATUS)); } if (!fake) { DiscordHandler.init(); DiscordHandler.sendMessageToChannel(Config.CHANNELS.MAIN_CHANNEL, Config.MESSAGES.SERVER_STARTING); CommandHandler.registerBroadcastCommand(); if (updater != null) { if (updater.getState() == Thread.State.NEW) { updater.start(); } else { updater.interrupt(); updater = new TopicUpdater(); updater.start(); } } else { updater = new TopicUpdater(); updater.start(); } } }).submit(instance); }).submit(instance); }