Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bot message for the first time praisers #516

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<void> => {
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<void> => {
const allKeys = settings.map((s) => s.key);
await SettingsModel.deleteMany({ key: { $in: allKeys } });
};

export { up, down };
8 changes: 8 additions & 0 deletions packages/discord-bot/src/handlers/praise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
roleMentionWarning,
undefinedReceiverWarning,
selfPraiseWarning,
firstTimePraiserInfo,
} from '../utils/praiseEmbeds';
import { assertPraiseGiver } from '../utils/assertPraiseGiver';
import { CommandHandler } from '../interfaces/CommandHandler';
Expand Down Expand Up @@ -67,6 +68,9 @@ export const praiseHandler: CommandHandler = async (
}

const userAccount = await getUserAccount(member as GuildMember);
const praiseItems = await PraiseModel.find({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q) Wouldn't this become an expensive call?
Could we send this message to users when they activate their praise account instead of sending it on first praise?

__
sema-logo  Summary: ❓ I have a question  |  Tags: Inefficient

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any huge performance concerns here since praising is relatively infequent. But yes, this does seem like an overly expensive call. To begin with I'd suggest we try doing PraiseModel.countDocuments( instead.

Copy link
Collaborator

@Vyvy-vi Vyvy-vi Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should make this more feasible 👍

giver: userAccount._id,
});

if (!userAccount.user) {
await interaction.editReply(await notActivatedError());
Expand Down Expand Up @@ -180,5 +184,9 @@ export const praiseHandler: CommandHandler = async (
await msg.reply(await selfPraiseWarning());
}

if (praiseItems.length === 0) {
await msg.reply(await firstTimePraiserInfo());
}

return;
};
13 changes: 13 additions & 0 deletions packages/discord-bot/src/utils/praiseEmbeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,16 @@ export const selfPraiseWarning = async (): Promise<string> => {
}
return 'SELF-PRAISE NOT ALLOWED, PRAISE GIVERS UNABLE TO PRAISE THEMSELVES (message not set)';
};

/**
* Generate response info message FIRST_TIME_PRAISER
*
* @returns {Promise<string>}
*/
export const firstTimePraiserInfo = async (): Promise<string> => {
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)';
};