forked from callsmusic/vcpb
-
Notifications
You must be signed in to change notification settings - Fork 4
/
helpers.py
65 lines (52 loc) · 1.57 KB
/
helpers.py
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
61
62
63
64
65
import os
import re
from pyrogram.errors import exceptions
import pickle
from config import GROUP, USERS_MUST_JOIN
if "data" not in os.listdir():
open("data", "ab").close()
class State():
Playing = "PLAYING"
NothingSpecial = "NOTHING_SPECIAL"
Paused = "PAUSED"
Skipped = "SKIPPED"
Streaming = "STREAMING"
def is_youtube(url):
exp1 = r"(http|https)\:\/\/((www|m)\.|)youtu\.be\/.+"
exp2 = r"(http|https)\:\/\/((www|m)\.|)youtube\.com\/watch.+"
match = bool(re.match(exp1, url)) or bool(re.match(exp2, url))
return match
def format_dur(seconds: int) -> str:
"""Inputs time in seconds, to get beautified time,
as string"""
result = ""
v_m = 0
remainder = seconds
r_ange_s = {
"d": (24 * 60 * 60),
"h": (60 * 60),
"m": 60,
"s": 1
}
for age in r_ange_s:
divisor = r_ange_s[age]
v_m, remainder = divmod(remainder, divisor)
v_m = int(v_m)
if v_m != 0:
result += f" {v_m}{age} "
return " ".join(result.split())
chat = None
def wrap(func):
global chat
def wrapper(client, message):
global chat
if USERS_MUST_JOIN:
if not chat:
chat = client.get_chat(GROUP)
try:
if chat.get_member(message.from_user.id).status in ("left", "kicked"):
return
except exceptions.bad_request_400.UserNotParticipant:
return
return func(client, message)
return wrapper