forked from Techfreak555/TFT-Auto_Rename_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
82 lines (64 loc) · 2.29 KB
/
utils.py
File metadata and controls
82 lines (64 loc) · 2.29 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pytz, random, string
from datetime import date
from shortzy import Shortzy
from config import *
from datetime import datetime, timedelta
TOKENS = {}
VERIFIED = {}
async def get_verify_shorted_link(link):
shortzy = Shortzy(api_key=API, base_site=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):
"""
Verifies a user and stores their verification time.
"""
user = await bot.get_users(userid)
TOKENS[user.id] = {token: True}
tz = pytz.timezone('Asia/Kolkata')
now = datetime.now(tz) # Get current time in IST
VERIFIED[user.id] = now.strftime('%Y-%m-%d %H:%M:%S') # Store timestamp as a string
async def check_verification(bot, userid):
"""
Checks if a user is verified within the last 10 minutes.
"""
user = await bot.get_users(userid)
tz = pytz.timezone('Asia/Kolkata')
now = datetime.now(tz) # Get current time in IST
if user.id in (ADMIN + [Config.OWNER]):
return True # Admins are always verified
if user.id in VERIFIED:
exp_time_str = VERIFIED[user.id]
# Convert stored string back to datetime (without timezone)
exp_time = datetime.strptime(exp_time_str, '%Y-%m-%d %H:%M:%S')
# Make it timezone-aware
exp_time = tz.localize(exp_time)
# Check if the verification is still valid (within 10 minutes)
if now - exp_time < timedelta(USER_LIMIT_TIME):
return True
else:
return False
return False
# Tech freak
# Don't Remove Credit!!!
# Telegram Channel @Tech_freak_tamil
# Developer @devilo7