Advertisement
disk6969

telethon giveaway info

Nov 12th, 2023 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. from telethon.tl.types.payments import GiveawayInfoResults
  2. from telethon.tl.functions.payments import GetGiveawayInfoRequest
  3.  
  4. def giveaway_info(client, chat, msg_id):
  5.   format = "%Y-%m-%d %H:%M:%S %Z"
  6.  
  7.   result = client(GetGiveawayInfoRequest(chat, msg_id))
  8.  
  9.   created = result.start_date.strftime(format)
  10.   print('Giveaway created at', created)
  11.  
  12.   if isinstance(result, GiveawayInfoResults):
  13.     finished_at = result.finish_date.strftime(format)
  14.     won = result.winner
  15.     print('Giveaway already finished at:', finished_at)
  16.     print('Our result:', "Won" if won else "Lost")
  17.   else:
  18.     finish_date = client.get_messages(chat, ids=msg_id).media.until_date.strftime(format)
  19.     participant = result.participating
  20.     print('Giveaway starting at:', finish_date)
  21.     print('We are:', 'Participating' if participant else 'Not participating')
  22.  
  23. with TelegramClient(...) as client:
  24.     giveaway_info(client, "@one_vampi", 171)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement