-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
94 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Command } from './command.class.js'; | ||
import { ClockLoader } from '../loaders/clockLoader.class.js'; | ||
|
||
export class ClockCommand extends Command { | ||
public command = 'clock'; | ||
public description = 'π ΠΠ΅ΠΌΠΎ Π³ΠΎΠ΄ΠΈΠ½Π½ΠΈΠΊΠ°'; | ||
|
||
handle(): void { | ||
this.bot.command(this.command, async (ctx) => { | ||
await ctx.deleteMessage(); | ||
const clockLoader = new ClockLoader(ctx); | ||
await clockLoader.start(); | ||
await new Promise((resolve) => setTimeout(resolve, 25000)); | ||
const messageId = clockLoader.stop(); | ||
if (messageId) { | ||
await ctx.telegram.deleteMessage(ctx.chat.id, messageId); | ||
} | ||
}); | ||
} | ||
|
||
async dispose() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './command.class.js'; | ||
|
||
export * from './classifyMessage.command.js'; | ||
export * from './clock.command.js'; | ||
export * from './recognizeSpeech.command.js'; | ||
export * from './start.command.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Loader } from './loader.class.js'; | ||
|
||
export class ClockLoader extends Loader { | ||
// prettier-ignore | ||
private emojiList = ['π','π','π','π','π','π','π','π§','π','π','π','π','π ','π‘','π’','π£','π€','π₯','π¦','π','π','π','π','π','π']; | ||
private emojiIndex = 0; | ||
private messageId?: number; | ||
private timeoutId: NodeJS.Timeout | number = 0; | ||
|
||
get currentEmoji() { | ||
return this.emojiList[this.emojiIndex]; | ||
} | ||
|
||
async start(reply = false, ms = 300) { | ||
if (this.messageId === undefined) { | ||
const message = await this.ctx.reply(this.currentEmoji, { | ||
reply_parameters: reply ? { message_id: this.ctx.message.message_id } : undefined, | ||
}); | ||
this.messageId = message.message_id; | ||
} | ||
|
||
clearTimeout(this.timeoutId); | ||
this.timeoutId = setTimeout(async () => { | ||
this.emojiIndex = this.emojiIndex < this.emojiList.length - 1 ? this.emojiIndex + 1 : 0; | ||
await this.ctx.telegram.editMessageText(this.ctx.chat.id, this.messageId, '', this.currentEmoji); | ||
|
||
this.start(); | ||
}, ms); | ||
} | ||
|
||
stop() { | ||
clearTimeout(this.timeoutId); | ||
return this.messageId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NarrowedContext } from 'telegraf'; | ||
import { Message, Update } from 'telegraf/types'; | ||
import { IBotContext } from '../context/context.interface.js'; | ||
|
||
export abstract class Loader { | ||
constructor(public readonly ctx: NarrowedContext<IBotContext, Update.MessageUpdate<Message>>) {} | ||
|
||
public abstract start(...args: unknown[]): Promise<void>; | ||
|
||
public abstract stop(): void; | ||
} |