import { dedent, definePlugin } from 'kivibot' const map = new Map() const reasonsDataURL = 'https://proxy.viki.moe/vikiboss/4a970efd8b81b0069ae02d1db42e7303/raw/4ecffb1befebb4b4bd930f9bdf62f00b37069c38/aq-center-reasons.json?proxy-host=gist.githubusercontent.com' export default definePlugin({ name: 'aq', version: '1.5.0', async setup(ctx) { const { data = {} } = await ctx.http.get(reasonsDataURL) Object.entries(data as { [key in string]: any }).map(([_k, v]) => { map.set(v.reason, [v.reasonDesc || v.title, v.description]) }) ctx.handle('message', async (e) => { if (['机器人违规记录', '机器人赛博案底'].includes(e.raw_message) && ctx.isOwner(e)) { const authCode = await ctx.getAuthCodeOfBot.call(ctx.bot, 1109907872) const list = await ctx.getViolationRecords.call(ctx.bot, authCode, 1109907872) const messages = await ctx.bot.makeForwardMsg(makeRecordListMessage(list, e.sender.user_id, e.sender.nickname)) await e.reply(`共查询到 ${list.length} 条违规记录。`, true) await e.reply(messages) } if (['我的违规记录', '违规记录', '我的赛博案底', '赛博案底'].includes(e.raw_message)) { const { url, code } = await ctx.requestLoginViaDevTools.call(ctx.bot) const { message_id } = await e.reply(`请在一分钟内点击下列链接登录。\n${url}`, true) const timeout = setTimeout(async () => { clearInterval(interval) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) await e.reply('登录超时,请重新发送「赛博案底」获取新的链接。', true) }, 60_000) const interval = setInterval(async () => { const { status, ticket } = await ctx.queryDevToolsLoginStatus.call(ctx.bot, code) if (status === 'Wait') return clearInterval(interval) clearTimeout(timeout) if (status === 'Used') { ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) return } if (status === 'OK' && ticket) { ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) const authCode = await ctx.getAuthCodeViaTicket.call(ctx.bot, ticket, 1109907872) const list = await ctx.getViolationRecords.call(ctx.bot, authCode, 1109907872) if (!list.length) { await e.reply('泰酷辣!没有查到任何违规记录!', true) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) return } const messages = await ctx.bot.makeForwardMsg( makeRecordListMessage(list, e.sender.user_id, e.sender.nickname), ) ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) await e.reply(`共查询到 ${list.length} 条违规记录。`, true) await e.reply(messages) return } ctx.isGroupMsg(e) && (await e.group.recallMsg(message_id)) await e.reply('登录失败,未知错误', true) }, 1000) } }) }, }) function makeRecordListMessage( list: { type: string time: string duration: string reason: number }[], id: number, nickname: string, ) { return list.map((v) => { const reason = map.get(v.reason) || String(v.reason) const duration = +v.duration ? `强制冻结 ${Math.round((+v.duration - +v.time) / 24 / 60 / 60)} 天,限制登录` : '临时冻结,可根据引导解冻' return { user_id: id, message: dedent(` 违规时间:${new Date(+v.time * 1000).toLocaleString('zh-CN')} 违规原因:${Array.isArray(reason) ? reason[0] : reason} 详细说明:${Array.isArray(reason) ? reason[1] : reason} 处理结果:${duration} `), nickname, time: Date.now(), } }) }