Skip to content

Commit

Permalink
revert: "resolve type issues" (#536)
Browse files Browse the repository at this point in the history
This reverts commit 6a3bb6a.
このHACKは不要になりました
  • Loading branch information
Mogyuchi authored Sep 2, 2024
1 parent 0b26f26 commit cabc723
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
10 changes: 3 additions & 7 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// do not 'import { EventEmitter } from "events"';
// it would also refer to 'declare module "node:events" { /* snip */ } in discord.js
// and cause 'EventEmitter to be non-generic.
// pay attention to https://github.com/discordjs/discord.js/pull/10360
import EventEmitter from "events";
import { EventEmitter, once } from "events";
import {
joinVoiceChannel,
type CreateVoiceConnectionOptions,
Expand Down Expand Up @@ -119,7 +115,7 @@ export default class Pipeline extends EventEmitter<PipelineEventsMap> {
}

async ready(signal?: AbortSignal) {
await Pipeline.once(this, "ready", { signal });
await once(this, "ready", { signal });
}

play() {
Expand Down Expand Up @@ -154,7 +150,7 @@ export default class Pipeline extends EventEmitter<PipelineEventsMap> {

async disconnect(signal?: AbortSignal) {
setImmediate(() => this.connection?.disconnect());
await Pipeline.once(this, "disconnect", { signal });
await once(this, "disconnect", { signal });
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/synthesis/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Readable } from "node:stream";
import { once } from "node:events";
import { StreamType, createAudioResource } from "@discordjs/voice";
import { EncoderType, Syrinx } from "@discordjs-japan/om-syrinx";
import type { Message } from "discord.js";
Expand All @@ -22,10 +22,7 @@ export async function synthesize(message: Message) {
const option = createSynthesisOption(message);

const stream = syrinx.synthesize(inputText, option);
// HACK: while `EventEmitter.once` or `once` from "node:events" somehow does not accept `Readable` type,
// `Readable.once` does accept it because it refers to 'declare module "node:events" { /* snip */ }' in discord.js.
// pay attention to https://github.com/discordjs/discord.js/pull/10360
await Readable.once(stream, "readable");
await once(stream, "readable");

if (stream.readableLength === 0) return null;
return createAudioResource(stream, {
Expand Down

0 comments on commit cabc723

Please sign in to comment.