use of net.dv8tion.jda.core.JDA in project FlareBot by FlareBot.
the class BotMetrics method count.
public boolean count() {
if (FlareBot.instance().getShardManager() == null)
return false;
for (JDA jda : Getters.getShards()) {
if (jda.getStatus() != JDA.Status.CONNECTED)
return false;
}
this.guildCount = Getters.getGuildCache().size();
this.userCount = Getters.getUserCache().size();
this.textChannelCount = Getters.getTextChannelCache().size();
this.voiceChannelCount = Getters.getVoiceChannelCache().size();
return true;
}
use of net.dv8tion.jda.core.JDA in project FlareBot by FlareBot.
the class FlareBot method postToBotList.
// TODO: Spread this out a little so we don't just burst.
private void postToBotList(String auth, String url) {
for (JDA client : shardManager.getShards()) {
if (shardManager.getShardsTotal() == 1) {
Request.Builder request = new Request.Builder().url(url).addHeader("Authorization", auth).addHeader("User-Agent", "Mozilla/5.0 FlareBot");
RequestBody body = RequestBody.create(WebUtils.APPLICATION_JSON, new JSONObject().put("server_count", client.getGuilds().size()).toString());
WebUtils.postAsync(request.post(body));
return;
}
try {
Request.Builder request = new Request.Builder().url(url).addHeader("Authorization", auth).addHeader("User-Agent", "Mozilla/5.0 FlareBot");
RequestBody body = RequestBody.create(WebUtils.APPLICATION_JSON, (new JSONObject().put("server_count", client.getGuilds().size()).put("shard_id", client.getShardInfo().getShardId()).put("shard_count", client.getShardInfo().getShardTotal()).toString()));
WebUtils.postAsync(request.post(body));
// Gonna spread these out just a bit so we don't burst (insert shard number here) requests all at once
Thread.sleep(20_000);
} catch (Exception e1) {
FlareBot.LOGGER.error("Could not POST data to a botlist", e1);
}
}
LOGGER.debug("Sent " + shardManager.getShardsTotal() + " requests to " + url);
}
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));
}
}
use of net.dv8tion.jda.core.JDA in project SkyBot by duncte123.
the class FakeTest method medium.
/**
* Test medium
* Mock Lists, don't share objects
*/
@Test
public void medium() {
Member member = new FakeInterface<>(Member.class).create();
JDA jda = member.getJDA();
assertNotEquals(jda, member.getJDA());
assertNotEquals(jda.getGuildById(member.getGuild().getId()), member.getGuild());
assertEquals(jda.getGuilds(), new ArrayList<>());
}
Aggregations