Search in sources :

Example 1 with CommandSubscriber

use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber 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 CommandSubscriber

use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class GameStats method command_Playing.

@CommandSubscriber(command = "playing", help = "Zeigt alle Nutzer die das angegebene Spiel spielen", pmAllowed = false)
public void command_Playing(final IMessage message, final String game) {
    if (game.isEmpty()) {
        // Kein Spiel angegeben
        Util.sendMessage(message.getChannel(), "Kein Spiel angegeben!");
        return;
    }
    IGuild guild = message.getGuild();
    /*
         * Nutzer, die gerade das Spiel spielen
         */
    List<IUser> usersPlayingNow = new ArrayList<>();
    for (IUser user : guild.getUsers()) {
        final Optional<String> playing = user.getPresence().getPlayingText();
        if (playing.isPresent() && playing.get().equalsIgnoreCase(game)) {
            usersPlayingNow.add(user);
        }
    }
    /*
         * Nutzer, die jemals das Spiel gespielt haben
         */
    List<IUser> usersPlayingAny = new ArrayList<>();
    if (gameStatsJSON.has(game)) {
        JSONArray gameArray = gameStatsJSON.getJSONArray(game);
        for (int i = 0; i < gameArray.length(); i++) {
            final IUser user = client.getUserByID(gameArray.getLong(i));
            if (user != null) {
                // Nutzer nur hinzufügen wenn er nicht schon in der anderen Liste enthalten ist
                if (!usersPlayingNow.contains(user)) {
                    usersPlayingAny.add(user);
                }
            }
        }
    }
    /*
         * Ausgabe
         */
    // Ähnliche Spiele
    String similarGames = "";
    for (String s : findSimilarKeys(game)) {
        similarGames = similarGames + s + '\n';
    }
    // Keine Nutzer spielen gerade oder haben jemals gespielt
    if (usersPlayingNow.isEmpty() && usersPlayingAny.isEmpty()) {
        Util.sendMessage(message.getChannel(), "**Niemand auf diesem Server spielt _" + game + "_**.");
        if (!similarGames.isEmpty()) {
            Util.sendMessage(message.getChannel(), "**Meintest du...** \n" + similarGames);
        }
        return;
    }
    // TODO: Nachricht in einzelnen Zeilen übergeben um saubereren Zeilenumbruch zu gewährleisten
    Util.sendMessage(message.getChannel(), "**Nutzer, die __jetzt__ _" + game + "_ spielen**\n" + userListToString(usersPlayingNow, guild));
    Util.sendMessage(message.getChannel(), "**__Alle anderen__ Nutzer, die _" + game + "_ spielen**\n" + userListToString(usersPlayingAny, guild));
    if (!similarGames.isEmpty()) {
        Util.sendMessage(message.getChannel(), "**Ähnliche Spiele:** \n" + similarGames);
    }
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 3 with CommandSubscriber

use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber 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 4 with CommandSubscriber

use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber 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 5 with CommandSubscriber

use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_Unmute.

@CommandSubscriber(command = "unmute", help = "Nutzer entmuten", pmAllowed = false, permissionLevel = CommandPermissions.MODERATOR)
public void command_Unmute(final IMessage message) {
    final List<IUser> mentions = message.getMentions();
    if (mentions.size() < 1) {
        Util.sendMessage(message.getChannel(), ":x: Fehler: Kein Nutzer angegeben!");
        return;
    } else if (mentions.size() > 1) {
        Util.sendMessage(message.getChannel(), ":x: Fehler: mehrere Nutzer erwähnt");
        return;
    }
    final IUser muteUser = mentions.get(0);
    if (!mutedUsers.containsKey(muteUser.getStringID())) {
        // Nutzer ist nicht gemuted
        Util.sendMessage(message.getChannel(), "Nutzer scheint nicht gemuted zu sein.");
        return;
    }
    ScheduledFuture future = mutedUsers.get(muteUser.getStringID());
    future.cancel(false);
    IRole muteRole = message.getGuild().getRoleByID(muteRoleID);
    muteUser.removeRole(muteRole);
    // :white_check_mark:
    message.addReaction(ReactionEmoji.of("✅"));
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Aggregations

CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)12 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)5 ScheduledFuture (java.util.concurrent.ScheduledFuture)3 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)3 CommandModule (de.nikos410.discordBot.util.modular.annotations.CommandModule)2 Method (java.lang.reflect.Method)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ChronoUnit (java.time.temporal.ChronoUnit)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 JSONObject (org.json.JSONObject)2 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 IChannel (sx.blah.discord.handle.obj.IChannel)1 IUser (sx.blah.discord.handle.obj.IUser)1