-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoiceCommandContext.cs
31 lines (25 loc) · 1.22 KB
/
VoiceCommandContext.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
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
using DSharpPlus.Lavalink;
namespace YumeChan.DreamJockey;
public sealed class VoiceCommandContext
{
public CommandContext Context { get; private init; }
public DiscordChannel Channel { get; init; }
public LavalinkExtension Lavalink { get; private init; }
public LavalinkNodeConnection Node { get; protected init; }
public VoiceCommandContext(CommandContext ctx, DiscordChannel? voiceChannel = null)
{
Context = ctx;
Lavalink = ctx.Client.GetLavalink();
Node ??= Lavalink.ConnectedNodes?.Values.First() ?? throw new ApplicationException("Lavalink is not connected.");
Channel ??= voiceChannel ?? ctx.Member?.VoiceState?.Channel ?? throw new InvalidOperationException($"No Voice channel has been set for current {nameof(VoiceCommandContext)}.");
if (Channel.Type is not ChannelType.Voice)
{
throw new InvalidOperationException("Designated channel is not a valid voice channel.");
}
}
public LavalinkGuildConnection? GetGuildConnection() => Node.GetGuildConnection(Channel.Guild);
public async Task<LavalinkGuildConnection> GetOrCreateGuildConnectionAsync() => Node.GetGuildConnection(Channel.Guild) ?? await Node.ConnectAsync(Channel);
}