Commit 7fce0a1b authored by nanahira's avatar nanahira

fix cqcode again

parent 3f952492
......@@ -17,7 +17,7 @@ export * from './config';
import { OneBotBot } from '@koishijs/plugin-adapter-onebot';
interface WhoSession extends Quester.File {
ips: string[];
ips: Set<string>;
data: Buffer;
}
......@@ -66,7 +66,7 @@ export default class WhoViewsPlugin extends StarterPlugin(
ctx.status = 404;
return (ctx.body = 'Not found');
}
whoSession.ips.push(ctx.ip);
whoSession.ips.add(ctx.ip);
ctx.type = whoSession.mime;
ctx.body = whoSession.data;
ctx.set('content-length', whoSession.data.length.toString());
......@@ -81,7 +81,11 @@ export default class WhoViewsPlugin extends StarterPlugin(
try {
const info = await this.http.file(picUrl);
const id = `${Random.id(20)}.${info.filename.split('.').pop()}`;
this.sessions.set(id, { ...info, ips: [], data: Buffer.from(info.data) });
this.sessions.set(id, {
...info,
ips: new Set(),
data: Buffer.from(info.data),
});
const pathWithoutSlash = this.config.path.replace(/^\//, '');
const sessionUrl = `${
this.config.selfUrl || this.ctx.root.config.selfUrl
......@@ -89,7 +93,7 @@ export default class WhoViewsPlugin extends StarterPlugin(
const messageSuffix = `让我 ${this.config.waitTime} 秒后康康谁在窥屏。`;
if (session.platform === 'onebot') {
const bot = session.bot as OneBotBot;
const messageOnebot = `[CQ:xml,data=<?xml version="1.0" encoding="UTF-8" standalone="yes"?><msg serviceID="1"><item><title>${messageSuffix}</title></item><source name="窥屏检测" icon="${sessionUrl}" action="" appid="-1" /></msg>]`;
const messageOnebot = `[CQ:cardimage,file=${sessionUrl},source=${messageSuffix},icon=${sessionUrl}]`;
if (session.guildId) {
await bot.internal.sendGroupMsg(session.guildId, messageOnebot);
} else {
......@@ -103,7 +107,7 @@ export default class WhoViewsPlugin extends StarterPlugin(
await new Promise((resolve) =>
setTimeout(resolve, this.config.waitTime * 1000),
);
const ips = this.sessions.get(id)?.ips || [];
const ips = [...(this.sessions.get(id)?.ips?.values() || [])];
this.sessions.delete(id);
if (!ips.length) return '没人窥屏。';
return ` ${ips.length} 人窥屏:\n\n${ips
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment