diff --git a/src/commands/review.ts b/src/commands/review.ts index 6993b3f..e28e917 100644 --- a/src/commands/review.ts +++ b/src/commands/review.ts @@ -55,11 +55,14 @@ export async function execute(interaction: ChatInputCommandInteraction) { const userId = interaction.user.id; const textReview = interaction.options.getString('text'); if (textReview == undefined || subjectCode == undefined) { - console.log('Error with arguments for create review command.'); + console.log('LOG: Error with arguments for create review command.'); return interaction.editReply({ content: `Error while creating a review for ${subjectCode}.`, }); } + console.log( + `LOG: Checking if user ${userId} has already submitted review for ${subjectCode}.` + ); const existingReview = await prisma.reviews.findMany({ where: { discordUserId: { @@ -70,13 +73,13 @@ export async function execute(interaction: ChatInputCommandInteraction) { }, }, }); - console.log(existingReview); if (existingReview.length != 0) { return interaction.editReply({ content: `You have already submitted review from subject ${subjectCode}.`, }); } try { + console.log(`LOG: Creating review for subject ${subjectCode}.`); await prisma.reviews.create({ data: { discordUserId: userId, @@ -85,7 +88,7 @@ export async function execute(interaction: ChatInputCommandInteraction) { }, }); } catch (err) { - console.log(`Database error: ${err}`); + console.log(`LOG: Database error: ${err}`); return interaction.editReply({ content: `Error while creating a review for ${subjectCode}.`, }); @@ -102,11 +105,17 @@ export async function execute(interaction: ChatInputCommandInteraction) { subjectCode: subjectCode?.toUpperCase(), }, }); + console.log( + `LOG: Submitted reviews for ${subjectCode}: ${submittedReviews}.` + ); if (submittedReviews.length == 0) { return interaction.editReply({ content: `No reviews for ${subjectCode?.toUpperCase()} :(`, }); } + console.log( + `LOG: Building embed for review ${submittedReviews[0].id}.` + ); const title = `Reviews for course ${subjectCode}`; const reviewer = await interaction.client.users.fetch( submittedReviews[0].discordUserId diff --git a/src/commands/verify.ts b/src/commands/verify.ts index 70fc05c..67504e7 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -49,6 +49,9 @@ export async function execute(interaction: ChatInputCommandInteraction) { }); let user; try { + console.log( + `LOG: Checking if user ${interaction.user.id} is already registered.` + ); user = await prisma.users.findMany({ where: { discordId: interaction.user.id, @@ -71,6 +74,7 @@ export async function execute(interaction: ChatInputCommandInteraction) { if (thesisId === undefined) { thesisId = bachelorThesisParsedUrl.pathname.split('/')[2]; } + console.log(`LOG: Checking if thesis ${thesisId} exists in database.`); user = await prisma.users.findMany({ where: { idThesis: thesisId, diff --git a/src/utils/assignRole.ts b/src/utils/assignRole.ts index f2fbbf8..a6d440d 100644 --- a/src/utils/assignRole.ts +++ b/src/utils/assignRole.ts @@ -26,6 +26,7 @@ export async function assignRole( bachelorThesisParsedUrl: URL ) { const today = new Date(); + console.log('LOG: Assigning role to user.'); if ( scrapedConfirmationStudy[ 'Status of studies as of ' + @@ -56,6 +57,9 @@ export async function assignRole( if (idThesis === undefined) { idThesis = bachelorThesisParsedUrl.pathname.split('/')[2]; } + console.log( + `LOG: Creating user in database with thesis ${idThesis}.` + ); await prisma.users.create({ data: { discordId: interaction.user.id, @@ -67,6 +71,7 @@ export async function assignRole( console.log(`Database error: ${err}`); return undefined; } + console.log(`LOG: Assigning role to user ${interaction.user.id}.`); if (roleVerified && roleProgramm) { member.roles.add(roleVerified); member.roles.add(roleProgramm); diff --git a/src/utils/scrapeConfirmationStudies.ts b/src/utils/scrapeConfirmationStudies.ts index 4ed15ca..ea3e965 100644 --- a/src/utils/scrapeConfirmationStudies.ts +++ b/src/utils/scrapeConfirmationStudies.ts @@ -6,6 +6,7 @@ import { load } from 'cheerio'; */ export async function scrapeConfirmationStudies(pathname: string) { let response; + console.log('LOG: Scraping confirmation of studies.'); try { response = await axios.get( 'https://is.muni.cz' + pathname + '?lang=en' @@ -15,9 +16,11 @@ export async function scrapeConfirmationStudies(pathname: string) { return null; } const $ = load(response.data); + console.log('LOG: Extracting user information from the confirmation page.'); const userInfo = $( '#el_potvrzeni > div.column.small-12.medium-8.large-8 > div' ); + console.log(`LOG: Parsed data from the page ${userInfo}.`); const children = userInfo .children() .map((_, el) => $(el).text()) diff --git a/src/utils/scrapeThesis.ts b/src/utils/scrapeThesis.ts index 552abb3..0df5ad5 100644 --- a/src/utils/scrapeThesis.ts +++ b/src/utils/scrapeThesis.ts @@ -5,6 +5,7 @@ import { load } from 'cheerio'; */ export async function scrapeThesis(bachelorThesisPath: string) { let response; + console.log('LOG: Scraping author name from the thesis.'); try { response = await axios.get( 'https://dspace.vutbr.cz' + bachelorThesisPath @@ -14,9 +15,11 @@ export async function scrapeThesis(bachelorThesisPath: string) { return null; } const $ = load(response.data); + console.log('LOG: Parsing author name from the page.'); const authorName = $( 'ds-metadata-representation-list.ds-item-page-mixed-author-field:nth-child(4) > ds-metadata-field-wrapper:nth-child(1) > div:nth-child(1) > div:nth-child(2) > ds-metadata-representation-loader:nth-child(1) > ds-plain-text-metadata-list-element:nth-child(1) > div:nth-child(1) > a:nth-child(1)' ).text(); + console.log(`LOG: Parsed author name from the page ${authorName}.`); return authorName .split(',') .reverse()