Update
- Allow linking two account numbers together, as long as they're both owned by the person running the command
This commit is contained in:
parent
b816e7d9c2
commit
dcb668ddc3
|
@ -72,5 +72,47 @@
|
||||||
{
|
{
|
||||||
"name": "cancel",
|
"name": "cancel",
|
||||||
"description": "Cancel verification and account number creation if you have one in-progress"
|
"description": "Cancel verification and account number creation if you have one in-progress"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "link",
|
||||||
|
"description": "Link two account numbers together so someone else can get calls for your account number too",
|
||||||
|
"type": 1,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"name": "from",
|
||||||
|
"description": "Account number to receive alerts from",
|
||||||
|
"type": 3,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "to",
|
||||||
|
"description": "Account number to forward alerts to",
|
||||||
|
"type": 3,
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "unlink",
|
||||||
|
"description": "Unlink two account numbers",
|
||||||
|
"type": 1,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"name": "from",
|
||||||
|
"description": "Account number to receive alerts from",
|
||||||
|
"type": 3,
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "to",
|
||||||
|
"description": "Account number to forward alerts to",
|
||||||
|
"type": 3,
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "links",
|
||||||
|
"description": "Get a list of linked accounts tied to your discord account"
|
||||||
}
|
}
|
||||||
]
|
]
|
63
index.js
63
index.js
|
@ -143,6 +143,18 @@ function sendAlert(accountNumber, transaction, placeName, systemName, zoneNumber
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.get("SELECT * FROM links WHERE linked_from = ?", accountNumber, (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else if (row) {
|
||||||
|
runCommand(`/var/lib/asterisk/bin/originate ${row.to} roblox.s.1 0 0 /tmp/${transaction}-alert "IktDQSBTZWN1cmlOZXQiIDwxNDQ3MjAwNDQ4OD4="`).then(() => {
|
||||||
|
console.log(`Alert sent to ${row.linked_to}`);
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -186,6 +198,18 @@ function sendTTS(accountNumber, transaction, text) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.get("SELECT * FROM links WHERE linked_from = ?", accountNumber, (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else if (row) {
|
||||||
|
runCommand(`/var/lib/asterisk/bin/originate ${row.linked_to} roblox.s.1 0 0 /tmp/${transaction}-tts "IktDQSBTZWN1cmlOZXQiIDwxNDQ3MjAwNDQ4OD4="`).then(() => {
|
||||||
|
console.log(`TTS sent to ${row.to}`);
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -418,6 +442,45 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "link": // Link two account numbers together, only allow linking if both accounts are owned by the user and verified
|
||||||
|
// check that both account numbers from and to are owned by the user and verified
|
||||||
|
accountNumberFrom = interaction.options.getString("from");
|
||||||
|
accountNumberTo = interaction.options.getString("to");
|
||||||
|
db.get("SELECT * FROM accounts WHERE discord_id = ? AND id = ? AND verified = 1", interaction.user.id, accountNumberFrom, (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else if (row) {
|
||||||
|
db.get("SELECT * FROM accounts WHERE discord_id = ? AND id = ? AND verified = 1", interaction.user.id, accountNumberTo, (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else if (row) {
|
||||||
|
// check that the link doesnt already exist in `link`
|
||||||
|
db.get("SELECT * FROM links WHERE linked_from = ? AND linked_to = ?", accountNumberFrom, accountNumberTo, (err, row) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
if (row) {
|
||||||
|
return interaction.reply({ content: "Those accounts are already linked.", ephemeral: true });
|
||||||
|
} else {
|
||||||
|
db.run("INSERT INTO links (linked_from, linked_to, discord_id) VALUES (?, ?, ?)", accountNumberFrom, accountNumberTo, interaction.user.id, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
} else {
|
||||||
|
return interaction.reply({ content: "Accounts linked.", ephemeral: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return interaction.reply({ content: "You don't own that account.", ephemeral: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return interaction.reply({ content: "You don't own that account.", ephemeral: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Discord.InteractionType.ApplicationCommandAutocomplete:
|
case Discord.InteractionType.ApplicationCommandAutocomplete:
|
||||||
|
|
6
migrations/2 - AddLinks.sql
Normal file
6
migrations/2 - AddLinks.sql
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS 'links' (
|
||||||
|
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
'linked_from' TEXT NOT NULL,
|
||||||
|
'linked_to' TEXT NOT NULL,
|
||||||
|
'discord_id' TEXT NOT NULL
|
||||||
|
)
|
Loading…
Reference in a new issue