Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 絵文字の作成者を取得するように修正 #699

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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