use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class Roll method command_Roll.
@CommandSubscriber(command = "roll", help = "Würfeln. Syntax: `roll AnzahlWuerfel;[AugenJeWuerfel=6]`")
public void command_Roll(final IMessage commandMessage, final String diceArgsInput) throws InterruptedException {
final IChannel channel = commandMessage.getChannel();
final EmbedBuilder outputBuilder = new EmbedBuilder();
if (diceArgsInput.matches("^[0-9]+;?[0-9]*")) {
try {
final String[] args = diceArgsInput.split(";");
final int diceCount = Integer.parseInt(args[0]);
final int dotCount = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_DOT_COUNT;
if (diceCount < 1 || dotCount < 1) {
throw new NumberFormatException("Würfelanzahl und maximale Augenzahl muss größer als 0 sein!");
}
final StringBuilder resultBuilder = new StringBuilder();
final int sum = IntStream.generate(() -> (rng.nextInt(dotCount) + 1)).limit(diceCount).reduce(0, (int acc, int number) -> {
resultBuilder.append(number);
resultBuilder.append("\n");
return acc + number;
});
resultBuilder.append(MessageFormat.format("Sum: {0}", sum));
outputBuilder.appendField(MessageFormat.format("Würfelt {0} Würfel mit einer maximalen Augenzahl von {1}!", diceCount, dotCount), resultBuilder.toString(), false);
EmbedObject rollObject = outputBuilder.build();
Util.sendEmbed(channel, rollObject);
} catch (NumberFormatException ex) {
Util.sendMessage(channel, MessageFormat.format("Konnte Eingabe '{0}' nicht verarbeiten." + "Bitte sicherstellen, dass sowohl die Würfelanzahl als auch die maximale Augenzahl Integer-Zahlen > 0 sind!", diceArgsInput));
}
} else {
Util.sendMessage(channel, "Syntax: `roll AnzahlWürfel;[AugenJeWürfel=6]`");
}
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class BotSetup method command_ListModules.
@CommandSubscriber(command = "modules", help = "Alle Module anzeigen")
public void command_ListModules(final IMessage message) {
String loadedModulesString = "";
for (final String key : bot.getLoadedModules().keySet()) {
loadedModulesString = loadedModulesString + key + '\n';
}
if (loadedModulesString.isEmpty()) {
loadedModulesString = "_keine_";
}
String unloadedModulesString = "";
for (final String key : bot.getUnloadedModules().keySet()) {
unloadedModulesString = unloadedModulesString + key + '\n';
}
if (unloadedModulesString.isEmpty()) {
unloadedModulesString = "_keine_";
}
final EmbedBuilder builder = new EmbedBuilder();
builder.appendField("Aktivierte Module", loadedModulesString, true);
builder.appendField("Deaktivierte Module", unloadedModulesString, true);
Util.sendEmbed(message.getChannel(), builder.build());
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class GeneralCommands method command_Quote.
@CommandSubscriber(command = "quote", help = "Zitiert die Nachricht mit der angegebenen ID", pmAllowed = false, passContext = false)
public void command_Quote(final IMessage commandMessage, final String id) {
if (id.isEmpty()) {
Util.sendMessage(commandMessage.getChannel(), "Keine ID angegeben!");
return;
}
final IUser commandAuthor = commandMessage.getAuthor();
final IGuild guild = commandMessage.getGuild();
final long quoteMessageID = Long.parseLong(id);
final IMessage quoteMessage = guild.getMessageByID(quoteMessageID);
if (quoteMessage == null) {
Util.sendMessage(commandMessage.getChannel(), "Nachricht mit der ID `" + quoteMessageID + "` nicht gefunden!");
return;
}
commandMessage.delete();
final IUser quoteAuthor = quoteMessage.getAuthor();
final IRole quoteAuthorTopRole = Util.getTopRole(quoteAuthor, quoteMessage.getGuild());
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.withAuthorIcon(quoteAuthor.getAvatarURL());
embedBuilder.withAuthorName(Util.makeUserString(quoteAuthor, guild));
embedBuilder.withDesc(quoteMessage.getContent());
embedBuilder.withColor(quoteAuthorTopRole.getColor());
final DateTimeFormatter timestampFormatter = DateTimeFormatter.ofPattern("dd.MM.YYYY, HH:mm");
final String timestampString = quoteMessage.getTimestamp().format(timestampFormatter);
embedBuilder.withFooterText(timestampString + " | Zitiert von: " + Util.makeUserString(commandAuthor, guild));
Util.sendEmbed(commandMessage.getChannel(), embedBuilder.build());
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class DiscordBot method command_help.
private void command_help(final IMessage message) {
final EmbedBuilder embedBuilder = new EmbedBuilder();
for (final String key : this.loadedModules.keySet()) {
Object module = this.loadedModules.get(key);
String moduleHelp = "";
for (Method method : module.getClass().getMethods()) {
if (method.isAnnotationPresent(CommandSubscriber.class)) {
final CommandSubscriber annotation = method.getDeclaredAnnotationsByType(CommandSubscriber.class)[0];
if (this.getUserPermissionLevel(message.getAuthor(), message.getGuild()) >= annotation.permissionLevel()) {
final String command = annotation.command();
final String help = annotation.help();
moduleHelp = moduleHelp + "`" + command + "` " + help + '\n';
}
}
}
final CommandModule[] annotations = module.getClass().getDeclaredAnnotationsByType(CommandModule.class);
final String moduleName = annotations[0].moduleName();
if (!moduleHelp.isEmpty()) {
embedBuilder.appendField(moduleName, moduleHelp, false);
}
}
final EmbedObject embedObject = embedBuilder.build();
Util.sendEmbed(message.getAuthor().getOrCreatePMChannel(), embedObject);
if (!message.getChannel().isPrivate()) {
Util.sendMessage(message.getChannel(), ":mailbox_with_mail:");
}
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class UserGroups method command_groups.
@CommandSubscriber(command = "groups", help = "Alle Rollen auflisten")
public void command_groups(final IMessage message) {
final StringBuilder stringBuilder = new StringBuilder();
final List<String> keyList = new LinkedList<>();
keyList.addAll(usergroupsJSON.keySet());
Collections.sort(keyList);
for (String key : keyList) {
if (stringBuilder.length() != 0) {
stringBuilder.append('\n');
}
stringBuilder.append(key);
}
if (stringBuilder.length() == 0) {
stringBuilder.append("_Keine_");
}
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.appendField("Verfügbare Gruppen:", stringBuilder.toString(), false);
embedBuilder.withFooterText("Weise dir mit '" + bot.configJSON.getString("prefix") + "group <Gruppe>' selbst eine dieser Gruppen zu");
Util.sendEmbed(message.getChannel(), embedBuilder.build());
}
Aggregations