Skip to content

Commit 57f567f

Browse files
committed
Use .env variables for AS attendance form QR code
1 parent 9473882 commit 57f567f

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/Client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default class Client extends DiscordClient implements BotClient {
8989
if (!process.env.MATCH_ROLE_ID) {
9090
throw new BotInitializationError('Match Role ID');
9191
}
92+
if (!process.env.AS_ATTENDANCE_FORM_URL) {
93+
throw new BotInitializationError('AS Funded Event Attendance Form')
94+
}
9295
this.settings.clientID = process.env.CLIENT_ID;
9396
this.settings.token = process.env.BOT_TOKEN;
9497
this.settings.prefix = process.env.BOT_PREFIX;
@@ -102,6 +105,7 @@ export default class Client extends DiscordClient implements BotClient {
102105
this.settings.portalAPI.password = process.env.MEMBERSHIP_PORTAL_API_PASSWORD;
103106
this.settings.discordGuildIDs = JSON.parse(process.env.DISCORD_GUILD_IDS) as Array<string>;
104107
this.settings.matchRoleID = process.env.MATCH_ROLE_ID;
108+
this.settings.asAttendanceForm = process.env.AS_ATTENDANCE_FORM_URL;
105109
this.initialize().then();
106110
}
107111

src/commands/Checkin.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import Command from '../Command';
99
import Logger from '../utils/Logger';
1010
import QR from './QR';
1111

12-
const AS_ATTENDANCE_FORM_URL = 'https://docs.google.com/forms/d/e/1FAIpQLSc-akfqTNzrWUmOub_rMDj5wExBUDfakMXDbeGicOrpxBr6jg/viewform';
13-
1412
/**
1513
* This Command DM's the caller the checkin code and Express Checkin link for any current and
1614
* upcoming events in today's timeframe. Optional argument `public` makes the embed with the
@@ -144,18 +142,19 @@ export default class Checkin extends Command {
144142

145143
// Now we finally check the command argument.
146144
// If we just had `checkin` in our call, no arguments...
145+
const asAttendanceForm = this.client.settings.asAttendanceForm;
147146
if (!isPublic) {
148147
const author = await this.client.users.fetch(interaction.member!.user.id);
149148
// What we need now is to construct the Payload to send for `checkin`.
150-
const privateMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide, needsASForm);
149+
const privateMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide, needsASForm, asAttendanceForm);
151150
await author.send(privateMessage);
152151
await super.edit(interaction, {
153152
content: 'Check your DM.',
154153
ephemeral: true,
155154
});
156155
await interaction.followUp(`**/checkin** was used privately by ${interaction.user}!`);
157156
} else {
158-
const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide, needsASForm);
157+
const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide, needsASForm, asAttendanceForm);
159158
await super.edit(interaction, publicMessage);
160159
}
161160
} catch (e) {
@@ -184,7 +183,7 @@ export default class Checkin extends Command {
184183
*/
185184
private async getFutureEvents(): Promise<PortalEvent[]> {
186185
try {
187-
const portalAPIResponse = (await got(`${this.client.settings.portalAPI.url}/event/future`, {
186+
const portalAPIResponse = (await got(`https://testing.api.acmucsd.com/api/v2/event/future`, {
188187
headers: {
189188
'Content-Type': 'application/json',
190189
Authorization: `Bearer ${this.client.apiToken}`,
@@ -322,8 +321,7 @@ export default class Checkin extends Command {
322321

323322
// Get the Data URL of the image (base-64 encoded string of image).
324323
// Easier to attach than saving files.
325-
const qrCodeDataUrl = await slide.toDataURL();
326-
return qrCodeDataUrl;
324+
return await slide.toDataURL();
327325
}
328326
// Only ACM portal checkin needed
329327
else{
@@ -402,7 +400,8 @@ export default class Checkin extends Command {
402400
events: PortalEvent[],
403401
isPublic: boolean,
404402
needsSlide: boolean,
405-
needsASForm: boolean
403+
needsASForm: boolean,
404+
asAttendanceForm: string,
406405
): Promise<InteractionPayload> {
407406
// This method became very complicated very quickly, so we'll break this down.
408407
// Create arrays to store our payload contents temporarily. We'll put this in our embed
@@ -422,9 +421,7 @@ export default class Checkin extends Command {
422421
const expressCheckinURL = new URL('https://members.acmucsd.com/checkin');
423422
expressCheckinURL.searchParams.set('code', event.attendanceCode);
424423

425-
const asFormFilledURL = new URL(AS_ATTENDANCE_FORM_URL +
426-
'?entry.219446721=Association+for+Computing+Machinery+(ACM)+-+'+
427-
event.title.replace(' ', '+'))
424+
const asFormFilledURL = new URL(asAttendanceForm + event.title.replace(' ', '+'))
428425
// +'&entry.570464428='+event.foodItems.replace(' ', '+') — for food items
429426

430427
// Add the Event's title and make it a hyperlink to the express check-in URL.

src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ export default {
4141
},
4242
discordGuildIDs: [],
4343
matchRoleID: '',
44+
asAttendanceForm: '',
4445
} as BotSettings;

src/types/bot/Bot.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export interface BotSettings {
140140
* ID for the role we use to match members in our /match command.
141141
*/
142142
matchRoleID: string;
143+
144+
/**
145+
* Link for the current AS attendance form
146+
*/
147+
asAttendanceForm: string;
143148
}
144149

145150
/**

0 commit comments

Comments
 (0)