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

feat(blacklist): add lodestone-id field #533

Merged
merged 1 commit into from
Nov 2, 2024
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
6 changes: 5 additions & 1 deletion src/blacklist/blacklist.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
characterName,
discordId,
reason,
lodestoneId,

Check warning on line 36 in src/blacklist/blacklist.utils.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/blacklist.utils.ts#L36

Added line #L36 was not covered by tests
}: BlacklistDocument): APIEmbedField[] {
const displayName = getDisplayName({ characterName, discordId });

return [
{ name: 'Player', value: displayName, inline: true },
{ name: 'Reason', value: reason, inline: true },
{ name: '\u200b', value: '\u200b', inline: true },
lodestoneId
? { name: 'Lodestone ID', value: String(lodestoneId), inline: true }
: { name: '\u200b', value: '\u200b', inline: true },

Check warning on line 45 in src/blacklist/blacklist.utils.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/blacklist.utils.ts#L43-L45

Added lines #L43 - L45 were not covered by tests
];
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventsHandler, type IEventHandler } from '@nestjs/cqrs';
import { type APIEmbedField, EmbedBuilder } from 'discord.js';
import { titleCase } from 'title-case';
import { createFields } from '../../../common/embed-helpers.js';
import { DiscordService } from '../../../discord/discord.service.js';
import { SettingsCollection } from '../../../firebase/collections/settings-collection.js';
import { getDisplayName } from '../../blacklist.utils.js';
Expand Down Expand Up @@ -28,13 +29,18 @@

const toFrom = type === 'added' ? 'to' : 'from';

const fields: APIEmbedField[] = [
const fields = createFields([

Check warning on line 32 in src/blacklist/events/handlers/blacklist-updated.event-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/events/handlers/blacklist-updated.event-handler.ts#L32

Added line #L32 was not covered by tests
{
name: 'User',
value: titleCase(getDisplayName(entry)),
inline: true,
},
];
{
name: 'Lodestone ID',
value: entry.lodestoneId?.toString(),
inline: true,
},
]);

Check warning on line 43 in src/blacklist/events/handlers/blacklist-updated.event-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/events/handlers/blacklist-updated.event-handler.ts#L38-L43

Added lines #L38 - L43 were not covered by tests

if (type === 'added') {
fields.push({ name: 'Reason', value: entry.reason, inline: true });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

const discordId = getDiscordId(interaction);
const characterName = interaction.options.getString('character');
const lodestoneId = interaction.options.getInteger('lodestone-id');

Check warning on line 23 in src/blacklist/subcommands/add/blacklist-add.command-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/subcommands/add/blacklist-add.command-handler.ts#L23

Added line #L23 was not covered by tests
const reason = interaction.options.getString('reason', true);

const props: BlacklistDocument = {
discordId,
characterName: characterName?.toLowerCase() ?? null,
reason,
lodestoneId,

Check warning on line 30 in src/blacklist/subcommands/add/blacklist-add.command-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/subcommands/add/blacklist-add.command-handler.ts#L30

Added line #L30 was not covered by tests
};

const entry = await this.blacklistCollection.upsert(guildId, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

const discordId = getDiscordId(interaction);
const characterName = interaction.options.getString('character');
const lodestoneId = interaction.options.getInteger('lodestone-id');

Check warning on line 22 in src/blacklist/subcommands/remove/blacklist-remove.command-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/subcommands/remove/blacklist-remove.command-handler.ts#L22

Added line #L22 was not covered by tests

const entry = await this.blacklistCollection.remove(guildId, {
discordId,
characterName: characterName?.toLowerCase() ?? null,
lodestoneId,

Check warning on line 27 in src/blacklist/subcommands/remove/blacklist-remove.command-handler.ts

View check run for this annotation

Codecov / codecov/patch

src/blacklist/subcommands/remove/blacklist-remove.command-handler.ts#L27

Added line #L27 was not covered by tests
});

await interaction.editReply('Success!');
Expand Down
5 changes: 4 additions & 1 deletion src/firebase/collections/blacklist-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
*/
public remove(
guildId: string,
props: BlacklistDocumentKeys,
props: ExactType<

Check warning on line 72 in src/firebase/collections/blacklist-collection.ts

View check run for this annotation

Codecov / codecov/patch

src/firebase/collections/blacklist-collection.ts#L72

Added line #L72 was not covered by tests
BlacklistDocument,
'discordId' | 'characterName' | 'lodestoneId'
>,

Check warning on line 75 in src/firebase/collections/blacklist-collection.ts

View check run for this annotation

Codecov / codecov/patch

src/firebase/collections/blacklist-collection.ts#L75

Added line #L75 was not covered by tests
): Promise<BlacklistDocument | undefined> {
const pipeline$ = this.query$(guildId, props).pipe(
mergeMap(async (result) => {
Expand Down
1 change: 1 addition & 0 deletions src/firebase/models/blacklist.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface BlacklistDocument {
characterName: string | null;
discordId: string | null;
reason: string;
lodestoneId: number | null;
}
12 changes: 10 additions & 2 deletions src/slash-commands/commands/blacklist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
PermissionFlagsBits,
SlashCommandBuilder,
type SlashCommandIntegerOption,
type SlashCommandStringOption,
SlashCommandSubcommandBuilder,
type SlashCommandUserOption,
Expand All @@ -26,6 +27,11 @@ const characterOption = (option: SlashCommandStringOption) =>
.setName('character')
.setDescription('The character name incase no discord id is known');

const lodestoneIdOption = (option: SlashCommandIntegerOption) =>
option
.setName('lodestone-id')
.setDescription('The Lodestone ID of the character');

const BlacklistAddSubCommand = new SlashCommandSubcommandBuilder()
.setName('add')
.setDescription('A list of players to keep an eye on')
Expand All @@ -37,14 +43,16 @@ const BlacklistAddSubCommand = new SlashCommandSubcommandBuilder()
)
.addUserOption(userOption)
.addStringOption(discordIdOption)
.addStringOption(characterOption);
.addStringOption(characterOption)
.addIntegerOption(lodestoneIdOption);

const BlacklistRemoveSubCommand = new SlashCommandSubcommandBuilder()
.setName('remove')
.setDescription('Remove a user from the blacklist')
.addUserOption(userOption)
.addStringOption(discordIdOption)
.addStringOption(characterOption);
.addStringOption(characterOption)
.addIntegerOption(lodestoneIdOption);

const BlacklistDisplayCommand = new SlashCommandSubcommandBuilder()
.setName('display')
Expand Down
Loading