Do some stuff
This commit is contained in:
parent
e6a8051cb8
commit
d695de2740
33
index.js
33
index.js
|
@ -130,7 +130,7 @@ function sendDemo(accountNumber, transaction, placeName, systemName, zoneNumber,
|
||||||
}
|
}
|
||||||
// Account exists and is verified
|
// Account exists and is verified
|
||||||
// Send the alert
|
// Send the alert
|
||||||
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(ttsCommands[0].command.replace("%s", `/tmp/${transaction}.wav`), `${process.env.CALL_PREFIX_TEXT} ${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(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-alert.wav`).then(() => {
|
||||||
runCommand(`rm /tmp/${transaction}.wav`)
|
runCommand(`rm /tmp/${transaction}.wav`)
|
||||||
// strip extension from filename
|
// strip extension from filename
|
||||||
|
@ -204,7 +204,7 @@ function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber
|
||||||
|
|
||||||
// Account exists and is verified
|
// Account exists and is verified
|
||||||
// Send the alert
|
// Send the alert
|
||||||
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(ttsCommands[row.ttsOverride].command.replace("%s", `/tmp/${transaction}.wav`), `${process.env.CALL_PREFIX_TEXT} ${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(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-alert.wav`).then(() => {
|
||||||
runCommand(`rm /tmp/${transaction}.wav`)
|
runCommand(`rm /tmp/${transaction}.wav`)
|
||||||
// strip extension from filename
|
// strip extension from filename
|
||||||
|
@ -267,7 +267,7 @@ function sendTTS(accountNumber, transaction, text) {
|
||||||
} else if (row) {
|
} else if (row) {
|
||||||
// Account exists and is verified
|
// Account exists and is verified
|
||||||
// Send the alert
|
// Send the alert
|
||||||
runCommand(ttsCommands[row.ttsOverride].command.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`), `${process.env.CALL_PREFIX_TEXT} ${textFiltered}`).then((output) => {
|
||||||
runCommand(`ffmpeg -y -i /tmp/${transaction}.wav -ar 8000 -ac 1 -c:a pcm_s16le /tmp/${transaction}-tts.wav`).then(() => {
|
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`)
|
runCommand(`rm /tmp/${transaction}.wav`)
|
||||||
// strip extension from filename
|
// strip extension from filename
|
||||||
|
@ -315,6 +315,7 @@ function sendTTS(accountNumber, transaction, text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendVerificationCode(account) {
|
function sendVerificationCode(account) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
// Get verification code from database
|
// Get verification code from database
|
||||||
db.get("SELECT * FROM accounts WHERE id = ?", account, (err, row) => {
|
db.get("SELECT * FROM accounts WHERE id = ?", account, (err, row) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -333,7 +334,7 @@ function sendVerificationCode(account) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Send verification code to phone number
|
// Send verification code to phone number
|
||||||
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(ttsCommands[row.ttsOverride].command.replace("%s", `/tmp/${account}-code.wav`), `${process.env.CALL_PREFIX_TEXT} 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(`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`)
|
runCommand(`rm /tmp/${account}-code.wav`)
|
||||||
// strip extension from filename
|
// strip extension from filename
|
||||||
|
@ -348,6 +349,7 @@ function sendVerificationCode(account) {
|
||||||
// Account does not exist or is not verified
|
// Account does not exist or is not verified
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function generatePhoneCode() {
|
function generatePhoneCode() {
|
||||||
|
@ -422,15 +424,20 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} else {
|
} else {
|
||||||
|
sendVerificationCode(accountNumber).then(() => {
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: `Account created. Our system will call you shortly with a verification code. Please enter that code into \`/verify\``,
|
content: `Account created. Our system will call you shortly with a verification code. Please enter that code into \`/verify\``,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
}).then(() => {
|
})
|
||||||
setTimeout(() => {
|
}).catch(err => {
|
||||||
sendVerificationCode(accountNumber);
|
if (err == "Cooldown") {
|
||||||
}, 5000); // Wait 5 seconds before calling so user has time to read message
|
interaction.reply({
|
||||||
|
content: "You are on cooldown, please wait before trying again.",
|
||||||
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -462,11 +469,19 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} else if (row) {
|
} else if (row) {
|
||||||
sendVerificationCode(row.id);
|
sendVerificationCode(row.id).then(() => {
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: `Verification code resent to ${row.phone}`,
|
content: `Verification code resent to ${row.phone}`,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
}).catch((err) => {
|
||||||
|
if (err == "Cooldown") {
|
||||||
|
interaction.reply({
|
||||||
|
content: "You are on cooldown, please wait before trying again.",
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
interaction.reply({ ephemeral: true, content: "You don't have an unverified account." });
|
interaction.reply({ ephemeral: true, content: "You don't have an unverified account." });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue