-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll.ts
34 lines (29 loc) · 1.02 KB
/
poll.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Event } from '@tlgr/component';
import { Context, Telegraf } from 'telegraf';
import { KeyboardButton, Update } from 'telegraf/typings/core/types/typegram';
import Keyboard from './keyboard';
type Options = {
};
type User = Event<'answer_user', [poll: Context<Update>['poll'], instance: Poll]>;
type Anonymous = Event<'answer_anonymous', [answer: Context<Update>['pollAnswer'], instance: Poll]>;
export default class Poll extends Keyboard<[User, Anonymous]> {
constructor(readonly bot: Telegraf, readonly text: string = 'create poll', readonly options?: Options) {
super(bot, text, {
prefix: '@tlgr/button/keyboard/poll'
});
bot.on('poll', (ctx, next) => {
this.emit(new Event('answer_anonymous', ctx.poll, this))
next();
});
bot.on('poll_answer', (ctx, next) => {
this.emit(new Event('answer_user', ctx.pollAnswer, this));
next();
});
}
render(): KeyboardButton.RequestPollButton {
return {
request_poll: { type: 'regular' },
text: this.text,
}
}
}