diff --git a/package.json b/package.json index 194af5d..6834ed7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "devdenbot", - "version": "7.0.2", + "version": "7.0.3", "type": "module", "main": "src/index.ts", "scripts": { diff --git a/src/modules/learning/learning.command.ts b/src/modules/learning/learning.command.ts index 1174149..a182a2b 100644 --- a/src/modules/learning/learning.command.ts +++ b/src/modules/learning/learning.command.ts @@ -16,6 +16,7 @@ import { LearningResource } from './learningResource.model.js' const resources: Array<{ name: string, value: string }> = [] export async function updateResourcesForCommands () { + logger.debug('Updating resource for commands') await updateAllResources() const result = getAllCachedResources() .map(([fileName, res]) => ({ @@ -24,10 +25,11 @@ export async function updateResourcesForCommands () { })) resources.length = 0 resources.push(...result) + logger.debug(`resources = ${JSON.stringify(resources)}`) } const extraFooter = - '\n\n[**Contribute to our resource collection!**](https://github.com/TheDeveloperDen/LearningResources)' + '\n\n[**Contribute to our resource collection!**](https://github.com/TheDeveloperDen/LearningResources)' function createBulletList (title: string, entries: string[]) { if (entries.length === 0) return '' @@ -44,17 +46,17 @@ export function getResourceEmbed ( const embed = createStandardEmbed(member) .setTitle(resourceSet.name) .setDescription( - `**${resourceSet.description}**\n\n` + - resourceSet.resources - .map((res) => { - const pros = createBulletList('Pros', res.pros) - const cons = createBulletList('Cons', res.cons) - const description = res.description ? `${res.description}\n` : '' - const linkedName = `[${res.name}](${res.url})` - const price = res.price ? `${res.price}` : 'Free!' - return `${linkedName} - ${price}${description}\n${pros}\n${cons}`.trim() - }).join('\n\n') + - extraFooter + `**${resourceSet.description}**\n\n` + + resourceSet.resources + .map((res) => { + const pros = createBulletList('Pros', res.pros) + const cons = createBulletList('Cons', res.cons) + const description = res.description ? `${res.description}\n` : '' + const linkedName = `[${res.name}](${res.url})` + const price = res.price ? `${res.price}` : 'Free!' + return `${linkedName} - ${price}${description}\n${pros}\n${cons}`.trim() + }).join('\n\n') + + extraFooter ) if (!user || !member) { @@ -76,7 +78,7 @@ export function getResourceEmbed ( if (!emoji) { logger.warn( - `Could not find emoji ${resourceSet.emoji} for resource ${resourceSet.name}` + `Could not find emoji ${resourceSet.emoji} for resource ${resourceSet.name}` ) } else { embed.setTitle(`${stringifyEmoji(emoji)} ${resourceSet.name}`) @@ -104,7 +106,7 @@ const LearningGetSubcommand: ExecutableSubcommand = { const resource = await getResource(name) if (resource == null) { return await interaction.reply( - `Could not find resource ${name}` + `Could not find resource ${name}` ) } @@ -154,10 +156,10 @@ const LearningListSubcommand: ExecutableSubcommand = { .setFooter({ ...standardFooter(), text: `Requested by ${ - pseudoMention( - interaction.user - ) - } | Learning Resources` + pseudoMention( + interaction.user + ) + } | Learning Resources` }) await interaction.reply({ diff --git a/src/modules/learning/resourcesCache.util.ts b/src/modules/learning/resourcesCache.util.ts index cddda44..2dda50d 100644 --- a/src/modules/learning/resourcesCache.util.ts +++ b/src/modules/learning/resourcesCache.util.ts @@ -28,7 +28,7 @@ export async function updateAllResources () { cache.clear(); (await queryAll()).forEach(([fileName, resource]) => { cache.set(fileName, resource) - logger.info(`Updated cache for ${resource.name}`) + logger.info(`Updated cache for ${resource.name} to ${JSON.stringify(resource)}`) }) } @@ -39,6 +39,7 @@ export function getAllCachedResources (): Array<[FileName, LearningResource]> { const baseUrl = 'https://learningresources.developerden.org' async function queryResource (fileName: FileName): Promise { + logger.debug(`Querying resource ${fileName}...`) const resource = (await fetch(`${baseUrl}/${fileName}`)) .text() .then((r) => parse(r)) diff --git a/src/util/users.ts b/src/util/users.ts index cdde3fd..995900b 100644 --- a/src/util/users.ts +++ b/src/util/users.ts @@ -1,40 +1,40 @@ -import {GuildMember, PartialGuildMember, User} from 'discord.js' -import {config} from '../Config.js' +import { GuildMember, PartialGuildMember, User } from 'discord.js' +import { config } from '../Config.js' export const userShouldBePinged = ( - user: GuildMember | PartialGuildMember + user: GuildMember | PartialGuildMember ): boolean => - !user.roles.cache.has( - config.roles.noPing - ) + !user.roles.cache.has( + config.roles.noPing + ) export const pseudoMention = (user: User): string => - user.discriminator === '0' ? user.username : `${user.username}#${user.discriminator}` + user.discriminator === '0' ? user.username : `${user.username}#${user.discriminator}` export const mention = ( - user: GuildMember | User | PartialGuildMember + user: GuildMember | User | PartialGuildMember ): string => { - if (user instanceof User) { - return actualMention(user) - } else { - return userShouldBePinged(user) - ? actualMention(user) - : pseudoMention( - user.user - ) - } + if (user instanceof User) { + return actualMention(user) + } else { + return userShouldBePinged(user) + ? actualMention(user) + : pseudoMention( + user.user + ) + } } export const actualMention = ( - user: GuildMember | User | PartialGuildMember + user: GuildMember | User | PartialGuildMember ): string => `<@${user.id}>` export const mentionWithNoPingMessage = (user: GuildMember): string => - userShouldBePinged(user) - ? `<@${user.id}> (Don't want to be pinged? )` - : pseudoMention(user.user) + userShouldBePinged(user) + ? `<@${user.id}> (Don't want to be pinged? )` + : pseudoMention(user.user) export const isSpecialUser = (user: GuildMember): boolean => - user.premiumSinceTimestamp != + user.premiumSinceTimestamp != null || user.roles.cache.has(config.roles.staff) || user.roles.cache.has(config.roles.notable ?? '')