-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
66 lines (51 loc) · 1.86 KB
/
Copy pathbot.py
File metadata and controls
66 lines (51 loc) · 1.86 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
import asyncio
from urllib.parse import urlencode, urljoin
from aiogram import Bot, Dispatcher, types
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart, CommandObject
from config import BOT_TOKEN, SECRET_KEY, REDIRECT_URL
from scripts import get_text, check_hash, create_hash
dp = Dispatcher()
@dp.message(CommandStart())
async def main_handler(message: types.Message, command: CommandObject) -> None:
if not command.args:
return
data = command.args.split('-')
if len(data) < 2:
return
hash_ = data[0]
user_data = data[1]
lang = data[2] if len(data) > 2 else None
if not check_hash([SECRET_KEY, user_data], hash_):
return
params = {
'data': user_data,
'auth_at': int(message.date.timestamp()),
'user_id': message.from_user.id,
'username': message.from_user.username,
'first_name': message.from_user.first_name,
'last_name': message.from_user.last_name
}
params['hash'] = create_hash([SECRET_KEY, *params.values()])
await message.answer(
get_text('message', lang, message.from_user.language_code),
reply_markup=types.InlineKeyboardMarkup(
inline_keyboard=[[
types.InlineKeyboardButton(text=get_text('button', lang, message.from_user.language_code),
url=urljoin(REDIRECT_URL, '?' + urlencode(params)))
]]
)
)
async def main() -> None:
# Initialize Bot instance with default bot properties which will be passed to all API calls
bot = Bot(
token=BOT_TOKEN,
default=DefaultBotProperties(
parse_mode=ParseMode.HTML
)
)
# And the run events dispatching
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())