tardis-bot/modules/Canttalk/index.js

40 lines
2.0 KiB
JavaScript
Raw Normal View History

const printf=require('printf');
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();
2021-05-02 17:01:14 +00:00
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]));
}
});
}