Add string customization and example.env
This commit is contained in:
		
							
								
								
									
										13
									
								
								example.env
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								example.env
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
							
								
								
									
										1
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								index.js
									
									
									
									
									
								
							@@ -22,6 +22,7 @@ async function initDB() {
 | 
				
			|||||||
const api = {
 | 
					const api = {
 | 
				
			||||||
    db: undefined,
 | 
					    db: undefined,
 | 
				
			||||||
    queue: undefined,
 | 
					    queue: undefined,
 | 
				
			||||||
 | 
					    strings: require('./strings/'+process.env.STRING_SET+'.json'),
 | 
				
			||||||
    ttsEngines: (() => {
 | 
					    ttsEngines: (() => {
 | 
				
			||||||
        let engines = {};
 | 
					        let engines = {};
 | 
				
			||||||
        console.log(`Registering TTS engines...`);
 | 
					        console.log(`Registering TTS engines...`);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								modules/.DS_Store
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								modules/.DS_Store
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					const printf=require('printf');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = async (bot, api) => {
 | 
					module.exports = async (bot, api) => {
 | 
				
			||||||
    bot.on('message', async (message) => {
 | 
					    bot.on('message', async (message) => {
 | 
				
			||||||
        if (!message.content.startsWith(process.env.PREFIX)) {
 | 
					        if (!message.content.startsWith(process.env.PREFIX)) {
 | 
				
			||||||
@@ -19,20 +21,20 @@ module.exports = async (bot, api) => {
 | 
				
			|||||||
    api.registerCommand('myvoice', async (args, message) => {
 | 
					    api.registerCommand('myvoice', async (args, message) => {
 | 
				
			||||||
        let userEngine, userVoice;
 | 
					        let userEngine, userVoice;
 | 
				
			||||||
        if (args.length > 3) {
 | 
					        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]]) {
 | 
					        if (api.ttsEngines[args[1]]) {
 | 
				
			||||||
            userEngine = args[1];
 | 
					            userEngine = args[1];
 | 
				
			||||||
            if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) {
 | 
					            if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) {
 | 
				
			||||||
                userVoice = 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 {
 | 
					            } else {
 | 
				
			||||||
                userVoice = api.ttsEngines[userEngine].getDefaultVoice();
 | 
					                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);
 | 
					            await api.db.run('update TTSPreferences set engine=?, voice=? where user_id=?', userEngine, userVoice, message.author.id);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            api.respond(message, args[1] + " is not a valid engine name");
 | 
					            api.respond(message, printf(api.strings.INVALID_ENGINE, args[1]));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					const printf=require('printf');
 | 
				
			||||||
const AudioQueue=require('../../AudioQueue.js')
 | 
					const AudioQueue=require('../../AudioQueue.js')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = function (bot, api) {
 | 
					module.exports = function (bot, api) {
 | 
				
			||||||
@@ -20,9 +21,9 @@ module.exports = function (bot, api) {
 | 
				
			|||||||
        let username = newState.member.displayName;
 | 
					        let username = newState.member.displayName;
 | 
				
			||||||
        let str = "";
 | 
					        let str = "";
 | 
				
			||||||
        if (!joined) {
 | 
					        if (!joined) {
 | 
				
			||||||
            str = username + " left the channel";
 | 
					            str = printf(api.strings.USER_LEFT, username);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            str = username + " joined the channel";
 | 
					            str = printf(api.strings.USER_JOINED, username);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        api.queue.add(__dirname + "/sysmsg.wav");
 | 
					        api.queue.add(__dirname + "/sysmsg.wav");
 | 
				
			||||||
        api.speak(channel, str);
 | 
					        api.speak(channel, str);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,20 +1,22 @@
 | 
				
			|||||||
 | 
					const printf=require('printf');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = function (bot, api) {
 | 
					module.exports = function (bot, api) {
 | 
				
			||||||
	api.registerCommand('announcevoice', (args, message) => {
 | 
						api.registerCommand('announcevoice', (args, message) => {
 | 
				
			||||||
		let channel = bot.voice.connections.first().channel;
 | 
							let channel = bot.voice.connections.first().channel;
 | 
				
			||||||
		if (args.length > 3) {
 | 
							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]]) {
 | 
							if (api.ttsEngines[args[1]]) {
 | 
				
			||||||
			api.announcementEngine = api.ttsEngines[args[1]];
 | 
								api.announcementEngine = api.ttsEngines[args[1]];
 | 
				
			||||||
			if (api.announcementEngine.validateVoice(args[2])) {
 | 
								if (api.announcementEngine.validateVoice(args[2])) {
 | 
				
			||||||
				api.announcementVoice = 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 {
 | 
								} else {
 | 
				
			||||||
				api.announcementVoice = api.announcementEngine.getDefaultVoice();
 | 
									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 {
 | 
							} 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());
 | 
						api.registerCommand('flush',()=>api.queue.flush());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,6 @@ module.exports = function (bot, api) {
 | 
				
			|||||||
        await api.joinChannel(channel);
 | 
					        await api.joinChannel(channel);
 | 
				
			||||||
        let conn=api.getConnectionForVoiceChannel(channel);
 | 
					        let conn=api.getConnectionForVoiceChannel(channel);
 | 
				
			||||||
        api.queue=new AudioQueue(conn);
 | 
					        api.queue=new AudioQueue(conn);
 | 
				
			||||||
        api.speak(channel, `Running`);
 | 
					        api.speak(channel, api.strings.WELCOME);
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										15
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -15,6 +15,7 @@
 | 
				
			|||||||
        "microsoft-cognitiveservices-speech-sdk": "^1.16.0",
 | 
					        "microsoft-cognitiveservices-speech-sdk": "^1.16.0",
 | 
				
			||||||
        "node-fetch": "^2.6.1",
 | 
					        "node-fetch": "^2.6.1",
 | 
				
			||||||
        "opusscript": "^0.0.8",
 | 
					        "opusscript": "^0.0.8",
 | 
				
			||||||
 | 
					        "printf": "^0.6.1",
 | 
				
			||||||
        "sha1": "^1.1.1",
 | 
					        "sha1": "^1.1.1",
 | 
				
			||||||
        "sqlite": "^4.0.21",
 | 
					        "sqlite": "^4.0.21",
 | 
				
			||||||
        "sqlite3": "^5.0.2"
 | 
					        "sqlite3": "^5.0.2"
 | 
				
			||||||
@@ -1587,6 +1588,14 @@
 | 
				
			|||||||
      "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
 | 
					      "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
 | 
				
			||||||
      "optional": true
 | 
					      "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": {
 | 
					    "node_modules/prism-media": {
 | 
				
			||||||
      "version": "1.2.9",
 | 
					      "version": "1.2.9",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz",
 | 
				
			||||||
@@ -1854,7 +1863,6 @@
 | 
				
			|||||||
      "hasInstallScript": true,
 | 
					      "hasInstallScript": true,
 | 
				
			||||||
      "dependencies": {
 | 
					      "dependencies": {
 | 
				
			||||||
        "node-addon-api": "^3.0.0",
 | 
					        "node-addon-api": "^3.0.0",
 | 
				
			||||||
        "node-gyp": "3.x",
 | 
					 | 
				
			||||||
        "node-pre-gyp": "^0.11.0"
 | 
					        "node-pre-gyp": "^0.11.0"
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      "optionalDependencies": {
 | 
					      "optionalDependencies": {
 | 
				
			||||||
@@ -3425,6 +3433,11 @@
 | 
				
			|||||||
      "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
 | 
					      "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
 | 
				
			||||||
      "optional": true
 | 
					      "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": {
 | 
					    "prism-media": {
 | 
				
			||||||
      "version": "1.2.9",
 | 
					      "version": "1.2.9",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@
 | 
				
			|||||||
    "microsoft-cognitiveservices-speech-sdk": "^1.16.0",
 | 
					    "microsoft-cognitiveservices-speech-sdk": "^1.16.0",
 | 
				
			||||||
    "node-fetch": "^2.6.1",
 | 
					    "node-fetch": "^2.6.1",
 | 
				
			||||||
    "opusscript": "^0.0.8",
 | 
					    "opusscript": "^0.0.8",
 | 
				
			||||||
 | 
					    "printf": "^0.6.1",
 | 
				
			||||||
    "sha1": "^1.1.1",
 | 
					    "sha1": "^1.1.1",
 | 
				
			||||||
    "sqlite": "^4.0.21",
 | 
					    "sqlite": "^4.0.21",
 | 
				
			||||||
    "sqlite3": "^5.0.2"
 | 
					    "sqlite3": "^5.0.2"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								strings/en.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								strings/en.json
									
									
									
									
									
										Normal file
									
								
							@@ -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."
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										10
									
								
								strings/es.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								strings/es.json
									
									
									
									
									
										Normal file
									
								
							@@ -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."
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								tts/.DS_Store
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								tts/.DS_Store
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user