Skip to content

Commit

Permalink
Merge pull request #924 from tsg-ut/dev/sqrt10/twitter
Browse files Browse the repository at this point in the history
"X" 発言に Twitter スタンプを送る
  • Loading branch information
hakatashi authored Sep 29, 2024
2 parents 6359a17 + cb4bddf commit 8afb19c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions http-local-fwd
Submodule http-local-fwd added at 76d564
31 changes: 31 additions & 0 deletions sushi-bot/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,37 @@ it('does not react to "twitter.com"', async () => {
expect(slack.webClient.reactions.add).not.toHaveBeenCalled();
});

it('reacts to "X" with :twitter:', () => new Promise((resolve) => {
slack.on('reactions.add', ({name, channel, timestamp}) => {
expect(name).toBe('twitter');
expect(channel).toBe(slack.fakeChannel);
expect(timestamp).toBe(slack.fakeTimestamp);
resolve();
});

slack.eventClient.emit('message', {
channel: slack.fakeChannel,
text: '私のXアカウントは@Sqrt10_31622776です',
user: slack.fakeUser,
ts: slack.fakeTimestamp,
});
}));

it('does not react to words including letter "x" (e.g. "fox", "xylophone")', async () => {
slack.webClient.reactions.add.mockReturnValue(null);

slack.eventClient.emit('message', {
channel: slack.fakeChannel,
text: 'The quick brown fox jumps over the lazy dog.',
user: slack.fakeUser,
ts: slack.fakeTimestamp,
});

await new Promise((resolve) => process.nextTick(resolve));

expect(slack.webClient.reactions.add).not.toHaveBeenCalled();
});

it('reacts to sushi in an attachment', async () => {
slack.on('reactions.add', ({ name, channel, timestamp }) => {
expect(name).toBe('sushi');
Expand Down
6 changes: 6 additions & 0 deletions sushi-bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ export default async function ({eventClient, webClient: slack}: SlackInterface)
slack.reactions.add({name: 'x-logo', channel, timestamp})
}
}

{
if (allText.match(/\bx(?!\.com)\b/i)) {
slack.reactions.add({ name: 'twitter', channel, timestamp})
}
}
});

schedule.scheduleJob('0 19 * * *', async (date) => {
Expand Down

0 comments on commit 8afb19c

Please sign in to comment.