From cd51b092fc262a8af27cd9b6889bdb78546b6e08 Mon Sep 17 00:00:00 2001 From: guilevi Date: Sun, 2 May 2021 18:26:18 +0200 Subject: [PATCH] Add string customization and example.env --- .DS_Store | Bin 8196 -> 10244 bytes example.env | 13 +++++++++++++ index.js | 1 + modules/.DS_Store | Bin 8196 -> 8196 bytes modules/Canttalk/index.js | 10 ++++++---- modules/announcer/index.js | 5 +++-- modules/ttsSettings/index.js | 10 ++++++---- modules/welcomer/index.js | 2 +- package-lock.json | 15 ++++++++++++++- package.json | 1 + strings/en.json | 10 ++++++++++ strings/es.json | 10 ++++++++++ tts/.DS_Store | Bin 10244 -> 10244 bytes 13 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 example.env create mode 100644 strings/en.json create mode 100644 strings/es.json diff --git a/.DS_Store b/.DS_Store index d116d56fef87c294dd28532e8cbb973f2609e239..99e6f00b1a9c97141dd69e03d5fd9dd3e67ed255 100644 GIT binary patch delta 597 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-#6q~50$f&k4U^hRb+GZYsT}&dzh88*s zMkZ#pItta6Mg}?xCKd*hs6;glV delta 118 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8FDWo2aMAsIW0$H$S7oW*&iEOq10GJvZ|U zr!h|E5}O9*ycFBaB*+X@4+Ik2K*ANIbz|ap=E?jjfgFqw0~sdA^GuyADHy)_rPu~0 E09&~jy8r+H diff --git a/example.env b/example.env new file mode 100644 index 0000000..40180df --- /dev/null +++ b/example.env @@ -0,0 +1,13 @@ +TOKEN=DISCORD_BOT_TOKEN_HERE +GUILD=GUILD_ID_HERE +CHANNEL=VOICE_CHANNEL_ID_HERE +STRING_SET=en +VOICE_TMP_PATH=./voice_tmp/ +DB_FILE=DATABASE_PATH_HERE +PREFIX=+ +ANNOUNCEMENT_ENGINE=espeak +ANNOUNCEMENT_VOICE=en +watsonURL=WATSON_URL_HERE +watsonAPIKey=WATSON_API_KEY_HERE +TTS_CHANNEL=CANTTALK_TEXT_CHANNEL_ID_HERE +GOOGLE_APPLICATION_CREDENTIALS=GOOGLE_CLOUD_KEY_HERE \ No newline at end of file diff --git a/index.js b/index.js index 5b6cb33..e697667 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,7 @@ async function initDB() { const api = { db: undefined, queue: undefined, + strings: require('./strings/'+process.env.STRING_SET+'.json'), ttsEngines: (() => { let engines = {}; console.log(`Registering TTS engines...`); diff --git a/modules/.DS_Store b/modules/.DS_Store index 99fe5ecad0cbba6fdf97e82378721d1b48c5b6e6..b27a43c734b7dd6b9c44728c1d20b1d7ef41527e 100644 GIT binary patch delta 114 zcmZp1XmQw}D=_(*V2g;cp@oiuk%?KYjzYDik%5kaiG{)BJR#G`MS{YcxdmleaH%lg XTr4_?X*0XTH$9!xsi^7u|chlLbaulfsTTSnMrLeCx^JIp{-{^Ze>+< uO>N!u$rFX;8D~r`6cpRcD=5n{IY!8PbE)Vgrp>GpKUgLk3Y7tQ6PW { bot.on('message', async (message) => { if (!message.content.startsWith(process.env.PREFIX)) { @@ -19,20 +21,20 @@ module.exports = async (bot, api) => { 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."); + 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, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName); + api.respond(message, printf(api.strings.USER_VOICE_CHANGED, userVoice, 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."); + api.respond(message, printf(api.strings.INVALID_VOICE, api.announcementVoice, api.announcementEngine.longName)); } 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"); + api.respond(message, printf(api.strings.INVALID_ENGINE, args[1])); } }); } \ No newline at end of file diff --git a/modules/announcer/index.js b/modules/announcer/index.js index 572caf1..2de4bf5 100644 --- a/modules/announcer/index.js +++ b/modules/announcer/index.js @@ -1,3 +1,4 @@ +const printf=require('printf'); const AudioQueue=require('../../AudioQueue.js') module.exports = function (bot, api) { @@ -20,9 +21,9 @@ module.exports = function (bot, api) { let username = newState.member.displayName; let str = ""; if (!joined) { - str = username + " left the channel"; + str = printf(api.strings.USER_LEFT, username); } else { - str = username + " joined the channel"; + str = printf(api.strings.USER_JOINED, username); } api.queue.add(__dirname + "/sysmsg.wav"); api.speak(channel, str); diff --git a/modules/ttsSettings/index.js b/modules/ttsSettings/index.js index 7953a89..50e0ce6 100644 --- a/modules/ttsSettings/index.js +++ b/modules/ttsSettings/index.js @@ -1,20 +1,22 @@ +const printf=require('printf'); + module.exports = function (bot, api) { api.registerCommand('announcevoice', (args, message) => { let channel = bot.voice.connections.first().channel; if (args.length > 3) { - return api.respond(message, "You tried to change my voice with too many arguments."); + return api.respond(message, printf(api.strings.TOO_MANY_ARGUMENTS)); } if (api.ttsEngines[args[1]]) { api.announcementEngine = api.ttsEngines[args[1]]; if (api.announcementEngine.validateVoice(args[2])) { api.announcementVoice = args[2]; - api.respond(message, "My new voice is " + api.announcementVoice + " from " + api.announcementEngine.longName); + api.respond(message, printf(api.strings.SYSTEM_VOICE_CHANGED, api.announcementVoice, api.announcementEngine.longName)); } else { 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."); + api.respond(message, printf(api.strings.INVALID_VOICE, api.announcementVoice, api.announcementEngine.longName)); } } else { - api.respond(message, args[1] + " is not a valid engine name"); + api.respond(message, printf(api.strings.INVALID_ENGINE, args[1])); } }); api.registerCommand('flush',()=>api.queue.flush()); diff --git a/modules/welcomer/index.js b/modules/welcomer/index.js index 09c398b..72f5c6c 100644 --- a/modules/welcomer/index.js +++ b/modules/welcomer/index.js @@ -8,6 +8,6 @@ module.exports = function (bot, api) { await api.joinChannel(channel); let conn=api.getConnectionForVoiceChannel(channel); api.queue=new AudioQueue(conn); - api.speak(channel, `Running`); + api.speak(channel, api.strings.WELCOME); }) } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ee7ec89..7e9a4ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "microsoft-cognitiveservices-speech-sdk": "^1.16.0", "node-fetch": "^2.6.1", "opusscript": "^0.0.8", + "printf": "^0.6.1", "sha1": "^1.1.1", "sqlite": "^4.0.21", "sqlite3": "^5.0.2" @@ -1587,6 +1588,14 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "node_modules/printf": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/printf/-/printf-0.6.1.tgz", + "integrity": "sha512-is0ctgGdPJ5951KulgfzvHGwJtZ5ck8l042vRkV6jrkpBzTmb/lueTqguWHy2JfVA+RY6gFVlaZgUS0j7S/dsw==", + "engines": { + "node": ">= 0.9.0" + } + }, "node_modules/prism-media": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz", @@ -1854,7 +1863,6 @@ "hasInstallScript": true, "dependencies": { "node-addon-api": "^3.0.0", - "node-gyp": "3.x", "node-pre-gyp": "^0.11.0" }, "optionalDependencies": { @@ -3425,6 +3433,11 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "printf": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/printf/-/printf-0.6.1.tgz", + "integrity": "sha512-is0ctgGdPJ5951KulgfzvHGwJtZ5ck8l042vRkV6jrkpBzTmb/lueTqguWHy2JfVA+RY6gFVlaZgUS0j7S/dsw==" + }, "prism-media": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz", diff --git a/package.json b/package.json index 69425e9..9c91a32 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "microsoft-cognitiveservices-speech-sdk": "^1.16.0", "node-fetch": "^2.6.1", "opusscript": "^0.0.8", + "printf": "^0.6.1", "sha1": "^1.1.1", "sqlite": "^4.0.21", "sqlite3": "^5.0.2" diff --git a/strings/en.json b/strings/en.json new file mode 100644 index 0000000..9df8b39 --- /dev/null +++ b/strings/en.json @@ -0,0 +1,10 @@ +{ + "WELCOME": "Beep boop. I'm a bot. Hi.", + "USER_JOINED": "%s joined the channel.", + "USER_LEFT": "%s left the channel.", + "SYSTEM_VOICE_CHANGED": "My new voice is %s from %s", + "USER_VOICE_CHANGED": "Your new voice is %s from %s", + "INVALID_ENGINE": "%s is not a valid engine name.", + "INVALID_VOICE": "invalid voice name. Using default voice %s for %s instead.", + "TOO_MANY_ARGUMENTS": "too many arguments for command." +} \ No newline at end of file diff --git a/strings/es.json b/strings/es.json new file mode 100644 index 0000000..8a79d64 --- /dev/null +++ b/strings/es.json @@ -0,0 +1,10 @@ +{ + "WELCOME": "Hola hola, soy un bot.", + "USER_JOINED": "%s se ha unido al canal.", + "USER_LEFT": "%s ha salido del canal.", + "SYSTEM_VOICE_CHANGED": "Mi nueva voz es %s de %s", + "USER_VOICE_CHANGED": "Tu nueva voz es %s de %s", + "INVALID_ENGINE": "%s no es un nombre de motor válido.", + "INVALID_VOICE": "Nombre de voz no válido. Usando voz por defecto %s para %s.", + "TOO_MANY_ARGUMENTS": "Demasiados argumentos para el comando." +} \ No newline at end of file diff --git a/tts/.DS_Store b/tts/.DS_Store index 3d43c49500da60d66e4e5bc15cdf1eb641c17925..3755d0cbb8f7d4d81831e89b8c0117eee7b9ab44 100644 GIT binary patch delta 84 zcmZn(XbG4Q$z8;dnp9p~kd%|3w6Sm+`@{y`&FmZ;9L#JCdXpCmK9U5|42cX?45bV} lm1V(2c{%xc=?n}EjGK7`rZH}wFO&k*pzw=j^Is8WW&mPa8HoS@ delta 99 zcmZn(XbG4Q$z9Bl&ybf?UR;orv$1d*`@{y`&FmZ;9Ge9MCo^)gG9)roF_bbCO@1eO xOB~K)NG%I4%FD^mOJ`tUV4VC=SYq=IA%EV94J@146@IZy-Ysag*