nyxx/nyxx/lib/src/core/channel/guild/VoiceChannel.dart
Szymon Uglis c71d310d6e
Changelog, license update, Implement stage channels, implements new permissions
Remove unnecessary stuff from tests and analyzer options, remove travis config file
2021-04-07 22:54:14 +02:00

53 lines
1.9 KiB
Dart

part of nyxx;
class VoiceGuildChannel extends GuildChannel {
/// The channel's bitrate.
late final int? bitrate;
/// The channel's user limit.
late final int? userLimit;
VoiceGuildChannel._new(INyxx client, Map<String, dynamic> raw, [Snowflake? guildId]) : super._new(client, raw, guildId) {
this.bitrate = raw["bitrate"] as int?;
this.userLimit = raw["user_limit"] as int?;
}
/// Edits channel properties
Future<VoiceGuildChannel> edit({String? name, int? bitrate, int? position, int? userLimit, String? auditReason}) =>
client._httpEndpoints.editVoiceChannel(this.id, name: name, bitrate: bitrate, position: position, userLimit: userLimit, auditReason: auditReason);
/// Connects client to channel
void connect({bool selfMute = false, bool selfDeafen = false}) {
if (this.client is! Nyxx) {
throw new UnsupportedError("Cannot connect with NyxxRest");
}
try {
final shard = (this.client as Nyxx).shardManager.shards.firstWhere((element) => element.guilds.contains(this.guild.id));
shard.changeVoiceState(this.guild.id, this.id, selfMute: selfMute, selfDeafen: selfDeafen);
} on Error {
throw InvalidShardException._new("Cannot find shard for this channel!");
}
}
/// Disconnects use from channel.
void disconnect() {
if (this.client is! Nyxx) {
throw new UnsupportedError("Cannot connect with NyxxRest");
}
try {
final shard = (this.client as Nyxx).shardManager.shards.firstWhere((element) => element.guilds.contains(this.guild.id));
shard.changeVoiceState(this.guild.id, null);
} on Error {
throw InvalidShardException._new("Cannot find shard for this channel!");
}
}
}
class StageVoiceGuildChannel extends VoiceGuildChannel {
StageVoiceGuildChannel._new(INyxx client, Map<String, dynamic> raw, [Snowflake? guildId]) : super._new(client, raw, guildId);
}