add /api/player/disconnect endpoint
This commit is contained in:
@@ -2,29 +2,25 @@
|
||||
using Emzi0767.Utilities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TomatenMusic_Api.Models;
|
||||
using TomatenMusic_Api.Models.EventArgs;
|
||||
|
||||
namespace TomatenMusic_Api;
|
||||
|
||||
public class InProcessEventBus
|
||||
{
|
||||
public event AsyncEventHandler<InProcessEventBus, ChannelConnectEventArgs>? OnConnectRequest;
|
||||
public event AsyncEventHandler<InProcessEventBus, ChannelConnectArgs>? OnConnectRequest;
|
||||
|
||||
public void OnConnectRequestEvent(ChannelConnectEventArgs e)
|
||||
public event AsyncEventHandler<InProcessEventBus, ChannelDisconnectArgs>? OnDisconnectRequest;
|
||||
|
||||
|
||||
public void OnConnectRequestEvent(ChannelConnectArgs e)
|
||||
{
|
||||
_ = OnConnectRequest?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public class ChannelConnectEventArgs : AsyncEventArgs
|
||||
{
|
||||
public ulong Guild_Id { get; set; }
|
||||
|
||||
public DiscordChannel Channel { get; set; }
|
||||
|
||||
public ChannelConnectEventArgs(ulong guild_Id, DiscordChannel channel)
|
||||
{
|
||||
Guild_Id = guild_Id;
|
||||
Channel = channel;
|
||||
}
|
||||
public void OnDisconnectRequestEvent(ChannelDisconnectArgs e)
|
||||
{
|
||||
_ = OnDisconnectRequest?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using TomatenMusic;
|
||||
using TomatenMusic.Music;
|
||||
using TomatenMusic_Api.Models;
|
||||
using TomatenMusic_Api.Models.EventArgs;
|
||||
using static TomatenMusic_Api.InProcessEventBus;
|
||||
|
||||
namespace TomatenMusic_Api
|
||||
@@ -24,11 +25,17 @@ namespace TomatenMusic_Api
|
||||
private void Initialize()
|
||||
{
|
||||
_inProcessEventBus.OnConnectRequest += _inProcessEventBus_OnConnectRequest;
|
||||
_inProcessEventBus.OnDisconnectRequest += _inProcessEventBus_OnDisconnectRequest;
|
||||
}
|
||||
|
||||
private async Task _inProcessEventBus_OnConnectRequest(InProcessEventBus sender, ChannelConnectEventArgs e)
|
||||
private async Task _inProcessEventBus_OnDisconnectRequest(InProcessEventBus sender, ChannelDisconnectArgs e)
|
||||
{
|
||||
GuildPlayer player = _audioService.GetPlayer<GuildPlayer>(e.GuildId);
|
||||
player.DisconnectAsync();
|
||||
}
|
||||
|
||||
private async Task _inProcessEventBus_OnConnectRequest(InProcessEventBus sender, ChannelConnectArgs e)
|
||||
{
|
||||
_logger.LogInformation("Channel Connected!");
|
||||
GuildPlayer player = await _audioService.JoinAsync<GuildPlayer>(e.Guild_Id, e.Channel.Id, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user