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));
}
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);
}
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();
}
});
}
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());
}
}
Aggregations