Skip to content

Commit

Permalink
fix: more things
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Dec 28, 2023
1 parent 7981554 commit fa1b9da
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/arguments/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export class CoreArgument extends Argument<boolean> {
}

private get getDefaultTruthValues() {
return (this.defaultTruthValues ??= getT('en-US')(LanguageKeys.Arguments.BooleanTrueOptions).filter(filterNullish));
return (this.defaultTruthValues ??= getT()(LanguageKeys.Arguments.BooleanTrueOptions).filter(filterNullish));
}

private get getDefaultFalseValues() {
return (this.defaultFalseValues ??= getT('en-US')(LanguageKeys.Arguments.BooleanFalseOptions).filter(filterNullish));
return (this.defaultFalseValues ??= getT()(LanguageKeys.Arguments.BooleanFalseOptions).filter(filterNullish));
}
}
7 changes: 5 additions & 2 deletions src/arguments/channelName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import type { Guild, GuildChannel, ThreadChannel, User } from 'discord.js';
export class UserArgument extends Argument<GuildChannel | ThreadChannel> {
public resolveChannel(query: string, guild: Guild) {
const channelId = ChannelMentionRegex.exec(query) ?? SnowflakeRegex.exec(query);
return (channelId !== null && guild.channels.cache.get(channelId[1])) ?? null;
return (channelId !== null && guild.channels.cache.get(channelId.groups!.id)) ?? null;
}

public async run(parameter: string, { message, minimum, context, filter }: ChannelArgumentContext) {
if (!isGuildMessage(message)) return this.error({ parameter, identifier: LanguageKeys.Arguments.GuildChannelMissingGuildError, context });
filter = this.getFilter(message.author, filter);

const resChannel = this.resolveChannel(parameter, message.guild);
if (resChannel && filter(resChannel)) return this.ok(resChannel);
if (resChannel) {
if (filter(resChannel)) return this.ok(resChannel);
return this.error({ parameter, identifier: LanguageKeys.Arguments.GuildChannelMismatchingError, context });
}

const result = await new FuzzySearch(message.guild.channels.cache, (entry) => entry.name, filter).run(message, parameter, minimum);
if (result) return this.ok(result[1]);
Expand Down
1 change: 1 addition & 0 deletions src/languages/en-US/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"floatTooLarge": "The parameter `{{parameter}}` is too high! It needs to be less than {{maximum}}!",
"floatTooSmall": "The parameter `{{parameter}}` is too low! It needs to be at least {{minimum}}!",
"guildChannelError": "I could not resolve `{{parameter}}` to a channel from this server, please make sure you typed its name or ID correctly!",
"guildChannelMismatchingError": "The parameter `{{parameter}}` resolved to an incompatible channel type in this server, please try another channel!",
"guildChannelMissingGuildError": "I was not able to resolve `{{parameter}}` because this argument requires to be run in a server channel.",
"guildPrivateThreadChannelError": "I could not resolve `{{parameter}}` to a private thread channel, please make sure you typed its name or ID correctly!",
"guildPublicThreadChannelError": "I could not resolve `{{parameter}}` to a public thread channel, please make sure you typed its name or ID correctly!",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/database/entities/GuildEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class GuildEntity extends BaseEntity implements IBaseEntity {

@ConfigurableKey({ description: LanguageKeys.Settings.Language, type: 'language' })
@Column('varchar', { name: 'language', default: 'en-US' })
public language = 'en-US';
public language: LocaleString = 'en-US';

@ConfigurableKey({ description: LanguageKeys.Settings.DisableNaturalPrefix })
@Column('boolean', { name: 'disable-natural-prefix', default: false })
Expand Down Expand Up @@ -672,7 +672,7 @@ export class GuildEntity extends BaseEntity implements IBaseEntity {
* Gets the [[Language]] for this entity.
*/
public getLanguage(): TFunction {
return getT(this.language as LocaleString);
return getT(this.language);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n/languageKeys/keys/Arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const FloatError = FT<{ parameter: string }>('arguments:floatError');
export const FloatTooLarge = FT<{ parameter: string; maximum: number }>('arguments:floatTooLarge');
export const FloatTooSmall = FT<{ parameter: string; minimum: number }>('arguments:floatTooSmall');
export const GuildChannelError = FT<{ parameter: string }>('arguments:guildChannelError');
export const GuildChannelMismatchingError = FT<{ parameter: string }>('arguments:guildChannelMismatchingError');
export const GuildChannelMissingGuildError = FT<{ parameter: string }>('arguments:guildChannelMissingGuildError');
export const GuildPrivateThreadChannelError = FT<{ parameter: string }>('arguments:guildPrivateThreadChannelError');
export const GuildPublicThreadChannelError = FT<{ parameter: string }>('arguments:guildPublicThreadChannelError');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/i18n/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function getT(locale?: LocaleString | Nullish) {
* @returns The fetched language as a {@link LocaleString}.
*/
export async function fetchLanguage(context: InternationalizationContext) {
return ((await container.i18n.fetchLanguage(context)) ?? 'en-US') as LocaleString;
return (await container.i18n.fetchLanguage(context))! as LocaleString;
}

Check warning on line 135 in src/lib/i18n/translate.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/i18n/translate.ts#L133-L135

Added lines #L133 - L135 were not covered by tests

/**
Expand Down
10 changes: 7 additions & 3 deletions src/lib/structures/SettingsMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ export class SettingsMenu {
}

private async onReaction(reaction: LLRCData): Promise<void> {
// If the message is not the menu's message, ignore:
if (!this.response || reaction.messageId !== this.response.id) return;

// If the user is not the author, ignore:
if (reaction.userId !== this.message.author.id) return;

this.llrc?.setTime(TIMEOUT);
if (reaction.emoji.name === EMOJIS.STOP) {
this.llrc?.end();
Expand All @@ -160,11 +165,10 @@ export class SettingsMenu {

const channelId = this.response.channel.id;
const messageId = this.response.id;
const reactionId = encodeURIComponent(reaction);
try {
return await (userId === this.message.client.user!.id
? api().channels.deleteUserMessageReaction(channelId, messageId, reactionId, userId)
: api().channels.deleteOwnMessageReaction(channelId, messageId, reactionId));
? api().channels.deleteUserMessageReaction(channelId, messageId, reaction, userId)
: api().channels.deleteOwnMessageReaction(channelId, messageId, reaction));
} catch (error) {
if (error instanceof DiscordAPIError) {
if (error.code === RESTJSONErrorCodes.UnknownMessage) {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UserTask extends Task {

if (user) {
const timestamp = time(new Date(), TimestampStyles.ShortDateTime);
const reminderHeader = getT('en-US')(LanguageKeys.System.ReminderHeader, { timestamp });
const reminderHeader = getT()(LanguageKeys.System.ReminderHeader, { timestamp });

await resolveOnErrorCodes(
//
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('Utils', () => {
${AttachmentText} | ${ExpectedReturn} | ${ExpectedEmbedImageURL} | ${'non-image attachment'}
${AttachmentImage} | ${'attachment URL'} | ${AttachmentImage.proxyURL} | ${'image attachment'}
`(`AND $description THEN returns $returns`, ({ attachment, expected }) => {
const message: DeepPartial<Message> = { attachments: createAttachments(attachment), embeds };
const message: DeepPartial<Message> = { attachments: createAttachments(attachment), embeds, stickers: new Collection() };

expect(getImage(message)).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getEmojiReactionFormat } from '#utils/functions';
import { encodedBunnyTwemoji, serializedAnimatedSkyraGlasses, serializedStaticSkyra } from '../../../../mocks/constants.js';
import { bunnyTwemoji, encodedBunnyTwemoji, serializedAnimatedSkyraGlasses, serializedStaticSkyra } from '../../../../mocks/constants.js';

describe('getEmojiReactionFormat', () => {
test('GIVEN encoded twemoji THEN returns encoded twemoji', () => {
expect(getEmojiReactionFormat(encodedBunnyTwemoji)).toBe(encodedBunnyTwemoji);
expect(getEmojiReactionFormat(encodedBunnyTwemoji)).toBe(bunnyTwemoji);
});

test('GIVEN custom serialized static emoji THEN returns :_:819227046453444620>', () => {
Expand Down

0 comments on commit fa1b9da

Please sign in to comment.