-
Notifications
You must be signed in to change notification settings - Fork 707
/
utils.py
76 lines (70 loc) · 2.52 KB
/
utils.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
66
67
68
69
70
71
72
73
74
75
76
import logging, asyncio, os, re, random, pytz, aiohttp, requests, string, json, http.client
from datetime import date, datetime
from config import SHORTLINK_API, SHORTLINK_URL
from shortzy import Shortzy
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
TOKENS = {}
VERIFIED = {}
async def get_verify_shorted_link(link):
if SHORTLINK_URL == "api.shareus.io":
url = f'https://{SHORTLINK_URL}/easy_api'
params = {
"key": SHORTLINK_API,
"link": link,
}
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params, raise_for_status=True, ssl=False) as response:
data = await response.text()
return data
except Exception as e:
logger.error(e)
return link
else:
# response = requests.get(f"https://{SHORTLINK_URL}/api?api={SHORTLINK_API}&url={link}")
# data = response.json()
# if data["status"] == "success" or rget.status_code == 200:
# return data["shortenedUrl"]
shortzy = Shortzy(api_key=SHORTLINK_API, base_site=SHORTLINK_URL)
link = await shortzy.convert(link)
return link
async def check_token(bot, userid, token):
user = await bot.get_users(userid)
if user.id in TOKENS.keys():
TKN = TOKENS[user.id]
if token in TKN.keys():
is_used = TKN[token]
if is_used == True:
return False
else:
return True
else:
return False
async def get_token(bot, userid, link):
user = await bot.get_users(userid)
token = ''.join(random.choices(string.ascii_letters + string.digits, k=7))
TOKENS[user.id] = {token: False}
link = f"{link}verify-{user.id}-{token}"
shortened_verify_url = await get_verify_shorted_link(link)
return str(shortened_verify_url)
async def verify_user(bot, userid, token):
user = await bot.get_users(userid)
TOKENS[user.id] = {token: True}
tz = pytz.timezone('Asia/Kolkata')
today = date.today()
VERIFIED[user.id] = str(today)
async def check_verification(bot, userid):
user = await bot.get_users(userid)
tz = pytz.timezone('Asia/Kolkata')
today = date.today()
if user.id in VERIFIED.keys():
EXP = VERIFIED[user.id]
years, month, day = EXP.split('-')
comp = date(int(years), int(month), int(day))
if comp<today:
return False
else:
return True
else:
return False