-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
79 lines (78 loc) · 3.54 KB
/
Program.cs
File metadata and controls
79 lines (78 loc) · 3.54 KB
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using cqhttp.Cyan.ApiCall.Requests;
using cqhttp.Cyan.Events.CQEvents;
using cqhttp.Cyan.Events.CQEvents.Base;
using cqhttp.Cyan.Events.CQResponses;
using cqhttp.Cyan.Instance;
using cqhttp.Cyan.Messages;
using cqhttp.Cyan.Utils;
namespace WRBot {
class Program {
static List<string> privateCommands = new List<string> { "help", "init", "get_wr", "submit" };
public static string getText (Message m) {
string ret = "";
foreach (var i in m.data) {
if (i.type == "text")
ret += i.data["text"];
}
return ret;
}
static string helpMsg = @"此bot为交互式bot,调用相应的命令会有相应的指引。请大胆使用,enjoy。
支持的命令:
/help 展示此消息
/init 设置登陆周报平台所需的credentials
/get_wr 获取本周大家的周报
/submit 提交自己的周报(only sunday)
/status 在群里就能使用, 查看有多少人已经提交周报
bot(应该)会在每周日早八点在XDSEC 2018群里提醒大家写周报, 也(应该)会在周日下午四点公布尚未提交周报的人";
static void Main (string[] args) {
cqhttp.Cyan.Logger.LogLevel = cqhttp.Cyan.Enums.Verbosity.INFO;
CQApiClient cli = new CQHTTPClient (
accessUrl: "http://127.0.0.1:5700",
listen_port : 210
);
Group.Jobs.StartJobs (cli, 00000000);
Private.Operation.LoadData ();
cli.OnEvent += (client, e) => {
if (e is MessageEvent) {
string text_message = getText ((e as MessageEvent).message);
Command cmd;
try {
cmd = Parser.ParseCommand (text_message, (e as MessageEvent).sender.nickname);
} catch { return new EmptyResponse (); }
if (e is GroupMessageEvent) {
GroupMessageEvent ge = (e as GroupMessageEvent);
cmd.endPoint = (client, (ge.messageType, ge.group_id));
if (privateCommands.IndexOf (cmd.operation) != -1) {
client.SendTextAsync (
cmd.endPoint.Item2, "请私聊调用这项功能"
);
client.SendTextAsync (
cqhttp.Cyan.Enums.MessageType.private_,
ge.sender.user_id, helpMsg
);
} else {
Group.Jobs.Handle (cmd);
}
} else if (e is PrivateMessageEvent) {
PrivateMessageEvent pe = (e as PrivateMessageEvent);
cmd.endPoint = (cli, (pe.messageType, pe.sender_id));
if (cmd.operation == "help") {
cli.SendTextAsync (cmd.endPoint.Item2, helpMsg);
return new EmptyResponse ();
}
try {
Private.Operation.Handle (cmd).Wait ();
} catch (AggregateException ee) {
throw ee.InnerException;
}
}
}
return new EmptyResponse ();
};
Console.ReadLine ();
}
}
}