use of net.dv8tion.jda.core.EmbedBuilder in project MOOTBoot by LeshDev.
the class clock method onMessageReceived.
public void onMessageReceived(MessageReceivedEvent e) {
Message msg = e.getMessage();
if (!msg.getRawContent().toLowerCase().startsWith("-clock") || bannedList.black.contains(e.getAuthor().getIdLong()) || e.getAuthor().isBot() || !permittedList.perm.contains(e.getAuthor().getIdLong())) {
return;
}
EmbedBuilder eB = new EmbedBuilder();
eB.setTitle("Time");
eB.setColor(lib.randomColor());
eB.setDescription(currentTime());
e.getChannel().sendMessage(eB.build()).queue(sentMsg -> {
if (msg.getRawContent().contains("temp")) {
sentMsg.delete().queueAfter(5, SECONDS);
msg.delete().queue();
}
});
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class CustomCmds method custom.
@Command
public static void custom(CommandRegistry cr) {
String any = "[\\d\\D]*?";
cr.register("custom", new SimpleCommand(Category.UTILS) {
@Override
public void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length < 1) {
onHelp(event);
return;
}
String action = args[0];
if (action.equals("list") || action.equals("ls")) {
String filter = event.getGuild().getId() + ":";
List<String> commands = customCommands.keySet().stream().filter(s -> s.startsWith(filter)).map(s -> s.substring(filter.length())).collect(Collectors.toList());
EmbedBuilder builder = new EmbedBuilder().setAuthor("Commands for this guild", null, event.getGuild().getIconUrl()).setColor(event.getMember().getColor());
builder.setDescription(commands.isEmpty() ? "There is nothing here, just dust." : forType(commands));
event.getChannel().sendMessage(builder.build()).queue();
return;
}
if (db().getGuild(event.getGuild()).getData().isCustomAdminLock() && !CommandPermission.ADMIN.test(event.getMember())) {
event.getChannel().sendMessage("This guild only accepts custom commands from administrators.").queue();
return;
}
if (action.equals("clear")) {
if (CommandPermission.ADMIN.test(event.getMember())) {
event.getChannel().sendMessage(EmoteReference.ERROR + "You cannot do that, silly.").queue();
return;
}
List<CustomCommand> customCommands = db().getCustomCommands(event.getGuild());
if (customCommands.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's no Custom Commands registered in this Guild.").queue();
}
int size = customCommands.size();
customCommands.forEach(CustomCommand::deleteAsync);
customCommands.forEach(c -> CustomCmds.customCommands.remove(c.getId()));
event.getChannel().sendMessage(EmoteReference.PENCIL + "Cleared **" + size + " Custom Commands**!").queue();
return;
}
if (args.length < 2) {
onHelp(event);
return;
}
String cmd = args[1];
if (action.equals("make")) {
if (!NAME_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
List<String> responses = new ArrayList<>();
boolean created = InteractiveOperations.create(event.getChannel(), "Custom Command Creation", 60000, OptionalInt.of(60000), e -> {
if (!e.getAuthor().equals(event.getAuthor()))
return false;
String c = e.getMessage().getRawContent();
if (!c.startsWith("&"))
return false;
c = c.substring(1);
if (c.startsWith("~>cancel") || c.startsWith("~>stop")) {
event.getChannel().sendMessage(EmoteReference.CORRECT + "Command Creation canceled.").queue();
return true;
}
if (c.startsWith("~>save")) {
String arg = c.substring(6).trim();
String saveTo = !arg.isEmpty() ? arg : cmd;
if (!NAME_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return false;
}
if (CommandProcessor.REGISTRY.commands().containsKey(saveTo) && !CommandProcessor.REGISTRY.commands().get(saveTo).equals(customCommand)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "A command already exists with this name!").queue();
return false;
}
if (responses.isEmpty()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "No responses were added. Stopping creation without saving...").queue();
} else {
CustomCommand custom = CustomCommand.of(event.getGuild().getId(), cmd, responses);
custom.saveAsync();
customCommands.put(custom.getId(), custom.getValues());
CommandProcessor.REGISTRY.commands().put(cmd, customCommand);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Saved to command ``" + cmd + "``!").queue();
TextChannelGround.of(event).dropItemWithChance(8, 2);
}
return true;
}
responses.add(c);
e.getMessage().addReaction(EmoteReference.CORRECT.getUnicode()).queue();
return false;
});
if (created) {
event.getChannel().sendMessage(EmoteReference.PENCIL + "Started **\"Creation of Custom Command ``" + cmd + "``\"**!\nSend ``&~>stop`` to stop creation **without saving**.\nSend ``&~>save`` to stop creation an **save the new Command**. Send any text beginning with ``&`` to be added to the Command Responses.\nThis Interactive Operation ends without saving after 60 seconds of inactivity.").queue();
} else {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's already an Interactive Operation happening on this channel.").queue();
}
return;
}
if (action.equals("remove") || action.equals("rm")) {
if (!NAME_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
CustomCommand custom = db().getCustomCommand(event.getGuild(), cmd);
if (custom == null) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "There's no Custom Command ``" + cmd + "`` in this Guild.").queue();
return;
}
//delete at DB
custom.deleteAsync();
//reflect at local
customCommands.remove(custom.getId());
//clear commands if none
if (customCommands.keySet().stream().noneMatch(s -> s.endsWith(":" + cmd)))
CommandProcessor.REGISTRY.commands().remove(cmd);
event.getChannel().sendMessage(EmoteReference.PENCIL + "Removed Custom Command ``" + cmd + "``!").queue();
return;
}
if (action.equals("raw")) {
if (!NAME_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
CustomCommand custom = db().getCustomCommand(event.getGuild(), cmd);
if (custom == null) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "There's no Custom Command ``" + cmd + "`` in this Guild.").queue();
return;
}
Pair<String, Integer> pair = DiscordUtils.embedList(custom.getValues(), Object::toString);
event.getChannel().sendMessage(baseEmbed(event, "Command ``" + cmd + "``:").setDescription(pair.getLeft()).setFooter("(Showing " + pair.getRight() + " responses of " + custom.getValues().size() + ")", null).build()).queue();
return;
}
if (action.equals("import")) {
if (!NAME_WILDCARD_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
Map<String, Guild> mapped = MantaroBot.getInstance().getMutualGuilds(event.getAuthor()).stream().collect(Collectors.toMap(ISnowflake::getId, g -> g));
List<Pair<Guild, CustomCommand>> filtered = MantaroData.db().getCustomCommandsByName(("*" + cmd + "*").replace("*", any)).stream().map(customCommand -> {
Guild guild = mapped.get(customCommand.getGuildId());
return guild == null ? null : Pair.of(guild, customCommand);
}).filter(Objects::nonNull).collect(Collectors.toList());
if (filtered.size() == 0) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There are no custom commands matching your search query.").queue();
return;
}
DiscordUtils.selectList(event, filtered, pair -> "``" + pair.getValue().getName() + "`` - Guild: ``" + pair.getKey() + "``", s -> baseEmbed(event, "Select the Command:").setDescription(s).setFooter("(You can only select custom commands from guilds that you are a member of)", null).build(), pair -> {
String cmdName = pair.getValue().getName();
List<String> responses = pair.getValue().getValues();
CustomCommand custom = CustomCommand.of(event.getGuild().getId(), cmdName, responses);
custom.saveAsync();
customCommands.put(custom.getId(), custom.getValues());
event.getChannel().sendMessage(String.format("Imported custom command ``%s`` from guild `%s` with responses ``%s``", cmdName, pair.getKey().getName(), String.join("``, ``", responses))).queue();
TextChannelGround.of(event).dropItemWithChance(8, 2);
});
return;
}
if (args.length < 3) {
onHelp(event);
return;
}
String value = args[2];
if (action.equals("rename")) {
if (!NAME_PATTERN.matcher(cmd).matches() || !NAME_PATTERN.matcher(value).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
if (CommandProcessor.REGISTRY.commands().containsKey(value) && !CommandProcessor.REGISTRY.commands().get(value).equals(customCommand)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "A command already exists with this name!").queue();
return;
}
CustomCommand oldCustom = db().getCustomCommand(event.getGuild(), cmd);
if (oldCustom == null) {
event.getChannel().sendMessage(EmoteReference.ERROR2 + "There's no Custom Command ``" + cmd + "`` in this Guild.").queue();
return;
}
CustomCommand newCustom = CustomCommand.of(event.getGuild().getId(), value, oldCustom.getValues());
//change at DB
oldCustom.deleteAsync();
newCustom.saveAsync();
//reflect at local
customCommands.remove(oldCustom.getId());
customCommands.put(newCustom.getId(), newCustom.getValues());
//add mini-hack
CommandProcessor.REGISTRY.commands().put(cmd, customCommand);
//clear commands if none
if (customCommands.keySet().stream().noneMatch(s -> s.endsWith(":" + cmd)))
CommandProcessor.REGISTRY.commands().remove(cmd);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Renamed command ``" + cmd + "`` to ``" + value + "``!").queue();
//easter egg :D
TextChannelGround.of(event).dropItemWithChance(8, 2);
return;
}
if (action.equals("add") || action.equals("new")) {
if (!NAME_PATTERN.matcher(cmd).matches()) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Not allowed character.").queue();
return;
}
if (CommandProcessor.REGISTRY.commands().containsKey(cmd) && !CommandProcessor.REGISTRY.commands().get(cmd).equals(customCommand)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "A command already exists with this name!").queue();
return;
}
CustomCommand custom = CustomCommand.of(event.getGuild().getId(), cmd, Collections.singletonList(value));
if (action.equals("add")) {
CustomCommand c = db().getCustomCommand(event, cmd);
if (c != null)
custom.getValues().addAll(c.getValues());
}
//save at DB
custom.saveAsync();
//reflect at local
customCommands.put(custom.getId(), custom.getValues());
//add mini-hack
CommandProcessor.REGISTRY.commands().put(cmd, customCommand);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Saved to command ``" + cmd + "``!").queue();
//easter egg :D
TextChannelGround.of(event).dropItemWithChance(8, 2);
return;
}
onHelp(event);
}
@Override
public String[] splitArgs(String content) {
return SPLIT_PATTERN.split(content, 3);
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "CustomCommand Manager").setDescription("**Manages the Custom Commands of the Guild.**").addField("Guide", "https://github.com/Mantaro/MantaroBot/wiki/Custom-Commands", false).addField("Usage:", "`~>custom` - Shows this help\n" + "`~>custom <list|ls> [detailed]` - **List all commands. If detailed is supplied, it prints the responses of each command.**\n" + "`~>custom debug` - **Gives a Hastebin of the Raw Custom Commands Data. (OWNER-ONLY)**\n" + "`~>custom clear` - **Remove all Custom Commands from this Guild. (OWNER-ONLY)**\n" + "`~>custom add <name> <responses>` - **Add a new Command with the response provided.**\n" + "`~>custom make <name>` - **Starts a Interactive Operation to create a command with the specified name.**\n" + "`~>custom <remove|rm> <name>` - **Removes a command with an specific name.**\n" + "`~>custom import <search>` - **Imports a command from another guild you're in.**", false).build();
}
});
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class AnimeCmds method characterData.
private static void characterData(GuildMessageReceivedEvent event, CharacterData character) {
String JAP_NAME = character.getName_japanese() == null ? "" : "\n(" + character.getName_japanese() + ")";
String CHAR_NAME = character.getName_first() + " " + character.getName_last() + JAP_NAME;
String ALIASES = character.getName_alt() == null ? "No aliases" : "Also known as: " + character.getName_alt();
String IMAGE_URL = character.getImage_url_med();
String CHAR_DESCRIPTION = character.getInfo().isEmpty() ? "No info." : character.getInfo().length() <= 1024 ? character.getInfo() : character.getInfo().substring(0, 1020 - 1) + "...";
EmbedBuilder embed = new EmbedBuilder();
embed.setColor(Color.LIGHT_GRAY).setThumbnail(IMAGE_URL).setAuthor("Information for " + CHAR_NAME, "http://anilist.co/character/" + character.getId(), IMAGE_URL).setDescription(ALIASES).addField("Information", CHAR_DESCRIPTION, true).setFooter("Information provided by AniList", null);
event.getChannel().sendMessage(embed.build()).queue();
}
use of net.dv8tion.jda.core.EmbedBuilder 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.EmbedBuilder 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();
}
});
}
Aggregations