Large Transaction Update

This commit is contained in:
Logan Cusano
2023-02-27 00:20:54 -05:00
parent 0c4fee091e
commit 384dd7011f
6 changed files with 79 additions and 31 deletions

View File

@@ -12,13 +12,29 @@ const {
welcomeResponse
} = require("../controllers/accountController");
exports.authorizeTokenUsage = async (interaction, command, next) => {
/**
* Authorize a transaction amount for an account
*
* @param {*} interaction
* @param {*} command
* @param {undefined|number} _tokens The amount of tokens to authorize, set to undefined if the value is in the interaction
* @param {*} next
* @returns
*/
exports.authorizeTokenUsage = async (interaction, command, _tokens = undefined, next) => {
log.DEBUG("Command requires tokens? ", command.isPrivileged)
if(!command.requiresTokens) return next(true);
if(!interaction.member && (!interaction.options.getNumber("tokens") || !command.defaultTokenUsage)) throw new Error("No member or tokens specified before attempting to authorize");
if(!interaction.member && (!_tokens || !interaction.options.getNumber("tokens") || !command.defaultTokenUsage)) throw new Error("No member or tokens specified before attempting to authorize");
const memberId = interaction.member.id;
const tokensToBeUsed = interaction.options.getNumber("tokens") ?? command.defaultTokenUsage
var tokensToBeUsed;
if (!_tokens || _tokens && isNaN(_tokens)){
if (interaction.options.getNumber("tokens")) tokensToBeUsed = interaction.options.getNumber("tokens");
else tokensToBeUsed = command.defaultTokenUsage;
}
else tokensToBeUsed = _tokens;
log.DEBUG(`Authorizing ${memberId} for a purchase worth ${tokensToBeUsed} tokens`)
log.DEBUG("Checking for account associated with discord ID: ", memberId);
await checkForAccount(memberId, async (err, results) => {