forked from khyperia/acegikmo-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
88 lines (78 loc) · 3.11 KB
/
Program.cs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
namespace AcegikmoDiscordBot
{
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable CS8618 // Non-nullable field is uninitialized.
#pragma warning disable CS0649
[DataContract]
internal class ConfigClass
{
[DataMember]
internal string token;
}
#pragma warning restore CS0649
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
#pragma warning restore IDE1006 // Naming Styles
internal class Program : IDisposable
{
public static ulong ASHL = 139525105846976512UL;
public static ulong ACEGIKMO_SERVER = 422202998610198528UL;
public static ulong ACEGIKMO_DELETED_MESSAGES = 612767753031647240UL;
private readonly Log _log;
public static readonly ConfigClass Config = GetConfig();
private readonly DiscordSocketClient _client;
private static ConfigClass GetConfig()
{
using var stream = File.OpenRead("config.json");
var json = new DataContractJsonSerializer(typeof(ConfigClass));
return (ConfigClass)(json.ReadObject(stream) ?? throw new Exception("Deserialization of config.json failed"));
}
private static async Task Main()
{
using var program = new Program();
await program.Run();
}
private Program()
{
_client = new DiscordSocketClient(new DiscordSocketConfig
{
ExclusiveBulkDelete = true,
GatewayIntents =
GatewayIntents.Guilds |
GatewayIntents.GuildMembers |
GatewayIntents.GuildMessages |
GatewayIntents.GuildMessageReactions,
});
_log = new Log();
Console.CancelKeyPress += (sender, args) => Dispose();
}
private async Task Run()
{
_client.Log += a => { Console.WriteLine(a); return Task.CompletedTask; };
_client.MessageDeleted += new DeleteEcho(_log).MessageDeletedAsync;
_client.MessageReceived += new EchoCommand().MessageReceivedAsync;
_client.MessageReceived += new GamesCommand().MessageReceivedAsync;
_client.MessageReceived += new HelpCommand().MessageReceivedAsync;
_client.MessageReceived += new PronounCommand().MessageReceivedAsync;
_client.MessageReceived += new MemberizerCommand(_log).MessageReceivedAsync;
_client.MessageReceived += new TimingThing(_log).MessageReceivedAsync;
_client.MessageReceived += _log.MessageReceivedAsync;
_client.MessageUpdated += _log.MessageUpdatedAsync;
await _client.LoginAsync(TokenType.Bot, Config.token);
await _client.StartAsync();
// Block the program until it is closed.
await Task.Delay(-1);
}
public void Dispose()
{
_client.Dispose();
_log.Dispose();
}
}
}