Skip to content

Commit

Permalink
Merge pull request #521 from commons-stack/feat/ephemeral-warnings
Browse files Browse the repository at this point in the history
fix: ephemeral warnings
  • Loading branch information
kristoferlund authored Aug 8, 2022
2 parents 28e2f77 + 7cf4957 commit e34da81
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 67 deletions.
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

0 comments on commit e34da81

Please sign in to comment.