Add createChannel endpoint; #104
This commit is contained in:
parent
1041762178
commit
10747150b3
|
@ -396,6 +396,10 @@ class Guild extends SnowflakeEntity {
|
|||
/// Request members from gateway. Requires privileged intents in order to work.
|
||||
void requestChunking() => this.shard.requestMembers(this.id);
|
||||
|
||||
/// Allows to create new guil channel
|
||||
Future<IChannel> createChannel(ChannelBuilder channelBuilder) =>
|
||||
this.client.httpEndpoints.createGuildChannel(this.id, channelBuilder);
|
||||
|
||||
/// Deletes the guild.
|
||||
Future<void> delete() =>
|
||||
client._httpEndpoints.deleteGuild(this.id);
|
||||
|
|
|
@ -192,6 +192,8 @@ abstract class IHttpEndpoints {
|
|||
Future<DMChannel> createDMChannel(Snowflake userId);
|
||||
|
||||
Future<GuildPreview> fetchGuildPreview(Snowflake guildId);
|
||||
|
||||
Future<IChannel> createGuildChannel(Snowflake guildId, ChannelBuilder channelBuilder);
|
||||
}
|
||||
|
||||
class _HttpEndpoints implements IHttpEndpoints {
|
||||
|
@ -1150,6 +1152,17 @@ class _HttpEndpoints implements IHttpEndpoints {
|
|||
return GuildPreview._new(_client, response.jsonBody as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
return Future.error(response);
|
||||
}
|
||||
@override
|
||||
Future<IChannel> createGuildChannel(Snowflake guildId, ChannelBuilder channelBuilder) async {
|
||||
final response = await _httpClient._execute(
|
||||
BasicRequest._new("/guilds/${guildId.toString()}/channels", method: "POST", body: channelBuilder._build()));
|
||||
|
||||
if (response is HttpResponseSuccess) {
|
||||
return IChannel._deserialize(_client, response.jsonBody as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
return Future.error(response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,9 +88,45 @@ class ChannelBuilder implements Builder {
|
|||
/// Type of channel
|
||||
ChannelType type;
|
||||
|
||||
/// Channel topic (0-1024 characters)
|
||||
String? topic;
|
||||
|
||||
/// The bitrate (in bits) of the voice channel (voice only)
|
||||
int? bitrate;
|
||||
|
||||
/// The user limit of the voice channel (voice only)
|
||||
int? userLimit;
|
||||
|
||||
/// Amount of seconds a user has to wait before sending another message (0-21600);
|
||||
/// bots, as well as users with the permission manage_messages or manage_channel, are unaffected
|
||||
int? rateLimitPerUser;
|
||||
|
||||
/// Sorting position of the channel
|
||||
int? position;
|
||||
|
||||
/// Id of the parent category for a channel
|
||||
SnowflakeEntity? parentChannel;
|
||||
|
||||
/// The channel's permission overwrites
|
||||
List<PermissionOverrideBuilder>? overrides;
|
||||
|
||||
/// Whether the channel is nsfw
|
||||
bool? nsfw;
|
||||
|
||||
/// Builder for creating mini channel instance
|
||||
ChannelBuilder(this.name, this.type);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> _build() => {"name": name, "type": type._value};
|
||||
Map<String, dynamic> _build() => {
|
||||
"name": name,
|
||||
"type": type._value,
|
||||
if (topic != null) "topic": topic,
|
||||
if (bitrate != null) "bitrate": bitrate,
|
||||
if (userLimit != null) "user_limit": userLimit,
|
||||
if (rateLimitPerUser != null) "rate_limit_per_user": rateLimitPerUser,
|
||||
if (position != null) "position": position,
|
||||
if (parentChannel != null) "parent_id": parentChannel!.id,
|
||||
if (nsfw != null) "nsfw": nsfw,
|
||||
if (overrides != null) "permission_overwrites" : overrides!.map((e) => e._build())
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue