-
Notifications
You must be signed in to change notification settings - Fork 7
/
command_handlers.py
125 lines (96 loc) · 3.24 KB
/
command_handlers.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
from peewee import DoesNotExist
from telegram.ext import CommandHandler, run_async
import bot_states
import keyboards
import lang
from decorators import user_auth
from models import User
@run_async
def _start_command(bot, update, args):
chat_id = update.message.chat_id
first_name = update.message.chat.first_name
username = update.message.from_user.username
try:
user = User.get(chat_id=chat_id)
text = f'{first_name}, вы уже зарегистрированны в системе. Добро пожаловать домой!'
except DoesNotExist:
referral = None
try:
if len(args) > 0:
referred_by = args[0]
referral = User.get(chat_id=referred_by)
except DoesNotExist:
pass
user = User.create(
chat_id=chat_id,
username=username,
first_name=update.message.from_user.first_name,
last_name=update.message.from_user.last_name,
referral=referral
)
text = f'{first_name}, вы были успешно зарегистрированны в системе!'
bot.send_message(chat_id=user.chat_id, text=text, reply_markup=keyboards.main_keyboard())
return bot_states.MAIN
@run_async
@user_auth
def _transfer_balance_to_deposit_command(bot, update):
bot.send_message(
chat_id=bot.chat_id,
text=lang.transfer_balance_to_deposit(bot.user.balance),
reply_markup=keyboards.back_keyboard()
)
return bot_states.TRANSFER_BALANCE_TO_DEPOSIT
@run_async
@user_auth
def _wallet_change_command(bot, update):
bot.send_message(
chat_id=bot.chat_id,
text=lang.enter_new_wallet(),
reply_markup=keyboards.back_keyboard()
)
return bot_states.WALLET_CHANGE
@run_async
@user_auth
def _transfer_balance_to_user(bot, update):
bot.send_message(
chat_id=bot.chat_id,
text=lang.transfer_balance_to_user(bot.user.balance),
reply_markup=keyboards.back_keyboard()
)
return bot_states.TRANSFER_BALANCE_TO_USER
@run_async
@user_auth
def _withdrawal_command(bot, update):
bot.send_message(
chat_id=bot.chat_id,
text=lang.create_withdrawal(bot.user.balance),
reply_markup=keyboards.back_keyboard()
)
return bot_states.CREATE_WITHDRAWAL
@run_async
@user_auth
def _demo_top_up(bot, update):
bot.send_message(
chat_id=bot.chat_id,
text='Сколько?',
reply_markup=keyboards.back_keyboard()
)
return bot_states.DEMO_TOP_UP
def transfer_balance_to_deposit():
handler = CommandHandler('transfer_deposit', _transfer_balance_to_deposit_command)
return handler
def change_wallet_initiation_handler():
handler = CommandHandler('wallet', _wallet_change_command)
return handler
def start_command_handler():
handler = CommandHandler('start', _start_command, pass_args=True)
return handler
def transfer_balance_to_user():
handler = CommandHandler('transfer_user', _transfer_balance_to_user)
return handler
def withdraw_command_handler():
handler = CommandHandler('withdraw', _withdrawal_command)
return handler
def demo_top_up():
handler = CommandHandler('demo_top_up', _demo_top_up)
return handler