Search in sources :

Example 31 with EmbedBuilder

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]`");
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 32 with EmbedBuilder

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());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 33 with EmbedBuilder

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());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 34 with EmbedBuilder

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:");
    }
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandModule(de.nikos410.discordBot.util.modular.annotations.CommandModule) JSONObject(org.json.JSONObject) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Method(java.lang.reflect.Method) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Example 35 with EmbedBuilder

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());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Aggregations

EmbedBuilder (sx.blah.discord.util.EmbedBuilder)103 IOException (java.io.IOException)19 Random (java.util.Random)17 IUser (sx.blah.discord.handle.obj.IUser)14 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)13 LoadingMessage (me.shadorc.shadbot.utils.object.LoadingMessage)13 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)12 JSONObject (org.json.JSONObject)11 IMessage (sx.blah.discord.handle.obj.IMessage)10 List (java.util.List)9 AbstractCommand (me.shadorc.shadbot.core.command.AbstractCommand)9 EmbedUtils (me.shadorc.shadbot.utils.embed.EmbedUtils)9 JSONException (org.json.JSONException)9 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)8 Utils (me.shadorc.shadbot.utils.Utils)8 IChannel (sx.blah.discord.handle.obj.IChannel)8 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)7 FormatUtils (me.shadorc.shadbot.utils.FormatUtils)7 File (java.io.File)6 CommandCategory (me.shadorc.shadbot.core.command.CommandCategory)6