imp(wetsock) plugin handling and implementation

This commit is contained in:
gh0sTedBuddy
2024-04-07 20:07:50 +01:00
parent 2c72652e15
commit 2a2a8c800f
4 changed files with 269 additions and 23 deletions

33
lib/WetSock/Message.js Normal file
View File

@@ -0,0 +1,33 @@
/**
* Represents a chat message.
*/
export default class ChatMessage {
#origin;
#data;
#message;
/**
* Creates an instance of ChatMessage.
* @param {string} rawText - The raw text of the chat message.
*/
constructor(rawText) {
this.#origin = rawText;
try {
this.#data = JSON.parse(rawText.trim());
this.#message = this.#data.message;
} catch(err) {}
}
/**
* Emits the properties of the chat message through the provided WebSocket.
* @param {WebSocket} wetsock - The WebSocket instance to emit the properties through.
*/
emitProps(wetsock) {
if (!this.#data || typeof this.#data !== 'object') return;
for (const key in this.#data) {
if (typeof this.#data[key] === 'string' && this.#data[key].indexOf(' ') === -1) {
wetsock.emit(`message:${key}:${this.#data[key]}`, this);
}
}
}
}