UNPKG

linkup-bot-lib

Version:

64 lines (63 loc) 2.23 kB
"use strict"; /** * @module Message */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AudioMessage = void 0; const Message_1 = require("./Message"); const b4a_1 = __importDefault(require("b4a")); class AudioMessage extends Message_1.Message { audioUrl; audioType; audioData; /** * @description Creates a new Audio message. * @since 1.0 * @author MiTask * @constructor * @param peerName Peer username * @param peerAvatar Peer avatar URL * @param topic Chat room topic string * @param timestamp UNIX Timestamp * @param audioUrl URL to the audio file * @param audioType Type of the audio file * @param audioData Audio file data in base64 String format */ constructor(peerName, peerAvatar, topic, timestamp, audioUrl, audioType, audioData) { super("audio", peerName, peerAvatar, topic, timestamp); this.audioUrl = audioUrl; this.audioType = audioType; this.audioData = audioData; // Add audio data property } /** * @since 1.0 * @author MiTask * @returns {String} JSON String with all of the information about the message */ toJsonString() { return JSON.stringify({ ...this.toJson(), audioUrl: this.audioUrl, audioType: this.audioType, audio: this.audioData // Include audio data in JSON }); } /** * @description Creates a new audio message instance. * @since 1.0 * @author MiTask * @param bot Bot Client class * @param audioUrl URL to the audio file * @param audioType Type of the audio file * @param audioBuffer Audio file data * @returns {AudioMessage} AudioMessage instance. */ static new(bot, audioUrl, audioType, audioBuffer) { const audioData = b4a_1.default.toString(audioBuffer, 'base64'); // Convert audio buffer to base64 return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audioUrl, audioType, audioData); } } exports.AudioMessage = AudioMessage;