Skip to content

Commit

Permalink
feat: ボイスチャンネル関連の機能で成功時にメッセージを送信する (#661)
Browse files Browse the repository at this point in the history
* feat: sucess message

* fix: replace processing order

* chore: fix test-case

* feat: replace stdout

* feat: move start method

* fix: add properties
  • Loading branch information
m2en authored Jan 19, 2023
1 parent 9329ec9 commit 60a9d0a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const scheduleRunner = new ScheduleRunner(clock);
const commandProxy = new DiscordCommandProxy(client, PREFIX);
const commandRunner = new CommandRunner(commandProxy);
const stats = new DiscordMemberStats(client, GUILD_ID as Snowflake);
const output = new DiscordOutput(client, mainChannelId);

// ほとんど変わらないことが予想され環境変数で管理する必要性が薄いので、ハードコードした。
const KAWAEMON_ID = '391857452360007680' as Snowflake;
Expand Down Expand Up @@ -164,7 +165,8 @@ if (features.includes('COMMAND')) {
userRepo: stats,
guildRepo: stats,
roleCreateRepo: roleManager,
queen: new MathRandomGenerator()
queen: new MathRandomGenerator(),
stdout: output
});
}

Expand All @@ -173,7 +175,6 @@ const provider = new VoiceRoomProxy<VoiceChannelParticipant>(
(voiceState) => new DiscordParticipant(voiceState)
);
const voiceRoomRunner = new VoiceRoomResponseRunner(provider);
const output = new DiscordOutput(client, mainChannelId);
if (features.includes('VOICE_ROOM')) {
voiceRoomRunner.addResponder(new VoiceDiff(output));
}
Expand Down
6 changes: 5 additions & 1 deletion src/service/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type { CommandRunner } from '../runner/command.js';
import { HelpCommand } from './command/help.js';
import { Meme } from './command/meme.js';
import type { Schema } from '../model/command-schema.js';
import type { StandardOutput } from './output.js';
import type { VoiceConnectionFactory } from './voice-connection.js';

export const registerAllCommandResponder = ({
Expand All @@ -51,7 +52,8 @@ export const registerAllCommandResponder = ({
userRepo,
guildRepo,
roleCreateRepo,
queen
queen,
stdout
}: {
typoRepo: TypoRepository;
reservationRepo: ReservationRepository;
Expand All @@ -72,6 +74,7 @@ export const registerAllCommandResponder = ({
guildRepo: GuildStatsRepository;
roleCreateRepo: RoleCreateManager;
queen: DiceQueen;
stdout: StandardOutput;
}) => {
const allResponders = [
new TypoReporter(typoRepo, clock, scheduleRunner),
Expand All @@ -81,6 +84,7 @@ export const registerAllCommandResponder = ({
controller: roomController,
clock,
scheduleRunner,
stdout,
repo: reservationRepo
}),
new GyokuonCommand({
Expand Down
12 changes: 10 additions & 2 deletions src/service/command/gyokuon.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GyokuonAssetKey, GyokuonCommand } from './gyokuon.js';
import { it, vi } from 'vitest';
import { expect, it, vi } from 'vitest';

import { MockVoiceConnectionFactory } from '../../adaptor/index.js';
import { createMockMessage } from './command-message.js';
Expand All @@ -16,6 +16,14 @@ it('use case of gyokuon', async () => {
});

await responder.on(
createMockMessage(parseStringsOrThrow(['gyokuon'], responder.schema))
createMockMessage(
parseStringsOrThrow(['gyokuon'], responder.schema),
(message) => {
expect(message).toStrictEqual({
title: 'こるく天皇の玉音放送だよ',
description: '全鯖民に対しての大詔だから椅子から立って聞いてね'
});
}
)
);
});
4 changes: 4 additions & 0 deletions src/service/command/gyokuon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class GyokuonCommand implements CommandResponder<typeof SCHEMA> {
return;
}

await message.reply({
title: 'こるく天皇の玉音放送だよ',
description: '全鯖民に対しての大詔だから椅子から立って聞いてね'
});
await this.start(message.senderGuildId, roomId);
return;
}
Expand Down
23 changes: 22 additions & 1 deletion src/service/command/kaere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { KaereCommand, type KaereMusicKey } from './kaere.js';
import { expect, it, vi } from 'vitest';
import { ScheduleRunner } from '../../runner/index.js';
import type { StandardOutput } from '../output.js';
import { createMockMessage } from './command-message.js';
import { parseStringsOrThrow } from '../../adaptor/proxy/command/schema.js';

Expand All @@ -15,18 +16,38 @@ it('use case of kaere', async () => {
const clock = new MockClock(new Date(0));
const scheduleRunner = new ScheduleRunner(clock);
const repo = new InMemoryReservationRepository();

const output: StandardOutput = {
sendEmbed(message) {
expect(message).toStrictEqual({
title: '提督、もうこんな時間だよ',
description: '早く寝よう'
});
return Promise.resolve();
}
};

const responder = new KaereCommand({
connectionFactory,
controller: {
disconnectAllUsersIn: fn
},
clock,
scheduleRunner,
stdout: output,
repo
});

await responder.on(
createMockMessage(parseStringsOrThrow(['kaere'], responder.schema))
createMockMessage(
parseStringsOrThrow(['kaere'], responder.schema),
(message) => {
expect(message).toStrictEqual({
title: '提督、もうこんな時間だよ',
description: '早く寝よう'
});
}
)
);

await responder.on(
Expand Down
7 changes: 7 additions & 0 deletions src/service/command/kaere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { addDays, isBefore, setHours, setMinutes, setSeconds } from 'date-fns';

import type { EmbedMessage } from '../../model/embed-message.js';
import type { Snowflake } from '../../model/id.js';
import type { StandardOutput } from '../output.js';
import type { VoiceConnectionFactory } from '../voice-connection.js';

export type KaereMusicKey = 'NEROYO';
Expand Down Expand Up @@ -146,6 +147,7 @@ export class KaereCommand implements CommandResponder<typeof SCHEMA> {
controller: VoiceRoomController;
clock: Clock;
scheduleRunner: ScheduleRunner;
stdout: StandardOutput;
repo: ReservationRepository;
}
) {
Expand All @@ -168,6 +170,7 @@ export class KaereCommand implements CommandResponder<typeof SCHEMA> {
});
return;
}

await this.start(message.senderGuildId, roomId);
return;
}
Expand Down Expand Up @@ -196,6 +199,10 @@ export class KaereCommand implements CommandResponder<typeof SCHEMA> {
this.doingKaere = false;
return false;
});
await this.deps.stdout.sendEmbed({
title: '提督、もうこんな時間だよ',
description: '早く寝よう'
});
await connection.playToEnd('NEROYO');
if (this.bedModeEnabled) {
try {
Expand Down

0 comments on commit 60a9d0a

Please sign in to comment.