-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_functions.py
89 lines (64 loc) · 2.59 KB
/
start_functions.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
from bot_instance import dp, bot, logger
from aiogram.types import CallbackQuery, Message
from aiogram.dispatcher.filters import CommandStart
from bot_instance import bot
from globals import *
from registration import start_registration
from localisation import buttons
from sessions import session_required, user_sessions, UserSession
from sending_fucntions import send_main_menu
from aiogram.dispatcher import FSMContext
from fake_message import FakeMessage
import db
from states import SetLanguageStates
from aiogram.dispatcher import FSMContext
@dp.callback_query_handler(lambda call: call.data == "restart")
async def restart_bot(call: CallbackQuery):
logger.action(f"User {call.from_user.id} restarted bot")
user = call.from_user
chat_id = call.message.chat.id
# Создание объекта FakeMessage для вызова start()
fake_message = FakeMessage(chat_id, user)
await bot.answer_callback_query(call.id)
await start(fake_message)
@dp.message_handler(CommandStart())
@session_required
async def start_command(message: Message, state: FSMContext, raw_state = None, command = None):
await start(message)
@session_required
async def select_language(message: Message):
await bot.send_message(
message.chat.id,
"Выберите язык.\nSelect language.",
reply_markup=buttons.get_language_buttons()
)
await SetLanguageStates.SET_LANGUAGE.set()
@dp.callback_query_handler(lambda call: call.data in ['ru_RU', 'en_US'], state=SetLanguageStates.SET_LANGUAGE)
@session_required
async def set_language(call: CallbackQuery, state: FSMContext, *args, **kwargs):
logger.action(f"User {call.message.chat.id} set language {call.data}")
if call.message.reply_markup is not None:
await bot.edit_message_reply_markup(
call.message.chat.id,
call.message.message_id,
reply_markup=None
)
user_sessions[call.message.chat.id].language = call.data
await state.finish()
await start(call.message)
@check_ban
async def start(message: Message):
logger.action(f"User {message.chat.id} started bot")
chat_id = message.chat.id
if chat_id not in user_sessions:
user_sessions[chat_id] = UserSession()
if message.from_user.username is None:
await send_no_username_message(chat_id)
return
if user_sessions[chat_id].language is None:
await select_language(message)
return
if db.find_account_exists(chat_id):
await send_main_menu(message)
else:
await start_registration(message, dp.current_state(chat=message.chat.id))