Basic bot

This commit is contained in:
Myx
2024-04-11 04:22:49 +02:00
commit 5b996ecd1d
13 changed files with 332 additions and 0 deletions

View 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);
}
}

View 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));
}