From 126327a152b1be6049eb6205b49c8c9053978351 Mon Sep 17 00:00:00 2001 From: fiatrete Date: Sat, 10 Jun 2023 20:33:39 +0800 Subject: [PATCH] fix discord bot internal event errors --- discord_bot/README.md | 2 +- discord_bot/src/bot/bot-app.mts | 6 +++--- discord_bot/src/bot/index.mts | 4 ++-- discord_bot/src/bot/websocket-server.mts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/discord_bot/README.md b/discord_bot/README.md index 4e7fce7..99a6bb1 100644 --- a/discord_bot/README.md +++ b/discord_bot/README.md @@ -2,7 +2,7 @@ ## What is Jarvis Discord Bot? -Using Jarvis Discord Bot you can interact with Jarvis through Discord app on various devices and share him with your friends. In the early versions of Jarvis, you could only interact with Jarvis through a simple web page. This limited your interaction with Jarvis to computers and browsers, and you had to be on the same local network. +Using Jarvis Discord Bot you can interact with Jarvis through Discord app on various devices and share him with your friends. In the early versions of Jarvis, you could only interact with Jarvis through a simple web page. This limited your interaction with Jarvis to computers and browsers, and you had to be on the same local network. ## How to setup diff --git a/discord_bot/src/bot/bot-app.mts b/discord_bot/src/bot/bot-app.mts index 7ced65e..950ebe2 100644 --- a/discord_bot/src/bot/bot-app.mts +++ b/discord_bot/src/bot/bot-app.mts @@ -18,7 +18,7 @@ import base64 from "base64-js" import { ExchangeMessageData } from "../types/index.mjs" interface BotAppEvents { - message: (data: ExchangeMessageData) => void + message_request: (data: ExchangeMessageData) => void } declare interface BotApp { @@ -91,7 +91,7 @@ class BotApp extends EventEmitter { const chatId = message.channel.id this.cachedMessages.set(msgId, message) - this.emit("message", { + this.emit("message_request", { user: { id: `${message.author.id}`, }, @@ -131,7 +131,7 @@ class BotApp extends EventEmitter { return } - this.emit("message", { + this.emit("message_request", { user: { id: useId, }, diff --git a/discord_bot/src/bot/index.mts b/discord_bot/src/bot/index.mts index 5246ba6..4e133a5 100644 --- a/discord_bot/src/bot/index.mts +++ b/discord_bot/src/bot/index.mts @@ -17,7 +17,7 @@ class App { parseInt(process.env.WEBSOCKET_PORT as string, 10) ) - botApp.on("message", this.handleBotAppMessage) + botApp.on("message_request", this.handleBotAppMessageRequest) websocketServer.on("message_response", this.handleWebsocketMessageResponse) this.botApp = botApp @@ -28,7 +28,7 @@ class App { private websocketServer: WebsocketServer - private handleBotAppMessage = (data: ExchangeMessageData) => { + private handleBotAppMessageRequest = (data: ExchangeMessageData) => { console.log("handleBotAppMessageRequest", data) this.websocketServer.sendMessageRequest(data) } diff --git a/discord_bot/src/bot/websocket-server.mts b/discord_bot/src/bot/websocket-server.mts index 2ff86b3..b91fbef 100644 --- a/discord_bot/src/bot/websocket-server.mts +++ b/discord_bot/src/bot/websocket-server.mts @@ -55,13 +55,13 @@ class WebsocketServer extends EventEmitter { socket.on("disconnect", (reason: string) => { console.log("socket disconnect", reason, Date.now()) }) - socket.on("message_response", (data: ExchangeMessageData) => { + socket.on("chat_message", (data: ExchangeMessageData) => { this.emit("message_response", data) }) } sendMessageRequest = (data: ExchangeMessageData) => { - this.sioServer.emit("message_request", data) + this.sioServer.emit("chat_message", data) } start = () => {