-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_func.py
More file actions
60 lines (53 loc) · 2.04 KB
/
helper_func.py
File metadata and controls
60 lines (53 loc) · 2.04 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
# +++ Modified By Yato [telegram username: @i_killed_my_clan & @ProYato] +++ # aNDI BANDI SANDI JISNE BHI CREDIT HATAYA USKI BANDI RAndi
import base64
import re
import asyncio
from pyrogram import filters
from pyrogram.enums import ChatMemberStatus
from config import ADMINS
from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant
from pyrogram.errors import FloodWait
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.filters import Filter
from config import OWNER_ID
from database.database import is_admin
class IsAdmin(Filter):
async def __call__(self, client, message):
return await is_admin(message.from_user.id)
is_admin_filter = IsAdmin()
class IsOwnerOrAdmin(Filter):
async def __call__(self, client, message):
user_id = message.from_user.id
return user_id == OWNER_ID or await is_admin(user_id)
is_owner_or_admin = IsOwnerOrAdmin()
async def encode(string):
string_bytes = string.encode("ascii")
base64_bytes = base64.urlsafe_b64encode(string_bytes)
base64_string = (base64_bytes.decode("ascii")).strip("=")
return base64_string
async def decode(base64_string):
base64_string = base64_string.strip("=")
base64_bytes = (base64_string + "=" * (-len(base64_string) % 4)).encode("ascii")
string_bytes = base64.urlsafe_b64decode(base64_bytes)
string = string_bytes.decode("ascii")
return string
def get_readable_time(seconds: int) -> str:
count = 0
up_time = ""
time_list = []
time_suffix_list = ["s", "m", "h", "days"]
while count < 4:
count += 1
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
if seconds == 0 and remainder == 0:
break
time_list.append(int(result))
seconds = int(remainder)
hmm = len(time_list)
for x in range(hmm):
time_list[x] = str(time_list[x]) + time_suffix_list[x]
if len(time_list) == 4:
up_time += f"{time_list.pop()}, "
time_list.reverse()
up_time += ":".join(time_list)
return up_time