From 18cd324ffcb6a54dd01d4d7628e3002328f5c14c Mon Sep 17 00:00:00 2001 From: Matthew Stanciu Date: Sat, 11 Jan 2020 21:27:00 -0500 Subject: [PATCH] Allow permissioned ambassadors to add leaders to clubs --- src/interactions/leaderAdd.js | 2 +- src/utils/index.js | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/interactions/leaderAdd.js b/src/interactions/leaderAdd.js index 46ef523d..d25274e4 100644 --- a/src/interactions/leaderAdd.js +++ b/src/interactions/leaderAdd.js @@ -18,7 +18,7 @@ const interactionLeaderAdd = (bot, message) => { return } - if (!commandUser.club) { + if (!(commandUser.club && commandUser.ambassador)) { console.log(`${commandUser.user} doesn't have a club`) bot.replyPrivateDelayed(message, transcript('leaderAdd.invalidClub')) return diff --git a/src/utils/index.js b/src/utils/index.js index 694ae1e9..b71ab9a9 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -42,7 +42,7 @@ export const airPatch = (baseName, recordID, values, options = {}) => } console.log( `Airtable updated my ${baseName} record from ${timestamp} in ${Date.now() - - timestamp}ms` + timestamp}ms` ) resolve(record) }) @@ -69,7 +69,7 @@ export const airCreate = (baseName, fields, options = {}) => } console.log( `Airtable saved my ${baseName} record from ${timestamp} in ${Date.now() - - timestamp}ms` + timestamp}ms` ) resolve(record) }) @@ -134,7 +134,7 @@ export const airGet = ( } console.log( `AirTable got back to me from my question at ${timestamp} with ${ - data.length + data.length } records. The query took ${Date.now() - timestamp}ms` ) resolve(data) @@ -251,6 +251,15 @@ export const getInfoForUser = user => airFind('People', 'Slack ID', user).then( person => (results.person = person) ), + airFind('Ambassadors', 'Slack ID', user).then( + () => { + airGet('Ambassadors', 'IF(Permissioned = 1, "true", "false"').then( + permissionedAmbassador => { + results.permissionedAmbassador = permissionedAmbassador + } + ) + } + ) ]) .then(async () => { if (!results.person && results.slackUser) { @@ -316,7 +325,7 @@ export const getInfoForUser = user => .then(() => { console.log( `Finished pulling up the info about user '${user}' from ${timestamp} in ${Date.now() - - timestamp}ms` + timestamp}ms` ) resolve(results) }) @@ -504,7 +513,7 @@ export const transcript = (search, vars) => { return evalTranscript(recurseTranscript(searchArr, transcriptObj), vars) } const evalTranscript = (target, vars = {}) => - function() { + function () { return eval('`' + target + '`') }.call({ ...vars,