const printf=require('printf'); const fs = require('fs'); const path = require('path'); module.exports = async (bot, api) => { bot.on('message', async (message) => { if (!message.content.startsWith(process.env.PREFIX)) { if (message.channel.id == process.env.TTS_CHANNEL) { let chan=message.member.voice.channel; let userRow = await api.db.get('select * from TTSPreferences where user_id=?', message.author.id); if (!userRow) { await api.db.run('insert into TTSPreferences (user_id,engine,voice) values (?,?,?)', [message.author.id, api.announcementEngine.shortName, api.announcementVoice]); userRow = await api.db.get('select * from TTSPreferences where user_id=?', message.author.id); } if (api.ttsEngines[userRow.engine]) { api.speak(chan,message.content, api.ttsEngines[userRow.engine], userRow.voice) } else { } } } }); api.registerCommand('myvoice', async (args, message) => { let userEngine, userVoice; if (args.length > 3) { return api.respond(message, printf(api.strings.TOO_MANY_ARGUMENTS)); } if (api.ttsEngines[args[1]]) { userEngine = args[1]; if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) { userVoice = args[2].toLowerCase(); api.respond(message, printf(api.strings.USER_VOICE_CHANGED, userVoice, api.ttsEngines[userEngine].longName)); } else { userVoice = api.ttsEngines[userEngine].getDefaultVoice(); api.respond(message, printf(api.strings.INVALID_VOICE, userVoice, api.ttsEngines[userEngine].longName)); } await api.db.run('update TTSPreferences set engine=?, voice=? where user_id=?', userEngine, userVoice, message.author.id); } else { api.respond(message, printf(api.strings.INVALID_ENGINE, args[1])); } }); api.registerCommand('random', async (args, message) => { const files = fs.readdirSync(process.env["VOICE_TMP_PATH"]); const rnd = files[Math.floor(Math.random()*files.length)]; console.log(rnd); api.queue.add(__dirname + "/../../sysmsg.wav"); api.queue.add(process.env["VOICE_TMP_PATH"] + "/" + rnd); }); }