use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class OsuStatsCmd method osustats.
@Command
public static void osustats(CommandRegistry cr) {
cr.register("osustats", new SimpleCommand(Category.GAMES) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
String noArgs = content.split(" ")[0];
TextChannelGround.of(event).dropItemWithChance(4, 5);
switch(noArgs) {
case "best":
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from osu! server...").queue(sentMessage -> {
Future<String> task = threadpool.submit(() -> best(content));
try {
sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
} catch (Exception e) {
if (e instanceof TimeoutException) {
task.cancel(true);
sentMessage.editMessage(EmoteReference.ERROR + "Request timeout. Maybe osu! API is slow?").queue();
} else
log.warn("Exception thrown while fetching data", e);
}
});
break;
case "recent":
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Retrieving information from server...").queue(sentMessage -> {
Future<String> task = threadpool.submit(() -> recent(content));
try {
sentMessage.editMessage(task.get(16, TimeUnit.SECONDS)).queue();
} catch (Exception e) {
if (e instanceof TimeoutException) {
task.cancel(true);
sentMessage.editMessage(EmoteReference.ERROR + "Request timeout. Maybe osu! API is slow?").queue();
} else
log.warn("Exception thrown while fetching data", e);
}
});
break;
case "user":
event.getChannel().sendMessage(user(content)).queue();
break;
default:
onError(event);
break;
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "osu! command").setDescription("**Retrieves information from the osu!API**.").addField("Usage", "`~>osustats best <player>` - **Retrieves best scores of the user specified in the specified gamemode**.\n" + "`~>osustats recent <player>` - **Retrieves recent scores of the user specified in the specified gamemode.**\n" + "`~>osustats user <player>` - **Retrieves information about a osu! player**.\n", false).addField("Parameters", "`player` - **The osu! player to look info for.**", false).build();
}
});
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class QuoteCmd method quote.
@Command
public static void quote(CommandRegistry cr) {
cr.register("quote", new SimpleCommand(Category.MISC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (content.isEmpty()) {
onHelp(event);
return;
}
String action = args[0];
String phrase = content.replace(action + " ", "");
Guild guild = event.getGuild();
ManagedDatabase db = MantaroData.db();
EmbedBuilder builder = new EmbedBuilder();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
List<Message> messageHistory;
try {
messageHistory = event.getChannel().getHistory().retrievePast(100).complete();
} catch (Exception e) {
if (e instanceof PermissionException) {
event.getChannel().sendMessage(EmoteReference.CRYING + "I don't have permission to do this :<").queue();
return;
}
event.getChannel().sendMessage(EmoteReference.ERROR + "It seems like discord is on fire, as my" + " " + "request to retrieve message history was denied" + "with the error `" + e.getClass().getSimpleName() + "`").queue();
log.warn("Shit exploded on Discord's backend. <@155867458203287552>", e);
return;
}
if (action.equals("addfrom")) {
Message message = messageHistory.stream().filter(msg -> msg.getContent().toLowerCase().contains(phrase.toLowerCase()) && !msg.getContent().startsWith(db.getGuild(guild).getData().getGuildCustomPrefix() == null ? MantaroData.config().get().getPrefix() : db.getGuild(guild).getData().getGuildCustomPrefix()) && !msg.getContent().startsWith(MantaroData.config().get().getPrefix())).findFirst().orElse(null);
if (message == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I couldn't find a message matching the specified search" + " criteria. Please try again with a more specific query.").queue();
return;
}
TextChannel channel = guild.getTextChannelById(message.getChannel().getId());
Quote quote = Quote.of(guild.getMember(message.getAuthor()), channel, message);
db.getQuotes(guild).add(quote);
event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
quote.saveAsync();
return;
}
if (action.equals("random")) {
try {
Quote quote = CollectionUtils.random(db.getQuotes(event.getGuild()));
event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "This server has no set quotes!").queue();
}
return;
}
if (action.equals("readfrom")) {
try {
List<Quote> quotes = db.getQuotes(guild);
for (int i2 = 0; i2 < quotes.size(); i2++) {
if (quotes.get(i2).getContent().contains(phrase)) {
Quote quote = quotes.get(i2);
event.getChannel().sendMessage(buildQuoteEmbed(dateFormat, builder, quote)).queue();
break;
}
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "I didn't find any quotes! (no quotes match the criteria).").queue();
}
return;
}
if (action.equals("removefrom")) {
try {
List<Quote> quotes = db.getQuotes(guild);
for (int i2 = 0; i2 < quotes.size(); i2++) {
if (quotes.get(i2).getContent().contains(phrase)) {
Quote quote = quotes.get(i2);
db.getQuotes(guild).remove(i2);
quote.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Removed quote with content: " + quote.getContent()).queue();
break;
}
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "No quotes match the criteria.").queue();
}
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Quote command").setDescription("**Quotes a message by search term.**").addField("Usage", "`~>quote addfrom <phrase>`- **Add a quote with the content defined by the specified number. For example, providing 1 will quote " + "the last message.**\n" + "`~>quote removefrom <phrase>` - **Remove a quote based on your text query.**\n" + "`~>quote readfrom <phrase>` - **Search for the first quote which matches your search criteria and prints " + "it.**\n" + "`~>quote random` - **Get a random quote.** \n", false).addField("Parameters", "`phrase` - A part of the quote phrase.", false).setColor(Color.DARK_GRAY).build();
}
});
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class UtilsCmds method dictionary.
@Command
public static void dictionary(CommandRegistry registry) {
registry.register("dictionary", new SimpleCommand(Category.UTILS) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You need to specify a word.").queue();
return;
}
String word = content;
JSONObject main;
String definition, part_of_speech, headword, example;
try {
main = Unirest.get("http://api.pearson.com/v2/dictionaries/laes/entries?headword=" + word).asJson().getBody().getObject();
JSONArray results = main.getJSONArray("results");
JSONObject result = results.getJSONObject(0);
JSONArray senses = result.getJSONArray("senses");
headword = result.getString("headword");
if (result.has("part_of_speech"))
part_of_speech = result.getString("part_of_speech");
else
part_of_speech = "Not found.";
if (senses.getJSONObject(0).get("definition") instanceof JSONArray)
definition = senses.getJSONObject(0).getJSONArray("definition").getString(0);
else
definition = senses.getJSONObject(0).getString("definition");
try {
if (senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).get("example") instanceof JSONArray) {
example = senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).getJSONArray("example").getJSONObject(0).getString("text");
} else {
example = senses.getJSONObject(0).getJSONArray("translations").getJSONObject(0).getJSONObject("example").getString("text");
}
} catch (Exception e) {
example = "Not found";
}
} catch (Exception e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "No results.").queue();
return;
}
EmbedBuilder eb = new EmbedBuilder();
eb.setAuthor("Definition for " + word, null, event.getAuthor().getAvatarUrl()).setThumbnail("https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Wikt_dynamic_dictionary_logo.svg/1000px-Wikt_dynamic_dictionary_logo.svg.png").addField("Definition", "**" + definition + "**", false).addField("Example", "**" + example + "**", false).setDescription(String.format("**Part of speech:** `%s`\n" + "**Headword:** `%s`\n", part_of_speech, headword));
event.getChannel().sendMessage(eb.build()).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Dictionary command").setDescription("**Looks up a word in the dictionary.**").addField("Usage", "`~>dictionary <word>` - Searches a word in the dictionary.", false).addField("Parameters", "`word` - The word to look for", false).build();
}
});
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class MoneyCmds method loot.
@Command
public static void loot(CommandRegistry cr) {
RateLimiter rateLimiter = new RateLimiter(TimeUnit.MINUTES, 5);
Random r = new Random();
cr.register("loot", new SimpleCommand(Category.CURRENCY) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
String id = event.getAuthor().getId();
Player player = MantaroData.db().getPlayer(event.getMember());
if (!rateLimiter.process(id)) {
event.getChannel().sendMessage(EmoteReference.STOPWATCH + "Cooldown a lil bit, you can only do this once every 5 minutes.\n **You'll be able to use this command again " + "in " + Utils.getVerboseTime(rateLimiter.tryAgainIn(event.getAuthor())) + ".**").queue();
return;
}
TextChannelGround ground = TextChannelGround.of(event);
if (r.nextInt(450) == 0) {
//1 in 450 chance of it dropping a loot crate.
ground.dropItem(Items.LOOT_CRATE);
}
List<ItemStack> loot = ground.collectItems();
int moneyFound = ground.collectMoney() + Math.max(0, r.nextInt(50) - 10);
if (MantaroData.db().getUser(event.getMember()).isPremium() && moneyFound > 0) {
moneyFound = moneyFound + random.nextInt(moneyFound);
}
if (!loot.isEmpty()) {
String s = ItemStack.toString(ItemStack.reduce(loot));
String overflow;
if (player.getInventory().merge(loot)) {
overflow = "But you already had too many items, so you decided to throw away the excess. ";
} else {
overflow = "";
}
if (moneyFound != 0) {
if (player.addMoney(moneyFound)) {
event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found " + s + ", along " + "with $" + moneyFound + " credits!" + overflow).queue();
} else {
event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found " + s + ", along " + "with $" + moneyFound + " credits. " + overflow + "But you already had too many credits. Your bag overflowed" + ".\nCongratulations, you exploded a Java long. Here's a buggy money bag for you.").queue();
}
} else {
event.getChannel().sendMessage(EmoteReference.MEGA + "Digging through messages, you found " + s + ". " + overflow).queue();
}
} else {
if (moneyFound != 0) {
if (player.addMoney(moneyFound)) {
event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found **$" + moneyFound + " credits!**").queue();
} else {
event.getChannel().sendMessage(EmoteReference.POPPER + "Digging through messages, you found $" + moneyFound + " credits. But you already had too many credits. Your bag overflowed.\nCongratulations, you exploded " + "a Java long. Here's a buggy money bag for you.").queue();
}
} else {
event.getChannel().sendMessage(EmoteReference.SAD + "Digging through messages, you found nothing but dust").queue();
}
}
player.save();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Loot command").setDescription("**Loot the current chat for items, for usage in Mantaro's currency system.**\n" + "Currently, there are ``" + Items.ALL.length + "`` items available in chance," + "in which you have a `random chance` of getting one or more.").addField("Usage", "~>loot", false).build();
}
});
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class ImageCmds method catgirls.
@Command
public static void catgirls(CommandRegistry cr) {
cr.register("catgirl", new SimpleCommand(Category.IMAGE) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
boolean nsfw = args.length > 0 && args[0].equalsIgnoreCase("nsfw");
if (nsfw && !nsfwCheck(event, true, true))
return;
try {
JSONObject obj = Unirest.get(nsfw ? NSFWURL : BASEURL).asJson().getBody().getObject();
if (!obj.has("url")) {
event.getChannel().sendMessage("Unable to find image").queue();
} else {
event.getChannel().sendFile(CACHE.getInput(obj.getString("url")), "catgirl.png", null).queue();
}
} catch (UnirestException e) {
e.printStackTrace();
event.getChannel().sendMessage("Unable to get image").queue();
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Catgirl command").setDescription("**Sends catgirl images**").addField("Usage", "`~>catgirl` - **Returns catgirl images.**" + "\n´`~>catgirl nsfw` - **Returns lewd or questionable cargirl images.**", false).build();
}
});
}
Aggregations