Skip to content

Commit

Permalink
feat(subjects): use a google sheet as a database
Browse files Browse the repository at this point in the history
  • Loading branch information
noftaly committed Feb 15, 2024
1 parent 4717c19 commit 350a655
Show file tree
Hide file tree
Showing 23 changed files with 589 additions and 152 deletions.
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ ECLASS_DRIVE_URL="https://sharepoint.com"

# Main Guild IDS used for registrating some specific commands ("/lxp", "/recordings", "/eclass"). Coma-separated.
MAIN_GUILD_IDS=""

# +-----------------------+
# | Google Sheets |
# +-----------------------+

# Service Account email address ([email protected])
GOOGLE_SHEET_SVC_EMAIL=
# Service Account private key, with newlines replaced by "\n"
GOOGLE_SHEET_SVC_PRIVATE_KEY=
# Google Sheet ID from the URL
GOOGLE_SHEET_ID=
29 changes: 29 additions & 0 deletions config/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TimestampStyles,
userMention,
} from 'discord.js';
import { ValidationError } from '@/app/lib/structures/SubjectsManager';
import { LogStatuses } from '@/types/database';
import { timeFormat } from '@/utils';
import { settings } from '../settings';
Expand Down Expand Up @@ -442,3 +443,31 @@ export const setup = {
lineWithoutValue: '**{name}** : Aucune valeur associée',
},
} as const;

export const subjects = {
descriptions: {
name: 'subjects',
command: 'Gérer les matières définies sur le Google Sheet.',
subcommands: {
test: 'Vérifie que le Google Sheet est valide.',
refresh: 'Raffraichir les matières dans le bot en re-téléchargeant les données du Google Sheet.',
},
},
messages: {
refreshSuccess: 'Les matières ont bien été raffraichies !',
validationSuccess: 'La feuille est valide !',
validationErrors: 'Il y a des erreurs dans la feuille :\n{errors}',
errorLine: '- **Ligne {row} :** {error}',
errors: {
[ValidationError.DuplicatedIdentifier]: "L'idenfiant choisit n'est pas unique.",
[ValidationError.InvalidEmoji]: "L'emoji n'est pas valide.",
[ValidationError.DuplicatedClassCode]: "Le code de classe n'est pas unique.",
[ValidationError.InvalidTeachingUnit]: "L'unité d'enseignement n'est pas valide. Vérifie que ce soit bien une des valeurs du menu déroulant.",
[ValidationError.InvalidSchoolYear]: "L'année scolaire n'est pas valide. Vérifie que ce soit bien une des valeurs du menu déroulant.",
[ValidationError.InvalidGuild]: "Le serveur discord n'existe pas.",
[ValidationError.InvalidTextChannel]: "Le salon de texte n'existe pas.",
[ValidationError.InvalidTextDocsChannel]: "Le salon de texte pour les documents n'existe pas.",
[ValidationError.InvalidTextVoiceChannel]: "Le salon vocal n'existe pas.",
},
},
} as const;
4 changes: 2 additions & 2 deletions config/commands/professors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
userMention,
} from 'discord.js';
import { SchoolYear } from '@/types';
import type { SubjectBase } from '@/types/database';
import type { SubjectEntry } from '@/types/database';
import { EclassPlace, EclassStatus } from '@/types/database';
import { timeFormat } from '@/utils';

Expand Down Expand Up @@ -89,7 +89,7 @@ export const eclass = {
},
recordedValues: ['Non :x:', 'Oui :white_check_mark:'],
where: ({ place, placeInformation, subject }: {
place: EclassPlace; placeInformation: string | null; subject: SubjectBase;
place: EclassPlace; placeInformation: string | null; subject: SubjectEntry;
}): string => {
switch (place) {
case EclassPlace.Discord:
Expand Down
209 changes: 209 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
"discord.js": "^14.14.1",
"dotenv": "^16.4.2",
"fuzzy-search": "^3.2.1",
"google-auth-library": "^9.6.3",
"google-spreadsheet": "^4.1.1",
"lodash": "^4.17.21",
"marked": "^12.0.0",
"mathjax": "^3.2.2",
Expand Down
Loading

0 comments on commit 350a655

Please sign in to comment.