Commit 6cdd356b authored by nanahira's avatar nanahira

trace last message in chain ++

parent 331d443e
......@@ -20,6 +20,15 @@ import {
export * from './config';
import AragamiPlugin, { CacheKey, CacheTTL } from 'koishi-plugin-cache-aragami';
function plainText(text: string) {
return segment
.parse(text)
.filter((s) => s.type === 'text')
.map((s) => s.data.content)
.join('')
.trim();
}
export class SelfOnline {
@CacheKey()
selfId: string;
......@@ -37,7 +46,7 @@ export class LastMessage {
fromSession(session: Session) {
this.guildId = session.guildId;
this.userId = session.userId;
this.content = session.content;
this.content = plainText(session.content);
return this;
}
}
......@@ -61,6 +70,9 @@ class Utility extends base {
async saveLastMessage(session: Session) {
const message = new LastMessage().fromSession(session);
if (!message.content) {
return;
}
const previousSaving = await this.aragami.get(LastMessage, session.guildId);
if (previousSaving && session.userId === previousSaving.userId) {
message.content = previousSaving.content + '\n' + message.content;
......@@ -142,15 +154,10 @@ export default class OrderPicker extends base {
}
const lastMessageContent = await this.utility.fetchLastMessage(session);
if (!(await this.utility.isOnline(session.selfId))) return next();
let description = segment
.parse(session.content)
.filter((s) => s.type === 'text')
.map((s) => s.data.content)
.join('')
.trim();
if (!description) {
description = lastMessageContent || '';
let description = plainText(session.content);
if (lastMessageContent) {
description = lastMessageContent + '\n' + description;
}
await session.bot.sendPrivateMessage(
......
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