Skip to content

Commit

Permalink
Add method on LavalinkPlugin for connecting to Lavalink
Browse files Browse the repository at this point in the history
  • Loading branch information
abitofevrything committed Dec 9, 2023
1 parent 71fd9d0 commit 09281d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
11 changes: 1 addition & 10 deletions packages/nyxx_lavalink/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ extension LavalinkVoiceChannel on VoiceChannel {
_ => throw UnsupportedError('Cannot connect to Lavalink outside of a guild'),
};

client.gateway.updateVoiceState(
guildId,
GatewayVoiceStateBuilder(
channelId: id,
isMuted: false,
isDeafened: false,
),
);

return await plugin.onPlayerConnected.firstWhere((player) => player.guildId == guildId);
return await plugin.connect(client, id, guildId);
}
}
16 changes: 16 additions & 0 deletions packages/nyxx_lavalink/lib/src/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ class LavalinkPlugin extends NyxxPlugin<NyxxGateway> {
@override
NyxxPluginState<NyxxGateway, LavalinkPlugin> createState() => _LavalinkPluginState(this);

/// Connect to a voice channel using Lavalink.
///
/// The returned [LavalinkPlayer] can be used to control the player in the channel.
Future<LavalinkPlayer> connect(NyxxGateway client, Snowflake channelId, Snowflake guildId) async {
client.gateway.updateVoiceState(
guildId,
GatewayVoiceStateBuilder(
channelId: channelId,
isMuted: false,
isDeafened: false,
),
);

return await onPlayerConnected.firstWhere((player) => player.guildId == guildId);
}

Future<T> _withClient<T>(Future<T> Function(HttpLavalinkClient client) f) async {
if (_customClient case final customClient?) {
return f(customClient);
Expand Down

0 comments on commit 09281d9

Please sign in to comment.