fix discord bot internal event errors

This commit is contained in:
fiatrete
2023-06-10 20:33:39 +08:00
parent 3c8cb7cf27
commit 126327a152
4 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
## What is Jarvis Discord Bot? ## 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 ## How to setup
+3 -3
View File
@@ -18,7 +18,7 @@ import base64 from "base64-js"
import { ExchangeMessageData } from "../types/index.mjs" import { ExchangeMessageData } from "../types/index.mjs"
interface BotAppEvents { interface BotAppEvents {
message: (data: ExchangeMessageData) => void message_request: (data: ExchangeMessageData) => void
} }
declare interface BotApp { declare interface BotApp {
@@ -91,7 +91,7 @@ class BotApp extends EventEmitter {
const chatId = message.channel.id const chatId = message.channel.id
this.cachedMessages.set(msgId, message) this.cachedMessages.set(msgId, message)
this.emit("message", { this.emit("message_request", {
user: { user: {
id: `${message.author.id}`, id: `${message.author.id}`,
}, },
@@ -131,7 +131,7 @@ class BotApp extends EventEmitter {
return return
} }
this.emit("message", { this.emit("message_request", {
user: { user: {
id: useId, id: useId,
}, },
+2 -2
View File
@@ -17,7 +17,7 @@ class App {
parseInt(process.env.WEBSOCKET_PORT as string, 10) 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) websocketServer.on("message_response", this.handleWebsocketMessageResponse)
this.botApp = botApp this.botApp = botApp
@@ -28,7 +28,7 @@ class App {
private websocketServer: WebsocketServer private websocketServer: WebsocketServer
private handleBotAppMessage = (data: ExchangeMessageData) => { private handleBotAppMessageRequest = (data: ExchangeMessageData) => {
console.log("handleBotAppMessageRequest", data) console.log("handleBotAppMessageRequest", data)
this.websocketServer.sendMessageRequest(data) this.websocketServer.sendMessageRequest(data)
} }
+2 -2
View File
@@ -55,13 +55,13 @@ class WebsocketServer extends EventEmitter {
socket.on("disconnect", (reason: string) => { socket.on("disconnect", (reason: string) => {
console.log("socket disconnect", reason, Date.now()) console.log("socket disconnect", reason, Date.now())
}) })
socket.on("message_response", (data: ExchangeMessageData) => { socket.on("chat_message", (data: ExchangeMessageData) => {
this.emit("message_response", data) this.emit("message_response", data)
}) })
} }
sendMessageRequest = (data: ExchangeMessageData) => { sendMessageRequest = (data: ExchangeMessageData) => {
this.sioServer.emit("message_request", data) this.sioServer.emit("chat_message", data)
} }
start = () => { start = () => {