Commit 27d324b5 authored by nanahira's avatar nanahira

change command a bit

parent 74283f43
......@@ -4,6 +4,7 @@ import {
Inject,
InjectLogger,
LifecycleEvents,
PutArg,
PutSession,
StarterPlugin,
UseCommand,
......@@ -64,7 +65,12 @@ export default class ChatGPTApiPlugin
return `session:${session.platform}:${session.selfId}:${session.channelId}:${session.userId}`;
}
@UseCommand('chatgpt-reset', '重置 ChatGPT 对话')
@UseCommand('chatgpt <content:text>', '与 ChatGPT 对话,也可以直接发送消息。')
async chat(@PutSession() session: Session, @PutArg(0) content: string) {
return this.handle(session, content);
}
@UseCommand('chatgpt.reset', '重置 ChatGPT 对话')
async reset(@PutSession() session: Session) {
await this.__cache__
.cache('chatgptMessages')
......@@ -77,7 +83,10 @@ export default class ChatGPTApiPlugin
@UseMiddleware()
middleware(session: Session, next: Next) {
if (!this.config.prefix.length || session.parsed?.appel)
if (
(!this.config.prefix.length && session.content) ||
session.parsed?.appel
)
return this.handle(session, session.content);
const matchingPrefix = this.config.prefix.find((prefix) =>
session.content.startsWith(prefix),
......@@ -87,6 +96,7 @@ export default class ChatGPTApiPlugin
}
async handle(session: Session, text: string) {
if (!text) return;
const api = this.getApiInstance(session);
const key = this.sessionKey(session);
const lastMessage = await this.__cache__.cache('chatgptMessages').get(key);
......
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