Search in sources :

Example 41 with JDA

use of net.dv8tion.jda.core.JDA in project Saber-Bot by notem.

the class VerifyUtilities method verifyAnnouncementAdd.

/**
 *  Returns error message (or empty string) for announcement add keyword verification
 */
public static String verifyAnnouncementAdd(String[] args, int index, String head, MessageReceivedEvent event) {
    if (args.length - index < 3) {
        return "That's not the right number of arguments for **" + args[index - 2] + " " + args[index - 1] + "**!\n" + "Use ``" + head + " " + args[0] + " " + args[index - 2] + " " + args[index - 1] + " [#target] [time] [message]``";
    }
    JDA jda = Main.getShardManager().getJDA(event.getGuild().getId());
    String channelId = args[index].replaceAll("[^\\d]", "");
    if (!channelId.matches("\\d+") || jda.getTextChannelById(channelId) == null) {
        return "**" + args[index] + "** is not a channel on your server!";
    }
    if (!VerifyUtilities.verifyTimeString(args[index + 1])) {
        return "**" + args[index + 1] + "** is not a properly formed announcement time!\n" + "Times use the format \"TYPE+/-OFFSET\". Ex: ``START+10m``, ``END-1h``";
    }
    return "";
}
Also used : JDA(net.dv8tion.jda.core.JDA)

Example 42 with JDA

use of net.dv8tion.jda.core.JDA in project Rubicon by Rubicon-Bot.

the class CommandAutochannel method execute.

@Override
protected Message execute(CommandManager.ParsedCommandInvocation parsedCommandInvocation, UserPermissions userPermissions) {
    String[] args = parsedCommandInvocation.getArgs();
    Guild guild = parsedCommandInvocation.getMessage().getGuild();
    JDA jda = RubiconBot.getJDA();
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("list")) {
            String entry = RubiconBot.getMySQL().getGuildValue(guild, "autochannels");
            StringBuilder out = new StringBuilder();
            for (String s : entry.split(",")) {
                out.append(jda.getVoiceChannelById(s).getName()).append("\n");
            }
            return new MessageBuilder().setEmbed(EmbedUtil.embed("Autochannels", out.toString()).setColor(Colors.COLOR_PRIMARY).build()).build();
        } else
            return createHelpMessage();
    } else if (args.length >= 2) {
        switch(args[0].toLowerCase()) {
            case "create":
            case "c":
                createChannel(parsedCommandInvocation);
                break;
            case "del":
            case "delete":
                invokeDelete(parsedCommandInvocation);
                break;
            case "add":
            case "set":
                addChannel(parsedCommandInvocation);
                break;
            default:
                return createHelpMessage();
        }
    } else
        return createHelpMessage();
    return null;
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) JDA(net.dv8tion.jda.core.JDA) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

JDA (net.dv8tion.jda.core.JDA)42 Guild (net.dv8tion.jda.core.entities.Guild)10 TextChannel (net.dv8tion.jda.core.entities.TextChannel)9 Document (org.bson.Document)9 Permission (net.dv8tion.jda.core.Permission)7 Main (ws.nmathe.saber.Main)7 Consumer (java.util.function.Consumer)6 Message (net.dv8tion.jda.core.entities.Message)6 JSONObject (org.json.JSONObject)5 Logging (ws.nmathe.saber.utils.Logging)5 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 Date (java.util.Date)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Member (net.dv8tion.jda.core.entities.Member)4 Bson (org.bson.conversions.Bson)4 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)3 User (net.dv8tion.jda.core.entities.User)3 PermissionException (net.dv8tion.jda.core.exceptions.PermissionException)3