-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
75 lines (61 loc) · 2.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
using System;
using System.IO;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using OsxPhotos;
namespace SofiBot
{
class Program
{
private DiscordSocketClient client;
private CommandService commandService;
private ServiceProvider services;
private CommandHandler commandHandler;
static void Main(string[] args) =>
new Program().MainAsync().GetAwaiter().GetResult();
Program()
{
client = new DiscordSocketClient();
client.Log += Log;
client.JoinedGuild += JoinedGuild;
client.GuildAvailable += JoinedGuild;
commandService = new CommandService(new CommandServiceConfig
{
LogLevel = LogSeverity.Debug,
CaseSensitiveCommands = false,
});
services = new ServiceCollection()
.AddSingleton(client)
.AddSingleton(commandService)
.AddSingleton<OsxPhotoService>()
.AddTransient<ShellCommand>()
.BuildServiceProvider();
// unused
// .AddSingleton<ViewFactory>()
// .AddSingleton<CommandListeners>()
// .AddScoped<ReactionContext>()
commandHandler = ActivatorUtilities.CreateInstance<CommandHandler>(services);
}
public async Task MainAsync()
{
await commandHandler.InstallCommandsAsync();
await client.LoginAsync(TokenType.Bot, File.ReadAllText("token.txt"));
await client.StartAsync();
await Task.Delay(-1);
}
private async Task JoinedGuild(SocketGuild guild)
{
Console.WriteLine($"Guild Event {guild}");
// await guild.DefaultChannel.SendMessageAsync("Hello World!");
await Task.CompletedTask;
}
private async Task Log(LogMessage msg)
{
Console.WriteLine($"[SofiBot.Log] {msg.ToString()}");
await Task.CompletedTask;
}
}
}