|
@@ -1,9 +1,10 @@
|
|
|
-from asyncio import run
|
|
|
+from asyncio import run, sleep
|
|
|
|
|
|
from telethon import TelegramClient
|
|
|
from telethon.events import NewMessage
|
|
|
from telethon.utils import resolve_bot_file_id
|
|
|
|
|
|
+from actions import get_all_birthdays
|
|
|
from utils import (
|
|
|
parse_command,
|
|
|
get_link_to_user,
|
|
@@ -23,7 +24,7 @@ bot = TelegramClient(
|
|
|
config.API_ID,
|
|
|
config.API_HASH
|
|
|
).start(bot_token=config.API_TOKEN)
|
|
|
-
|
|
|
+
|
|
|
@bot.on(NewMessage)
|
|
|
async def on_message(event):
|
|
|
try:
|
|
@@ -104,8 +105,35 @@ async def on_message(event):
|
|
|
file=gif,
|
|
|
reply_to=reply_to
|
|
|
)
|
|
|
-
|
|
|
+
|
|
|
+# cursed
|
|
|
+async def notify_birthdays():
|
|
|
+ while True:
|
|
|
+ birthdays = await get_all_birthdays()
|
|
|
+
|
|
|
+ for birthday in birthdays:
|
|
|
+ age = calculate_age(birthday.date)
|
|
|
+
|
|
|
+ if age.days_until < 1:
|
|
|
+ try:
|
|
|
+ try:
|
|
|
+ entity = await bot.get_entity(birthday.user_id)
|
|
|
+ except ValueError:
|
|
|
+ await bot.get_participants(birthday.peer_id)
|
|
|
+
|
|
|
+ entity = await bot.get_entity(birthday.user_id)
|
|
|
+
|
|
|
+ await bot.send_message(
|
|
|
+ birthday.peer_id,
|
|
|
+ f'{get_link_to_user(entity)}, поздравляю с днём рождения!!~~'
|
|
|
+ )
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+ await sleep(60 * 60 * 24) # 24 hours.
|
|
|
+
|
|
|
with bot:
|
|
|
bot.loop.run_until_complete(init_db())
|
|
|
+ bot.loop.create_task(notify_birthdays())
|
|
|
bot.start()
|
|
|
bot.run_until_disconnected()
|