-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
52 lines (44 loc) · 1.06 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require('dotenv').config();
const Calendar = require('../');
const { Telegraf } = require('telegraf');
// create the bot
const bot = new Telegraf(process.env.CALENDAR_BOT_TOKEN);
// instantiate the calendar
const calendar = new Calendar(bot, {
startWeekDay: 1,
weekDayNames: ['L', 'M', 'M', 'G', 'V', 'S', 'D'],
monthNames: [
'Gen',
'Feb',
'Mar',
'Apr',
'Mag',
'Giu',
'Lug',
'Ago',
'Set',
'Ott',
'Nov',
'Dic',
],
});
// listen for the selected date event
calendar.setDateListener((context, date) => context.reply(date));
// retrieve the calendar HTML
bot.command('calendar', (context) => {
const today = new Date();
const minDate = new Date();
minDate.setMonth(today.getMonth() - 2);
const maxDate = new Date();
maxDate.setMonth(today.getMonth() + 2);
maxDate.setDate(today.getDate());
context.reply(
'Here you are',
calendar.setMinDate(minDate).setMaxDate(maxDate).getCalendar()
);
});
bot.catch((err) => {
console.error('Error in bot:', err);
});
bot.startPolling();
module.exports = bot;