-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
52 lines (50 loc) · 2.03 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
using System;
using System.Collections.Generic;
using System.IO;
using cqhttp.Cyan.Clients;
using cqhttp.Cyan.Enums;
using cqhttp.Cyan.Events.CQEvents.Base;
using cqhttp.Cyan.Events.CQResponses;
using Newtonsoft.Json.Linq;
namespace EssentialBot {
class Program {
public static CQApiClient client;
public static Dictionary<string, string> Globals =
new Dictionary<string, string> ();
static void LoadCfg () {
if (File.Exists ("config.json")) {
string config = File.ReadAllText ("config.json");
try {
var config_parsed = JToken.Parse (config);
var coolq_config = config_parsed["coolq_config"];
Globals = config_parsed["globals"].ToObject<Dictionary<string, string>> ();
client = new CQHTTPClient (
access_url: coolq_config["api_addr"].ToObject<string> (),
listen_port: coolq_config["listen_port"].ToObject<int> (),
access_token: coolq_config["access_token"].ToObject<string> (),
secret: coolq_config["listen_secret"].ToObject<string> (),
use_group_table: true
);
} catch {
throw new Exception ("Config file parse error");
}
return;
}
throw new ArgumentNullException ("缺乏正常启动所需的配置文件或参数");
}
static void Main (string[] args) {
LoadCfg ();
cqhttp.Cyan.Config.log_default_verbosity = Verbosity.INFO;
client.OnEvent += (cli, e) => {
if (e is MessageEvent) {
Dispatcher.Dispatcher.Dispatch (
cli,
e as MessageEvent
);
}
return new EmptyResponse ();
};
Console.ReadLine ();
}
}
}