mirror of
https://github.com/Myxelium/Lunaris2.0.git
synced 2026-04-11 15:19:53 +00:00
Restructure
This commit is contained in:
31
Bot/Notification/DiscordEventListener.cs
Normal file
31
Bot/Notification/DiscordEventListener.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Discord.WebSocket;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Lunaris2.Notification;
|
||||
|
||||
public class DiscordEventListener(DiscordSocketClient client, IServiceScopeFactory serviceScope)
|
||||
{
|
||||
private readonly CancellationToken _cancellationToken = new CancellationTokenSource().Token;
|
||||
|
||||
private IMediator Mediator
|
||||
{
|
||||
get
|
||||
{
|
||||
var scope = serviceScope.CreateScope();
|
||||
return scope.ServiceProvider.GetRequiredService<IMediator>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartAsync()
|
||||
{
|
||||
client.SlashCommandExecuted += OnMessageReceivedAsync;
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task OnMessageReceivedAsync(SocketSlashCommand arg)
|
||||
{
|
||||
return Mediator.Publish(new MessageReceivedNotification(arg), _cancellationToken);
|
||||
}
|
||||
}
|
||||
9
Bot/Notification/MessageReceivedNotification.cs
Normal file
9
Bot/Notification/MessageReceivedNotification.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Discord.WebSocket;
|
||||
using MediatR;
|
||||
|
||||
namespace Lunaris2.Notification;
|
||||
|
||||
public class MessageReceivedNotification(SocketSlashCommand message) : INotification
|
||||
{
|
||||
public SocketSlashCommand Message { get; } = message ?? throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
Reference in New Issue
Block a user