Search in sources :

Example 6 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject in project BoltBot by DiscordBolt.

the class DiceModule method rollCommand.

@BotCommand(command = "roll", module = "Dice Module", description = "Roll a die!", usage = "Roll [#d##]", args = 2)
public static void rollCommand(CommandContext cc) throws CommandArgumentException {
    Matcher m = DIE_PATTERN.matcher(cc.getArgument(1));
    if (!m.matches()) {
        cc.replyWith("Your die was not formatted correctly. !Roll #d##");
        return;
    }
    int numDice = Integer.valueOf(Optional.ofNullable(m.group(1)).orElse("1"));
    int numSides = Integer.valueOf(Optional.ofNullable(m.group(2)).orElseThrow(() -> new CommandArgumentException("Your die was not formatted correctly. !Roll #d##")));
    if (numDice < 1 || numSides <= 1 || numDice > 100 || numSides > 100) {
        cc.replyWith("Your die has an invalid number of sides.");
        return;
    }
    if (cc.getChannel().getTopic().toLowerCase().contains("--print-rolls")) {
        EmbedObject embed = getDieEmbed(numDice, numSides);
        cc.replyWith(embed.title);
        cc.replyWith(embed);
    } else
        cc.replyWith(getDieEmbed(numDice, numSides));
}
Also used : Matcher(java.util.regex.Matcher) CommandArgumentException(com.discordbolt.api.command.exceptions.CommandArgumentException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) BotCommand(com.discordbolt.api.command.BotCommand)

Example 7 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject in project de-DiscordBot by DACH-Discord.

the class UserLog method userJoinNotify.

private void userJoinNotify(final IUser user) {
    final LocalDateTime joinTimeStamp = user.getCreationDate();
    int joinedDays = (int) joinTimeStamp.until(LocalDateTime.now(), ChronoUnit.DAYS);
    // String für Embed
    String embedString = "**Name:** " + user.getName() + '#' + user.getDiscriminator() + '\n' + "**ID:** " + user.getStringID() + '\n' + "**Discord beigetreten:** vor " + joinedDays + " Tagen";
    if (joinedDays <= 1) {
        embedString = embedString + '\n' + ":exclamation: Neuer Nutzer! :exclamation:";
    }
    // Embed
    final EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.appendField(":white_check_mark: Nutzer ist dem Server beigetreten!", embedString, false);
    embedBuilder.withThumbnail(user.getAvatarURL());
    embedBuilder.withFooterText(LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM. | HH:mm")));
    embedBuilder.withColor(new Color(119, 178, 85));
    final EmbedObject embedObject = embedBuilder.build();
    Util.sendEmbed(userLogChannel, embedObject);
}
Also used : LocalDateTime(java.time.LocalDateTime) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Example 8 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject in project DiscordSailv2 by Vaerys-Dawn.

the class RequestHandler method sendEmbedMessage.

public static RequestBuffer.RequestFuture<IMessage> sendEmbedMessage(String message, XEmbedBuilder builder, IChannel channel) {
    return RequestBuffer.request(() -> {
        String checkedMessage = message;
        if (builder == null)
            throw new IllegalArgumentException("Embed builder must never be null.");
        if (checkedMessage == null)
            checkedMessage = "";
        EmbedObject embed = builder.build();
        try {
            return channel.sendMessage(checkedMessage, embed);
        } catch (MissingPermissionsException e) {
            String debugMessage;
            if (checkedMessage.isEmpty())
                debugMessage = Utility.embedToString(embed);
            else
                debugMessage = checkedMessage + "\n" + Utility.embedToString(embed);
            missingPermissions(debugMessage, channel);
            return sendMessage(debugMessage, channel).get();
        }
    });
}
Also used : EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Example 9 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject in project Shadbot by Shadorc.

the class TriviaCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    if (categories.isEmpty()) {
        this.load();
    }
    if (context.getArg().equals("categories")) {
        EmbedObject embed = EmbedUtils.getDefaultEmbed().withAuthorName("Trivia categories").appendField("ID", FormatUtils.format(categories.keySet().toArray(), Object::toString, "\n"), true).appendField("Name", FormatUtils.format(categories.keySet().toArray(), categories::get, "\n"), true).build();
        BotUtils.sendMessage(embed, context.getChannel());
        return;
    }
    Integer categoryID = CastUtils.asPositiveInt(context.getArg());
    if (context.hasArg() && (categoryID == null || !categories.containsKey(categoryID))) {
        throw new IllegalCmdArgumentException(String.format("`%s` is not a valid ID. Use `%s%s categories` to see the complete list " + "of categories.", context.getArg(), context.getPrefix(), this.getName()));
    }
    TriviaManager triviaManager = MANAGERS.get(context.getChannel().getLongID());
    if (triviaManager == null) {
        triviaManager = new TriviaManager(this, context.getPrefix(), context.getChannel(), context.getAuthor(), categoryID);
    }
    if (MANAGERS.putIfAbsent(context.getChannel().getLongID(), triviaManager) == null) {
        try {
            triviaManager.start();
        } catch (ParseException err) {
            BotUtils.sendMessage(Emoji.RED_FLAG + " I can't get a question right now, please try again later.", context.getChannel());
            LogUtils.infof("{%s} Empty body.", this.getClass().getSimpleName());
            MANAGERS.remove(context.getChannel().getLongID());
        } catch (JSONException | IOException err) {
            Utils.handle("getting a question", context, err);
            MANAGERS.remove(context.getChannel().getLongID());
        }
    } else {
        BotUtils.sendMessage(Emoji.INFO + " A Trivia game has already been started.", context.getChannel());
    }
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) JSONException(org.json.JSONException) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Aggregations

EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)9 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)5 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 BotCommand (com.discordbolt.api.command.BotCommand)1 CommandArgumentException (com.discordbolt.api.command.exceptions.CommandArgumentException)1 CommandModule (de.nikos410.discordBot.util.modular.annotations.CommandModule)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)1 ParseException (org.apache.http.ParseException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 IChannel (sx.blah.discord.handle.obj.IChannel)1