forked from Yucked/Victoria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLavaSocketClient.cs
38 lines (34 loc) · 1.29 KB
/
LavaSocketClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Discord;
using Discord.WebSocket;
using System;
using System.Threading.Tasks;
namespace Victoria
{
/// <summary>
/// Represents a <see cref="DiscordSocketClient"/> connection to Lavalink server.
/// </summary>
public sealed class LavaSocketClient : LavaBaseClient
{
/// <summary>
/// Starts websocket connection with Lavalink server once <see cref="DiscordSocketClient"/> hits ready event.
/// </summary>
/// <param name="socketClient"><see cref="DiscordSocketClient"/></param>
/// <param name="configuration"><see cref="Configuration"/></param>
public Task StartAsync(DiscordSocketClient socketClient, Configuration configuration = null)
{
socketClient.Disconnected += OnDisconnected;
return InitializeAsync(socketClient, configuration);
}
private async Task OnDisconnected(Exception exception)
{
if (Configuration.PreservePlayers)
return;
foreach (var player in Players.Values)
{
await player.DisposeAsync().ConfigureAwait(false);
}
Players.Clear();
ShadowLog?.WriteLog(LogSeverity.Error, "WebSocket disconnected! Disposing all connected players.", exception);
}
}
}