-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProgram.cs
108 lines (96 loc) · 3.59 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
namespace AcegikmoDiscordBot;
#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.
internal class Program : IDisposable
{
public const ulong ASHL = 139525105846976512UL;
public const ulong MODERATOR_ROLE = 474015848311291944UL;
public const ulong ACEGIKMO_SERVER = 422202998610198528UL;
public const ulong ACEGIKMO_DELETED_MESSAGES = 612767753031647240UL;
public const ulong ACEGIKMO_MOD_LOUNGE = 474020456903737350UL;
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("Deserialization of config.json failed"));
}
private static async Task Main()
{
using var program = new Program();
await program.Run();
}
private Program()
{
_client = new(new()
{
GatewayIntents =
GatewayIntents.Guilds |
GatewayIntents.GuildMembers |
GatewayIntents.GuildMessages |
GatewayIntents.GuildMessageReactions |
GatewayIntents.MessageContent,
});
_log = new();
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.SlashCommandExecuted += EchoCommand.SlashCommandExecuted;
var games = new GamesCommand();
_client.MessageReceived += games.MessageReceivedAsync;
_client.SlashCommandExecuted += games.SlashCommandExecuted;
_client.MessageReceived += HelpCommand.MessageReceivedAsync;
_client.SlashCommandExecuted += PronounCommand.SlashCommandExecuted;
_client.MessageReceived += new MemberizerCommand(_log).MessageReceivedAsync;
var tmpBan = new TmpBan();
_client.SlashCommandExecuted += tmpBan.SlashCommandExecuted;
_client.MessageReceived += new TimingThing(tmpBan, _log).MessageReceivedAsync;
_client.MessageReceived += _log.MessageReceivedAsync;
_client.MessageUpdated += _log.MessageUpdatedAsync;
_client.MessageReceived += TwitterBonker.MessageReceivedAsync;
await _client.LoginAsync(TokenType.Bot, Config.token);
await _client.StartAsync();
_client.Ready += async () =>
{
var acegikmo = _client.GetGuild(ACEGIKMO_SERVER);
var commands = await acegikmo.BulkOverwriteApplicationCommandAsync(
GamesCommand.Commands
.Concat(PronounCommand.Commands)
.Concat(TmpBan.Commands)
.Concat(EchoCommand.Commands)
.ToArray()
);
};
// Block the program until it is closed.
await Task.Delay(-1);
}
public void Dispose()
{
_client.Dispose();
_log.Dispose();
}
}