-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (56 loc) · 2.21 KB
/
Program.cs
File metadata and controls
68 lines (56 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using CatBot.Services;
using Discord;
using Discord.WebSocket;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using System.Configuration;
namespace CatBot
{
internal class Program
{
private DiscordSocketClient? _client;
public static Task Main(string[] args) => new Program().MainAsync();
public static string? token = ConfigurationManager.AppSettings["token"];
public async Task MainAsync()
{
Console.ResetColor();
Console.Title = "Catbot!";
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Debug, theme: AnsiConsoleTheme.Code)
.Enrich.FromLogContext()
.CreateLogger();
Log.Information("CatBot!");
Log.Information("Ligando bot...");
if (token == null)
{
Log.Error("Faltando Token - Missing App.config");
Console.ReadKey();
Environment.Exit(1);
}
_client = new DiscordSocketClient();
var _commandHandler = new CommandHandler(_client);
_client.Log += (s) => Task.Run(() => Log.Information(s.Message));
_client.Ready += () => Task.Run(() => _client_Ready().ConfigureAwait(false));
_client.MessageReceived += (s) => Task.Run(() => _commandHandler.HandleCommandAsync(s).ConfigureAwait(false));
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
await Task.Delay(-1).ConfigureAwait(false);
}
private async Task _client_Ready()
{
var connectionState = _client.ConnectionState;
if (connectionState == ConnectionState.Connected)
{
Log.Information("Bot Ligado! - Aguardando comandos...");
await _client.SetGameAsync("Gatinhos! | !helpcat", null, ActivityType.Playing).ConfigureAwait(false);
await _client.SetStatusAsync(UserStatus.Idle).ConfigureAwait(false);
}
else
{
Log.Error("Erro na conexão do bot");
}
}
}
}