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 "";
}
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);
}
Aggregations