This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
68 lines (56 loc) · 1.9 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
using System.IO;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using TjulfarBot.Net.Managers;
using TjulfarBot.Net.Utils;
namespace TjulfarBot.Net
{
class Program
{
public static Program instance { get; private set; }
public Settings Settings { get; }
public DiscordSocketClient SocketClient { get; private set; }
public DatabaseManager DatabaseManager { get; }
private Program()
{
if (File.Exists("settings.json"))
{
Settings = (Settings) JsonTool.Deserialize(typeof(Settings), "settings.json");
}
else
{
Settings = Settings.Default;
JsonTool.Serialize(Settings, "settings.json");
}
DatabaseManager = new DatabaseManager();
}
private async Task StartBot()
{
var config = new DiscordSocketConfig()
{
AlwaysDownloadUsers = true
};
SocketClient = new DiscordSocketClient(config);
Listener.Set(SocketClient);
StreamReader reader = new StreamReader(File.OpenRead("token.txt"));
await SocketClient.LoginAsync(TokenType.Bot, await reader.ReadToEndAsync());
reader.Close();
await SocketClient.StartAsync();
await SocketClient.SetGameAsync("Tjulfars Kanal", null, ActivityType.Watching);
await Task.Delay(-1);
}
static void Main(string[] args)
{
instance = new Program();
instance.StartBot().GetAwaiter().GetResult();
}
public async Task Close()
{
await SocketClient.StopAsync();
await SocketClient.LogoutAsync();
SocketClient.Dispose();
JsonTool.Serialize(Settings, "settings.json");
}
}
}