imp(wetsock) plugin handling and implementation
This commit is contained in:
33
lib/WetSock/Message.js
Normal file
33
lib/WetSock/Message.js
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user