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

fix: ephemeral warnings #521

Merged
merged 4 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion packages/discord-bot/src/handlers/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const activationHandler: CommandHandler = async (interaction) => {
);

if (!userAccount) {
await interaction.reply('Unable to create user account.');
await interaction.reply({
content: 'Unable to create user account.',
ephemeral: true,
});
return;
}

Expand Down
62 changes: 30 additions & 32 deletions packages/discord-bot/src/handlers/forward.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PraiseModel } from 'api/dist/praise/entities';
import { Message, GuildMember, Util } from 'discord.js';
import { GuildMember, Util } from 'discord.js';
import { UserModel } from 'api/dist/user/entities';
import { EventLogTypeKey } from 'api/src/eventlog/types';
import { logEvent } from 'api/src/eventlog/utils';
Expand Down Expand Up @@ -169,39 +169,37 @@ export const forwardHandler: CommandHandler = async (
}
}

const msg = (
Receivers.length !== 0
? await interaction.editReply(
await forwardSuccess(
praiseGiver.user,
praised.map((id) => `<@!${id}>`),
reason
)
Receivers.length !== 0
? await interaction.editReply(
await forwardSuccess(
praiseGiver.user,
praised.map((id) => `<@!${id}>`),
reason
)
: warnSelfPraise
? await interaction.editReply(await selfPraiseWarning())
: await interaction.editReply(await invalidReceiverError())
) as Message;

if (receiverData.undefinedReceivers) {
await msg.reply(
await undefinedReceiverWarning(
receiverData.undefinedReceivers.join(', '),
praiseGiver.user
)
);
}
if (receiverData.roleMentions) {
await msg.reply(
await roleMentionWarning(
receiverData.roleMentions.join(', '),
praiseGiver.user
)
);
}
if (Receivers.length !== 0 && warnSelfPraise) {
await msg.reply(await selfPraiseWarning());
: warnSelfPraise
? await interaction.editReply(await selfPraiseWarning())
: await interaction.editReply(await invalidReceiverError());

const warningMsg =
(receiverData.undefinedReceivers
? (await undefinedReceiverWarning(
receiverData.undefinedReceivers.join(', '),
praiseGiver.user
)) + '\n'
: '') +
(receiverData.roleMentions
? (await roleMentionWarning(
receiverData.roleMentions.join(', '),
praiseGiver.user
)) + '\n'
: '') +
(Receivers.length !== 0 && warnSelfPraise
? (await selfPraiseWarning()) + '\n'
: '');

if (warningMsg && warningMsg.length !== 0) {
await interaction.followUp({ content: warningMsg, ephemeral: true });
}

return;
};
69 changes: 35 additions & 34 deletions packages/discord-bot/src/handlers/praise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PraiseModel } from 'api/dist/praise/entities';
import { EventLogTypeKey } from 'api/src/eventlog/types';
import { logEvent } from 'api/src/eventlog/utils';
import logger from 'jet-logger';
import { GuildMember, Message, User, Util } from 'discord.js';
import { GuildMember, User, Util } from 'discord.js';
import { settingValue } from 'api/dist/shared/settings';
import {
dmError,
Expand Down Expand Up @@ -148,44 +148,45 @@ export const praiseHandler: CommandHandler = async (
}
}

const msg = (
Receivers.length !== 0
? await interaction.editReply(
await praiseSuccess(
praised.map((id) => `<@!${id}>`),
reason
)
Receivers.length !== 0
? await interaction.editReply(
await praiseSuccess(
praised.map((id) => `<@!${id}>`),
reason
)
: warnSelfPraise
? await interaction.editReply(await selfPraiseWarning())
: await interaction.editReply(await invalidReceiverError())
) as Message;

if (receiverData.undefinedReceivers) {
await msg.reply(
await undefinedReceiverWarning(
receiverData.undefinedReceivers
.map((id) => id.replace(/[<>]/, ''))
.join(', '),
member.user as User
)
);
}
if (receiverData.roleMentions) {
await msg.reply(
await roleMentionWarning(
receiverData.roleMentions.join(', '),
member.user as User
)
);
}

if (Receivers.length !== 0 && warnSelfPraise) {
await msg.reply(await selfPraiseWarning());
: warnSelfPraise
? await interaction.editReply(await selfPraiseWarning())
: await interaction.editReply(await invalidReceiverError());

const warningMsg =
(receiverData.undefinedReceivers
? (await undefinedReceiverWarning(
receiverData.undefinedReceivers
.map((id) => id.replace(/[<>]/, ''))
.join(', '),
member.user as User
)) + '\n'
: '') +
(receiverData.roleMentions
? (await roleMentionWarning(
receiverData.roleMentions.join(', '),
member.user as User
)) + '\n'
: '') +
(Receivers.length !== 0 && warnSelfPraise
? (await selfPraiseWarning()) + '\n'
: '');

if (warningMsg && warningMsg.length !== 0) {
await interaction.followUp({ content: warningMsg, ephemeral: true });
}

if (praiseItemsCount === 0) {
await msg.reply(await firstTimePraiserInfo());
await interaction.followUp({
content: await firstTimePraiserInfo(),
ephemeral: true,
});
}

return;
Expand Down