use of net.dv8tion.jda.core.JDA in project MantaroBot by Mantaro.
the class MantaroShard method updateStatus.
void updateStatus() {
Runnable changeStatus = () -> {
AtomicInteger users = new AtomicInteger(0), guilds = new AtomicInteger(0);
if (MantaroBot.getInstance() != null) {
Arrays.stream(MantaroBot.getInstance().getShards()).map(MantaroShard::getJDA).forEach(jda -> {
users.addAndGet(jda.getUsers().size());
guilds.addAndGet(jda.getGuilds().size());
});
}
String newStatus = random(SPLASHES.get(), RANDOM).replace("%ramgb%", String.valueOf(((long) (Runtime.getRuntime().maxMemory() * 1.2D)) >> 30L)).replace("%usercount%", users.toString()).replace("%guildcount%", guilds.toString()).replace("%shardcount%", String.valueOf(getTotalShards())).replace("%prettyusercount%", pretty(users.get())).replace("%prettyguildcount%", pretty(guilds.get()));
getJDA().getPresence().setGame(Game.of(config().get().prefix + "help | " + newStatus + " | [" + getId() + "]"));
log.debug("Changed status to: " + newStatus);
};
changeStatus.run();
Async.task("Splash Thread", changeStatus, 600, TimeUnit.SECONDS);
}
use of net.dv8tion.jda.core.JDA in project MantaroBot by Mantaro.
the class MantaroListener method logStatusChange.
private void logStatusChange(StatusChangeEvent event) {
JDA jda = event.getJDA();
if (jda.getShardInfo() == null)
return;
if (event.getStatus().equals(JDA.Status.CONNECTED)) {
MantaroBot.getInstance().getStatsClient().increment("shard.connect");
MantaroBot.getInstance().getStatsClient().recordEvent(com.timgroup.statsd.Event.builder().withTitle("shard.connected").withText("Shard connected").withDate(new Date()).build());
}
log.info(String.format("Shard #%d: Changed from %s to %s", jda.getShardInfo().getShardId(), event.getOldStatus(), event.getStatus()));
}
use of net.dv8tion.jda.core.JDA in project FlareBot by FlareBot.
the class StatusCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
int quaterShards = Getters.getShards().size() / 4;
double ping = Getters.getShards().stream().mapToLong(JDA::getPing).average().orElse(-1);
int deadShard = 0;
int reconnecting = 0;
int connecting = 0;
int noVoiceConnections = 0;
int highResponseTime = 0;
for (int shardId = 0; shardId < Getters.getShards().size(); shardId++) {
JDA jda = ShardUtils.getShardById(shardId);
if (jda == null) {
connecting++;
continue;
}
boolean reconnect = ShardUtils.isReconnecting(shardId);
if (ShardUtils.isDead(shardId))
deadShard++;
if (reconnect)
reconnecting++;
if (jda.getVoiceChannelCache().stream().noneMatch(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())))
noVoiceConnections++;
if (ShardUtils.getLastEventTime(shardId) >= 1500 && !reconnect)
highResponseTime++;
}
StringBuilder sb = new StringBuilder();
if (reconnecting > Math.min(quaterShards, 10))
sb.append("⚠ WARNING: A lot of shards are currently reconnecting! This could mean the bot is unable to be " + "used on several thousand servers for a few minutes! (").append(reconnecting).append(" shards reconnecting)").append("\n");
if (highResponseTime > Math.min(quaterShards, 20))
sb.append("⚠ WARNING: We seem to be experiencing a high event time on quite a few shards, this is usually " + "down to discord not wanting to co-op with us :( please be patient while these ").append(highResponseTime).append(" shards go back to normal!").append("\n");
if (deadShard > 5)
sb.append(" SEVERE: We have quite a few dead shards! Please report this on the [Support Server](").append(Constants.INVITE_URL).append(")").append("\n");
String status = deadShard == 0 && highResponseTime == 0 && reconnecting < (Math.max(quaterShards, 5)) ? "Good! :)" : "Issues :/";
if (deadShard > 5)
status = "Severe issues! Discord could be dying! @EVERYONE RUN!";
sb.append("Bot Status: ").append(status).append("\n\n");
sb.append(String.format("FlareBot Version: %s\n" + "JDA Version: %s\n" + "Current Shard: %s\n" + "* Average Ping: %s\n" + "* Ping By Shard: %s\n" + "* Dead Shards: %s shards\n" + "* No Voice Connections: %s shards\n" + "* Shards Reconnecting: %s shards\n" + "* Shards Connecting: %s shards\n" + "* High Last Event Time: %s shards\n" + "Guilds: %d | Users: %d | Connected VCs: %d | Active VCs: %d", FlareBot.getVersion(), JDAInfo.VERSION, channel.getJDA().getShardInfo() == null ? 0 : channel.getJDA().getShardInfo().getShardId(), ping, Arrays.toString(ShardUtils.getPingsForShards()), deadShard, noVoiceConnections, reconnecting, connecting, highResponseTime, Getters.getGuildCache().size(), Getters.getUserCache().size(), Getters.getConnectedVoiceChannels(), Getters.getActiveVoiceChannels()));
channel.sendMessage("**FlareBot's Status**\n```prolog\n" + sb.toString() + "\n```").queue();
}
use of net.dv8tion.jda.core.JDA in project Rubicon by Rubicon-Bot.
the class CommandPortal method closePortal.
private void closePortal(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
JDA jda = parsedCommandInvocation.getMessage().getJDA();
Guild messageGuild = parsedCommandInvocation.getMessage().getGuild();
TextChannel messageChannel = parsedCommandInvocation.getMessage().getTextChannel();
// Check if portal exists
String oldGuildPortalEntry = RubiconBot.getMySQL().getGuildValue(messageGuild, "portal");
if (oldGuildPortalEntry.equals("closed")) {
messageChannel.sendMessage(EmbedUtil.error("Portal error!", "Portal is already closed").build()).queue();
return;
}
if (oldGuildPortalEntry.equals("waiting")) {
RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
messageChannel.sendMessage(EmbedUtil.success("Portal", "Successful closed portal request.").build()).queue();
return;
}
Guild partnerGuild = jda.getGuildById(RubiconBot.getMySQL().getPortalValue(messageGuild, "partnerid"));
// Close Channels
TextChannel channelOne = null;
TextChannel channelTwo = null;
try {
channelOne = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(messageGuild, "channelid"));
channelTwo = jda.getTextChannelById(RubiconBot.getMySQL().getPortalValue(partnerGuild, "channelid"));
} catch (NullPointerException ignored) {
// Channels doesn't exist
}
if (channelOne != null)
channelOne.getManager().setName(closedChannelName).queue();
if (channelTwo != null)
channelTwo.getManager().setName(closedChannelName).queue();
// Close and delete DB Portal
RubiconBot.getMySQL().updateGuildValue(messageGuild, "portal", "closed");
RubiconBot.getMySQL().deletePortal(messageGuild);
RubiconBot.getMySQL().updateGuildValue(partnerGuild, "portal", "closed");
RubiconBot.getMySQL().deletePortal(partnerGuild);
EmbedBuilder portalClosedMessage = new EmbedBuilder();
portalClosedMessage.setAuthor("Portal closed!", null, jda.getSelfUser().getEffectiveAvatarUrl());
portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
portalClosedMessage.setColor(Colors.COLOR_ERROR);
channelOne.sendMessage(portalClosedMessage.build()).queue();
portalClosedMessage.setDescription("Portal was closed. Create a new one with `" + parsedCommandInvocation.getPrefix() + "portal create`");
channelTwo.sendMessage(portalClosedMessage.build()).queue();
channelOne.getManager().setTopic("Portal closed").queue();
channelTwo.getManager().setTopic("Portal closed").queue();
}
use of net.dv8tion.jda.core.JDA in project SkyBot by duncte123.
the class ShardInfoCommand method executeCommand.
@Override
public void executeCommand(@NotNull String invoke, @NotNull String[] args, @NotNull GuildMessageReceivedEvent event) {
List<String> headers = new ArrayList<>();
headers.add("Shard ID");
headers.add("Status");
headers.add("Ping");
headers.add("Guild Count");
headers.add("Connected VCs");
List<List<String>> table = new ArrayList<>();
List<JDA> shards = new ArrayList<>(event.getJDA().asBot().getShardManager().getShards());
Collections.reverse(shards);
for (JDA jda : shards) {
List<String> row = new ArrayList<>();
row.add((jda.getShardInfo().getShardId() + 1) + (event.getJDA().getShardInfo().getShardId() == jda.getShardInfo().getShardId() ? " (current)" : ""));
row.add(WordUtils.capitalizeFully(jda.getStatus().toString().replace("_", " ")));
row.add(String.valueOf(jda.getPing()));
row.add(String.valueOf(jda.getGuilds().size()));
row.add(String.valueOf(jda.getVoiceChannels().stream().filter(vc -> vc.getMembers().contains(vc.getGuild().getSelfMember())).count()));
table.add(row);
if (table.size() == 20) {
MessageUtils.sendMsg(event, makeAsciiTable(headers, table));
table = new ArrayList<>();
}
}
if (table.size() > 0) {
MessageUtils.sendMsg(event, makeAsciiTable(headers, table));
}
}
Aggregations