-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (64 loc) · 2.22 KB
/
main.py
File metadata and controls
88 lines (64 loc) · 2.22 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import datetime
import os
import asyncio
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
from flask import Flask
from threading import Thread
# نامهای سفارشی هفته
week_days = {
"Saturday": "کیوانشید",
"Sunday": "مهرشید",
"Monday": "ماهشید",
"Tuesday": "بهرامشید",
"Wednesday": "تیرشید",
"Thursday": "اورمزدشید",
"Friday": "آدینه"
}
app = Flask('')
@app.route('/')
def main():
return 'Your bot is alive!'
def run():
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
def keep_alive():
server = Thread(target=run)
server.start()
keep_alive()
# پاسخ به /start
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
today = datetime.datetime.now().strftime('%A')
week_day = week_days.get(today, today)
await update.message.reply_text(f"درود! امروز {week_day} است. ☀️")
# پیام روزانه به دهلیز
async def send_daily_message(application):
today = datetime.datetime.now().strftime('%A')
week_day = week_days.get(today, today)
message = f"بامداد نیک! امروز «{week_day}» است. 🌞"
chat_id = "@The_Persian_Gostar"
try:
await application.bot.send_message(chat_id=chat_id, text=message)
print("✅ Daily message sent.")
except Exception as e:
print("❌ Error sending daily message:", e)
async def main():
load_dotenv()
TOKEN = os.getenv("BOT_TOKEN")
app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
# Scheduler راهاندازی
scheduler = AsyncIOScheduler()
scheduler.add_job(send_daily_message,
CronTrigger(hour=1, minute=30),
args=[app])
scheduler.start()
print("🤖 Bot is running...")
await app.run_polling()
import nest_asyncio
if __name__ == '__main__':
import asyncio
nest_asyncio.apply()
asyncio.get_event_loop().run_until_complete(main())