Skip to content

Commit c7f0dfb

Browse files
authored
Fix thx (#87)
* fix(thx): Regex * test
1 parent 081c203 commit c7f0dfb

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/thx.spec.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { getMessageMock } from '../test/mocks';
55

66
describe('thx', () => {
77
let id = 0;
8-
const msgReply = 'protip: napisz `@nazwa ++`, żeby komuś podziękować! Możesz podziękować kilku osobom w jednej wiadomości!';
8+
const msgReply =
9+
'protip: napisz `@nazwa ++`, żeby komuś podziękować! Możesz podziękować kilku osobom w jednej wiadomości!';
910

1011
it('it should ignore random messages', async () => {
1112
const msg = getMessageMock('msg', { content: 'msg', channel: { id: ++id } });
@@ -16,14 +17,26 @@ describe('thx', () => {
1617
expect(msg.reply).not.to.have.been.calledOnceWith(msgReply);
1718
});
1819

19-
it('it should respond to thanks', async () => {
20-
const msg = getMessageMock('msg', { content: 'dzięki', channel: { id: ++id } });
21-
msg.reply.resolves();
20+
[
21+
'thx',
22+
'thank',
23+
'thanks',
24+
'dzieki',
25+
'dzięki',
26+
'dziekuje',
27+
'dziekuję',
28+
'dziękuje',
29+
'dziękuję',
30+
].forEach((text) =>
31+
it(`it should respond to ${text}`, async () => {
32+
const msg = getMessageMock('msg', { content: text, channel: { id: ++id } });
33+
msg.reply.resolves();
2234

23-
await thx(msg as unknown as Discord.Message);
35+
await thx(msg as unknown as Discord.Message);
2436

25-
expect(msg.reply).to.have.been.calledOnceWith(msgReply);
26-
});
37+
expect(msg.reply).to.have.been.calledOnceWith(msgReply);
38+
}),
39+
);
2740

2841
[
2942
'dzięki temu',

src/thx.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const thxTimeoutCache = new Cache({ stdTTL: THX_TIMEOUT_S });
66

77
export const thx = (msg: Discord.Message) => {
88
if (
9-
!/(thx|thank|dzięki|dziękuję|dzieki|dziekuje)($|(\s+(?!temu|niej|niemu|tobie)+.*))/i.test(
9+
!/(thx|thank|thanks|dzi[e|ę]ki|dzi[e|ę]kuj[e|ę])($|(\s+(?!temu|niej|niemu|tobie|nim)+.*))/i.test(
1010
msg.content,
1111
)
1212
) {
@@ -21,5 +21,7 @@ export const thx = (msg: Discord.Message) => {
2121
}
2222

2323
thxTimeoutCache.set(msg.channel.id, new Date());
24-
return msg.reply('protip: napisz `@nazwa ++`, żeby komuś podziękować! Możesz podziękować kilku osobom w jednej wiadomości!');
24+
return msg.reply(
25+
'protip: napisz `@nazwa ++`, żeby komuś podziękować! Możesz podziękować kilku osobom w jednej wiadomości!',
26+
);
2527
};

0 commit comments

Comments
 (0)