Search in sources :

Example 1 with Channel

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

the class InitCommand method action.

@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
    String body;
    if (args.length > 0) {
        boolean isAChannel = false;
        TextChannel chan = null;
        String chanId = null;
        try {
            chanId = args[0].replaceAll("[^\\d]", "");
            chan = event.getGuild().getTextChannelById(chanId);
            if (chan != null)
                isAChannel = true;
        } catch (Exception ignored) {
        }
        if (// use the argument as the new channel's name
        !isAChannel) {
            String chanTitle = args[0].replaceAll("[^A-Za-z0-9_ \\-]", "").replaceAll("[ ]", "_");
            Main.getScheduleManager().createSchedule(event.getGuild().getId(), chanTitle);
            body = "A new schedule channel named **" + chanTitle.toLowerCase() + "** has been created!\n" + "You can now use the create command to create events on that schedule, or the sync command to sync " + "that schedule to a Google Calendar.";
        } else // convert the channel to a schedule
        {
            if (Main.getScheduleManager().isASchedule(chan.getId())) {
                // clear the channel of events
                TextChannel finalChan = chan;
                Main.getDBDriver().getEventCollection().find(eq("channelId", chan.getId())).forEach((Consumer<? super Document>) document -> {
                    String msgId = document.getString("messageId");
                    finalChan.deleteMessageById(msgId).complete();
                    Main.getEntryManager().removeEntry(document.getInteger("_id"));
                });
                body = "The schedule <#" + chanId + "> has been cleared!";
            } else {
                // create a new schedule
                Main.getScheduleManager().createSchedule(chan);
                body = "The channel <#" + chanId + "> has been converted to a schedule channel!\n" + "You can now use the create command to create events on that schedule, or the sync " + "command to sync that schedule to a Google Calendar.";
            }
        }
    } else // create a new schedule using the default name
    {
        Main.getScheduleManager().createSchedule(event.getGuild().getId(), null);
        body = "A new schedule channel named **new_schedule** has been created!\n" + "You can now use the create command to create events on that schedule, or the sync command" + " to sync that schedule to a Google Calendar.";
    }
    MessageUtilities.sendMsg(body, event.getChannel(), null);
}
Also used : Document(org.bson.Document) Command(ws.nmathe.saber.commands.Command) CommandInfo(ws.nmathe.saber.commands.CommandInfo) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Logging(ws.nmathe.saber.utils.Logging) Channel(net.dv8tion.jda.core.entities.Channel) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) List(java.util.List) Permission(net.dv8tion.jda.core.Permission) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) MessageUtilities(ws.nmathe.saber.utils.MessageUtilities) Filters.eq(com.mongodb.client.model.Filters.eq) Main(ws.nmathe.saber.Main) TextChannel(net.dv8tion.jda.core.entities.TextChannel)

Example 2 with Channel

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

the class PurgeCommand method action.

@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
    TextChannel channel = event.getGuild().getJDA().getTextChannelById(args[0].replaceAll("[^\\d]", ""));
    // number of messages to remove
    Integer[] count = { 100 };
    // ID of bot to check messages against
    String botId = event.getJDA().getSelfUser().getId();
    processing.put(event.getGuild().getId(), channel.getId());
    channel.getIterableHistory().stream().filter(message -> message.getAuthor().getId().equals(botId) && (count[0]-- > 0)).forEach((message -> {
        message.getChannel().sendTyping().queue();
        // sleep for half a second before continuing
        try {
            Thread.sleep(500);
        } catch (InterruptedException ignored) {
        }
        Bson query = eq("messageId", message.getId());
        if (Main.getDBDriver().getEventCollection().count(query) == 0) {
            MessageUtilities.deleteMsg(message);
        }
    }));
    processing.remove(event.getGuild().getId(), channel.getId());
    // send success message
    String content = "Finished purging old message.";
    MessageUtilities.sendMsg(content, event.getTextChannel(), null);
}
Also used : Bson(org.bson.conversions.Bson) Command(ws.nmathe.saber.commands.Command) CommandInfo(ws.nmathe.saber.commands.CommandInfo) RateLimiter(ws.nmathe.saber.core.RateLimiter) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Map(java.util.Map) MessageReceivedEvent(net.dv8tion.jda.core.events.message.MessageReceivedEvent) MessageUtilities(ws.nmathe.saber.utils.MessageUtilities) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Filters.eq(com.mongodb.client.model.Filters.eq) Channel(net.dv8tion.jda.core.entities.Channel) Main(ws.nmathe.saber.Main) TextChannel(net.dv8tion.jda.core.entities.TextChannel) Bson(org.bson.conversions.Bson)

Example 3 with Channel

use of net.dv8tion.jda.core.entities.Channel in project FredBoat by Frederikam.

the class AkinatorListener method onGuildMessageReceived.

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
    Channel channel = event.getChannel();
    if (!channel.getId().equals(channelId)) {
        return;
    }
    byte answer;
    // <editor-fold defaultstate="collapsed" desc="switch">
    switch(event.getMessage().getContentStripped().trim().toLowerCase()) {
        case "yes":
            answer = 0;
            break;
        case "y":
            answer = 0;
            break;
        case "no":
            answer = 1;
            break;
        case "n":
            answer = 1;
            break;
        case "idk":
            answer = 2;
            break;
        case "p":
            answer = 3;
            break;
        case "probably":
            answer = 3;
            break;
        case "pn":
            answer = 4;
            break;
        case "probably not":
            answer = 4;
            break;
        default:
            answer = -1;
            break;
    }
    if (answer == -1) {
        return;
    }
    lastActionReceived = System.currentTimeMillis();
    if (lastQuestionWasGuess) {
        if (answer != 0 && answer != 1) {
            return;
        }
        context.sendTyping();
        answerGuess(answer);
    } else {
        context.sendTyping();
        answerQuestion(answer);
    }
}
Also used : Channel(net.dv8tion.jda.core.entities.Channel)

Example 4 with Channel

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

the class PurgeCommand method verify.

@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event) {
    String head = prefix + this.name();
    int index = 0;
    // verify current argument count
    if (args.length != 1) {
        return "This command requires a channel as an argument!";
    }
    // verify argument 1 is properly formed
    if (!args[index].matches("<#[\\d]+>")) {
        return "Your channel name, *" + args[index] + "*, looks malformed!";
    }
    // verify that argument is a proper link to a channel
    Channel channel = event.getJDA().getTextChannelById(args[index].replaceAll("[^\\d]", ""));
    if (channel == null) {
        return "I could not find " + args[index] + " on your guild!";
    }
    // basic protection against misuse
    if (limiter.isOnCooldown(event.getGuild().getId())) {
        return "The purge command has been used on your guild recently.\n" + "Please wait at least one minute before reusing the command!";
    }
    if (processing.keySet().contains(event.getGuild().getId())) {
        return "I am still purging messages from <#" + processing.getOrDefault(event.getGuild().getId(), "0") + ">.\n" + "You may not issue another purge command until this finishes.";
    }
    return "";
}
Also used : TextChannel(net.dv8tion.jda.core.entities.TextChannel) Channel(net.dv8tion.jda.core.entities.Channel)

Example 5 with Channel

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

the class CommandAutochannel method createChannel.

private void createChannel(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
    String[] args = parsedCommandInvocation.getArgs();
    Guild guild = parsedCommandInvocation.getMessage().getGuild();
    StringBuilder names = new StringBuilder();
    for (int i = 1; i < args.length; i++) {
        names.append(args[i]).append(" ");
    }
    String name = names.toString();
    name = names.replace(name.lastIndexOf(" "), name.lastIndexOf(" ") + 1, "").toString();
    Channel channel = guild.getController().createVoiceChannel(name).complete();
    String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "autochannels");
    String newEntry = oldEntry + ", " + channel.getId();
    RubiconBot.getMySQL().updateGuildValue(guild, "autochannels", newEntry);
    Message mymsg = parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.success("Created Autochannel", "Successfully created autochannel -> " + channel.getName() + "").build()).complete();
    new Timer().schedule(new TimerTask() {

        @Override
        public void run() {
            mymsg.delete().queue();
        }
    }, 5000);
}
Also used : Message(net.dv8tion.jda.core.entities.Message) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) Channel(net.dv8tion.jda.core.entities.Channel) Guild(net.dv8tion.jda.core.entities.Guild)

Aggregations

Channel (net.dv8tion.jda.core.entities.Channel)5 TextChannel (net.dv8tion.jda.core.entities.TextChannel)3 Filters.eq (com.mongodb.client.model.Filters.eq)2 MessageReceivedEvent (net.dv8tion.jda.core.events.message.MessageReceivedEvent)2 Main (ws.nmathe.saber.Main)2 Command (ws.nmathe.saber.commands.Command)2 CommandInfo (ws.nmathe.saber.commands.CommandInfo)2 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)2 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Permission (net.dv8tion.jda.core.Permission)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Message (net.dv8tion.jda.core.entities.Message)1 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)1 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)1 Document (org.bson.Document)1 Bson (org.bson.conversions.Bson)1