Add canttalk module, few changes here and there to accomodate for it

This commit is contained in:
2021-04-09 03:00:55 +02:00
parent 3b1a419db4
commit 1fe978eec6
12 changed files with 757 additions and 12 deletions

BIN
modules/.DS_Store vendored

Binary file not shown.

38
modules/Canttalk/index.js Normal file
View File

@@ -0,0 +1,38 @@
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, "You tried to change your speaking voice with too many arguments.");
}
if (api.ttsEngines[args[1]]) {
userEngine = args[1];
if (api.ttsEngines[userEngine].validateVoice(args[2])) {
userVoice = args[2];
api.respond(message, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName);
} else {
userVoice = api.ttsEngines[userEngine].getDefaultVoice();
api.respond(message, "Your voice name was invalid, so I switched to the default voice (" + userVoice + ") for " + api.ttsEngines[userEngine].longName + " instead.");
}
await api.db.run('update TTSPreferences set engine=?, voice=? where user_id=?', userEngine, userVoice, message.author.id);
} else {
api.respond(message, args[1] + " is not a valid engine name");
}
});
}

View File

@@ -13,6 +13,8 @@ module.exports = function (bot, api) {
api.announcementVoice = api.announcementEngine.getDefaultVoice();
api.respond(message, "Your voice name was invalid, so I switched to the default voice (" + api.announcementVoice + ") for " + api.announcementEngine.longName + " instead.");
}
} else {
api.respond(message, args[1] + " is not a valid engine name");
}
});
}