fix discord bot internal event errors
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user