- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
bot.onText(/\/now/, (message) => {
const DayOfTheWeek = new Date().toLocaleString('en-GB', { weekday: 'long' });
const currentTime = new Date();
let timeLeft = null;
let currentLesson = "";
for (let LessonId of Object.keys(lessons.v1[DayOfTheWeek])) {
const lesson = lessons.v1[DayOfTheWeek][LessonId];
const date = `${currentTime.getFullYear()}-${(currentTime.getMonth()+1).toString().padStart(2, '0')}-${currentTime.getDate().toString().padStart(2, '0')}`;
const startLessonTime = new Date(`${date}T${lesson.start}:00.001Z`);
const endLessonTime = new Date(`${date}T${lesson.end}:00.001Z`);
if (currentTime.toLocaleString('en-GB', {timeZone: 'Europe/Moscow'}) >= startLessonTime.toLocaleString('en-GB', {timeZone: 'Africa/Ouagadougou'}) && currentTime.toLocaleString('en-GB', {timeZone: 'Europe/Moscow'}) <= endLessonTime.toLocaleString('en-GB', {timeZone: 'Africa/Ouagadougou'})) {
currentLesson = lesson.name;timeLeft = (endLessonTime-currentTime) / 1000;
timeLeft=timeLeft-10800+2;
break;
};
};
if (currentLesson && timeLeft) {
const minutes = Math.floor(timeLeft / 60);
const seconds = Math.floor(timeLeft % 60);
bot.sendMessage(message.chat.id, `щяс урок: ${currentLesson}\nдо конца осталось ${minutes} минут ${seconds} секунд`);
} else {
bot.sendMessage(message.chat.id, 'Сейчас нет уроков');
};
});
Комментарии (0) RSS
Добавить комментарий