Search in sources :

Example 11 with TextChannel

use of net.dv8tion.jda.api.entities.TextChannel in project Saber-Bot by notem.

the class InitCommand method verify.

@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event) {
    if (Main.getScheduleManager().isLimitReached(event.getGuild().getId())) {
        return "You have reached the limit for schedules! Please delete one of your guild's schedules before trying again.";
    }
    if (args.length > 1) {
        return "That's too many arguments! Use ``" + prefix + this.name() + " [<name>|<channel>]``";
    }
    if (args.length == 1) {
        if (// first arg is a discord channel link
        args[0].matches("<#[\\d]+>")) {
            String chanId = args[0].replaceFirst("<#", "").replaceFirst(">", "");
            String commandChannelId = Main.getGuildSettingsManager().getGuildSettings(event.getGuild().getId()).getCommandChannelId();
            if (chanId.equals(commandChannelId) || chanId.equals(event.getChannel().getId())) {
                return "Your guild's command channel cannot be converted to a schedule!";
            }
            TextChannel channel = event.getGuild().getTextChannelById(chanId);
            if (channel == null) {
                return "I could not find the channel, " + args[0] + "!";
            }
            if (// refuse to convert channels with messages
            channel.getHistory().retrievePast(6).complete().size() > 5) {
                return "That channel is not empty! I will not convert an active channel to a schedule channel!";
            }
        } else // otherwise arg must be channel name
        {
            if (args[0].length() > 100 || args[0].length() < 2) {
                return "Schedule name must be between 2 and 100 characters long!";
            }
            boolean canCreateChannels = event.getGuild().getMember(event.getJDA().getSelfUser()).getPermissions().contains(Permission.MANAGE_CHANNEL);
            if (!canCreateChannels) {
                return "I need the Manage Channels permission to create a new schedule!";
            }
        }
    }
    return "";
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel)

Example 12 with TextChannel

use of net.dv8tion.jda.api.entities.TextChannel in project Saber-Bot by notem.

the class GlobalMsgCommand method action.

@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
    String msg = "";
    for (String arg : args) {
        msg += arg + " ";
    }
    for (Guild guild : Main.getShardManager().getGuilds()) {
        String channelId = Main.getGuildSettingsManager().getGuildSettings(guild.getId()).getCommandChannelId();
        if (// look for default control channel name
        channelId == null) {
            Collection<TextChannel> chans = guild.getTextChannelsByName(Main.getBotSettingsManager().getControlChan(), true);
            for (TextChannel chan : chans) {
                MessageUtilities.sendMsg(msg, chan, null);
            }
        } else // send to configured control channel
        {
            MessageChannel chan = guild.getTextChannelById(channelId);
            if (chan != null) {
                MessageUtilities.sendMsg(msg, chan, null);
            }
        }
    }
    MessageUtilities.sendPrivateMsg("Finished sending announcements to guilds!", event.getAuthor(), null);
}
Also used : TextChannel(net.dv8tion.jda.api.entities.TextChannel) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

TextChannel (net.dv8tion.jda.api.entities.TextChannel)12 Document (org.bson.Document)5 Main (ws.nmathe.saber.Main)5 Consumer (java.util.function.Consumer)4 JDA (net.dv8tion.jda.api.JDA)4 Bson (org.bson.conversions.Bson)4 MessageUtilities (ws.nmathe.saber.utils.MessageUtilities)4 Calendar (com.google.api.services.calendar.Calendar)3 Filters.eq (com.mongodb.client.model.Filters.eq)3 Permission (net.dv8tion.jda.api.Permission)3 Guild (net.dv8tion.jda.api.entities.Guild)3 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)3 Logging (ws.nmathe.saber.utils.Logging)3 Credential (com.google.api.client.auth.oauth2.Credential)2 Filters (com.mongodb.client.model.Filters)2 Projections.fields (com.mongodb.client.model.Projections.fields)2 Projections.include (com.mongodb.client.model.Projections.include)2 ZonedDateTime (java.time.ZonedDateTime)2 Message (net.dv8tion.jda.api.entities.Message)2 MessageReceivedEvent (net.dv8tion.jda.api.events.message.MessageReceivedEvent)2