Skip to content

Commit

Permalink
增加trigger,定时发送消息反馈是否正常
Browse files Browse the repository at this point in the history
  • Loading branch information
lcjqyml committed Nov 15, 2024
1 parent 1d0242c commit 17e8f71
Show file tree
Hide file tree
Showing 4 changed files with 10,606 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,23 @@ export class ChatBot {
}
}

private triggerActions(talker: ContactInterface, text: string) {
if (text !== Config.checkOnlineTrigger) {
return false;
}
setInterval(async () => {
await this.onPrivateMessage(talker, Config.checkOnlineCommand);
}, Config.checkOnlineInterval);
return true;
}

// reply to private message
private async onPrivateMessage(talker: ContactInterface, text: string) {
const sessionId = pinyin(talker.name(), {style: pinyin.STYLE_TONE2}).join("");
const chatbot = this;
if (this.triggerActions(talker, text)) {
text = Config.checkOnlineCommand;
}
await this.onChat(text, `friend-${sessionId}`, sessionId,
async function (responseData: ResponseData) {
await chatbot.reply(talker, text, responseData);
Expand Down Expand Up @@ -297,6 +310,7 @@ export class ChatBot {
const room = message.room();
const messageType = message.type();
const isPrivateChat = !room;
Logger.log(`收到${isPrivateChat ? "" : room.topic()} > ${talker.name()}(${talker.id})的消息`)
if (
this.isNonsense(talker, messageType, rawText) ||
!this.triggerGPTMessage(rawText, isPrivateChat)
Expand Down Expand Up @@ -328,3 +342,4 @@ export class ChatBot {
return tmpName;
}
}

8 changes: 7 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ else {
privateChatTrigger: process.env.PRIVATE_CHAT_TRIGGER,
groupChatTrigger: process.env.GROUP_CHAT_TRIGGER,
responseQuote: process.env.RESPONSE_QUOTE,
checkOnlineTrigger: process.env.CHECK_ONLINE_CONTACT,
checkOnlineCommand: process.env.CHECK_ONLINE_COMMAND,
checkOnlineInterval: process.env.CHECK_ONLINE_INTERVAL,
};
}

Expand All @@ -45,7 +48,10 @@ export const Config: IConfig = {
autoAcceptRoomInvite: configFile.autoAcceptRoomInvite == "true",
privateChatTrigger: configFile.privateChatTrigger || "",
groupChatTrigger: configFile.groupChatTrigger || "",
responseQuote: configFile.responseQuote == "true"
responseQuote: configFile.responseQuote == "true",
checkOnlineTrigger: configFile.checkOnlineTrigger || "__check__",
checkOnlineCommand: configFile.checkOnlineContact || "ping",
checkOnlineInterval: configFile.checkOnlineContact || 60 * 60 * 1000,
};

Logger.log("Config ->")
Expand Down
3 changes: 3 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ export interface IConfig {
privateChatTrigger: string,
groupChatTrigger: string,
responseQuote: boolean,
checkOnlineTrigger: string,
checkOnlineCommand: string,
checkOnlineInterval: number,
}
Loading

0 comments on commit 17e8f71

Please sign in to comment.