62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using Discord;
|
|
using Discord.WebSocket;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace GodReplacementProduct;
|
|
|
|
public class Program
|
|
{
|
|
static void Main(string[] args) {
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
builder.Services.AddHostedService<GodReplacementBot>();
|
|
|
|
var config = new DiscordSocketConfig()
|
|
{
|
|
};
|
|
builder.Services.AddSingleton(config);
|
|
builder.Services.AddSingleton<DiscordSocketClient>();
|
|
|
|
var host = builder.Build();
|
|
host.Run();
|
|
}
|
|
}
|
|
|
|
public sealed class GodReplacementBot : IHostedService {
|
|
private readonly ILogger _logger;
|
|
private readonly IConfiguration _config;
|
|
private readonly DiscordSocketClient _client;
|
|
|
|
public GodReplacementBot(
|
|
ILogger<GodReplacementBot> logger,
|
|
IConfiguration config,
|
|
DiscordSocketClient client
|
|
) {
|
|
_logger = logger;
|
|
_config = config;
|
|
_client = client;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken) {
|
|
_client.Log += Log;
|
|
var token = _config.GetValue<string>("GodReplacementProject:DiscordToken");
|
|
|
|
await _client.LoginAsync(TokenType.Bot, token);
|
|
await _client.StartAsync();
|
|
|
|
await Task.Delay(Timeout.Infinite);
|
|
}
|
|
|
|
public async Task StopAsync(CancellationToken cancellationToken) {
|
|
await _client.StopAsync();
|
|
}
|
|
|
|
private Task Log(LogMessage msg) {
|
|
Console.WriteLine(msg.ToString());
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|