Skip to content

Commit

Permalink
fix: 絵文字の作成者を取得するように修正 (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuroXina authored Feb 3, 2023
1 parent 01bde80 commit 800c6c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
12 changes: 7 additions & 5 deletions src/adaptor/proxy/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Client } from 'discord.js';

import type { Snowflake } from '../../model/id.js';
import type { EmojiEventProvider } from '../../runner/index.js';
import type { EmojiData } from '../../service/emoji-log.js';

Expand All @@ -9,11 +10,12 @@ export class EmojiProxy implements EmojiEventProvider<EmojiData> {
constructor(private readonly client: Client) {}

onEmojiCreate(handler: EmojiHandler<EmojiData>): void {
this.client.on('emojiCreate', (emoji) =>
handler({
this.client.on('emojiCreate', async (emoji) => {
const author = await emoji.fetchAuthor();
await handler({
emoji: emoji.toString(),
emojiAuthorId: emoji.author?.id ?? undefined
})
);
emojiAuthorId: author.id as Snowflake
});
});
}
}
17 changes: 2 additions & 15 deletions src/service/emoji-log.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { expect, it, vi } from 'vitest';

import type { Snowflake } from '../model/id.js';
import { EmojiLog } from './emoji-log.js';

it('create emoji', async () => {
const sendEmbed = vi.fn(() => Promise.resolve());
const responder = new EmojiLog({ sendEmbed });
await responder.on('CREATE', {
emoji: '<:kawaehand:903283802443501618>',
emojiAuthorId: '586824421470109716'
emojiAuthorId: '586824421470109716' as Snowflake
});

expect(sendEmbed).toHaveBeenCalledWith({
Expand All @@ -16,17 +17,3 @@ it('create emoji', async () => {
'<@586824421470109716> が <:kawaehand:903283802443501618> を作成しました'
});
});

it('create emoji(author undefined)', async () => {
const sendEmbed = vi.fn(() => Promise.resolve());
const responder = new EmojiLog({ sendEmbed });
await responder.on('CREATE', {
emoji: '<:kawaehand:903283802443501618>',
emojiAuthorId: undefined
});

expect(sendEmbed).toHaveBeenCalledWith({
title: '絵文字警察',
description: '誰かが <:kawaehand:903283802443501618> を作成しました'
});
});
3 changes: 2 additions & 1 deletion src/service/emoji-log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Snowflake } from '../model/id.js';
import type { EmojiEventResponder, RoleEvent } from '../runner/index.js';
import type { StandardOutput } from './output.js';

export interface EmojiData {
emoji: string;
emojiAuthorId: string | undefined;
emojiAuthorId: Snowflake;
}

export class EmojiLog implements EmojiEventResponder<EmojiData> {
Expand Down

0 comments on commit 800c6c1

Please sign in to comment.