Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion getter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion getter/core/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion getter/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion getter/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
67 changes: 53 additions & 14 deletions getter/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions getter/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ def emit(self, record):
"asyncio",
"telethon",
"telethon.network.mtprotosender",
"pytgcalls",
):
logging.getLogger(name).setLevel(logging.ERROR)
2 changes: 1 addition & 1 deletion getter/plugins/admintools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions getter/plugins/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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 = "<b><u>I’m on AFK!</u></b>\n"
text += f"Last seen {afk_time} ago."
reason = f"<pre>{afk.reason}</pre>" if afk.reason else "No reason."
Expand Down
12 changes: 6 additions & 6 deletions getter/plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}`")


Expand Down
4 changes: 2 additions & 2 deletions getter/plugins/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion getter/plugins/fakeaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading