diff --git a/getter/__main__.py b/getter/__main__.py index 9ccbe38..4cb0786 100644 --- a/getter/__main__.py +++ b/getter/__main__.py @@ -72,7 +72,7 @@ async def main() -> None: from .plugins.pmpermit import handle_pmpermit await asyncio.gather(*[handle_afk(), handle_pmpermit()]) - loaded_time = time_formatter((monotonic() - load) * 1000) + loaded_time = time_formatter(monotonic() - load) loaded_msg = ">> Loaded Plugins: {} , Commands: {} (took {}) : {}".format( plugins_help.count, plugins_help.total, diff --git a/getter/core/base_client.py b/getter/core/base_client.py index 4c453cc..5680b80 100644 --- a/getter/core/base_client.py +++ b/getter/core/base_client.py @@ -256,7 +256,7 @@ def uid(self) -> int: @property def uptime(self) -> str: - return time_formatter((time() - StartTime) * 1000) + return time_formatter(time() - StartTime) def to_dict(self) -> dict: return dict(getmembers(self)) diff --git a/getter/core/constants.py b/getter/core/constants.py index d5744c3..ff0d843 100644 --- a/getter/core/constants.py +++ b/getter/core/constants.py @@ -204,7 +204,7 @@ SHRUGS = ("┐(´д`)┌", "┐(´~`)┌", "┐(´ー`)┌", "┐( ̄ヘ ̄)┌", "╮(╯∀╰)╭", "╮(╯_╰)╭", "┐(´д`)┌", "┐(´∀`)┌", "ʅ(́◡◝)ʃ", "ლ(゚д゚ლ)", "┐(゚~゚)┌", "┐('д')┌", "ლ(╹ε╹ლ)", "ლ(ಠ益ಠ)ლ", "┐(‘~`;)┌", "ヘ(´-`;)ヘ", "┐( -“-)┌", "乁༼☯‿☯✿༽ㄏ", "ʅ(´◔౪◔)ʃ", "ಠ_ಠ", "ʕ•ᴥ•ʔ", "ლ(•ω •ლ)", r"¯\_(ツ)_/¯", r"¯\_(⊙_ʖ⊙)_/¯", "(☞ ͡° ͜ʖ ͡°)☞", "c༼ ͡° ͜ʖ ͡° ༽⊃", "乁ʕ •̀ •́ ʔㄏ", r"¯\_༼ ಥ ‿ ಥ ༽_/¯", "乁( ⁰͡ Ĺ̯ ⁰͡ ) ㄏ", "(ง ͠° ͟ل͜ ͡°)ง", "༼ つ ◕_◕ ༽つ", "( ͡° ͜ʖ ͡°)", "( ͡°( ͡° ͜ʖ( ͡° ͜ʖ ͡°)ʖ ͡°) ͡°)") # fmt: skip -EMOJIS = ("💋", "💘", "💝", "💖", "💗", "💓", "💞", "💕", "💌", "❣️", "💔", "❤", "🧡", "💛", "💚", "💙", "💜", "🖤", "💟", "💍", "💎", "💐", "💒", "🌸", "💮", "🏵", "🌹", "🥀", "🌺", "🌻", "🌼", "🌷", "🌱", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "☘️", "🍀", "🍁", "🍂", "🍃", "🍄", "🥭", "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🍎", "🍏", "🍐", "🍑", "🍒", "🥬", "🍓", "🥝", "🍅", "🥥", "🥑", "🍆", "🥔", "🥕", "🌽", "🌶", "🥯", "🥒", "🥦", "🥜", "🌰", "🍞", "🥐", "🥖", "🥨", "🥞", "🧀", "🍖", "🍗", "🥩", "🥓", "🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🥙", "🥚", "🧂", "🍳", "🥘", "🍲", "🥣", "🥗", "🍿", "🥫", "🍱", "🍘", "🍙", "🍚", "🍛", "🍜", "🥮", "🍝", "🍠", "🍢", "🍣", "🍤", "🍥", "🍡", "🥟", "🥠", "🥡", "🍦", "🍧", "🍨", "🍩", "🍪", "🧁", "🎂", "🍰", "🥧", "🍫", "🍬", "🍭", "🍮", "🍯", "🍼", "🥛", "☕", "🍵", "🍶", "🍾", "🍷", "🍸", "🍹", "🍺", "🍻", "🥂", "🥃", "🥤", "🥢", "🍽", "🍴", "🥄", "🏺", "🙈", "🙉", "🦝", "🐵", "🐒", "🦍", "🐶", "🐕", "🐩", "🐺", "🦊", "🐱", "🐈", "🦁", "🐯", "🐅", "🐆", "🐴", "🐎", "🦄", "🦓", "🦌", "🐮", "🦙", "🐂", "🐃", "🐄", "🐷", "🦛", "🐖", "🐗", "🐽", "🐏", "🐑", "🐐", "🐪", "🐫", "🦒", "🐘", "🦏", "🐭", "🐁", "🐀", "🦘", "🐹", "🦡", "🐰", "🐇", "🐿", "🦔", "🦇", "🐻", "🐨", "🐼", "🐾", "🦃", "🐔", "🦢", "🐓", "🐣", "🐤", "🦚", "🐥", "🐦", "🦜", "🐧", "🕊", "🦅", "🦆", "🦉", "🐸", "🐊", "🐢", "🦎", "🐍", "🐲", "🐉", "🦕", "🦖", "🐳", "🐋", "🐬", "🐟", "🐠", "🐡", "🦈", "🐙", "🐚", "🦀", "🦟", "🦐", "🦑", "🦠", "🐌", "🦋", "🐛", "🐜", "🐝", "🐞", "🦗", "🕷", "🕸", "🦂", "🦞", "👓", "🕶", "👔", "👕", "👖", "🧣", "🧤", "🧥", "🧦", "👗", "👘", "👙", "👚", "👛", "👜", "👝", "🛍", "🎒", "👞", "👟", "👠", "👡", "👢", "👑", "👒", "🎩", "🎓", "🧢", "⛑️", "📿", "💄", "🌂", "☂️", "🎽", "🥽", "🥼", "🥾", "🥿", "🧺", "🚂", "🚃", "🚄", "🚅", "🚆", "🚇", "🚈", "🚉", "🚊", "🚝", "🚞", "🚋", "🚌", "🚍", "🚎", "🚐", "🚑", "🚒", "🚓", "🚔", "🚕", "🚖", "🚗", "🚘", "🚙", "🚚", "🚛", "🚜", "🚲", "🛴", "🛵", "🚏", "🛣", "🛤", "⛵", "🛶", "🚤", "🛳", "⛴", "🛥", "🚢", "✈️", "🛩", "🛫", "🛬", "🚁", "🚟", "🚠", "🚡", "🛰", "🚀", "🛸", "🌍", "🌎", "🌏", "🌐", "🗺", "🗾", "🏔", "⛰", "🗻", "🏕", "🏖", "🏜", "🏝", "🏞", "🏟", "🏛", "🏗", "🏘", "🏚", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥", "🏦", "🏨", "🏩", "🏪", "🏫", "🏬", "🏭", "🏯", "🏰", "🗼", "🗽", "⛪", "🕌", "🕍", "⛩", "🕋", "⛲", "⛺", "🏙", "🎠", "🎡", "🎢", "🎪", "⛳", "🗿", "💦", "🌋", "🌁", "🌃", "🌄", "🌅", "🌆", "🌇", "🌉", "🌌", "🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘", "🌙", "🌚", "🌛", "🌜", "🌡", "☀", "🌝", "🌞", "🌟", "🌠", "☁", "⛅", "⛈️", "🌤", "🌥", "🌦", "🌧", "🌨", "🌩", "🌪", "🌫", "🌬", "🌀", "🌈", "☔", "❄", "☃️", "⛄️", "☄️", "💧", "🌊", "🎑", "👁️🗨️", "💤", "💥", "💨", "💫", "💬", "🗨", "🗯", "💭", "🕳", "🚨", "🛑", "⭐", "🎃", "🎄", "✨", "🎈", "🎉", "🎊", "🎋", "🎍", "🎎", "🎏", "🎐", "🎀", "🎁", "🃏", "🀄", "🦷", "🦴", "🛀", "👣", "💣", "🔪", "🧱", "🛢", "⛽", "🛹", "🚥", "🚦", "🚧", "??", "🧳", "⛱️", "🔥", "🧨", "🎗", "🎟", "🎫", "🧧", "🔮", "🎲", "🎴", "🎭", "🖼", "🎨", "🎤", "🔍", "🔎", "🕯", "💡", "🔦", "🏮", "📜", "🧮", "🔑", "🗝", "🔨", "⛏️", "⚒️", "🛠", "🗡", "⚔️", "🔫", "🏹", "🛡", "🔧", "🔩", "⚙️", "🗜", "⚖️", "⛓️", "⚗️", "🔬", "🔭", "📡", "💉", "💊", "🚪", "🛏", "🛋", "🚽", "🚿", "🛁", "🛒", "🚬", "⚰️", "⚱️", "🧰", "🧲", "🧪", "🧴", "🧷", "🧹", "🧻", "🧼", "🧽", "🧯", "💠", "♟️", "⌛", "⏳", "⚡", "🎆", "🎇") # fmt: skip +EMOJIS = ("💋", "💘", "💝", "💖", "💗", "💓", "💞", "💕", "💌", "❣️", "💔", "❤", "🧡", "💛", "💚", "💙", "💜", "🖤", "💟", "💍", "💎", "💐", "💒", "🌸", "💮", "🏵", "🌹", "🥀", "🌺", "🌻", "🌼", "🌷", "🌱", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "☘️", "🍀", "🍁", "🍂", "🍃", "🍄", "🥭", "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🍎", "🍏", "🍐", "🍑", "🍒", "🥬", "🍓", "🥝", "🍅", "🥥", "🥑", "🍆", "🥔", "🥕", "🌽", "🌶", "🥯", "🥒", "🥦", "🥜", "🌰", "🍞", "🥐", "🥖", "🥨", "🥞", "🧀", "🍖", "🍗", "🥩", "🥓", "🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🥙", "🥚", "🧂", "🍳", "🥘", "🍲", "🥣", "🥗", "🍿", "🥫", "🍱", "🍘", "🍙", "🍚", "🍛", "🍜", "🥮", "🍝", "🍠", "🍢", "🍣", "🍤", "🍥", "🍡", "🥟", "🥠", "🥡", "🍦", "🍧", "🍨", "🍩", "🍪", "🧁", "🎂", "🍰", "🥧", "🍫", "🍬", "🍭", "🍮", "🍯", "🍼", "🥛", "☕", "🍵", "🍶", "🍾", "🍷", "🍸", "🍹", "🍺", "🍻", "🥂", "🥃", "🥤", "🥢", "🍽", "🍴", "🥄", "🏺", "🙈", "🙉", "🦝", "🐵", "🐒", "🦍", "🐶", "🐕", "🐩", "🐺", "🦊", "🐱", "🐈", "🦁", "🐯", "🐅", "🐆", "🐴", "🐎", "🦄", "🦓", "🦌", "🐮", "🦙", "🐂", "🐃", "🐄", "🐷", "🦛", "🐖", "🐗", "🐽", "🐏", "🐑", "🐐", "🐪", "🐫", "🦒", "🐘", "🦏", "🐭", "🐁", "🐀", "🦘", "🐹", "🦡", "🐰", "🐇", "🐿", "🦔", "🦇", "🐻", "🐨", "🐼", "🐾", "🦃", "🐔", "🦢", "🐓", "🐣", "🐤", "🦚", "🐥", "🐦", "🦜", "🐧", "🕊", "🦅", "🦆", "🦉", "🐸", "🐊", "🐢", "🦎", "🐍", "🐲", "🐉", "🦕", "🦖", "🐳", "🐋", "🐬", "🐟", "🐠", "🐡", "🦈", "🐙", "🐚", "🦀", "🦟", "🦐", "🦑", "🦠", "🐌", "🦋", "🐛", "🐜", "🐝", "🐞", "🦗", "🕷", "🕸", "🦂", "🦞", "👓", "🕶", "👔", "👕", "👖", "🧣", "🧤", "🧥", "🧦", "👗", "👘", "👙", "👚", "👛", "👜", "👝", "🛍", "🎒", "👞", "👟", "👠", "👡", "👢", "👑", "👒", "🎩", "🎓", "🧢", "⛑️", "📿", "💄", "🌂", "☂️", "🎽", "🥽", "🥼", "🥾", "🥿", "🧺", "🚂", "🚃", "🚄", "🚅", "🚆", "🚇", "🚈", "🚉", "🚊", "🚝", "🚞", "🚋", "🚌", "🚍", "🚎", "🚐", "🚑", "🚒", "🚓", "🚔", "🚕", "🚖", "🚗", "🚘", "🚙", "🚚", "🚛", "🚜", "🚲", "🛴", "🛵", "🚏", "🛣", "🛤", "⛵", "🛶", "🚤", "🛳", "⛴", "🛥", "🚢", "✈️", "🛩", "🛫", "🛬", "🚁", "🚟", "🚠", "🚡", "🛰", "🚀", "🛸", "🌍", "🌎", "🌏", "🌐", "🗺", "🗾", "🏔", "⛰", "🗻", "🏕", "🏖", "🏜", "🏝", "🏞", "🏟", "🏛", "🏗", "🏘", "🏚", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥", "🏦", "🏨", "🏩", "🏪", "🏫", "🏬", "🏭", "🏯", "🏰", "🗼", "🗽", "⛪", "🕌", "🕍", "⛩", "🕋", "⛲", "⛺", "🏙", "🎠", "🎡", "🎢", "🎪", "⛳", "🗿", "💦", "🌋", "🌁", "🌃", "🌄", "🌅", "🌆", "🌇", "🌉", "🌌", "🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘", "🌙", "🌚", "🌛", "🌜", "🌡", "☀", "🌝", "🌞", "🌟", "🌠", "☁", "⛅", "⛈️", "🌤", "🌥", "🌦", "🌧", "🌨", "🌩", "🌪", "🌫", "🌬", "🌀", "🌈", "☔", "❄", "☃️", "⛄️", "☄️", "💧", "🌊", "🎑", "👁️🗨️", "💤", "💥", "💨", "💫", "💬", "🗨", "🗯", "💭", "🕳", "🚨", "🛑", "⭐", "🎃", "🎄", "✨", "🎈", "🎉", "🎊", "🎋", "🎍", "🎎", "🎏", "🎐", "🎀", "🎁", "🃏", "🀄", "🦷", "🦴", "🛀", "👣", "💣", "🔪", "🧱", "🛢", "⛽", "🛹", "🚥", "🚦", "🚧", "🛎", "🧳", "⛱️", "🔥", "🧨", "🎗", "🎟", "🎫", "🧧", "🔮", "🎲", "🎴", "🎭", "🖼", "🎨", "🎤", "🔍", "🔎", "🕯", "💡", "🔦", "🏮", "📜", "🧮", "🔑", "🗝", "🔨", "⛏️", "⚒️", "🛠", "🗡", "⚔️", "🔫", "🏹", "🛡", "🔧", "🔩", "⚙️", "🗜", "⚖️", "⛓️", "⚗️", "🔬", "🔭", "📡", "💉", "💊", "🚪", "🛏", "🛋", "🚽", "🚿", "🛁", "🛒", "🚬", "⚰️", "⚱️", "🧰", "🧲", "🧪", "🧴", "🧷", "🧹", "🧻", "🧼", "🧽", "🧯", "💠", "♟️", "⌛", "⏳", "⚡", "🎆", "🎇") # fmt: skip # https://cloud.google.com/translate/docs/languages LANG_CODES = { diff --git a/getter/core/decorators.py b/getter/core/decorators.py index 2c6df90..dd25173 100644 --- a/getter/core/decorators.py +++ b/getter/core/decorators.py @@ -148,7 +148,7 @@ async def wrapper(kst: Message) -> Callable: await fun(kst) except FloodWaitError as fw: FLOOD_WAIT = fw.seconds - FLOOD_WAIT_HUMAN = time_formatter((FLOOD_WAIT + 10) * 1000) + FLOOD_WAIT_HUMAN = time_formatter(FLOOD_WAIT + 10) kst.client.log.warning( f"A FloodWait Error of {FLOOD_WAIT}. Sleeping for {FLOOD_WAIT_HUMAN} and try again." ) diff --git a/getter/core/utils.py b/getter/core/utils.py index b4e301b..f7571c7 100644 --- a/getter/core/utils.py +++ b/getter/core/utils.py @@ -66,26 +66,65 @@ def humanbytes(size: float) -> str: return "0 B" power = 1024 pos = 0 - power_dict = {0: "", 1: "K", 2: "M", 3: "G", 4: "T", 5: "P", 6: "E", 7: "Z", 8: "Y"} + power_dict = { + 0: "", + 1: "K", + 2: "M", + 3: "G", + 4: "T", + 5: "P", + 6: "E", + 7: "Z", + 8: "Y", + } while size > power: size /= power pos += 1 return f"{size:.2f}{power_dict[pos]}B" -def time_formatter(ms: float) -> str: - minutes, seconds = divmod(int(ms / 1000), 60) - hours, minutes = divmod(minutes, 60) - days, hours = divmod(hours, 24) - weeks, days = divmod(days, 7) - time_units = ( - f"{weeks}w, " if weeks else "", - f"{days}d, " if days else "", - f"{hours}h, " if hours else "", - f"{minutes}m, " if minutes else "", - f"{seconds}s, " if seconds else "", - ) - return "".join(time_units)[:-2] or "0s" +def time_formatter( + dur: float, + readable: bool = False, +) -> str: + if dur > 1e10: + dur //= 1000 + total = int(dur) + sec = total % 60 + total //= 60 + mins = total % 60 + total //= 60 + hour = total % 24 + total //= 24 + day = total % 7 + week = total // 7 + if not (week or day or hour or mins or sec): + return "0sec" if readable else "0s" + if readable: + parts = [] + if week: + parts.append(f"{week}week") + if day: + parts.append(f"{day}day") + if hour: + parts.append(f"{hour}hour") + if mins: + parts.append(f"{mins}min") + if sec: + parts.append(f"{sec}sec") + return ", ".join(parts) + parts = [] + if week: + parts.append(f"{week}w") + if day: + parts.append(f"{day}d") + if hour: + parts.append(f"{hour}h") + if mins: + parts.append(f"{mins}m") + if sec: + parts.append(f"{sec}s") + return ", ".join(parts) def until_time( diff --git a/getter/logger.py b/getter/logger.py index 8e0d478..3b6a4a7 100644 --- a/getter/logger.py +++ b/getter/logger.py @@ -71,5 +71,6 @@ def emit(self, record): "asyncio", "telethon", "telethon.network.mtprotosender", + "pytgcalls", ): logging.getLogger(name).setLevel(logging.ERROR) diff --git a/getter/plugins/admintools.py b/getter/plugins/admintools.py index 2b2f2fd..0ef406e 100644 --- a/getter/plugins/admintools.py +++ b/getter/plugins/admintools.py @@ -513,7 +513,7 @@ async def _(kst): if not (sec or sec.isdecimal()): return await kst.eor("`Provide a valid seconds!`", time=5) sec = int(sec) - pinfor = time_formatter(sec * 1000) + pinfor = time_formatter(sec) is_notify = any(_ in " ".join(opts[1:]).strip() for _ in ("-n", "notify")) msg_id = kst.reply_to_msg_id try: diff --git a/getter/plugins/afk.py b/getter/plugins/afk.py index 5717f27..daa2068 100644 --- a/getter/plugins/afk.py +++ b/getter/plugins/afk.py @@ -80,7 +80,7 @@ async def StopAFK(kst): if afk: start = datetime.fromtimestamp(afk.start) end = datetime.now().replace(microsecond=0) - afk_time = time_formatter((end - start).seconds * 1000) + afk_time = time_formatter((end - start).seconds) try: for x, y in afk.last.items(): await kst.client.delete_messages(int(x), [y]) @@ -109,7 +109,7 @@ async def OnAFK(kst): if afk: start = datetime.fromtimestamp(afk.start) end = datetime.now().replace(microsecond=0) - afk_time = time_formatter((end - start).seconds * 1000) + afk_time = time_formatter((end - start).seconds) text = "I’m on AFK!\n" text += f"Last seen {afk_time} ago." reason = f"
{afk.reason}" if afk.reason else "No reason."
diff --git a/getter/plugins/core.py b/getter/plugins/core.py
index e24c43e..71913d2 100644
--- a/getter/plugins/core.py
+++ b/getter/plugins/core.py
@@ -221,12 +221,12 @@ async def _(kst):
if error.lower().startswith(("too many", "a wait of")) or success > max_success:
if INVITE_WORKER.get(chat_id):
INVITE_WORKER.pop(chat_id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
try:
waitfor = int("".join(filter(str.isdigit, error.lower())))
except ValueError:
waitfor = 0
- flood = time_formatter(waitfor * 1000)
+ flood = time_formatter(waitfor)
done_limit = done_limit_text.format(
flood,
error,
@@ -266,7 +266,7 @@ async def _(kst):
except ChannelPrivateError as err:
if INVITE_WORKER.get(chat_id):
INVITE_WORKER.pop(chat_id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
done_error = done_error_text.format(
str(err),
success,
@@ -284,7 +284,7 @@ async def _(kst):
pass
if INVITE_WORKER.get(chat_id):
INVITE_WORKER.pop(chat_id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
done = done_text.format(
success,
failed,
@@ -397,7 +397,7 @@ async def _(kst):
pass
except BaseException:
pass
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
await yy.eor("`Uploading CSV Files...`")
await yy.eor(
getmembers_text.format(
@@ -531,7 +531,7 @@ async def _(kst):
pass
if INVITE_WORKER.get(chat_id):
INVITE_WORKER.pop(chat_id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
await yy.eor(f"`✅ Completed adding {success} {mode} in {taken}` at `{local_now}`")
diff --git a/getter/plugins/fake.py b/getter/plugins/fake.py
index 7679a6f..7368f46 100644
--- a/getter/plugins/fake.py
+++ b/getter/plugins/fake.py
@@ -73,7 +73,7 @@ async def _(kst):
if gg.is_group or gg.is_channel:
await asyncio.sleep(0.2)
done += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = fgban_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
done,
@@ -120,7 +120,7 @@ async def _(kst):
if gg.is_group or gg.is_channel:
await asyncio.sleep(0.2)
done += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = fungban_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
done,
diff --git a/getter/plugins/fakeaction.py b/getter/plugins/fakeaction.py
index 0315970..fb5261d 100644
--- a/getter/plugins/fakeaction.py
+++ b/getter/plugins/fakeaction.py
@@ -24,7 +24,7 @@ async def _(kst):
action = "record-" + action
sec = await kst.client.get_text(kst, group=2)
sec = int(60 if not sec.replace(".", "", 1).isdecimal() else sec)
- typefor = time_formatter(sec * 1000)
+ typefor = time_formatter(sec)
await kst.eor(f"`Starting fake {act} for {typefor}...`", time=3, silent=True)
async with await kst.send_action(action=action):
await asyncio.sleep(sec)
diff --git a/getter/plugins/globaltools.py b/getter/plugins/globaltools.py
index 383a481..087ec71 100644
--- a/getter/plugins/globaltools.py
+++ b/getter/plugins/globaltools.py
@@ -3,11 +3,11 @@
# AGPL-3.0 License
import asyncio
+import random
from contextlib import suppress
from datetime import datetime
from io import BytesIO
from json import dumps
-from random import choice, randrange
from time import monotonic
from telethon.errors import FloodWaitError
@@ -136,7 +136,7 @@
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GBAN_LOCK.locked():
return await kst.eor("`Please wait until previous •gban• finished...`", time=5, silent=True)
async with _GBAN_LOCK:
@@ -186,14 +186,14 @@ async def _(kst):
if gg.is_group or gg.is_channel:
try:
await ga.edit_permissions(gg.id, user.id, view_messages=False)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
await ga.edit_permissions(gg.id, user.id, view_messages=False)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
except BaseException:
@@ -201,7 +201,7 @@ async def _(kst):
await add_gban(user.id, date, reason)
await ga.block(user.id)
await ga.archive(user.id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = gban_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -228,7 +228,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _UNGBAN_LOCK.locked():
return await kst.eor("`Please wait until previous •ungban• finished...`", time=5, silent=True)
async with _UNGBAN_LOCK:
@@ -252,21 +252,21 @@ async def _(kst):
if gg.is_group or gg.is_channel:
try:
await ga.edit_permissions(gg.id, user.id)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
await ga.edit_permissions(gg.id, user.id)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
except BaseException:
failed += 1
await del_gban(user.id)
await ga.unblock(user.id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = ungban_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -292,7 +292,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GMUTE_LOCK.locked():
return await kst.eor("`Please wait until previous •gmute• finished...`", time=5, silent=True)
async with _GMUTE_LOCK:
@@ -318,20 +318,20 @@ async def _(kst):
if gg.is_group:
try:
await ga.edit_permissions(gg.id, user.id, send_messages=False)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
await ga.edit_permissions(gg.id, user.id, send_messages=False)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
except BaseException:
failed += 1
await add_gmute(user.id, date, reason)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = gmute_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -357,7 +357,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _UNGMUTE_LOCK.locked():
return await kst.eor("`Please wait until previous •ungmute• finished...`", time=5, silent=True)
async with _UNGMUTE_LOCK:
@@ -381,20 +381,20 @@ async def _(kst):
if gg.is_group:
try:
await ga.edit_permissions(gg.id, user.id, send_messages=True)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
await ga.edit_permissions(gg.id, user.id, send_messages=True)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
except BaseException:
failed += 1
await del_gmute(user.id)
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = ungmute_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -418,7 +418,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GDEL_LOCK.locked():
return await kst.eor("`Please wait until previous •gdel• finished...`", time=5, silent=True)
async with _GDEL_LOCK:
@@ -456,7 +456,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _UNGDEL_LOCK.locked():
return await kst.eor("`Please wait until previous •ungdel• finished...`", time=5, silent=True)
async with _UNGDEL_LOCK:
@@ -601,7 +601,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev or kst.is_sudo:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GKICK_LOCK.locked():
return await kst.eor("`Please wait until previous •gkick• finished...`", time=5, silent=True)
async with _GKICK_LOCK:
@@ -624,19 +624,19 @@ async def _(kst):
if gg.is_group or gg.is_channel:
try:
await ga.kick_participant(gg.id, user.id)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
await ga.kick_participant(gg.id, user.id)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
except BaseException:
failed += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = gkick_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -657,7 +657,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GPROMOTE_LOCK.locked():
return await kst.eor("`Please wait until previous •gpromote• finished...`", time=5, silent=True)
async with _GPROMOTE_LOCK:
@@ -696,11 +696,11 @@ async def _(kst):
anonymous=False,
title=title,
)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = gpromote_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -722,7 +722,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GDEMOTE_LOCK.locked():
return await kst.eor("`Please wait until previous •gdemote• finished...`", time=5, silent=True)
async with _GDEMOTE_LOCK:
@@ -757,11 +757,11 @@ async def _(kst):
manage_call=False,
anonymous=False,
)
- await asyncio.sleep(0.5)
success += 1
+ await asyncio.sleep(random.uniform(0.5, 1.5))
except BaseException:
failed += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = gdemote_text.format(
mentionuser(user.id, display_name(user), width=15, html=True),
success + failed,
@@ -782,7 +782,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GCAST_LOCK.locked():
return await kst.eor("`Please wait until previous •gcast• finished...`", time=5, silent=True)
async with _GCAST_LOCK:
@@ -826,8 +826,8 @@ async def _(kst):
message=message,
link_preview=True,
)
- await asyncio.sleep(randrange(2, 5))
success += 1
+ await asyncio.sleep(random.uniform(2.5, 5.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
@@ -836,15 +836,15 @@ async def _(kst):
message=message,
link_preview=True,
)
- await asyncio.sleep(randrange(2, 5))
success += 1
+ await asyncio.sleep(random.uniform(2.5, 5.5))
except Exception as err2:
error += "• " + str(err2) + "\n"
failed += 1
except Exception as err1:
error += "• " + str(err1) + "\n"
failed += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = r"\\**#Gcast**// {} in {}-{}={} {}.".format(
taken,
success + failed,
@@ -873,7 +873,7 @@ async def _(kst):
)
async def _(kst):
if kst.is_dev:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
if not kst.is_dev and _GUCAST_LOCK.locked():
return await kst.eor("`Please wait until previous •gucast• finished...`", time=5, silent=True)
async with _GUCAST_LOCK:
@@ -911,8 +911,8 @@ async def _(kst):
message=message,
link_preview=True,
)
- await asyncio.sleep(randrange(2, 5))
success += 1
+ await asyncio.sleep(random.uniform(2.5, 5.5))
except FloodWaitError as fw:
await asyncio.sleep(fw.seconds + 10)
try:
@@ -921,13 +921,13 @@ async def _(kst):
message=message,
link_preview=True,
)
- await asyncio.sleep(randrange(2, 5))
success += 1
+ await asyncio.sleep(random.uniform(2.5, 5.5))
except BaseException:
failed += 1
except BaseException:
failed += 1
- taken = time_formatter((monotonic() - start_time) * 1000)
+ taken = time_formatter(monotonic() - start_time)
text = rf"\\**#Gucast**// {taken} in {success + failed}-{failed}={success} users."
await yy.eor(text)
@@ -956,7 +956,7 @@ async def _(kst):
async def gblacklisted(kst, mode):
if kst.is_dev:
- await asyncio.sleep(choice((4, 6, 8)))
+ await asyncio.sleep(random.choice((4, 6, 8)))
ga = kst.client
yy = await kst.eor("`Processing...`")
where = await ga.get_text(kst)
diff --git a/getter/plugins/vctools.py b/getter/plugins/vctools.py
index 9c40016..a252a38 100644
--- a/getter/plugins/vctools.py
+++ b/getter/plugins/vctools.py
@@ -155,7 +155,7 @@ async def _(kst):
except FloodWaitError as fw:
# from telethon.errors import FloodWaitError
flood = fw.seconds
- await yy.eor("`Inviting wait in {}...`".format(time_formatter((flood + 5) * 1000)))
+ await yy.eor("`Inviting wait in {}...`".format(time_formatter(flood + 5))
await asyncio.sleep(flood + 5)
await ga(InviteToGroupCallRequest(call=call, users=user))
done += 6