|
1 | 1 | import asyncio |
| 2 | +import datetime |
2 | 3 | from contextlib import suppress |
3 | 4 | from typing import List |
4 | 5 |
|
@@ -43,12 +44,16 @@ async def cmd_ro(message: types.Message, chat: Chat): |
43 | 44 | logger.error("Failed to restrict chat member: {error!r}", error=e) |
44 | 45 | return False |
45 | 46 |
|
| 47 | + if duration >= datetime.timedelta(days=367): |
| 48 | + duration = "forever" |
| 49 | + else: |
| 50 | + duration = format_timedelta( |
| 51 | + duration, locale=chat.language, granularity="seconds", format="short" |
| 52 | + ) |
| 53 | + |
46 | 54 | await message.reply_to_message.answer( |
47 | 55 | _("<b>Read-only</b> activated for user {user}. Duration: {duration}").format( |
48 | | - user=message.reply_to_message.from_user.get_mention(), |
49 | | - duration=format_timedelta( |
50 | | - duration, locale=chat.language, granularity="seconds", format="short" |
51 | | - ), |
| 56 | + user=message.reply_to_message.from_user.get_mention(), duration=duration |
52 | 57 | ) |
53 | 58 | ) |
54 | 59 | return True |
@@ -78,12 +83,16 @@ async def cmd_ban(message: types.Message, chat: Chat): |
78 | 83 | logger.error("Failed to kick chat member: {error!r}", error=e) |
79 | 84 | return False |
80 | 85 |
|
| 86 | + if duration >= datetime.timedelta(days=367): |
| 87 | + duration = "forever" |
| 88 | + else: |
| 89 | + duration = format_timedelta( |
| 90 | + duration, locale=chat.language, granularity="seconds", format="short" |
| 91 | + ) |
| 92 | + |
81 | 93 | await message.reply_to_message.answer( |
82 | 94 | _("User {user} <b>banned</b> for {duration}").format( |
83 | | - user=message.reply_to_message.from_user.get_mention(), |
84 | | - duration=format_timedelta( |
85 | | - duration, locale=chat.language, granularity="seconds", format="short" |
86 | | - ), |
| 95 | + user=message.reply_to_message.from_user.get_mention(), duration=duration |
87 | 96 | ) |
88 | 97 | ) |
89 | 98 | return True |
|
0 commit comments