- Impliment /voice to change voice on account
- Fix migrations (kind of)
This commit is contained in:
Christopher Cookman 2024-10-29 07:51:23 -06:00
parent a43f291835
commit fdc05cd165
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
4 changed files with 49 additions and 38 deletions

View file

@ -19,12 +19,8 @@ db.on("open", () => {
fs.readdirSync("./migrations").forEach((file) => {
if (file.endsWith(".sql")) {
const migration = fs.readFileSync(`./migrations/${file}`, "utf8");
try {
db.run(migration)
console.log(`${colors.cyan("[DB]")} ${file} ${colors.green("executed")}`);
} catch (error) {
console.log(`${colors.red("[DB]")} ${file} ${colors.red("failed")}`);
}
}
});
});
@ -134,7 +130,7 @@ function sendDemo(accountNumber, transaction, placeName, systemName, zoneNumber,
}
// Account exists and is verified
// Send the alert
runCommand(ttsCommands[0].replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${systemName} has reported a ${event}, ZONE ${zoneNumber}, ${zoneName}, at ${placeName}`).then((output) => {
runCommand(ttsCommands[0].command.replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${systemName} has reported a ${event}, ZONE ${zoneNumber}, ${zoneName}, at ${placeName}`).then((output) => {
runCommand(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-alert.wav`).then(() => {
runCommand(`rm /tmp/${transaction}.wav`)
// strip extension from filename
@ -208,7 +204,7 @@ function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber
// Account exists and is verified
// Send the alert
runCommand(ttsCommands[row.ttsOverride].value.replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${systemName} has reported a ${event}, ZONE ${zoneNumber}, ${zoneName}, at ${placeName}`).then((output) => {
runCommand(ttsCommands[row.ttsOverride].command.replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${systemName} has reported a ${event}, ZONE ${zoneNumber}, ${zoneName}, at ${placeName}`).then((output) => {
runCommand(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-alert.wav`).then(() => {
runCommand(`rm /tmp/${transaction}.wav`)
// strip extension from filename
@ -271,7 +267,7 @@ function sendTTS(accountNumber, transaction, text) {
} else if (row) {
// Account exists and is verified
// Send the alert
runCommand(ttsCommands[row.ttsOverride].value.replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${textFiltered}`).then((output) => {
runCommand(ttsCommands[row.ttsOverride].command.replace("%s", `/tmp/${transaction}.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. ${textFiltered}`).then((output) => {
runCommand(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-tts.wav`).then(() => {
runCommand(`rm /tmp/${transaction}.wav`)
// strip extension from filename
@ -337,7 +333,7 @@ function sendVerificationCode(account) {
});
}
// Send verification code to phone number
runCommand(ttsCommands[row.ttsOverride].value.replace("%s", `/tmp/${account}-code.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. To verify your phone number, use the slash verify command on Discord. Your verification code is ${row.verification_code.split("").join(", ")}. Repeating, your code is ${row.verification_code.split("").join(", ")}. Once again, your code is ${row.verification_code.split("").join(", ")}`).then((output) => {
runCommand(ttsCommands[row.ttsOverride].command.replace("%s", `/tmp/${account}-code.wav`), `Hello. This is an automated call from KCA SecuriNet Monitoring. To verify your phone number, use the slash verify command on Discord. Your verification code is ${row.verification_code.split("").join(", ")}. Repeating, your code is ${row.verification_code.split("").join(", ")}. Once again, your code is ${row.verification_code.split("").join(", ")}`).then((output) => {
runCommand(`ffmpeg -y -i /tmp/${account}-code.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${account}-verification.wav`).then(() => {
runCommand(`rm /tmp/${account}-code.wav`)
// strip extension from filename
@ -661,29 +657,43 @@ client.on("interactionCreate", async (interaction) => {
}
});
break;
case "voice":
accountNumber = interaction.options.getString("account_number");
db.get("SELECT * FROM accounts WHERE id = ?;", accountNumber, (err, row) => {
if (err) {
console.error(err)
} else if (row) {
newVoice = interaction.options.getString("voice")
if (!ttsCommands[newVoice]) return interaction.reply({ content: "Thats not a valid option", ephemeral: true });
console.log(newVoice)
db.run("UPDATE accounts SET ttsOverride = ? WHERE id = ?", newVoice, accountNumber, (row, err) => {
if (err) {
console.error(err)
return interaction.reply({ content: "An error occured, Contact system administrator", ephemeral: true });
}
return interaction.reply({ content: "Changed!", ephemeral: true })
})
}
})
break;
}
break;
case Discord.InteractionType.ApplicationCommandAutocomplete:
switch (interaction.commandName) {
case "deactivate" || "voice":
// Get all active accounts owned by the user
db.all("SELECT * FROM accounts WHERE discord_id = ? AND verified = 1", interaction.user.id, (err, rows) => {
if (err) {
console.error(err);
} else if (rows) {
let accountList = [];
rows.forEach((row) => {
accountList.push({
name: `${row.id} - ${row.phone}`,
value: `${row.id}`
});
});
interaction.respond(accountList);
}
// Get all active accounts owned by the user
db.all("SELECT * FROM accounts WHERE discord_id = ? AND verified = 1", interaction.user.id, (err, rows) => {
if (err) {
console.error(err);
} else if (rows) {
let accountList = [];
rows.forEach((row) => {
accountList.push({
name: `${row.id} - ${row.phone}`,
value: `${row.id}`
});
});
break;
interaction.respond(accountList);
}
break;
});
}
});

View file

@ -5,5 +5,8 @@ CREATE TABLE IF NOT EXISTS 'accounts' (
'verified' INTEGER NOT NULL DEFAULT 0,
'verification_code' TEXT,
'code_sent_at' TEXT,
'discord_id' TEXT
'discord_id' TEXT,
'ttsOverride' INTEGER NOT NULL DEFAULT 0,
'cooldown' TEXT,
'armState' INTEGER NOT NULL DEFAULT 0
)

View file

@ -1,9 +0,0 @@
-- Add ttsOverride column to the accounts table
SELECT COUNT(*)
FROM pragma_table_info('accounts')
WHERE name = 'ttsOverride';
-- Step 2: If the count is 0, add the 'cooldown' column
ALTER TABLE accounts ADD COLUMN ttsOverride TEXT INTEGER NOT NULL DEFAULT 0;
-- Retroactively set ttsOverride to 0 for all accounts that dont have it set at all
UPDATE 'accounts' SET 'ttsOverride' = 0 WHERE 'ttsOverride' IS NULL;

View file

@ -1,10 +1,17 @@
[
{
"name": "Piper - Amy (Default)",
"value": "piper -m /opt/alarm-monitoring/tts/en_US-amy-medium.onnx -f %s"
"value": "0",
"command": "piper -m /opt/alarm-monitoring/tts/en_US-amy-medium.onnx -f %s"
},
{
"name": "Flite - OG SecuriNet Voice",
"value": "flite -o %s"
"value": "1",
"command": "flite -o %s"
},
{
"name": "DECTalk Paul",
"value": "2",
"command": "/usr/bin/dectalk/say -fo %s -"
}
]