Search in sources :

Example 6 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber 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 7 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber 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)

Example 8 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class UserLog method command_Userlog_Test.

@CommandSubscriber(command = "userlog_test", help = "Userlog-Ausgabe testen", permissionLevel = CommandPermissions.ADMIN)
public void command_Userlog_Test(final IMessage message) {
    final IUser user = message.getAuthor();
    userJoinNotify(user);
    userLeaveNotify(user);
    userBanNotify(user);
}
Also used : IUser(sx.blah.discord.handle.obj.IUser) CommandSubscriber(de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)

Example 9 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_voicelog.

@CommandSubscriber(command = "voicelog", help = "Die letzten 20 Aktivitäten in Sprachkanälen auflisten", pmAllowed = false, permissionLevel = PermissionLevel.MODERATOR, ignoreParameterCount = true)
public void command_voicelog(final IMessage message, final String listCountArg) {
    final int listCount;
    if (listCountArg == null) {
        listCount = 20;
    } else {
        try {
            listCount = Integer.parseInt(listCountArg);
        } catch (NumberFormatException e) {
            DiscordIO.sendMessage(message.getChannel(), ":x: Die angegebene Anzahl ist keine gültige Zahl!");
            return;
        }
    }
    final List<String> guildVoiceLog = getVoiceLogForGuild(message.getGuild());
    final StringBuilder stringBuilder = new StringBuilder();
    boolean entriesSkipped = false;
    for (int i = guildVoiceLog.size() - 1; i > (guildVoiceLog.size() - listCount - 1) && i >= 0; i--) {
        final String lineToAdd = guildVoiceLog.get(i);
        if (stringBuilder.length() + lineToAdd.length() <= 1024) {
            stringBuilder.append(guildVoiceLog.get(i));
            stringBuilder.append(String.format("%n"));
        } else {
            entriesSkipped = true;
        }
    }
    final EmbedBuilder responseBuilder = new EmbedBuilder();
    final String content = stringBuilder.length() > 0 ? stringBuilder.toString() : "_keine_";
    responseBuilder.appendField(String.format("__Die letzten %s Voice-Interaktionen (von neu nach alt)__", listCount), content, false);
    if (entriesSkipped) {
        responseBuilder.withFooterText("Einer oder mehrere Einträge wurden ignoriert, weil die maximale Textlänge erreicht wurde.");
    }
    DiscordIO.sendEmbed(message.getChannel(), responseBuilder.build());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Example 10 with CommandSubscriber

use of de.nikos410.discordbot.framework.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.

the class ModStuff method command_setModlogChannel.

@CommandSubscriber(command = "setModlogChannel", help = "Kanal in dem die Modlog Nachrichten gesendet werden einstellen", pmAllowed = false, passContext = false, permissionLevel = PermissionLevel.ADMIN)
public void command_setModlogChannel(final IMessage message, final String channelParameter) {
    final IChannel modlogChannel = ChannelUtils.getChannelFromMessage(message, channelParameter);
    if (modlogChannel == null) {
        // No valid channel was specified
        DiscordIO.sendMessage(message.getChannel(), "Kein gültiger Kanal angegeben!");
        return;
    }
    final IGuild guild = message.getGuild();
    final JSONObject guildJSON;
    if (modstuffJSON.has(guild.getStringID())) {
        guildJSON = modstuffJSON.getJSONObject(guild.getStringID());
    } else {
        guildJSON = new JSONObject();
        modstuffJSON.put(guild.getStringID(), guildJSON);
    }
    guildJSON.put("modlogChannel", modlogChannel.getLongID());
    saveJSON();
    // :white_check_mark:
    message.addReaction(ReactionEmoji.of("✅"));
}
Also used : JSONObject(org.json.JSONObject) CommandSubscriber(de.nikos410.discordbot.framework.annotations.CommandSubscriber)

Aggregations

CommandSubscriber (de.nikos410.discordbot.framework.annotations.CommandSubscriber)30 JSONObject (org.json.JSONObject)23 IGuild (sx.blah.discord.handle.obj.IGuild)14 CommandSubscriber (de.nikos410.discordBot.util.modular.annotations.CommandSubscriber)12 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)11 ChronoUnit (java.time.temporal.ChronoUnit)5 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)5 LocalDateTime (java.time.LocalDateTime)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 IChannel (sx.blah.discord.handle.obj.IChannel)4 ModuleWrapper (de.nikos410.discordbot.framework.ModuleWrapper)3 CommandUtils (de.nikos410.discordbot.util.CommandUtils)3 Method (java.lang.reflect.Method)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)3 JSONArray (org.json.JSONArray)3 IUser (sx.blah.discord.handle.obj.IUser)3 CommandModule (de.nikos410.discordBot.util.modular.annotations.CommandModule)2 CommandWrapper (de.nikos410.discordbot.framework.CommandWrapper)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2