-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (40 loc) · 1.63 KB
/
index.js
File metadata and controls
49 lines (40 loc) · 1.63 KB
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
// Import necessary libraries
const { Telegraf, Markup } = require('telegraf');
const moment = require('moment-timezone'); // استفاده از moment-timezone بجای moment
// Load environment variables
require("dotenv").config();
// Telegram API token
const TOKEN = process.env.TELEGRAM_API_TOKEN;
// Initialize the bot with the API token
const bot = new Telegraf(TOKEN, {
telegram: {
apiRoot: 'https://public-telegram-bypass.solyfarzane9040.workers.dev/bot'
}
});
// Set timezone to Tehran
moment.tz.setDefault('Asia/Tehran');
// Initial message text and target date
const messageText = "برای مشاهده زمان باقی مانده تا شروع همایش روی دکمه زیر کلیک کنید.";
const targetDate = moment("2024-02-29");
// Function to calculate remaining time
function calculateRemainingTime() {
const now = moment();
const remainingTime = moment.duration(targetDate.diff(now));
const days = remainingTime.days();
const hours = remainingTime.hours();
const minutes = remainingTime.minutes();
return `${days} روز، ${hours} ساعت و ${minutes} دقیقه`;
}
// Command to start the bot
bot.start((ctx) => {
ctx.reply(`🥕 سلام ${ctx.from.first_name} جان!\n${messageText}`, Markup.inlineKeyboard([
Markup.button.callback('⏳ نمایش زمان باقیمانده ⏳', 'showRemainingTime')
]));
});
// Action to display remaining time
bot.action('showRemainingTime', (ctx) => {
const remainingTime = calculateRemainingTime();
ctx.answerCbQuery(`🥕 زمان باقیمانده: ${remainingTime}`);
});
// Launch the bot
bot.launch();