Initial Commit
This commit is contained in:
commit
9b2f95aee4
108 changed files with 4815 additions and 0 deletions
34
Flux_System_Assistant/Services/DiscordStartupService.cs
Normal file
34
Flux_System_Assistant/Services/DiscordStartupService.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using Flux_System_Assistant.Utility;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace Flux_System_Assistant.Services;
|
||||
|
||||
public class DiscordStartupService : IHostedService
|
||||
{
|
||||
private readonly DiscordSocketClient _discord;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public DiscordStartupService(DiscordSocketClient discord, IConfiguration config, ILogger logger)
|
||||
{
|
||||
_discord = discord;
|
||||
_config = config;
|
||||
|
||||
_discord.Log += msg => LoggerService.OnLogAsync(logger, msg);
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _discord.LoginAsync(TokenType.Bot, _config["token"]);
|
||||
await _discord.StartAsync();
|
||||
}
|
||||
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _discord.StopAsync();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue