-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helenite.cs
54 lines (41 loc) · 1.39 KB
/
Helenite.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
using DimBot;
using Newtonsoft.Json;
using System.IO;
DiscordSocketClient bot = new(new DiscordSocketConfig()
{
GatewayIntents = (GatewayIntents)0b1111110000011, // https://discord.com/developers/docs/topics/gateway#list-of-intents
MessageCacheSize = 100
});
DimSecret dimSecret = JsonConvert.DeserializeObject<DimSecret>(File.ReadAllText("dimsecret.json"));
Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
async Task HandleCommandAsync(SocketMessage msgParam)
{
var msg = msgParam as SocketUserMessage;
if (msg == null) return;
// Create a number to track where the prefix ends and the command begins
int argPos = 0;
// Determine if the message is a command based on the prefix and make sure no bots trigger commands
if (!(msg.HasStringPrefix(Missile.DefaultPrefix, ref argPos) ||
msg.HasMentionPrefix(bot.CurrentUser, ref argPos)) ||
msg.Author.IsBot)
return;
await Missile.s_cmdSvc.ExecuteAsync(
context: new SocketCommandContext(bot, msg),
argPos: argPos,
services: null);
}
async Task MainAsync()
{
bot.Log += Log;
Missile.s_cmdSvc.Log += Log;
await bot.LoginAsync(TokenType.Bot, dimSecret.token);
await bot.StartAsync();
bot.MessageReceived += HandleCommandAsync;
await Missile.s_cmdSvc.AddModulesAsync(assembly: System.Reflection.Assembly.GetEntryAssembly(), services: null);
await Task.Delay(-1);
}
MainAsync().Wait();