Skip to content

Commit

Permalink
Fix username cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Sep 12, 2024
1 parent cd7c686 commit 6b5a219
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/util/discord.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/util/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
ComponentType,
type Guild,
type InteractionReplyOptions,
PermissionsBitField,
escapeMarkdown
PermissionsBitField
} from 'discord.js';
import { chunk } from 'e';

Expand Down Expand Up @@ -73,5 +72,5 @@ export function makeComponents(components: ButtonBuilder[]): InteractionReplyOpt
}

export function cleanUsername(username: string) {
return escapeMarkdown(stripEmojis(username)).substring(0, 32);
return stripEmojis(username).substring(0, 32).replaceAll('@', '');
}
9 changes: 9 additions & 0 deletions tests/misc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect, test } from 'vitest';

import { cleanUsername } from '../src/index';

test('cleanUsername', () => {
expect(cleanUsername('just_as')).toEqual('just_as');
expect(cleanUsername('just as')).toEqual('just as');
expect(cleanUsername('@justas')).toEqual('justas');
});

0 comments on commit 6b5a219

Please sign in to comment.