Add string customization and example.env
parent
cbb4a6898b
commit
cd51b092fc
|
@ -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 = {
|
||||
db: undefined,
|
||||
queue: undefined,
|
||||
strings: require('./strings/'+process.env.STRING_SET+'.json'),
|
||||
ttsEngines: (() => {
|
||||
let engines = {};
|
||||
console.log(`Registering TTS engines...`);
|
||||
|
|
Binary file not shown.
|
@ -1,3 +1,5 @@
|
|||
const printf=require('printf');
|
||||
|
||||
module.exports = async (bot, api) => {
|
||||
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]));
|
||||
}
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
}
|
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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."
|
||||
}
|
|
@ -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."
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue