-
Notifications
You must be signed in to change notification settings - Fork 1
/
ApexGacha.cs
53 lines (45 loc) · 1.62 KB
/
ApexGacha.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
using System;
using System.Reflection;
using System.Threading.Tasks;
using ConsoleAppFramework;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.Options;
namespace ApexRandomBot
{
public class ApexGacha : ConsoleAppBase
{
private IOptions<Config> _config;
private DiscordSocketClient _client;
private CommandService _command;
public ApexGacha(IOptions<Config> config)
{
_config = config;
}
public async Task ExecuteAsync()
{
_client = new DiscordSocketClient();
_command = new CommandService();
_client.Log += message =>
{
Console.WriteLine($"{message.Message} : {message.Exception}");
return Task.CompletedTask;
};
_client.MessageReceived += MessageHandle;
await _command.AddModulesAsync(Assembly.GetEntryAssembly(), null);
await _client.LoginAsync(TokenType.Bot, _config.Value.DiscordToken);
await _client.StartAsync();
await Task.Delay(-1, Context.CancellationToken);
await _client.StopAsync();
}
private async Task MessageHandle(SocketMessage message)
{
if (!(message is SocketUserMessage msg) || msg.Author.IsBot) return;
var argPos = 0;
if (!(msg.HasCharPrefix('!', ref argPos)) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) return;
var context = new CommandContext(_client, msg);
await _command.ExecuteAsync(context, argPos, null);
}
}
}