diff --git a/packages/api/src/database/migrations/17_settings_first_time_praiser.ts b/packages/api/src/database/migrations/17_settings_first_time_praiser.ts new file mode 100644 index 000000000..f32887883 --- /dev/null +++ b/packages/api/src/database/migrations/17_settings_first_time_praiser.ts @@ -0,0 +1,35 @@ +import { SettingGroup } from '@/settings/types'; +import { SettingsModel } from '../../settings/entities'; + +const settings = [ + { + key: 'FIRST_TIME_PRAISER', + value: + '**😃 We noticed this is the first time you praise!**\n Find here some info about what makes good Praise: https://givepraise.xyz', + type: 'Textarea', + label: 'First Time Praiser Message', + description: 'Make a great new praise!', + group: SettingGroup.DISCORD, + }, +]; + +const up = async (): Promise => { + const settingUpdates = settings.map((s) => ({ + updateOne: { + filter: { key: s.key }, + + // Insert setting if not found, otherwise continue + update: { $setOnInsert: { ...s } }, + upsert: true, + }, + })); + + await SettingsModel.bulkWrite(settingUpdates); +}; + +const down = async (): Promise => { + const allKeys = settings.map((s) => s.key); + await SettingsModel.deleteMany({ key: { $in: allKeys } }); +}; + +export { up, down }; diff --git a/packages/discord-bot/src/handlers/praise.ts b/packages/discord-bot/src/handlers/praise.ts index 0d9939640..374adc63d 100644 --- a/packages/discord-bot/src/handlers/praise.ts +++ b/packages/discord-bot/src/handlers/praise.ts @@ -15,6 +15,7 @@ import { roleMentionWarning, undefinedReceiverWarning, selfPraiseWarning, + firstTimePraiserInfo, } from '../utils/praiseEmbeds'; import { assertPraiseGiver } from '../utils/assertPraiseGiver'; import { CommandHandler } from '../interfaces/CommandHandler'; @@ -67,6 +68,9 @@ export const praiseHandler: CommandHandler = async ( } const userAccount = await getUserAccount(member as GuildMember); + const praiseItemsCount = await PraiseModel.countDocuments({ + giver: userAccount._id, + }); if (!userAccount.user) { await interaction.editReply(await notActivatedError()); @@ -180,5 +184,9 @@ export const praiseHandler: CommandHandler = async ( await msg.reply(await selfPraiseWarning()); } + if (praiseItemsCount === 0) { + await msg.reply(await firstTimePraiserInfo()); + } + return; }; diff --git a/packages/discord-bot/src/utils/praiseEmbeds.ts b/packages/discord-bot/src/utils/praiseEmbeds.ts index 52405b1a0..2fc14cd32 100644 --- a/packages/discord-bot/src/utils/praiseEmbeds.ts +++ b/packages/discord-bot/src/utils/praiseEmbeds.ts @@ -262,3 +262,16 @@ export const selfPraiseWarning = async (): Promise => { } return 'SELF-PRAISE NOT ALLOWED, PRAISE GIVERS UNABLE TO PRAISE THEMSELVES (message not set)'; }; + +/** + * Generate response info message FIRST_TIME_PRAISER + * + * @returns {Promise} + */ +export const firstTimePraiserInfo = async (): Promise => { + const msg = (await settingValue('FIRST_TIME_PRAISER')) as string; + if (msg) { + return msg; + } + return 'YOU ARE PRAISING FOR THE FIRST TIME. WELCOME TO PRAISE! (message not set)'; +};