Skip to content

Commit

Permalink
Nov 13 Patches before onboarding (#189)
Browse files Browse the repository at this point in the history
* fix: bad timer type and dependency issues

* fix: breaking changes in google sheet lib

* fix: wrong logger

* fix: incorrect enum value

* fix: make the on ready handler temporary

* fix: temporarily remove typedoc, remove unused dependencies

* fix: dependencies for typedoc

* fix: missing arg for typedoc

* style: reduce clutter

* syle: cleanup gitignore

* fix: update eslint version

* fix: temporarily let pm2 deal with log rotation

* fix: add permission check before every write to google sheets

* style: remove unnecessary ternary

* feat: swap to env files

* Revert "feat: swap to env files"

This reverts commit 00837a7.
  • Loading branch information
tomli380576 authored Nov 16, 2023
1 parent c2c7a50 commit d347ac1
Show file tree
Hide file tree
Showing 23 changed files with 1,487 additions and 8,415 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"semi": [2, "always"],
"eqeqeq": 2,
"no-throw-literal": "error",
"@typescript-eslint/no-unnecessary-condition": "error"
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/no-unused-vars": "warn"
}
}
12 changes: 0 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ test/*.js
dist/
node_modules/
.env
.nyc_output/
.vscode/
test_dir/
.DS_Store
src/extensions/google_client_id.json
.DS_Store
.DS_Store
src/extensions/token.json
src/extensions/google_client_id.json
src/extensions/token.json
src/extensions/session-calendar/google_client_id.json
src/extensions/session-calendar/token.json
src/extensions/attendance/attendance-config.ts
src/extensions/session-calendar/calendar-config.ts
yabob-prod-application-log*.log
9,552 changes: 1,272 additions & 8,280 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 8 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,38 @@
"scripts": {
"lint": "eslint src/",
"build": "npx tsc",
"test": "nyc mocha -r ts-node/register test/*.ts",
"format": "npx prettier -w .",
"start": "node dist/src/app.js",
"dev": "echo 'Compiling...' && npx tsc && echo 'Successfully Compiled.' && NODE_ENV=development node dist/src/app.js",
"dev_precompiled": "NODE_ENV=development node dist/src/app.js",
"devWithProfile": "echo 'Compiling...' && npx tsc && echo 'Successfully Compiled.' && NODE_ENV=development node --inspect dist/src/app.js",
"prod": "echo 'Compiling...' && npx tsc && echo 'Successfully Compiled.' && NODE_ENV=production pm2 start dist/src/app.js --name YABOB_PROD",
"prod_precompiled": "NODE_ENV=production pm2 start dist/src/app.js --name YABOB_PROD",
"makeDoc": "npx typedoc ./src --entryPointStrategy expand --mergeModulesMergeMode module --excludeInternal --name \"Yet Another Better Office-hour Bot\" --includeVersion"
"makeDoc": "npx typedoc --plugin typedoc-plugin-merge-modules ./src --entryPointStrategy expand --mergeModulesMergeMode module --excludeInternal --name \"Yet Another Better Office-hour Bot\" --includeVersion"
},
"devDependencies": {
"@types/google-spreadsheet": "^3.1.5",
"@types/lz-string": "^1.3.34",
"@types/mocha": "^9.0.0",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^7.32.0",
"mocha": "^9.1.0",
"nyc": "^15.1.0",
"pino-pretty": "^10.2.0",
"prettier": "2.7.1",
"ts-mockito": "^2.6.1",
"typedoc": "^0.23.17",
"typedoc-plugin-merge-modules": "^4.0.1",
"typescript": "^5.0.0"
"typedoc": "^0.25.3",
"typedoc-plugin-merge-modules": "^5.1.0",
"typescript": "^5.2.2"
},
"dependencies": {
"ascii-table3": "^0.9.0",
"axios": "^0.27.2",
"axios": "^1.6.1",
"csv-string": "^4.1.1",
"discord-api": "^0.0.1",
"discord-api-types": "^0.37.11",
"discord.js": "^14.8.0",
"dotenv": "^10.0.0",
"firebase-admin": "^11.5.0",
"google-spreadsheet": "^3.3.0",
"google-spreadsheet": "^4.1.1",
"googleapis": "^100.0.0",
"lru-cache": "^7.14.0",
"lz-string": "^1.4.4",
Expand Down
18 changes: 12 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from './interaction-handling/interaction-entry-point.js';
import { Guild, Interaction, Events } from 'discord.js';
import { AttendingServerV2 } from './attending-server/base-attending-server.js';
import { red, yellow } from './utils/command-line-colors.js';
import { green, red, yellow } from './utils/command-line-colors.js';
import { EmbedColor, SimpleEmbed } from './utils/embed-helper.js';
import { client, LOGGER } from './global-states.js';
import { environment } from './environment/environment-manager.js';
Expand All @@ -20,7 +20,7 @@ import { studentCommandHelpMessages } from '../help-channel-messages/StudentComm
/**
* After login startup sequence
*/
client.on(Events.ClientReady, async () => {
client.once(Events.ClientReady, async () => {
printTitleString();
// do the global initialization checks and collect static data
await Promise.all(interactionExtensions.map(ext => ext.initializationCheck()));
Expand All @@ -31,15 +31,20 @@ client.on(Events.ClientReady, async () => {
);
// create all the AttendingServerV2 objects
const setupResults = await Promise.allSettled(completeGuilds.map(joinGuild));
setupResults.forEach(
result => result.status === 'rejected' && LOGGER.error(`${result.reason}`)
);
setupResults.forEach(result => {
if (result.status === 'rejected') {
LOGGER.error(`${result.reason}`);
}
});
if (setupResults.filter(result => result.status === 'fulfilled').length === 0) {
LOGGER.fatal('All server setups failed. Aborting.');
process.exit(1);
}
LOGGER.info(
`✅ Ready to go! (${AttendingServerV2.activeServersCount} servers created) ✅`
green(
`✅ Ready to go! (${AttendingServerV2.activeServersCount} servers created) ✅`,
'Bg'
)
);
LOGGER.info('-------- Begin Server Logs --------');
updatePresence();
Expand Down Expand Up @@ -215,6 +220,7 @@ async function joinGuild(guild: Guild): Promise<AttendingServerV2> {
* Combines all the extension help messages and settings menu options
* - if we have more static data in interaction level extensions, collect them here
* - extensions only need to specify the corresponding properties
* - This should be called exactly ONCE
*/
function collectInteractionExtensionStaticData(): void {
const documentationLink = {
Expand Down
7 changes: 4 additions & 3 deletions src/attending-server/base-attending-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,13 @@ class AttendingServerV2 {
);
// for each queueName, if it's not in existingRoles, create it
await Promise.all(
queueNames.map(roleToCreate => {
!existingRoles.has(roleToCreate) &&
this.guild.roles.create({
queueNames.map(async roleToCreate => {
if (!existingRoles.has(roleToCreate)) {
await this.guild.roles.create({
name: roleToCreate,
position: 1
});
}
})
);
}
Expand Down
15 changes: 0 additions & 15 deletions src/attending-server/server-settings-menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ function SettingsSwitcher(
);
}

/** This creates an empty embed field in embeds */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const EmptyEmbedField = {
name: '\u200b',
value: '\u200b'
} as const;

/** Use this string to force a trailing new line in an embed field */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const trailingNewLine = '\n\u200b' as const;

/** Use this string to force a leading new line in an embed field */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const leadingNewLine = '\u200b\n' as const;

/**
* Options for the main menu of server settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ enum HelpSessionHeaders {

enum AttendanceHeaders {
HelperUserName = 'Helper Username',
TimeInLocal = 'Time In (Local Time)',
TimeOutLocal = 'Time Out (Local Time)',
LocalTimeIn = 'Time In (Local Time)',
LocalTimeOut = 'Time Out (Local Time)',
HelpedStudents = 'Helped Students',
HelperDiscordId = 'Helper Discord ID',
OfficeHourTimeMs = 'Office Hour Time (ms)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const ExpectedSheetErrors = {
'I can only accept server based interactions. ' +
`Are you sure ${guildName} has a initialized YABOB with the google sheets extension?`
),
noWriteAccess: new GoogleSheetConnectionError(
'YABOB does not have write access to the google sheet for this server, please contact the server admins to get your help time recorded.'
),
badNumericalValues: (sheetName: string, column?: string) =>
new CommandParseError(
`Some numbers in ${sheetName}${
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { EnsureCorrectEnum } from '../../../utils/type-aliases.js';

enum GoogleSheetCommandNames {
stats = 'stats',
weekly_report = 'weekly_report'
}

enum GoogleSheetButtonNames {
ResetGoogleSheetSettings = 'ResetGoogleSheetSettings',
ShowGoogleSheetSettingsModal = 'ShowGoogleSheetsSettingsModal'
ShowGoogleSheetSettingsModal = 'ShowGoogleSheetSettingsModal'
}

enum GoogleSheetModalNames {
GoogleSheetSettingsModal = 'GoogleSheetsSettingsModal',
GoogleSheetSettingsModalMenuVersion = 'GoogleSheetsSettingsModalMenuVersion'
GoogleSheetSettingsModal = 'GoogleSheetSettingsModal',
GoogleSheetSettingsModalMenuVersion = 'GoogleSheetSettingsModalMenuVersion'
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type AllEnumsCorrect = EnsureCorrectEnum<typeof GoogleSheetCommandNames> &
EnsureCorrectEnum<typeof GoogleSheetButtonNames> &
EnsureCorrectEnum<typeof GoogleSheetModalNames>; // checks if all names and values are the same

export { GoogleSheetCommandNames, GoogleSheetButtonNames, GoogleSheetModalNames };
Loading

0 comments on commit d347ac1

Please sign in to comment.