xync-bot 0.3.24.dev12__py3-none-any.whl → 0.3.26.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xync-bot might be problematic. Click here for more details.
- xync_bot/__main__.py +37 -0
- xync_bot/routers/__init__.py +41 -0
- xync_bot/routers/cond/__init__.py +1 -7
- xync_bot/routers/main/__init__.py +0 -0
- xync_bot/routers/{main.py → main/handler.py} +28 -60
- xync_bot/routers/pay/dep.py +0 -171
- xync_bot/routers/pay/handler.py +119 -105
- xync_bot/routers/pay/window.py +38 -52
- xync_bot/routers/send/__init__.py +117 -0
- xync_bot/shared.py +19 -0
- xync_bot/store.py +151 -0
- {xync_bot-0.3.24.dev12.dist-info → xync_bot-0.3.26.dev0.dist-info}/METADATA +1 -1
- xync_bot-0.3.26.dev0.dist-info/RECORD +23 -0
- xync_bot/__init__.py +0 -26
- xync_bot-0.3.24.dev12.dist-info/RECORD +0 -20
- {xync_bot-0.3.24.dev12.dist-info → xync_bot-0.3.26.dev0.dist-info}/WHEEL +0 -0
- {xync_bot-0.3.24.dev12.dist-info → xync_bot-0.3.26.dev0.dist-info}/top_level.txt +0 -0
xync_bot/routers/pay/handler.py
CHANGED
|
@@ -1,157 +1,169 @@
|
|
|
1
1
|
from asyncio import gather
|
|
2
2
|
from datetime import datetime
|
|
3
3
|
|
|
4
|
-
import PGram
|
|
5
4
|
from aiogram import Router, F
|
|
6
5
|
from aiogram.filters import Command
|
|
7
6
|
from aiogram.types import Message, CallbackQuery
|
|
8
7
|
from aiogram.fsm.context import FSMContext
|
|
9
|
-
from xync_bot.routers.pay.dep import fill_creds, fill_actors, dlt, ans
|
|
8
|
+
from xync_bot.routers.pay.dep import fill_creds, fill_actors, dlt, ans
|
|
10
9
|
from xync_schema import models
|
|
11
10
|
|
|
12
11
|
from xync_bot.routers.pay import cd, dep, window
|
|
12
|
+
from xync_bot.store import Store
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
pr = Router(name="pay")
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
@
|
|
18
|
-
async def h_start(msg: Message):
|
|
19
|
-
"""Step 1: Select target type"""
|
|
20
|
-
|
|
21
|
-
store.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
store.
|
|
25
|
-
store.
|
|
17
|
+
@pr.message(Command("pay"))
|
|
18
|
+
async def h_start(msg: Message, store: Store, **kwargs):
|
|
19
|
+
"""Step 1: Select a target type"""
|
|
20
|
+
uid = msg.from_user.id
|
|
21
|
+
store.pers[uid] = Store.Personal(1)
|
|
22
|
+
store.pers[uid].curr.is_target = True
|
|
23
|
+
await gather(window.type_select(msg, store), dlt(msg))
|
|
24
|
+
store.pers[uid].user = await models.User.get(username_id=msg.from_user.id)
|
|
25
|
+
store.pers[uid].creds, store.pers[uid].cur_creds = await fill_creds(store.pers[uid].user.person_id)
|
|
26
|
+
store.pers[uid].actors = await fill_actors(store.pers[uid].user.person_id)
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
@
|
|
29
|
-
async def h_got_fiat_type(query: CallbackQuery,
|
|
29
|
+
@pr.callback_query(cd.MoneyType.filter(F.is_fiat))
|
|
30
|
+
async def h_got_fiat_type(query: CallbackQuery, store: Store):
|
|
30
31
|
"""Step 2f: Select cur"""
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
uid = query.from_user.id
|
|
33
|
+
store.pers[uid].curr.is_fiat = True
|
|
34
|
+
await gather(window.cur_select(query.message, store), ans(query, "Понял, фиат"))
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
@
|
|
36
|
-
async def h_got_crypto_type(query: CallbackQuery,
|
|
37
|
+
@pr.callback_query(cd.MoneyType.filter(F.is_fiat.__eq__(0)))
|
|
38
|
+
async def h_got_crypto_type(query: CallbackQuery, store: Store):
|
|
37
39
|
"""Step 2c: Select coin"""
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
uid = query.from_user.id
|
|
41
|
+
store.pers.curr.is_fiat = False
|
|
42
|
+
await gather(window.coin_select(query.message, store), ans(query, "Понял, крипта"))
|
|
40
43
|
|
|
41
44
|
|
|
42
|
-
@
|
|
43
|
-
async def h_got_coin(query: CallbackQuery, callback_data: cd.Coin,
|
|
45
|
+
@pr.callback_query(cd.Coin.filter())
|
|
46
|
+
async def h_got_coin(query: CallbackQuery, callback_data: cd.Coin, store: Store):
|
|
44
47
|
"""Step 3c: Select target ex"""
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
uid = query.from_user.id
|
|
49
|
+
setattr(store.pay, ("t" if store.pers.curr.is_target else "s") + "_coin_id", callback_data.id)
|
|
50
|
+
await gather(window.ex_select(query.message, store), ans(query, "Эта монета есть на следующих биржах"))
|
|
47
51
|
|
|
48
52
|
|
|
49
|
-
@
|
|
50
|
-
async def h_got_cur(query: CallbackQuery, callback_data: cd.Cur,
|
|
53
|
+
@pr.callback_query(cd.Cur.filter())
|
|
54
|
+
async def h_got_cur(query: CallbackQuery, callback_data: cd.Cur, store: Store):
|
|
51
55
|
"""Step 3f: Select target pm"""
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
uid = query.from_user.id
|
|
57
|
+
setattr(store.pay, ("t" if store.pers.curr.is_target else "s") + "_cur_id", callback_data.id)
|
|
58
|
+
await gather(window.pm(query.message, store), ans(query, "Вот платежные системы доступные для этой валюты"))
|
|
54
59
|
|
|
55
60
|
|
|
56
|
-
@
|
|
57
|
-
async def h_got_target_pm(query: CallbackQuery, callback_data: cd.Pm, state: FSMContext):
|
|
61
|
+
@pr.callback_query(cd.Pm.filter(F.is_target))
|
|
62
|
+
async def h_got_target_pm(query: CallbackQuery, callback_data: cd.Pm, state: FSMContext, store: Store):
|
|
58
63
|
"""Step 4f: Fill target cred.detail"""
|
|
59
|
-
|
|
64
|
+
uid = query.from_user.id
|
|
65
|
+
store.pay.t_pmcur_id = callback_data.pmcur_id
|
|
60
66
|
await gather(
|
|
61
|
-
window.fill_cred_dtl(query.message),
|
|
67
|
+
window.fill_cred_dtl(query.message, store),
|
|
62
68
|
ans(query, "Теперь нужны реквизиты"),
|
|
63
69
|
state.set_state(dep.CredState.detail),
|
|
64
70
|
)
|
|
65
71
|
|
|
66
72
|
|
|
67
|
-
@
|
|
68
|
-
async def h_got_cred(query: CallbackQuery, callback_data: cd.Cred, state: FSMContext):
|
|
69
|
-
|
|
73
|
+
@pr.callback_query(cd.Cred.filter())
|
|
74
|
+
async def h_got_cred(query: CallbackQuery, callback_data: cd.Cred, state: FSMContext, store: Store):
|
|
75
|
+
uid = query.from_user.id
|
|
76
|
+
store.pay.cred_id = callback_data.id
|
|
70
77
|
await gather(
|
|
71
|
-
window.amount(query.message), ans(query, "Теперь нужна сумма"), state.set_state(dep.PaymentState.amount)
|
|
78
|
+
window.amount(query.message, store), ans(query, "Теперь нужна сумма"), state.set_state(dep.PaymentState.amount)
|
|
72
79
|
)
|
|
73
80
|
|
|
74
81
|
|
|
75
|
-
@
|
|
76
|
-
async def h_got_cred_dtl(msg: Message, state: FSMContext):
|
|
82
|
+
@pr.message(dep.CredState.detail)
|
|
83
|
+
async def h_got_cred_dtl(msg: Message, state: FSMContext, store: Store):
|
|
77
84
|
"""Step 4.1f: Fill target cred.name"""
|
|
78
|
-
|
|
79
|
-
await gather(window.fill_cred_name(msg), dlt(msg), state.set_state(dep.CredState.name))
|
|
85
|
+
store.pay.cred_dtl = msg.text
|
|
86
|
+
await gather(window.fill_cred_name(msg, store), dlt(msg), state.set_state(dep.CredState.name))
|
|
80
87
|
|
|
81
88
|
|
|
82
|
-
@
|
|
83
|
-
async def h_got_cred_name(msg: Message, state: FSMContext):
|
|
89
|
+
@pr.message(dep.CredState.name)
|
|
90
|
+
async def h_got_cred_name(msg: Message, state: FSMContext, store: Store):
|
|
84
91
|
"""Step 5f: Save target cred"""
|
|
85
|
-
|
|
92
|
+
uid = msg.from_user.id
|
|
86
93
|
cred, _ = await models.Cred.update_or_create(
|
|
87
94
|
{"name": msg.text},
|
|
88
95
|
detail=store.pay.cred_dtl,
|
|
89
|
-
person_id=store.
|
|
96
|
+
person_id=store.pers[uid].user.person_id,
|
|
90
97
|
pmcur_id=store.pay.t_pmcur_id,
|
|
91
98
|
)
|
|
92
99
|
store.pay.cred_id = cred.id
|
|
93
|
-
store.
|
|
94
|
-
await gather(window.amount(msg), dlt(msg), state.set_state(dep.PaymentState.amount))
|
|
100
|
+
store.pers[uid].creds[cred.id] = cred
|
|
101
|
+
await gather(window.amount(msg, store), dlt(msg), state.set_state(dep.PaymentState.amount))
|
|
95
102
|
|
|
96
103
|
|
|
97
|
-
@
|
|
98
|
-
async def h_got_ex(query: CallbackQuery, callback_data: cd.Ex, state: FSMContext):
|
|
104
|
+
@pr.callback_query(cd.Ex.filter())
|
|
105
|
+
async def h_got_ex(query: CallbackQuery, callback_data: cd.Ex, state: FSMContext, store: Store):
|
|
99
106
|
"""Step 4c: Save target"""
|
|
100
|
-
|
|
101
|
-
ist = store.curr.is_target
|
|
107
|
+
uid = query.from_user.id
|
|
108
|
+
ist = store.pers.curr.is_target
|
|
102
109
|
setattr(store.pay, ("t" if ist else "s") + "_ex_id", callback_data.id)
|
|
103
110
|
if ist:
|
|
104
|
-
await window.amount(query.message)
|
|
105
|
-
actor_id = store.
|
|
111
|
+
await window.amount(query.message, store)
|
|
112
|
+
actor_id = store.pers[uid].actors[store.pay.t_ex_id]
|
|
106
113
|
addr = await models.Addr.get(coin_id=store.pay.t_coin_id, actor_id=actor_id)
|
|
107
114
|
store.pay.addr_id = addr.id
|
|
108
115
|
else:
|
|
109
|
-
await window.set_ppo(query.message)
|
|
116
|
+
await window.set_ppo(query.message, store)
|
|
110
117
|
await ans(query, f"Биржа {store.glob.exs[callback_data.id]} выбрана")
|
|
111
118
|
await state.set_state(dep.PaymentState.amount)
|
|
112
119
|
|
|
113
120
|
|
|
114
|
-
@
|
|
115
|
-
async def h_got_amount(msg: Message, state: FSMContext):
|
|
116
|
-
"""Step 6: Save target amount"""
|
|
117
|
-
|
|
121
|
+
@pr.message(dep.PaymentState.amount)
|
|
122
|
+
async def h_got_amount(msg: Message, state: FSMContext, store: Store):
|
|
123
|
+
"""Step 6: Save a target amount"""
|
|
124
|
+
uid = msg.from_user.id
|
|
118
125
|
if not msg.text.isnumeric():
|
|
119
|
-
store.curr.msg_to_del = await msg.answer("Пожалуйста, введите корректное число")
|
|
126
|
+
store.pers.curr.msg_to_del = await msg.answer("Пожалуйста, введите корректное число")
|
|
120
127
|
return
|
|
121
|
-
if store.curr.msg_to_del:
|
|
122
|
-
await store.curr.msg_to_del.delete()
|
|
128
|
+
if store.pers.curr.msg_to_del:
|
|
129
|
+
await store.pers.curr.msg_to_del.delete()
|
|
123
130
|
store.pay.amount = float(msg.text)
|
|
124
131
|
"""Step 7: Select source type"""
|
|
125
|
-
store.curr.is_target = False
|
|
126
|
-
await gather(
|
|
132
|
+
store.pers.curr.is_target = False
|
|
133
|
+
await gather(
|
|
134
|
+
(window.type_select if store.pers.curr.is_fiat else window.cur_select)(msg, store), dlt(msg), state.clear()
|
|
135
|
+
)
|
|
127
136
|
|
|
128
137
|
|
|
129
|
-
@
|
|
130
|
-
async def h_got_source_pm(query: CallbackQuery, callback_data: cd.Pm):
|
|
131
|
-
|
|
138
|
+
@pr.callback_query(cd.Pm.filter(F.is_target.__eq__(0)))
|
|
139
|
+
async def h_got_source_pm(query: CallbackQuery, callback_data: cd.Pm, store: Store):
|
|
140
|
+
uid = query.from_user.id
|
|
132
141
|
store.pay.s_pmcur_id = callback_data.pmcur_id
|
|
133
142
|
await gather(
|
|
134
|
-
window.set_ppo(query.message),
|
|
143
|
+
window.set_ppo(query.message, store),
|
|
135
144
|
ans(query, store.glob.pmcurs[callback_data.pmcur_id]),
|
|
136
145
|
)
|
|
137
146
|
|
|
138
147
|
|
|
139
|
-
@
|
|
140
|
-
async def h_got_ppo(query: CallbackQuery, callback_data: cd.Ppo):
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
@pr.callback_query(cd.Ppo.filter())
|
|
149
|
+
async def h_got_ppo(query: CallbackQuery, callback_data: cd.Ppo, store: Store):
|
|
150
|
+
uid = query.from_user.id
|
|
151
|
+
store.pay.ppo = callback_data.num
|
|
152
|
+
await gather(window.set_urgency(query.message, store), ans(query, str(callback_data.num)))
|
|
143
153
|
|
|
144
154
|
|
|
145
|
-
@
|
|
146
|
-
async def h_got_urgency(query: CallbackQuery, callback_data: cd.Time):
|
|
147
|
-
query.
|
|
148
|
-
|
|
155
|
+
@pr.callback_query(cd.Time.filter())
|
|
156
|
+
async def h_got_urgency(query: CallbackQuery, callback_data: cd.Time, store: Store):
|
|
157
|
+
# payreq_id = store.pers[query.from_user.id].
|
|
158
|
+
store.pay.urg = callback_data.minutes
|
|
159
|
+
await window.create_payreq(query.message, store)
|
|
149
160
|
await ans(query, f"Ok {callback_data.minutes} min.")
|
|
150
161
|
|
|
151
162
|
|
|
152
163
|
# ACTIONS
|
|
153
|
-
@
|
|
164
|
+
@pr.callback_query(cd.Action.filter(F.act.__eq__(cd.ActionType.received)))
|
|
154
165
|
async def payment_confirmed(query: CallbackQuery, state: FSMContext):
|
|
166
|
+
uid = query.from_user.id
|
|
155
167
|
await ans(query, None)
|
|
156
168
|
payed_at = datetime.now()
|
|
157
169
|
await state.update_data(timer_active=False, payed_at_formatted=payed_at)
|
|
@@ -164,8 +176,9 @@ async def payment_confirmed(query: CallbackQuery, state: FSMContext):
|
|
|
164
176
|
await window.success(query.message)
|
|
165
177
|
|
|
166
178
|
|
|
167
|
-
@
|
|
179
|
+
@pr.callback_query(cd.Action.filter(F.act.__eq__(cd.ActionType.not_received)))
|
|
168
180
|
async def no_payment(query: CallbackQuery, state: FSMContext):
|
|
181
|
+
uid = query.from_user.id
|
|
169
182
|
await ans(query, None)
|
|
170
183
|
await state.update_data(timer_active=False)
|
|
171
184
|
await query.message.edit_text("Платеж не получен!")
|
|
@@ -174,80 +187,81 @@ async def no_payment(query: CallbackQuery, state: FSMContext):
|
|
|
174
187
|
await state.set_state(dep.Report.text)
|
|
175
188
|
|
|
176
189
|
|
|
177
|
-
@
|
|
190
|
+
@pr.message(dep.Report.text)
|
|
178
191
|
async def payment_not_specified(msg: Message, state: FSMContext):
|
|
192
|
+
uid = msg.from_user.id
|
|
179
193
|
await state.update_data(text=msg.text)
|
|
180
194
|
data = await state.get_data()
|
|
181
195
|
complaint_text = (
|
|
182
196
|
f"Жалоба на неполученный платеж:\n"
|
|
183
197
|
f"Пользователь: @{msg.from_user.username or msg.from_user.id}\n"
|
|
184
|
-
f"Детали платежа: {data[
|
|
198
|
+
f"Детали платежа: {data['text']}\n"
|
|
185
199
|
f"Время: {msg.date.strftime('%Y-%m-%d %H:%M:%S')}"
|
|
186
200
|
)
|
|
187
201
|
await msg.bot.send_message(chat_id="xyncpay", text=complaint_text)
|
|
188
202
|
|
|
189
203
|
|
|
190
204
|
# NAVIGATION
|
|
191
|
-
@
|
|
192
|
-
async def handle_home(query: CallbackQuery, state: FSMContext):
|
|
193
|
-
await gather(window.type_select(query.message), state.clear(), ans(query, "Создаем платеж заново"))
|
|
205
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_type, cd.PayStep.s_type])))
|
|
206
|
+
async def handle_home(query: CallbackQuery, state: FSMContext, store: Store):
|
|
207
|
+
await gather(window.type_select(query.message, store), state.clear(), ans(query, "Создаем платеж заново"))
|
|
194
208
|
|
|
195
209
|
|
|
196
|
-
@
|
|
197
|
-
async def to_coin_select(query: CallbackQuery, state: FSMContext):
|
|
210
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_coin, cd.PayStep.s_coin])))
|
|
211
|
+
async def to_coin_select(query: CallbackQuery, state: FSMContext, store: Store):
|
|
198
212
|
await ans(query, None)
|
|
199
213
|
is_target = await state.get_value("is_target")
|
|
200
214
|
pref = "t" if is_target else "s"
|
|
201
215
|
await state.update_data({pref + "_ex_id": None, pref + "_coin_id": None})
|
|
202
|
-
await window.coin_select(query.message)
|
|
216
|
+
await window.coin_select(query.message, store)
|
|
203
217
|
|
|
204
218
|
|
|
205
|
-
@
|
|
206
|
-
async def to_cur_select(query: CallbackQuery, state: FSMContext):
|
|
219
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_cur, cd.PayStep.s_cur])))
|
|
220
|
+
async def to_cur_select(query: CallbackQuery, state: FSMContext, store: Store):
|
|
207
221
|
await ans(query, None)
|
|
208
222
|
is_target = await state.get_value("is_target")
|
|
209
223
|
pref = "t" if is_target else "s"
|
|
210
224
|
await state.update_data({pref + "_pmcur_id": None, pref + "_cur_id": None})
|
|
211
|
-
await window.cur_select(query.message)
|
|
225
|
+
await window.cur_select(query.message, store)
|
|
212
226
|
|
|
213
227
|
|
|
214
|
-
@
|
|
215
|
-
async def to_pm_select(query: CallbackQuery,
|
|
228
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_pm, cd.PayStep.s_pm])))
|
|
229
|
+
async def to_pm_select(query: CallbackQuery, store: Store):
|
|
216
230
|
await ans(query, None)
|
|
217
|
-
await window.pm(query.message)
|
|
231
|
+
await window.pm(query.message, store)
|
|
218
232
|
|
|
219
233
|
|
|
220
|
-
@
|
|
221
|
-
async def back_to_cred_detail(query: CallbackQuery, state: FSMContext):
|
|
234
|
+
@pr.callback_query(cd.PayNav.filter(F.to.__eq__(cd.PayStep.t_cred_dtl)))
|
|
235
|
+
async def back_to_cred_detail(query: CallbackQuery, state: FSMContext, store: Store):
|
|
222
236
|
await ans(query, None)
|
|
223
237
|
await state.update_data(detail=None)
|
|
224
|
-
await window.fill_cred_dtl(query.message)
|
|
238
|
+
await window.fill_cred_dtl(query.message, store)
|
|
225
239
|
|
|
226
240
|
|
|
227
|
-
@
|
|
228
|
-
async def back_to_cred_name(query: CallbackQuery, state: FSMContext):
|
|
241
|
+
@pr.callback_query(cd.PayNav.filter(F.to.__eq__(cd.PayStep.t_cred_name)))
|
|
242
|
+
async def back_to_cred_name(query: CallbackQuery, state: FSMContext, store: Store):
|
|
229
243
|
await ans(query, None)
|
|
230
244
|
await state.update_data(name=None)
|
|
231
|
-
await window.fill_cred_name(query.message)
|
|
245
|
+
await window.fill_cred_name(query.message, store)
|
|
232
246
|
|
|
233
247
|
|
|
234
|
-
@
|
|
235
|
-
async def back_to_ex_select(query: CallbackQuery, state: FSMContext):
|
|
248
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_ex, cd.PayStep.s_ex])))
|
|
249
|
+
async def back_to_ex_select(query: CallbackQuery, state: FSMContext, store: Store):
|
|
236
250
|
await ans(query, None)
|
|
237
251
|
await state.update_data({("t" if await state.get_value("is_target") else "s") + "ex_id": None})
|
|
238
|
-
await window.ex_select(query.message)
|
|
252
|
+
await window.ex_select(query.message, store)
|
|
239
253
|
|
|
240
254
|
|
|
241
|
-
@
|
|
242
|
-
async def back_to_amount(query: CallbackQuery, state: FSMContext):
|
|
255
|
+
@pr.callback_query(cd.PayNav.filter(F.to.__eq__(cd.PayStep.t_amount)))
|
|
256
|
+
async def back_to_amount(query: CallbackQuery, state: FSMContext, store: Store):
|
|
243
257
|
await ans(query, None)
|
|
244
258
|
await state.update_data(amount=None)
|
|
245
|
-
await window.amount(query.message)
|
|
259
|
+
await window.amount(query.message, store)
|
|
246
260
|
await state.set_state(dep.PaymentState.amount)
|
|
247
261
|
|
|
248
262
|
|
|
249
|
-
@
|
|
250
|
-
async def back_to_payment(query: CallbackQuery, state: FSMContext):
|
|
263
|
+
@pr.callback_query(cd.PayNav.filter(F.to.in_([cd.PayStep.t_pm])))
|
|
264
|
+
async def back_to_payment(query: CallbackQuery, state: FSMContext, store: Store):
|
|
251
265
|
await ans(query, None)
|
|
252
266
|
await state.update_data(payment=None)
|
|
253
|
-
await window.pm(query.message)
|
|
267
|
+
await window.pm(query.message, store)
|
xync_bot/routers/pay/window.py
CHANGED
|
@@ -6,23 +6,15 @@ from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
|
|
6
6
|
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
|
7
7
|
from xync_schema import models
|
|
8
8
|
|
|
9
|
-
from xync_bot.routers.pay.dep import
|
|
10
|
-
edt,
|
|
11
|
-
need_ppo,
|
|
12
|
-
Store,
|
|
13
|
-
get_merch_target,
|
|
14
|
-
fmt_sec,
|
|
15
|
-
client_have_coin_amount,
|
|
16
|
-
client_target_repr,
|
|
17
|
-
)
|
|
18
|
-
|
|
9
|
+
from xync_bot.routers.pay.dep import edt, fmt_sec
|
|
19
10
|
from xync_bot.routers.pay import cd, dep
|
|
11
|
+
from xync_bot.store import Store
|
|
20
12
|
|
|
21
13
|
|
|
22
|
-
async def type_select(msg: Message):
|
|
14
|
+
async def type_select(msg: Message, store: Store):
|
|
23
15
|
"""Step 1: Select type"""
|
|
24
|
-
|
|
25
|
-
ist: bool = store.curr.is_target
|
|
16
|
+
uid = msg.from_user.id
|
|
17
|
+
ist: bool = store.pers[uid].curr.is_target
|
|
26
18
|
rm = InlineKeyboardMarkup(
|
|
27
19
|
inline_keyboard=[
|
|
28
20
|
[
|
|
@@ -30,33 +22,34 @@ async def type_select(msg: Message):
|
|
|
30
22
|
text="Банковская валюта", callback_data=cd.MoneyType(is_fiat=1, is_target=ist).pack()
|
|
31
23
|
),
|
|
32
24
|
InlineKeyboardButton(
|
|
33
|
-
text="Крипта",
|
|
25
|
+
text="Крипта",
|
|
26
|
+
callback_data=cd.MoneyType(is_fiat=0, is_target=store.pers[uid].curr.is_target).pack(),
|
|
34
27
|
),
|
|
35
28
|
]
|
|
36
29
|
]
|
|
37
30
|
)
|
|
38
|
-
if store.curr.is_target:
|
|
31
|
+
if store.pers[uid].curr.is_target:
|
|
39
32
|
txt = "Что нужно?"
|
|
40
33
|
else:
|
|
41
|
-
if store.pay.t_coin_id:
|
|
42
|
-
inf = f"{store.glob.coins[store.pay.t_coin_id]} на {store.glob.exs[store.pay.t_ex_id]}:{store.pay.addr_id}"
|
|
34
|
+
if store.pers[uid].pay.t_coin_id:
|
|
35
|
+
inf = f"{store.glob.coins[store.pers[uid].pay.t_coin_id]} на {store.glob.exs[store.pers[uid].pay.t_ex_id]}:{store.pay.addr_id}"
|
|
43
36
|
else:
|
|
44
37
|
cur = store.glob.curs[store.pay.t_cur_id].ticker
|
|
45
|
-
cred: models.Cred = store.
|
|
38
|
+
cred: models.Cred = store.pers[uid].creds[store.pay.cred_id]
|
|
46
39
|
inf = f"{cur} на {store.glob.pmcurs[store.pay.t_pmcur_id]}: {cred.repr()}"
|
|
47
40
|
txt = f"Нужен платеж: {store.pay.amount} {inf}\nЧем будете платить?"
|
|
48
|
-
if store.
|
|
41
|
+
if store.pers[uid].msg_id:
|
|
49
42
|
await edt(msg, txt, rm)
|
|
50
43
|
else:
|
|
51
44
|
msg = await msg.answer(txt, reply_markup=rm)
|
|
52
|
-
store.
|
|
45
|
+
store.pers[uid].msg_id = msg.message_id
|
|
53
46
|
|
|
54
47
|
|
|
55
|
-
async def cur_select(msg: Message):
|
|
48
|
+
async def cur_select(msg: Message, store: Store):
|
|
56
49
|
"""Common using cur func"""
|
|
57
50
|
builder = InlineKeyboardBuilder()
|
|
58
|
-
ist: bool =
|
|
59
|
-
for cur_id, cur in
|
|
51
|
+
ist: bool = store.curr.is_target
|
|
52
|
+
for cur_id, cur in store.glob.curs.items():
|
|
60
53
|
builder.button(text=cur.ticker + dep.flags[cur.ticker], callback_data=cd.Cur(id=cur_id, is_target=ist))
|
|
61
54
|
builder.button(text="Назад к выбору типа", callback_data=cd.PayNav(to=cd.PayStep.t_type))
|
|
62
55
|
builder.adjust(3, 3, 3, 3, 3, 1)
|
|
@@ -64,10 +57,9 @@ async def cur_select(msg: Message):
|
|
|
64
57
|
await edt(msg, "Выбери валюту котор" + sfx, builder.as_markup())
|
|
65
58
|
|
|
66
59
|
|
|
67
|
-
async def coin_select(msg: Message):
|
|
60
|
+
async def coin_select(msg: Message, store: Store):
|
|
68
61
|
"""Common using coin func"""
|
|
69
62
|
builder = InlineKeyboardBuilder()
|
|
70
|
-
store: Store = msg.bot.store
|
|
71
63
|
for coin_id, ticker in store.glob.coins.items():
|
|
72
64
|
builder.button(text=ticker, callback_data=cd.Coin(id=coin_id, is_target=store.curr.is_target))
|
|
73
65
|
builder.button(
|
|
@@ -79,8 +71,7 @@ async def coin_select(msg: Message):
|
|
|
79
71
|
await msg.edit_text("Выберите монету котор" + sfx, reply_markup=builder.as_markup())
|
|
80
72
|
|
|
81
73
|
|
|
82
|
-
async def ex_select(msg: Message):
|
|
83
|
-
store: Store = msg.bot.store
|
|
74
|
+
async def ex_select(msg: Message, store: Store):
|
|
84
75
|
ist = store.curr.is_target
|
|
85
76
|
coin_id = getattr(store.pay, ("t" if ist else "s") + "_coin_id")
|
|
86
77
|
builder = InlineKeyboardBuilder()
|
|
@@ -95,8 +86,7 @@ async def ex_select(msg: Message):
|
|
|
95
86
|
await msg.edit_text("На какую биржу?" if ist else "С какой биржи?", reply_markup=keyboard)
|
|
96
87
|
|
|
97
88
|
|
|
98
|
-
async def pm(msg: Message):
|
|
99
|
-
store: Store = msg.bot.store
|
|
89
|
+
async def pm(msg: Message, store: Store):
|
|
100
90
|
ist = store.curr.is_target
|
|
101
91
|
cur_id = getattr(store.pay, ("t" if ist else "s") + "_cur_id")
|
|
102
92
|
builder = InlineKeyboardBuilder()
|
|
@@ -111,13 +101,13 @@ async def pm(msg: Message):
|
|
|
111
101
|
await msg.edit_text("На какую платежную систему?" if ist else "C какой платежной системы?", reply_markup=keyboard)
|
|
112
102
|
|
|
113
103
|
|
|
114
|
-
async def fill_cred_dtl(msg: Message):
|
|
104
|
+
async def fill_cred_dtl(msg: Message, store: Store):
|
|
105
|
+
uid = msg.from_user.id
|
|
115
106
|
builder = InlineKeyboardBuilder()
|
|
116
|
-
store: Store = msg.bot.store
|
|
117
107
|
txt = "В"
|
|
118
|
-
if cred_ids := store.
|
|
108
|
+
if cred_ids := store.pers[uid].cur_creds.get(store.pay.t_pmcur_id):
|
|
119
109
|
for cred_id in cred_ids:
|
|
120
|
-
cred = store.
|
|
110
|
+
cred = store.pers[uid].creds[cred_id]
|
|
121
111
|
builder.button(text=cred.repr(), callback_data=cd.Cred(id=cred_id))
|
|
122
112
|
txt = "Выберите реквизиты куда нужно получить деньги, если в списке нет нужных, то\nв"
|
|
123
113
|
|
|
@@ -130,22 +120,20 @@ async def fill_cred_dtl(msg: Message):
|
|
|
130
120
|
)
|
|
131
121
|
|
|
132
122
|
|
|
133
|
-
async def fill_cred_name(msg: Message):
|
|
123
|
+
async def fill_cred_name(msg: Message, store: Store):
|
|
134
124
|
builder = InlineKeyboardBuilder()
|
|
135
125
|
builder.button(text="Назад к вводу реквизитов", callback_data=cd.PayNav(to=cd.PayStep.t_cred_dtl))
|
|
136
126
|
builder.button(text="Домой", callback_data=cd.PayNav(to=cd.PayStep.t_type))
|
|
137
127
|
builder.adjust(2)
|
|
138
|
-
store: Store = msg.bot.store
|
|
139
128
|
cur = store.glob.curs[store.pay.t_cur_id]
|
|
140
129
|
payment = store.glob.pmcurs[store.pay.t_pmcur_id]
|
|
141
130
|
detail = store.pay.cred_dtl
|
|
142
131
|
await edt(msg, f"{cur.ticker}:{payment}:{detail}: Введите имя получателя", builder.as_markup())
|
|
143
132
|
|
|
144
133
|
|
|
145
|
-
async def amount(msg: Message):
|
|
134
|
+
async def amount(msg: Message, store: Store):
|
|
146
135
|
"""Step 5: Filling target amount"""
|
|
147
136
|
builder = InlineKeyboardBuilder()
|
|
148
|
-
store: Store = msg.bot.store
|
|
149
137
|
if store.curr.is_fiat:
|
|
150
138
|
cur_coin = store.glob.curs[store.pay.t_cur_id].ticker
|
|
151
139
|
builder.button(text="Назад к вводу имени", callback_data=cd.PayNav(to=cd.PayStep.t_cred_name))
|
|
@@ -161,10 +149,9 @@ async def amount(msg: Message):
|
|
|
161
149
|
await edt(msg, f"Введите нужную сумму {cur_coin} для {t_name}", builder.as_markup())
|
|
162
150
|
|
|
163
151
|
|
|
164
|
-
async def set_ppo(msg: Message):
|
|
165
|
-
store: Store = msg.bot.store
|
|
152
|
+
async def set_ppo(msg: Message, store: Store):
|
|
166
153
|
ist = store.curr.is_target
|
|
167
|
-
if nppo := await need_ppo(
|
|
154
|
+
if nppo := await store.need_ppo():
|
|
168
155
|
builder = InlineKeyboardBuilder()
|
|
169
156
|
builder.button(text="Нет", callback_data=cd.Ppo(num=1, is_target=ist)).button(
|
|
170
157
|
text="Да", callback_data=cd.Ppo(num=2, is_target=ist)
|
|
@@ -180,9 +167,8 @@ async def set_ppo(msg: Message):
|
|
|
180
167
|
await set_urgency(msg)
|
|
181
168
|
|
|
182
169
|
|
|
183
|
-
async def set_urgency(msg: Message):
|
|
184
|
-
store
|
|
185
|
-
if not store.curr.is_fiat or await client_have_coin_amount(store):
|
|
170
|
+
async def set_urgency(msg: Message, store: Store):
|
|
171
|
+
if not store.curr.is_fiat or await store.client_have_coin_amount():
|
|
186
172
|
return await create_payreq(msg) # next
|
|
187
173
|
builder = InlineKeyboardBuilder()
|
|
188
174
|
(
|
|
@@ -198,19 +184,19 @@ async def set_urgency(msg: Message):
|
|
|
198
184
|
return await edt(msg, "Сколько можешь ждать?", builder.as_markup())
|
|
199
185
|
|
|
200
186
|
|
|
201
|
-
async def create_payreq(msg: Message):
|
|
202
|
-
|
|
187
|
+
async def create_payreq(msg: Message, store: Store):
|
|
188
|
+
uid = msg.from_user.id
|
|
203
189
|
pay_req, _ = await models.PayReq.update_or_create(
|
|
204
190
|
{"pay_until": datetime.now() + timedelta(minutes=store.pay.urg)},
|
|
205
191
|
amount=store.pay.amount,
|
|
206
192
|
parts=store.pay.ppo,
|
|
207
193
|
addr_id=store.pay.addr_id,
|
|
208
194
|
cred_id=store.pay.cred_id,
|
|
209
|
-
user=store.
|
|
195
|
+
user=store.pers[uid].user,
|
|
210
196
|
)
|
|
211
197
|
store.pay.pr_id = pay_req.id
|
|
212
|
-
inp, txt = await get_merch_target(
|
|
213
|
-
ccred, ctxt = await client_target_repr(
|
|
198
|
+
inp, txt = await store.get_merch_target()
|
|
199
|
+
ccred, ctxt = await store.client_target_repr()
|
|
214
200
|
txt += f"\nИ получите {store.pay.amount} {ctxt} в течение {fmt_sec(store.pay.urg * 60)}"
|
|
215
201
|
if store.pay.ppo > 1:
|
|
216
202
|
txt += f" максимум {store.pay.ppo} платежами"
|
|
@@ -224,14 +210,14 @@ async def create_payreq(msg: Message):
|
|
|
224
210
|
# create_task(window.run_timer(msg))В
|
|
225
211
|
|
|
226
212
|
|
|
227
|
-
async def run_timer(
|
|
213
|
+
async def run_timer(msg, state: FSMContext):
|
|
228
214
|
builder = InlineKeyboardBuilder()
|
|
229
215
|
builder.button(text="Платеж получен", callback_data=cd.Action(act=cd.ActionType.received))
|
|
230
216
|
|
|
231
217
|
seconds = await state.get_value("timer") * 60
|
|
232
218
|
|
|
233
219
|
try:
|
|
234
|
-
await
|
|
220
|
+
await msg.edit_text(f"⏳ Осталось {fmt_sec(seconds)}", reply_markup=builder.as_markup())
|
|
235
221
|
except Exception:
|
|
236
222
|
return
|
|
237
223
|
|
|
@@ -239,7 +225,7 @@ async def run_timer(message, state: FSMContext):
|
|
|
239
225
|
await sleep(1)
|
|
240
226
|
seconds -= 1
|
|
241
227
|
try:
|
|
242
|
-
await
|
|
228
|
+
await msg.edit_text(f"⏳ Осталось {fmt_sec(seconds)}", reply_markup=builder.as_markup())
|
|
243
229
|
await state.update_data(timer=seconds)
|
|
244
230
|
except Exception:
|
|
245
231
|
break
|
|
@@ -249,7 +235,7 @@ async def run_timer(message, state: FSMContext):
|
|
|
249
235
|
builder.button(text="Платеж получен", callback_data=cd.Action(act=cd.ActionType.received))
|
|
250
236
|
builder.button(text="Денег нет", callback_data=cd.Action(act=cd.ActionType.not_received))
|
|
251
237
|
try:
|
|
252
|
-
await
|
|
238
|
+
await msg.edit_text("⏳ Время вышло!", reply_markup=builder.as_markup())
|
|
253
239
|
except Exception:
|
|
254
240
|
pass
|
|
255
241
|
|