Skip to content

Commit

Permalink
Added GuildController#createTextChannel(String) and #createVoiceChann…
Browse files Browse the repository at this point in the history
…el(String).
  • Loading branch information
DV8FromTheWorld committed Oct 22, 2016
1 parent edebd56 commit 42de6ac
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 67 deletions.
66 changes: 3 additions & 63 deletions src/main/java/net/dv8tion/jda/core/entities/Guild.java
Expand Up @@ -117,21 +117,9 @@ public interface Guild extends ISnowflake
*/
List<TextChannel> getTextChannels();
List<TextChannel> getTextChannelsByName(String name, boolean ignoreCase);
//
// /**
// * Creates a new {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} in this Guild.
// * For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.Permission#MANAGE_CHANNEL MANAGE_CHANNEL Permission}
// *
// * @param name
// * the name of the TextChannel to create
// * @return
// * the ChannelManager for the created TextChannel
// * @throws net.dv8tion.jda.exceptions.GuildUnavailableException
// * if the guild is temporarily unavailable
// */
// ChannelManager createTextChannel(String name);
//

VoiceChannel getVoiceChannelById(String id);

/**
* The {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannels} available on the {@link net.dv8tion.jda.core.entities.Guild Guild}.
* The channels returned will be sorted according to their position.
Expand All @@ -140,20 +128,8 @@ public interface Guild extends ISnowflake
* An Immutable List of {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannels}.
*/
List<VoiceChannel> getVoiceChannels();

List<VoiceChannel> getVoiceChannelsByName(String name, boolean ignoreCase);
//
// /**
// * Creates a new {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel} in this Guild.
// * For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.Permission#MANAGE_CHANNEL MANAGE_CHANNEL Permission}
// *
// * @param name
// * the name of the VoiceChannel to create
// * @return
// * the ChannelManager for the created VoiceChannel
// * @throws net.dv8tion.jda.exceptions.GuildUnavailableException
// * if the guild is temporarily unavailable
// */
// ChannelManager createVoiceChannel(String name);

/**
* This returns the {@link net.dv8tion.jda.core.entities.Role Role} which has the same id as the one provided.<br>
Expand All @@ -175,42 +151,6 @@ public interface Guild extends ISnowflake
*/
List<Role> getRoles();
List<Role> getRolesByName(String name, boolean ignoreCase);
//
// /**
// * Creates a new {@link net.dv8tion.jda.core.entities.Role Role} in this Guild.
// * For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.Permission#MANAGE_ROLES MANAGE_ROLES Permission}
// *
// * @return
// * the RoleManager for the created Role
// * @throws net.dv8tion.jda.exceptions.GuildUnavailableException
// * if the guild is temporarily unavailable
// */
// RoleManager createRole();
//
// /**
// * Creates a new {@link net.dv8tion.jda.core.entities.Role Role} in this {@link net.dv8tion.jda.core.entities.Guild Guild} with the same settings as the given {@link net.dv8tion.jda.core.entities.Role Role}.
// * It will be placed at the bottom (just over the @everyone role) to avoid permission hierarchy conflicts.
// * For this to be successful, the logged in account has to have the {@link net.dv8tion.jda.Permission#MANAGE_ROLES MANAGE_ROLES Permission}
// * and all {@link net.dv8tion.jda.Permission Permissions} the given {@link net.dv8tion.jda.core.entities.Role Role} has.
// *
// * @param role
// * The {@link net.dv8tion.jda.core.entities.Role Role} that should be copied
// * @return
// * the RoleManager for the created Role
// * @throws net.dv8tion.jda.exceptions.GuildUnavailableException
// * if the guild is temporarily unavailable
// * @throws net.dv8tion.jda.exceptions.PermissionException
// * if the bot doesn't has {@link net.dv8tion.jda.Permission#MANAGE_ROLES MANAGE_ROLES Permission} and every Permission the given Role has
// */
// RoleManager createCopyOfRole(Role role);

//
// /**
// * Provides the {@link net.dv8tion.jda.core.entities.Role Role} that determines the color for the provided {@link net.dv8tion.jda.core.entities.User User}
// *
// * If the {@link net.dv8tion.jda.core.entities.User User} has the default color, this returns the same as getPublicRole();
// */
// Role getColorDeterminantRoleForUser(User user);

/**
* The @everyone {@link net.dv8tion.jda.core.entities.Role Role} of this {@link net.dv8tion.jda.core.entities.Guild Guild}
Expand Down
94 changes: 94 additions & 0 deletions src/main/java/net/dv8tion/jda/core/managers/GuildController.java
Expand Up @@ -872,6 +872,100 @@ protected void handleResponse(Response response, Request request)
};
}

/**
* Creates a new {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} in this Guild.
* For this to be successful, the logged in account has to have the
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission
*
* @param name
* the name of the TextChannel to create
* @return
* {@link net.dv8tion.jda.core.requests.RestAction RestAction} - <br>
* &nbsp;&nbsp;&nbsp;&nbsp;<b>Type</b>: {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}<br>
* &nbsp;&nbsp;&nbsp;&nbsp;<b>Value</b>: The newly created {@link net.dv8tion.jda.core.entities.TextChannel TextChannel}
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL} permission.
* @throws java.lang.IllegalArgumentException
* If the provided name is less than 2 characters or greater than 100 characters in length
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* if the guild is temporarily unavailable
*/
public RestAction<TextChannel> createTextChannel(String name)
{
checkAvailable();
checkPermission(Permission.MANAGE_CHANNEL);
checkNull(name, "name");

if (name.length() < 2 || name.length() > 100)
throw new IllegalArgumentException("Provided name must be 2 - 100 characters in length");

JSONObject body = new JSONObject()
.put("type", "text")
.put("name", name);
Route.CompiledRoute route = Route.Guilds.CREATE_CHANNEL.compile(guild.getId());
return new RestAction<TextChannel>(getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request request)
{
if (!response.isOk())
request.onFailure(response);

JSONObject chanJson = response.getObject();
TextChannel tc = EntityBuilder.get(api).createTextChannel(chanJson, guild.getId());

request.onSuccess(tc);
}
};
}

/**
* Creates a new {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel} in this Guild.
* For this to be successful, the logged in account has to have the
* {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL MANAGE_CHANNEL} Permission.
*
* @param name
* the name of the VoiceChannel to create
* @return
* {@link net.dv8tion.jda.core.requests.RestAction RestAction} - <br>
* &nbsp;&nbsp;&nbsp;&nbsp;<b>Type</b>: {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}<br>
* &nbsp;&nbsp;&nbsp;&nbsp;<b>Value</b>: The newly created {@link net.dv8tion.jda.core.entities.VoiceChannel VoiceChannel}
* @throws net.dv8tion.jda.core.exceptions.PermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.core.Permission#MANAGE_CHANNEL} permission.
* @throws java.lang.IllegalArgumentException
* If the provided name is less than 2 characters or greater than 100 characters in length
* @throws net.dv8tion.jda.core.exceptions.GuildUnavailableException
* if the guild is temporarily unavailable
*/
public RestAction<VoiceChannel> createVoiceChannel(String name)
{
checkAvailable();
checkPermission(Permission.MANAGE_CHANNEL);
checkNull(name, "name");

if (name.length() < 2 || name.length() > 100)
throw new IllegalArgumentException("Provided name must be 2 to 100 characters in length");

JSONObject body = new JSONObject()
.put("type", "voice")
.put("name", name);
Route.CompiledRoute route = Route.Guilds.CREATE_CHANNEL.compile(guild.getId());
return new RestAction<VoiceChannel>(getJDA(), route, body)
{
@Override
protected void handleResponse(Response response, Request request)
{
if (!response.isOk())
request.onFailure(response);

JSONObject chanJson = response.getObject();
VoiceChannel vc = EntityBuilder.get(api).createVoiceChannel(chanJson, guild.getId());

request.onSuccess(vc);
}
};
}

protected void checkAvailable()
{
if (!guild.isAvailable())
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/dv8tion/jda/core/requests/Route.java
Expand Up @@ -52,6 +52,7 @@ public static class Guilds
{
public static final Route GET_GUILD = new Route(GET, "guilds/{guild_id}", "guild_id");
public static final Route MODIFY_GUILD = new Route(PATCH, "guilds/{guild_id}", "guild_id");
public static final Route CREATE_CHANNEL = new Route(POST, "guilds/{guild_id}/channels", "guild_id");
public static final Route GET_CHANNELS = new Route(GET, "guilds/{guild_id}/channels", "guild_id");
public static final Route MODIFY_CHANNELS = new Route(PATCH, "guilds/{guild_id}/channels", "guild_id");
public static final Route GET_BANS = new Route(GET, "guilds/{guild_id}/bans", "guild_id");
Expand All @@ -60,7 +61,7 @@ public static class Guilds
public static final Route UNBAN = new Route(DELETE, "guilds/{guild_id}/bans/{user_id}", "guild_id");
public static final Route KICK_MEMBER = new Route(DELETE, "guilds/{guild_id}/members/{user_id}", "guild_id");
public static final Route MODIFY_MEMBER = new Route(PATCH, "guilds/{guild_id}/members/{user_id}", "guild_id");
public static final Route MODIFY_SELF_NICK = new Route(PATCH, "guilds/{guild_id}/members/@me/nick", "guild_id");
public static final Route MODIFY_SELF_NICK = new Route(PATCH, "guilds/{guild_id}/members/@me/nick", "guild_id");
public static final Route PRUNABLE_COUNT = new Route(GET, "guilds/{guild_id}/prune?days={}", "guild_id");
public static final Route PRUNE_MEMBERS = new Route(POST, "guilds/{guild_id}/prune?days={}", "guild_id");

Expand All @@ -80,9 +81,9 @@ public static class Roles

public static class Channels
{
public static final Route DELETE_CHANNEL = new Route(DELETE, "channels/{channel_id}", "channel_id");
public static final Route MODIFY_CHANNEL = new Route(PATCH, "channels/{channel_id}", "channel_id");
public static final Route SEND_TYPING = new Route(POST, "channels/{channel_id}/typing", "channel_id");
public static final Route DELETE_CHANNEL = new Route(DELETE, "channels/{channel_id}");
public static final Route MODIFY_CHANNEL = new Route(PATCH, "channels/{channel_id}", "channel_id");
public static final Route SEND_TYPING = new Route(POST, "channels/{channel_id}/typing", "channel_id");
public static final Route GET_PERMISSIONS = new Route(GET, "channels/{channel_id}/permissions", "channel_id");
public static final Route GET_PERM_OVERRIDE = new Route(GET, "channels/{channel_id}/permissions/{permoverride_id}", "channel_id");
public static final Route CREATE_PERM_OVERRIDE = new Route(PUT, "channels/{channel_id}/permissions/{permoverride_id}", "channel_id");
Expand Down

0 comments on commit 42de6ac

Please sign in to comment.