use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class MessageUtils method getDefaultEmbed.
public static EmbedBuilder getDefaultEmbed(User author) {
try {
final Random random = new Random();
final float hue = random.nextFloat();
final float saturation = (random.nextInt(2000) + 1000) / 10000f;
final float luminance = 2f;
final Color color = Color.getHSBColor(hue, saturation, luminance);
EmbedBuilder builder = new EmbedBuilder();
builder.setColor(color);
builder.setFooter("Requested by {0}".replace("{0}", author.getName() + "#" + author.getDiscriminator()), author.getAvatarUrl());
return builder;
} catch (Exception e) {
new BotException(e);
return null;
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class Music method getMusicEmbed.
private EmbedBuilder getMusicEmbed(Guild guild, User user) throws Exception {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(WordUtils.capitalize(getName()), getShard().url, guild.getSelfMember().getUser().getAvatarUrl());
return builder;
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class UD method noArgs.
@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
Shard shard = GuildUtils.getShard(guild);
if (args.length == 1) {
sendTranslatedMessage("Search a word's definition from Urban Dictionary. Example: {0}ud test".replace("{0}", GuildUtils.getPrefix(guild)), channel, user);
} else {
GetRequest getRequest = Unirest.get("http://api.urbandictionary.com/v0/define?term=" + message.getRawContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "").replaceAll(" ", "%20"));
String json = "";
try {
json = getRequest.asJson().getBody().toString();
} catch (UnirestException e) {
e.printStackTrace();
}
UrbanDictionary definition = shard.gson.fromJson(json, UrbanDictionary.class);
if (definition.getList().size() == 0) {
sendTranslatedMessage("There aren't any definitions for this word!", channel, user);
} else {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(message.getAuthor());
UDList list = definition.getList().get(0);
String def = "Definition";
String author = "Author";
String example = "Example";
String link = "Link";
String thumbsUp = "Thumbs Up";
String thumbsDown = "Thumbs Down";
String urbanDictionary = "Urban Dictionary";
builder.setAuthor(urbanDictionary, shard.bot.getAvatarUrl(), shard.bot.getAvatarUrl());
builder.setThumbnail("https://i.gyazo.com/6a40e32928743e68e9006396ee7c2a14.jpg");
builder.setColor(Color.decode("#00B7BE"));
String definitionText = list.getDefinition();
String exampleText = list.getExample();
if (definitionText.length() > 1024)
definitionText = definitionText.substring(0, 1023);
if (exampleText.length() > 1024)
exampleText = exampleText.substring(0, 1023);
builder.addField(def, definitionText, true);
builder.addField(example, exampleText, true);
builder.addField(thumbsUp, String.valueOf(list.getThumbsUp() + ":thumbsup:"), true);
builder.addField(thumbsDown, String.valueOf(list.getThumbsDown() + ":thumbsdown:"), true);
builder.addField(author, list.getAuthor(), true);
builder.addField(link, list.getPermalink(), true);
sendEmbed(builder, channel, user);
}
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class Blackjack method showResults.
public void showResults(int bet, Hand yourHand, Hand dealerHand, Guild guild, MessageChannel channel, User user, Message message, String[] args) {
try {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Blackjack | Game over", user.getEffectiveAvatarUrl(), user.getEffectiveAvatarUrl());
while (dealerHand.total() < 17) dealerHand.generate();
if (yourHand.total() > 21) {
builder.setDescription("You busted and lost {0} :frowning:".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).removeMoney(bet);
} else if (dealerHand.total() > 21) {
builder.setDescription("I busted! You won {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).addMoney(bet);
} else if (dealerHand.total() == yourHand.total())
builder.setDescription("We tied! You don't win or lose anything >.>");
else if (dealerHand.total() < yourHand.total()) {
builder.setDescription("You had a higher numbered hand than me! You win {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).addMoney(bet);
} else {
builder.setDescription("I had a higher numbered hand! You lose {0}".replace("{0}", RPGUtils.formatMoney(bet)));
Profile.get(user).removeMoney(bet);
}
builder.addField("Your hand", yourHand.readable(), true);
builder.addField("My hand", dealerHand.readable(), true);
sendEmbed(builder, channel, user);
sessions.remove(user.getId());
} catch (Exception e) {
new BotException(e);
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project Ardent by adamint.
the class RPGMoney method setupSubcommands.
@Override
public void setupSubcommands() throws Exception {
subcommands.add(new Subcommand("See who has the most money - globally!", "top", "top") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (args.length == 2) {
HashMap<User, Double> moneyAmounts = new HashMap<>();
Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).limit(20).run(connection);
top.forEach(hashMap -> {
Profile profile = asPojo(hashMap, Profile.class);
assert profile.getUser() != null;
moneyAmounts.put(profile.getUser(), profile.getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
String topMoney = "Global Richest Users";
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (u != null) {
description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
return;
}
try {
int page = Integer.parseInt(args[2]) - 1;
HashMap<User, Double> moneyAmounts = new HashMap<>();
Cursor<HashMap> top = r.db("data").table("profiles").orderBy().optArg("index", r.desc("money")).slice((page * 20), (page * 20) + 11).limit(25).run(connection);
top.forEach(hashMap -> {
Profile profile = asPojo(hashMap, Profile.class);
assert profile.getUser() != null;
moneyAmounts.put(profile.getUser(), profile.getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
String topMoney = "Global Richest Users | Page " + page;
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor(topMoney, getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (u != null) {
description.append("\n#" + ((page * 20) + current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
} catch (NumberFormatException e) {
sendTranslatedMessage("You need to specify a valid page number!", channel, user);
}
}
});
subcommands.add(new Subcommand("See who has the most money in your server", "server", "server", "guild", "topguild") {
@Override
public void onCall(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
if (!generatedFirstTimeFor.contains(guild.getId())) {
sendTranslatedMessage("Please wait a second, generating and caching your server's statistics", channel, user);
generatedFirstTimeFor.add(guild.getId());
}
HashMap<User, Double> moneyAmounts = new HashMap<>();
guild.getMembers().forEach(member -> {
User u = member.getUser();
moneyAmounts.put(u, Profile.get(u).getMoney());
});
Map<User, Double> sortedAmounts = MapUtils.sortByValue(moneyAmounts);
EmbedBuilder builder = MessageUtils.getDefaultEmbed(user);
builder.setAuthor("Richest Users | This Server", getShard().url, guild.getIconUrl());
StringBuilder description = new StringBuilder();
description.append("**Richest Users in this Server**");
final int[] current = { 0 };
sortedAmounts.forEach((u, money) -> {
if (current[0] < 10) {
description.append("\n#" + (current[0] + 1) + ": **" + u.getName() + "** " + RPGUtils.formatMoney(money));
current[0]++;
}
});
description.append("\n\nGet money by sending commands or asking questions on our support server ( https://ardentbot" + ".tk/guild )\n\nSee people's money by doing /money @User or see yours by just using /money");
sendEmbed(builder.setDescription(description.toString()), channel, user);
}
});
}
Aggregations