forked from VJBots/VJ-Url-Uploader-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
127 lines (115 loc) · 4.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import asyncio
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup
from pyrogram.errors import FloodWait, UserIsBlocked, MessageNotModified, PeerIdInvalid
from typing import Union
import pytz
import random
import re
import os
from datetime import datetime, date
import string
from typing import List
from database.users_chats_db import tech_vj
from bs4 import BeautifulSoup
import requests
import aiohttp
import json
from config import Config
TOKENS = {}
VERIFIED = {}
LOG_TEXT_P = """#NewUser
ID - <code>{}</code>
Nᴀᴍᴇ - {}"""
async def get_verify_shorted_link(link):
API = Config.TECH_VJ_API
URL = Config.TECH_VJ_URL
https = link.split(":")[0]
if "http" == https:
https = "https"
link = link.replace("http", https)
if URL == "api.shareus.in":
url = f"https://{URL}/shortLink"
params = {"token": API,
"format": "json",
"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.json(content_type="text/html")
if data["status"] == "success":
return data["shortlink"]
else:
logger.error(f"Error: {data['message']}")
return f'https://{URL}/shortLink?token={API}&format=json&link={link}'
except Exception as e:
logger.error(e)
return f'https://{URL}/shortLink?token={API}&format=json&link={link}'
else:
url = f'https://{URL}/api'
params = {'api': API,
'url': 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.json()
if data["status"] == "success":
return data['shortenedUrl']
else:
logger.error(f"Error: {data['message']}")
return f'https://{URL}/api?api={API}&link={link}'
except Exception as e:
logger.error(e)
return f'{URL}/api?api={API}&link={link}'
async def check_token(bot, userid, token):
user = await bot.get_users(userid)
if not await tech_vj.is_user_exist(user.id):
await tech_vj.add_user(user.id, user.first_name)
await bot.send_message(Config.TECH_VJ_LOG_CHANNEL, LOG_TEXT_P.format(user.id, user.mention))
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)
if not await tech_vj.is_user_exist(user.id):
await tech_vj.add_user(user.id, user.first_name)
await bot.send_message(Config.TECH_VJ_LOG_CHANNEL, LOG_TEXT_P.format(user.id, user.mention))
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)
if not await tech_vj.is_user_exist(user.id):
await tech_vj.add_user(user.id, user.first_name)
await bot.send_message(Config.TECH_VJ_LOG_CHANNEL, LOG_TEXT_P.format(user.id, user.mention))
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)
if not await tech_vj.is_user_exist(user.id):
await tech_vj.add_user(user.id, user.first_name)
await bot.send_message(Config.TECH_VJ_LOG_CHANNEL, LOG_TEXT_P.format(user.id, user.mention))
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