This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
bot.js
159 lines (140 loc) · 6.02 KB
/
bot.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { createClient } from "icqq";
import lodash from "lodash";
import { dispatch } from "#bot/dispatch";
import { init } from "#bot/init";
import { loadPlugins } from "#bot/plugin";
import { readConfig } from "#utils/config";
import { boardcast, say, sayMaster } from "#utils/oicq";
("use strict");
global.bots = [];
function create() {
async function sendMessage(bot, id, msg, type = "private", sender = undefined, delimiter = " ", atSender = true) {
return await bot.say(id, msg, type, sender, true, delimiter, atSender);
}
for (const account of global.config.accounts) {
// https://github.com/icqqjs/icqq#%E4%B8%8Eoicq2%E7%9A%84%E5%B7%AE%E5%BC%82
//const bot = createClient(account.qq, { platform: account.platform, log_level: "debug", data_dir: global.oicqdir });
const bot = createClient({ platform: account.platform, log_level: "debug", data_dir: global.oicqdir });
bot.account = account;
bot.boardcast = boardcast.bind(null, bot);
bot.say = say.bind(null, bot);
bot.sayMaster = sayMaster.bind(null, bot);
// 属性 sendMessage 和 sendMessage 为了兼容可能存在的旧插件
bot.sendMessage = sendMessage.bind(null, bot);
bot.sendMaster = bot.sayMaster;
global.bots.push(bot);
}
global.bots.logger = lodash.hasIn(global.bots, [0, "logger"]) ? global.bots[0].logger : () => {};
}
function report() {
function log(text) {
global.bots.logger.debug(`配置:${text}`);
}
function getDefaultAuth(on = true) {
return Object.entries(global.authority.default)
.map(([k, v]) => on === v && k)
.filter((c) => "boolean" !== typeof c);
}
log(`加载了 ${global.cookies.length} 条 Cookie 。`);
log(`登录账号 ${global.config.accounts.map((c) => c.qq).join(" 、 ")} 。`);
log(`管理者已设置为 ${global.config.masters.join(" 、 ")} 。`);
log(
0 === global.config.prefixes.length || global.config.prefixes.includes(null)
? "所有的消息都将被视为命令。"
: `命令前缀设置为 ${global.config.prefixes.join(" 、 ")} 。`
);
log(`${2 === global.config.atMe ? "只" : 0 === global.config.atMe ? "不" : ""}允许用户 @ 机器人。`);
log(`群回复将${1 === global.config.atUser ? "" : "不"}会 @ 用户。`);
log(`群消息复读的概率为 ${(global.config.repeatProb / 100).toFixed(2)}% 。`);
log(`上线${1 === global.config.groupHello ? "" : "不"}发送群通知。`);
log(`${1 === global.config.groupGreetingNew ? "" : "不"}向新群友问好。`);
log(`${1 === global.config.friendGreetingNew ? "" : "不"}向新好友问好。`);
log(`${1 === global.config.noticeMysNews ? "" : "不"}推送米游社新闻。`);
log(
`米游社新闻推送类型为 ${
Array.isArray(global.config.mysNewsType) && global.config.mysNewsType.length > 1
? global.config.mysNewsType.join(" 、 ")
: "空"
}。`
);
log(`角色查询${1 === global.config.characterTryGetDetail ? "尝试" : "不"}更新玩家信息。`);
log(`耗时操作前${1 === global.config.warnTimeCosts ? "" : "不"}发送提示。`);
log(`用户每隔 ${global.config.requestInterval} 秒可以使用一次机器人。`);
log(
`${
global.config.deleteGroupMsgTime > 0 ? global.config.deleteGroupMsgTime + " 秒后" : "不"
}尝试撤回机器人发送的群消息`
);
log(`广播中消息间时延 ${(global.config.boardcastDelay / 1000).toFixed(2)} 秒。`);
log(`深渊记录将缓存 ${global.config.cacheAbyEffectTime} 小时。`);
log(`玩家信息将缓存 ${global.config.cacheInfoEffectTime} 小时。`);
log(`清理数据库 aby 中超过 ${global.config.dbAbyEffectTime} 小时的记录。`);
log(`清理数据库 info 中超过 ${global.config.dbInfoEffectTime} 小时的记录。`);
log(`${1 === global.config.viewDebug ? "" : "不"}使用前端调试模式。`);
log(`${1 === global.config.saveImage ? "" : "不"}保存图片。`);
getDefaultAuth(true).forEach((c) => log(`默认打开权限 ${c} 。`));
getDefaultAuth(false).forEach((c) => log(`默认关闭权限 ${c} 。`));
}
async function run() {
const plugins = await loadPlugins();
for (const bot of global.bots) {
const events = [
"system.online",
"message.group",
"message.private",
"notice.friend.increase",
"notice.group.increase",
];
for (const e of events) {
bot.on(e, (msg) => dispatch(msg, plugins, e, bot));
}
await new Promise((resolve) => {
for (const e of ["system.online", "system.login.error"]) {
bot.on(e, () => resolve());
}
bot.on("system.login.slider", () => {
bot.logger.mark("输入滑动验证码请求中的 ticket 后按下回车键继续。");
process.stdin.once("data", (input) => {
bot.submitSlider(input.toString().trim());
resolve();
});
});
bot.on("system.login.qrcode", () => {
bot.logger.mark("手机扫码完成后按下回车键继续。");
process.stdin.once("data", () => {
bot.login();
resolve();
});
});
bot.on("system.login.device", (e) => {
bot.logger.mark("输入证方式(1:短信验证;2:扫码验证)。");
process.stdin.once("data", (input) => {
if ("1" === input.toString().trim()) {
bot.logger.mark("输入密保手机收到的短信验证码后按下回车键继续。");
bot.sendSmsCode();
process.stdin.once("data", (input) => {
bot.submitSmsCode(input.toString().trim());
resolve();
});
} else {
bot.logger.mark(`扫码完成后回车继续:${e.url}`);
process.stdin.once("data", () => {
bot.login();
resolve();
});
}
});
});
// https://github.com/icqqjs/icqq#%E4%B8%8Eoicq2%E7%9A%84%E5%B7%AE%E5%BC%82
//bot.login(bot.account.password);
bot.login(bot.account.qq, bot.account.password);
});
}
}
(async function main() {
readConfig();
create();
report();
await init();
run();
})();