use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class Stats method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("See what commands are being used", "commands", "commands") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
StringBuilder commandBars = new StringBuilder();
Map<String, Long> commandsUsed = getCommandData(ShardManager.getShards());
final int[] counter = { 0 };
final int[] totalCommandsReceived = { 0 };
commandsUsed.forEach((key, value) -> {
if (counter[0] < 7)
totalCommandsReceived[0] += value;
counter[0]++;
});
counter[0] = 0;
commandsUsed.forEach((key, value) -> {
if (counter[0] < 7) {
int percent = (int) (value * 100 / totalCommandsReceived[0]);
String bar = bar(percent);
if (bar != null) {
commandBars.append(bar + " " + percent + "% **" + key + "**\n");
}
}
counter[0]++;
});
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Command Statistics", getShard().url, getShard().bot.getAvatarUrl());
builder.setColor(Color.GREEN);
builder.setDescription("Command Usage\n" + commandBars.toString());
sendEmbed(builder, channel, user);
}
});
subcommands.add(new Subcommand("See how many server's I'm joining and leaving", "guilds") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Guild Statistics", getShard().url, getShard().bot.getAvatarUrl());
builder.setColor(Color.GREEN);
int lPH = 0;
int lPD = 0;
int lPS = 0;
long epochSecond = Instant.now().getEpochSecond();
long hBar = epochSecond - (60 * 60);
long dBar = epochSecond - (60 * 60 * 24);
long sBar = 0;
for (Instant i : Leave.botLeaveEvents) {
if (i.getEpochSecond() >= hBar)
lPH++;
if (i.getEpochSecond() >= dBar)
lPD++;
// Always true
if (i.getEpochSecond() >= sBar)
lPS++;
}
int jPH = 0;
int jPD = 0;
int jPS = 0;
for (Instant i : Join.botJoinEvents) {
if (i.getEpochSecond() >= hBar)
jPH++;
if (i.getEpochSecond() >= dBar)
jPD++;
// Always true
if (i.getEpochSecond() >= sBar)
jPS++;
}
builder.addField("Hourly", generateGuild(jPH, lPH), false);
builder.addField("Daily", generateGuild(jPD, lPD), false);
builder.addField("This Session", generateGuild(jPS, lPS), false);
builder.addField("Guilds", String.valueOf(InternalStats.collect().getGuilds()), false);
sendEmbed(builder, channel, user);
}
});
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class Iam method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("See a list of setup Iams", "view", "view") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Shard shard = GuildUtils.getShard(guild);
String title = "Auto Roles | /iam";
String givesYouRole = "will give you the role";
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(title, shard.url, shard.bot.getAvatarUrl());
StringBuilder msg = new StringBuilder();
msg.append("**" + title + "**");
for (Pair<String, Role> autorole : getAutoRoles(guild)) {
String roleName;
Role role = autorole.getV();
if (role == null)
roleName = "deleted-role";
else
roleName = role.getName();
msg.append("\n**" + autorole.getK() + "** " + givesYouRole + " **" + roleName + "**");
}
msg.append("\n\nAdd an autorole by doing /iam role and going through the setup wizard");
builder.setDescription(msg.toString());
sendEmbed(builder, channel, user);
}
});
subcommands.add(new Subcommand("Give yourself an autorole", "role", "role") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length > 2) {
String query = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
boolean found = false;
ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
for (Pair<String, Role> rolePair : autoroles) {
if (rolePair.getK().equalsIgnoreCase(query)) {
found = true;
Role role = rolePair.getV();
if (role == null)
sendTranslatedMessage("Hmm.. there's no role for this", channel, user);
else {
boolean failure = false;
try {
guild.getController().addRolesToMember(guild.getMember(user), role).queue();
} catch (Exception ex) {
failure = true;
sendTranslatedMessage("Please make sure I can add roles", channel, user);
}
if (!failure)
sendTranslatedMessage("Successfully gave you the role {0}".replace("{0}", role.getName()), channel, user);
}
}
}
if (!found)
sendTranslatedMessage("An autorole with that name wasn't found", channel, user);
} else
sendTranslatedMessage("You need to include an autorole name", channel, user);
}
});
subcommands.add(new Subcommand("Remove autoroles", "remove", "remove") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (UserUtils.hasManageServerOrStaff(guild.getMember(user))) {
String query = message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " " + args[1] + " ", "");
boolean found = false;
ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
for (Pair<String, Role> rolePair : autoroles) {
if (rolePair.getK().equalsIgnoreCase(query)) {
found = true;
r.db("data").table("autoroles").filter(row -> row.g("name").eq(query).and(row.g("guild_id").eq(guild.getId()))).delete().run(connection);
sendTranslatedMessage("Deleted the autorole **{0}**".replace("{0}", rolePair.getK()), channel, user);
}
}
if (!found)
sendTranslatedMessage("An autorole with that name wasn't found", channel, user);
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
subcommands.add(new Subcommand("Add an autorole", "add", "add") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) {
if (UserUtils.hasManageServerOrStaff(guild.getMember(user))) {
sendTranslatedMessage("Type the name of the autorole you want to add", channel, user);
interactiveOperation(channel, message, nameMessage -> {
String name = nameMessage.getContent();
sendTranslatedMessage("Type the name of the **discord role** you want this set to", channel, user);
interactiveOperation(channel, message, roleMessage -> {
try {
String role = roleMessage.getRawContent();
boolean found = false;
ArrayList<Pair<String, Role>> autoroles = getAutoRoles(guild);
for (Pair<String, Role> rolePair : autoroles) {
if (rolePair.getK().equalsIgnoreCase(name)) {
found = true;
}
}
if (found)
sendTranslatedMessage("An autorole with that name is already setup", channel, user);
else {
List<Role> roleList = guild.getRolesByName(role, true);
if (roleList.size() > 0) {
Role toAdd = roleList.get(0);
r.table("autoroles").insert(r.json(gson.toJson(new AutoroleModel(guild.getId(), name, toAdd.getId())))).run(connection);
sendTranslatedMessage("Successfully added autorole **{0}** which gives the role **{1}**".replace("{0}", name).replace("{1}", role), channel, user);
} else
sendTranslatedMessage("An role with that name wasn't found", channel, user);
}
} catch (Exception e) {
new BotException(e);
}
});
});
} else
sendTranslatedMessage("You need the Manage Server permission to use this command", channel, user);
}
});
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class TriviaGame method displayScores.
public EmbedBuilder displayScores(Shard shard, Command command) throws Exception {
Map<String, Integer> sorted = MapUtils.sortByValue(scores);
Guild guild = shard.jda.getGuildById(guildId);
EmbedBuilder builder = MessageUtils.getDefaultEmbed(guild.getSelfMember().getUser());
String currentScores = "Current Scores";
if (solo)
builder.setAuthor(currentScores + " | Solo Game", shard.url, guild.getIconUrl());
else
builder.setAuthor(currentScores + " | Everyone can play", shard.url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
description.append("**" + currentScores + "**");
Iterator<Map.Entry<String, Integer>> iterator = sorted.entrySet().iterator();
int currentPlace = 1;
while (iterator.hasNext()) {
Map.Entry<String, Integer> entry = iterator.next();
description.append("\n#" + currentPlace + ": **" + shard.jda.getUserById(entry.getKey()).getName() + "** " + entry.getValue() + " points");
currentPlace++;
}
if (currentPlace == 1) {
description.append("\nNo one has gotten a question right so far!");
}
description.append("\n\nCurrent Round: " + round);
return builder.setDescription(description.toString());
}
Aggregations