Search in sources :

Example 1 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject 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 2 with EmbedObject

use of sx.blah.discord.api.internal.json.objects.EmbedObject 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 3 with EmbedObject

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

the class UserLog method userLeaveNotify.

private void userLeaveNotify(final IUser user) {
    final EmbedBuilder embedBuilder = new EmbedBuilder();
    final DateTimeFormatter timeStampFormatter = DateTimeFormatter.ofPattern("dd.MM. | HH:mm");
    embedBuilder.withThumbnail(user.getAvatarURL());
    embedBuilder.appendField(":x: Nutzer hat den Server verlassen!", "**Name:** " + user.getName() + '#' + user.getDiscriminator() + '\n' + "**ID:** " + user.getStringID(), false);
    embedBuilder.withFooterText(LocalDateTime.now().format(timeStampFormatter));
    embedBuilder.withColor(new Color(221, 46, 68));
    final EmbedObject embedObject = embedBuilder.build();
    Util.sendEmbed(userLogChannel, embedObject);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Example 4 with EmbedObject

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

the class UserLog method userBanNotify.

private void userBanNotify(final IUser user) {
    final EmbedBuilder embedBuilder = new EmbedBuilder();
    final DateTimeFormatter timeStampFormatter = DateTimeFormatter.ofPattern("dd.MM. | HH:mm");
    embedBuilder.withThumbnail(user.getAvatarURL());
    embedBuilder.appendField(":hammer: Nutzer gebannt!", "**Name:** " + user.getName() + '#' + user.getDiscriminator() + '\n' + "**ID:** " + user.getStringID(), false);
    embedBuilder.withFooterText(LocalDateTime.now().format(timeStampFormatter));
    final EmbedObject embedObject = embedBuilder.build();
    Util.sendEmbed(userLogChannel, embedObject);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DateTimeFormatter(java.time.format.DateTimeFormatter) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject)

Example 5 with EmbedObject

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

the class LoggingHandler method logDelete.

public static void logDelete(CommandObject command, IMessage deletedMessage) {
    if (!shouldLog(command))
        return;
    if (messageEmpty(deletedMessage))
        return;
    StringBuffer content;
    StringBuffer extraContent = new StringBuffer();
    EmbedObject embed = null;
    int charLimit = 2000;
    String timestamp = getFormattedTimeStamp(command, deletedMessage);
    String format = "> **@%s's** Message %s was **Deleted** in channel: %s with contents:\n%s\n%s";
    // check embed
    if (deletedMessage.getEmbeds().size() != 0)
        embed = new EmbedObject(deletedMessage.getEmbeds().get(0));
    // add and attachments
    for (IMessage.Attachment atc : deletedMessage.getAttachments()) {
        if (extraContent.length() != 0)
            extraContent.append("\n");
        extraContent.append("<").append(atc.getUrl()).append(">");
    }
    // add all of the args
    List<String> vars = new ArrayList<String>() {

        {
            add(command.user.username);
            add(timestamp);
            add(command.channel.mention);
            add(extraContent.toString());
        }
    };
    // calculate the limit of content
    charLimit -= getVarsLength(vars);
    charLimit -= format.length() + Utility.embedToString(embed).length();
    // make sure that the length doesn't go over.
    content = new StringBuffer(Utility.unFormatMentions(command.message.get()));
    if (charLimit < 0) {
        logger.error("Message caused Charlimit to go under 0.\n" + "Content:" + content + "\nExtra Content:" + extraContent);
        return;
    }
    if (content.length() > charLimit) {
        content.setLength(charLimit);
        content.append("...");
    }
    vars.add(3, content.toString());
    content = new StringBuffer(String.format(format, vars.toArray()));
    sendLog(command, content.toString(), false, embed);
}
Also used : ArrayList(java.util.ArrayList) 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