-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
92 lines (76 loc) · 3.25 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
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.EventArgs;
using DSharpPlus.Interactivity;
using DSharpPlus.Interactivity.Extensions;
using DSharpPlus.SlashCommands;
using Newtonsoft.Json;
using OMNI.Commands;
using OMNI.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace OMNI
{
internal class Program
{
private static DiscordClient Client { get; set; }
static async Task Main(string[] args)
{
Console.Title = "OMNI";
string fileContents = File.ReadAllText("..\\..\\intro.txt");
Console.WriteLine(fileContents);
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string configFilePath = Path.Combine(appDataPath, ".omni", "config.json");
string directoryPath = Path.GetDirectoryName(configFilePath);
if (!File.Exists(configFilePath))
{
Console.WriteLine("OMNI has detected that the bot token has not yet been configured. Please set up the bot token to continue.\n");
Console.Write(" > Token: ");
string token = Console.ReadLine();
Console.WriteLine("\nThe following directory will be created for your token: " + configFilePath + "\n");
Console.WriteLine("Please note this directory before proceeding, as entering an incorrect token will cause the bot to crash.");
Console.WriteLine("If this occurs, delete the configuration and restart the setup.\n");
Console.Write(" > Press any key to continue.");
Console.ReadKey();
var tokenData = new Dictionary<string, string>
{
{ "Token", token }
};
Directory.CreateDirectory(directoryPath);
using (StreamWriter file = File.CreateText(configFilePath))
{
JsonSerializer jsonSerializer = new JsonSerializer
{
Formatting = Formatting.Indented
};
jsonSerializer.Serialize(file, tokenData);
}
}
var jsonReader = new JSONReader();
await jsonReader.ReadJSON(configFilePath);
var discordConfig = new DiscordConfiguration()
{
Intents = DiscordIntents.All,
Token = jsonReader.Token,
TokenType = TokenType.Bot,
AutoReconnect = true
};
Client = new DiscordClient(discordConfig);
Client.UseInteractivity(new InteractivityConfiguration()
{
Timeout = TimeSpan.FromMinutes(2)
});
Client.Ready += OnClientReady;
var slashCommandsConfiguration = Client.UseSlashCommands();
slashCommandsConfiguration.RegisterCommands<OmniCommands>();
await Client.ConnectAsync();
await Task.Delay(-1);
}
private static async Task OnClientReady(DiscordClient sender, ReadyEventArgs args)
{
await sender.UpdateStatusAsync(new DiscordActivity("tickets!", ActivityType.Watching));
}
}
}