@Override public int getPosition() { return getGuild().getChannels().indexOf(this); }
@Override public List<IChannel> getChannels(boolean includePrivate) { List<IChannel> channels = guildCache.stream() .flatMap(g -> g.getChannels().stream()) .collect(Collectors.toList()); if (includePrivate) channels.addAll(privateChannels.values()); return channels; }
public static boolean channelExists(String nameOrId, IGuild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (IChannel c : guild.getChannels()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) return true; } return false; }
@Override public List<IChannel> getChannels() { return getGuild().getChannels().stream() .filter(channel -> equals(channel.getCategory())) .collect(Collectors.toList()); }
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static IChannel getChannelFromNameOrId(String nameOrId, IGuild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (IChannel c : guild.getChannels()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) return c; } return null; }
/** * Checks if the specified channel exists. * * @param nameOrId The channel name or ID. * @param event The event received. * @return <code>true</code> if exists, else <code>false</code>. */ public static boolean channelExists(String nameOrId, MessageReceivedEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (IChannel c : event.getGuild().getChannels()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) return true; } return false; }
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @return the IChannel if successful, else <code>null</code>. */ public static String getChannelNameFromNameOrId(String nameOrId, IGuild guild) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (IChannel c : guild.getChannels()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) return c.getName(); } return "ERROR"; } }
/** * Gets the IChannel from its name. * * @param nameOrId The channel name or ID. * @param event The event received. * @return the IChannel if successful, else <code>null</code>. */ public static IChannel getChannelFromNameOrId(String nameOrId, MessageReceivedEvent event) { if (nameOrId.contains("#")) nameOrId = nameOrId.replace("#", ""); for (IChannel c : event.getGuild().getChannels()) { if (c.getName().equalsIgnoreCase(nameOrId) || c.getStringID().equals(nameOrId)) return c; } return null; }
public WebGuild fromGuild(IGuild g) { id = g.getStringID(); name = g.getName(); iconUrl = g.getIconURL(); botNick = g.getClient().getOurUser().getNicknameForGuild(g); settings = DatabaseManager.getManager().getSettings(g.getLongID()); //Handle lists and stuffs for (IRole r : g.getRoles()) { roles.add(new WebRole().fromRole(r, settings)); } WebChannel all = new WebChannel(); all.setId(0); all.setName("All Channels"); all.setDiscalChannel(settings.getDiscalChannel().equalsIgnoreCase("all")); channels.add(all); for (IChannel c : g.getChannels()) { channels.add(new WebChannel().fromChannel(c, settings)); } announcements.addAll(DatabaseManager.getManager().getAnnouncements(g.getLongID())); calendar = new WebCalendar().fromCalendar(DatabaseManager.getManager().getMainCalendar(Long.valueOf(id)), settings); return this; }
/** * Checks if the user sent the command in a DisCal channel (if set). * * @param event The event received to check for the correct channel. * @return <code>true</code> if in correct channel, otherwise <code>false</code>. */ public static boolean isCorrectChannel(MessageReceivedEvent event) { try { GuildSettings settings = DatabaseManager.getManager().getSettings(event.getGuild().getLongID()); if (settings.getDiscalChannel().equalsIgnoreCase("all")) return true; IChannel channel = null; for (IChannel c : event.getMessage().getGuild().getChannels()) { if (c.getStringID().equals(settings.getDiscalChannel())) { channel = c; break; } } if (channel != null) return event.getMessage().getChannel().getStringID().equals(channel.getStringID()); //If we got here, the channel no longer exists, reset data and return true. settings.setDiscalChannel("all"); DatabaseManager.getManager().updateSettings(settings); return true; } catch (Exception e) { //Catch any errors so that the bot always responds... Logger.getLogger().exception(event.getMessage().getAuthor(), "Failed to check for discal channel.", e, PermissionChecker.class); return true; } }