From 9f6184c6848cc12a1f25954fa4f5f34877d73e3e Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sun, 22 Oct 2023 23:36:07 +0200 Subject: [PATCH] fix: invite tracker --- index.ts | 16 ++++++++-------- inviteTracker.ts | 9 ++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/index.ts b/index.ts index 16588aa..9119ad5 100644 --- a/index.ts +++ b/index.ts @@ -128,7 +128,7 @@ const jwtClient = new google.auth.JWT( process.env.CLIENT_EMAIL, undefined, process.env.PRIVATE_KEY, - ['https://www.googleapis.com/auth/spreadsheets'] + [ 'https://www.googleapis.com/auth/spreadsheets' ] ); const sheets = google.sheets({ version: 'v4', auth: jwtClient }); @@ -144,7 +144,7 @@ client.on(Events.MessageCreate, async (message) => { let currentFeedbackQuestionIndex = userContext?.currentFeedbackQuestionIndex || 0; // Calculate the column where the answer should be placed. - const columnForAnswer = COLUMNS[currentFeedbackQuestionIndex + 1]; // +1 to skip the first column which might have the userID + const columnForAnswer = COLUMNS[ currentFeedbackQuestionIndex + 1 ]; // +1 to skip the first column which might have the userID // Find the row number for the current user (assuming the user's ID is in the first column) const response = await sheets.spreadsheets.values.get({ @@ -152,7 +152,7 @@ client.on(Events.MessageCreate, async (message) => { range: `${START_COLUMN}:${START_COLUMN}` // search in the first column only }); const rows = response.data.values || []; - let rowIndex = rows.findIndex((row: any) => row[0] === message.author.id.toString()) + 1; // +1 because index is 0-based and rows in Google Sheets are 1-based. + let rowIndex = rows.findIndex((row: any) => row[ 0 ] === message.author.id.toString()) + 1; // +1 because index is 0-based and rows in Google Sheets are 1-based. // If the user is not found, create a new row for them if (rowIndex === 0) { @@ -163,7 +163,7 @@ client.on(Events.MessageCreate, async (message) => { insertDataOption: 'INSERT_ROWS', resource: { values: [ - [message.author.id] // userID in the first column + [ message.author.id ] // userID in the first column ] } } as any); @@ -177,7 +177,7 @@ client.on(Events.MessageCreate, async (message) => { valueInputOption: 'RAW', resource: { values: [ - [message.content] + [ message.content ] ] } } as any); @@ -185,7 +185,7 @@ client.on(Events.MessageCreate, async (message) => { currentFeedbackQuestionIndex++; if (currentFeedbackQuestionIndex < Feedbackquestions.length) { - message.author.send(Feedbackquestions[currentFeedbackQuestionIndex]); + message.author.send(Feedbackquestions[ currentFeedbackQuestionIndex ]); await db.db('contrabot').collection("users").updateOne( { userId: message.author.id }, @@ -212,8 +212,8 @@ client.on(Events.MessageCreate, async (message) => { } }); -client.on('guildMemberAdd', () => { - trackInvites(); +client.on('guildMemberAdd', async () => { + await trackInvites(); }); export { client, db }; \ No newline at end of file diff --git a/inviteTracker.ts b/inviteTracker.ts index db6acd0..af8d29b 100644 --- a/inviteTracker.ts +++ b/inviteTracker.ts @@ -18,7 +18,7 @@ export async function trackInvites() { const invites = await guild.invites.fetch(); // Create an object to store invite data per user - const inviteData: { [key: string]: number } = {}; + const inviteData: { [ key: string ]: number } = {}; // Store number of invites per inviter invites.forEach((invite) => { @@ -29,8 +29,7 @@ export async function trackInvites() { const inviteCount = (invite.uses !== null ? invite.uses : 0); // Increment the invite count for the inviter - inviteData[inviterId] = (inviteData[inviterId] || 0) + inviteCount; - console.log(inviteData); + inviteData[ inviterId ] = (inviteData[ inviterId ] || 0) + inviteCount; } }); @@ -45,12 +44,12 @@ export async function trackInvites() { continue; // Skip this user and continue with others } - let inviteCount = inviteData[userId] || 0; + let inviteCount = inviteData[ userId ] || 0; // Update the invite count for the user in the database await db.db('contrabot').collection('users').updateOne( { userId: userId }, - { $set: { inviteCount: inviteCount } } + { $set: { inviteCount } } ); assignRoles(inviteCount, userId, guild);