use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class ServerInfoCommand method sendGuildInfo.
private void sendGuildInfo(Guild guild, TextChannel channel) {
EmbedBuilder eb = new EmbedBuilder();
eb.setTitle(guild.getName());
eb.setThumbnail(guild.getIconUrl());
eb.addField("Users", "**Total:** " + guild.getMembers().size() + "\n" + "\n" + "**Online:** " + guild.getMembers().stream().filter(member -> !member.getOnlineStatus().equals(OnlineStatus.OFFLINE)).count() + "\n" + "\n" + "**Owner:** " + MessageUtils.getTag(guild.getOwner().getUser()), true);
String afk = guild.getAfkChannel() == null ? "" : "**AFK:**\n" + "Channel: " + guild.getAfkChannel().getName() + "\n" + "\n" + "Timeout: " + FormatUtils.formatTime(guild.getAfkTimeout().getSeconds(), TimeUnit.SECONDS, true, false);
eb.addField("Channels", "**Text**\n" + "Total: " + guild.getTextChannels().size() + "\n" + "\n" + "**Voice**\n" + "Total: " + guild.getVoiceChannels().size() + "\n" + "\n" + "Active: " + guild.getVoiceChannels().stream().filter(voiceChannel -> voiceChannel.getMembers().size() > 0).count() + "\n" + "\n" + afk, true);
eb.addField("Misc info", "**Creation time:** " + guild.getCreationTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " UTC\n" + "\n" + "**Roles:** " + guild.getRoles().size() + "\n" + "\n" + "**Server region:** " + guild.getRegion().getName() + "\n" + "\n" + "**Verification Level:** " + GeneralUtils.getVerificationString(guild.getVerificationLevel()), true);
eb.setFooter("ID: " + guild.getId(), null);
eb.setColor(Color.CYAN);
channel.sendMessage(eb.build()).queue();
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class QueryCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
try {
CassandraController.runUnsafeTask(conn -> {
ResultSet set = conn.execute(MessageUtils.getMessage(args, 0));
List<String> header = new ArrayList<>();
List<List<String>> table = new ArrayList<>();
int columnsCount = set.getColumnDefinitions().size();
for (int i = 0; i < columnsCount; i++) {
header.add(set.getColumnDefinitions().getName(i));
}
for (Row setRow : set) {
List<String> row = new ArrayList<>();
for (int i = 0; i < columnsCount; i++) {
String value = setRow.getObject(i).toString();
row.add(value.substring(0, Math.min(30, value.length())));
}
table.add(row);
}
String output = MessageUtils.makeAsciiTable(header, table, null);
if (output.length() < 2000) {
channel.sendMessage(output).queue();
} else {
MessageUtils.sendErrorMessage("The query result set was very large, it has been posted to paste [here](" + MessageUtils.paste(output) + ")", channel, sender);
}
});
} catch (QueryExecutionException | QueryValidationException e) {
EmbedBuilder eb = new EmbedBuilder();
eb.setTitle("Failed to execute query");
eb.addField("Error", "```\n" + e.getMessage() + "\n```", false);
channel.sendMessage(eb.build()).queue();
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class PostUpdateCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) {
if (guild.getGuildId().equals("226785954537406464") && PerGuildPermissions.isStaff(sender)) {
if (args.length == 0) {
channel.sendMessage("You kinda need like.... a message to announce... like yeah...").queue();
return;
}
Role r = guild.getGuild().getRoleById(320304080926801922L);
r.getManager().setMentionable(true).queue(aVoid -> {
if (args[0].startsWith("pr:")) {
channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3)).build()).append(r.getAsMention()).build()).queue(bVoid -> channel.sendMessage("make sure to report any bugs over to be <#242206261767176192> channel " + "and if you need any support we're happy to help over in the <#226786463440699392> " + "channel!").queue());
} else {
String message = msg.getContentRaw();
message = message.substring(message.indexOf(" ") + 1);
channel.sendMessage(new MessageBuilder().setContent(r.getAsMention()).setEmbed(new EmbedBuilder().setTitle("Some announcement thing!").setDescription(message).setFooter("Announcement by " + member.getEffectiveName(), sender.getEffectiveAvatarUrl()).build()).build()).complete();
}
});
r.getManager().setMentionable(false).queue();
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class PlaylistsCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("mark")) {
if (getPermissions(channel).isCreator(sender)) {
if (args.length == 1 || args.length == 2) {
MessageUtils.sendUsage(this, channel, sender, args);
} else {
String playlist = MessageUtils.getMessage(args, 2);
CassandraController.runTask(session -> {
ResultSet set = session.execute(session.prepare("SELECT playlist_name FROM flarebot.playlist WHERE " + "guild_id = ? AND playlist_name = ?").bind().setString(0, channel.getGuild().getId()).setString(1, playlist));
if (set.one() != null) {
if (args[1].equalsIgnoreCase("global") || args[1].equalsIgnoreCase("local")) {
session.execute(session.prepare("UPDATE flarebot.playlist SET " + "scope = ? WHERE guild_id = ? AND playlist_name = ?").bind().setString(0, args[1].toLowerCase()).setString(1, channel.getGuild().getId()).setString(2, playlist));
channel.sendMessage(MessageUtils.getEmbed().setDescription("Changed the scope of '" + playlist + "' to " + args[1].toLowerCase()).build()).queue();
} else {
MessageUtils.sendErrorMessage("Invalid scope! Scopes are local and global!", channel);
}
} else {
MessageUtils.sendErrorMessage("That playlist could not be found!", channel);
}
});
}
}
}
} else {
channel.sendTyping().complete();
CassandraController.runTask(session -> {
ResultSet set = session.execute("SELECT playlist_name, scope FROM flarebot.playlist WHERE " + "scope = 'global' ALLOW FILTERING");
ArrayList<Row> tmp = new ArrayList<>(set.all());
set = session.execute("SELECT playlist_name, scope FROM flarebot.playlist WHERE " + "guild_id = '" + channel.getGuild().getId() + "' AND scope = 'local' ALLOW FILTERING");
tmp.addAll(set.all());
StringBuilder sb = new StringBuilder();
StringBuilder globalSb = new StringBuilder();
List<String> songs = new ArrayList<>();
int i = 1;
boolean loopingGlobal = true;
Iterator<Row> rows = tmp.iterator();
while (rows.hasNext() && songs.size() < 25) {
Row row = rows.next();
String toAppend;
if (row.getString("scope").equalsIgnoreCase("global")) {
toAppend = String.format("%s. %s\n", i++, MessageUtils.escapeMarkdown(row.getString("playlist_name")));
globalSb.append(toAppend);
} else {
if (loopingGlobal) {
loopingGlobal = false;
i = 1;
}
toAppend = String.format("%s. %s\n", i++, MessageUtils.escapeMarkdown(row.getString("playlist_name")));
if (sb.length() + toAppend.length() > 1024) {
songs.add(sb.toString());
sb = new StringBuilder();
}
sb.append(toAppend);
}
}
songs.add(sb.toString());
EmbedBuilder builder = MessageUtils.getEmbed(sender);
i = 1;
builder.addField("Global Playlists", (globalSb.toString().isEmpty() ? "No global playlists!" : globalSb.toString()), false);
for (String s : songs) {
builder.addField("Page " + i++, s.isEmpty() ? "**No playlists!**" : s, false);
}
channel.sendMessage(builder.build()).queue();
});
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class RepeatCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
Player player = FlareBot.instance().getMusicManager().getPlayer(channel.getGuild().getId());
if (player.getPlayingTrack() == null) {
MessageUtils.sendErrorMessage("Can't repeat when their is no song to repeat!", channel);
} else {
Queue<Track> queue = new ConcurrentLinkedQueue<>();
queue.add(player.getPlayingTrack().makeClone());
queue.addAll(player.getPlaylist());
player.getPlaylist().clear();
player.getPlaylist().addAll(queue);
channel.sendMessage(new EmbedBuilder().setColor(Color.green).setDescription("The player will now repeat the current track!").build()).queue();
}
}
Aggregations