Skip to content

Commit

Permalink
Added reply support
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiipsa committed Sep 27, 2023
1 parent 5cc4d05 commit 56c96d8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/modules/text-to-speech/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,25 @@ export class TextToSpeechBot implements PayableBot {
}

public getEstimatedPrice (ctx: OnMessageContext): number {
const str = ctx.match?.toString() ?? ''

const str = this.getTextFromMessage(ctx)
return str.length * 0.0001
}

public getTextFromMessage (ctx: OnMessageContext): string {
if (ctx.match?.toString()) {
return ctx.match.toString()
}

return ctx.message.reply_to_message?.text ?? ''
}

public async onEvent (ctx: OnMessageContext): Promise<void> {
if (ctx.hasCommand('voice')) {
const text = this.getTextFromMessage(ctx)
await this.onTextToSpeech(ctx, text)
}
}

public async onTextToSpeech (ctx: OnMessageContext, message: string): Promise<void> {
if (!message) {
await ctx.reply('/voice command should contain text.')
Expand All @@ -53,13 +67,6 @@ export class TextToSpeechBot implements PayableBot {
const inputFile = new InputFile(voiceResult)

await ctx.api.deleteMessage(ctx.chat.id, progressMessage.message_id)
await ctx.replyWithVoice(inputFile)
}

public async onEvent (ctx: OnMessageContext): Promise<void> {
if (ctx.hasCommand('voice')) {
const text = ctx.match.toString()
await this.onTextToSpeech(ctx, text)
}
await ctx.replyWithVoice(inputFile, { reply_to_message_id: ctx.message.message_id })
}
}

0 comments on commit 56c96d8

Please sign in to comment.