|
40 | 40 | log = logging.getLogger(__name__) |
41 | 41 |
|
42 | 42 |
|
| 43 | +def get_event_loop() -> asyncio.AbstractEventLoop: |
| 44 | + try: |
| 45 | + loop = asyncio.get_event_loop() |
| 46 | + except RuntimeError: |
| 47 | + loop = asyncio.new_event_loop() |
| 48 | + asyncio.set_event_loop(loop) |
| 49 | + |
| 50 | + return loop |
| 51 | + |
| 52 | + |
43 | 53 | async def ainput(prompt: str = "", *, hide: bool = False, loop: Optional[asyncio.AbstractEventLoop] = None): |
44 | 54 | """Just like the built-in input, but async""" |
45 | 55 | if isinstance(loop, asyncio.AbstractEventLoop): |
46 | 56 | loop = loop |
47 | 57 | else: |
48 | | - loop = asyncio.get_event_loop() |
| 58 | + loop = get_event_loop() |
49 | 59 |
|
50 | 60 | with ThreadPoolExecutor(1) as executor: |
51 | 61 | func = functools.partial(getpass if hide else input, prompt) |
@@ -902,6 +912,7 @@ async def send_media( |
902 | 912 | show_caption_above_media: bool = None, |
903 | 913 | reply_parameters: "types.ReplyParameters" = None, |
904 | 914 | schedule_date: datetime = None, |
| 915 | + repeat_period: int = None, |
905 | 916 | protect_content: bool = None, |
906 | 917 | business_connection_id: str = None, |
907 | 918 | allow_paid_broadcast: bool = None, |
@@ -933,6 +944,7 @@ async def send_media( |
933 | 944 | ), |
934 | 945 | "random_id": client.rnd_id(), |
935 | 946 | "schedule_date": datetime_to_timestamp(schedule_date), |
| 947 | + "schedule_repeat_period": repeat_period, |
936 | 948 | "noforwards": protect_content, |
937 | 949 | "allow_paid_floodskip": allow_paid_broadcast, |
938 | 950 | "reply_markup": await reply_markup.write(client) if reply_markup else None, |
@@ -986,3 +998,14 @@ async def send_media( |
986 | 998 | ) |
987 | 999 | break |
988 | 1000 | return message |
| 1001 | + |
| 1002 | + |
| 1003 | +def get_premium_duration_month_count(day_count: int) -> int: |
| 1004 | + return max(1, day_count // 30) |
| 1005 | + |
| 1006 | + |
| 1007 | +def get_premium_duration_day_count(month_count: int) -> int: |
| 1008 | + if month_count <= 0 or month_count > 10000000: |
| 1009 | + return 7 |
| 1010 | + |
| 1011 | + return month_count * 30 + month_count // 3 + month_count // 12 |
0 commit comments