-
Notifications
You must be signed in to change notification settings - Fork 22
/
bot.py
292 lines (228 loc) · 6.88 KB
/
bot.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
from config import *
from keyboard import *
from functions import *
def start_seller(user):
"""
This is the handler to start seller options
"""
keyboard = seller_menu()
user = get_user(msg=user)
bot.send_message(
user.id,
emoji.emojize(
":robot: What would you like to do today?",
use_aliases=True
),
reply_markup=keyboard
)
def start_buyer(user):
"""
This is the handler to start buyer options
"""
keyboard = buyer_menu()
user = get_user(msg=user)
bot.send_message(
user.id,
emoji.emojize(
":robot: What would you like to do today?",
use_aliases=True
),
reply_markup=keyboard
)
def select_coin(user):
"""
Selecting the right coin option for trade
"""
keyboard = coin_menu()
bot.send_message(
user.id,
emoji.emojize(
":money_bag: What is your preferred coin for payment ? ",
use_aliases=True
),
reply_markup=keyboard
)
##############TRADE CREATION
def trade_price(user):
"""
Receive user input on trade price
"""
question = bot.send_message(
user.id,
emoji.emojize(
":money_bag: How much are you expecting to be paid in your local currency? ",
use_aliases=True
)
)
question = question.wait()
bot.register_next_step_handler(question, trade_address)
def trade_address(msg):
"""
Recieve user input on trade wallet address
"""
price = msg.text
add_price(
user=msg.from_user,
price=float(price)
)
#REQUEST WALLET ADDRESS
question = bot.send_message(
msg.from_user.id,
emoji.emojize(
":money_bag: Paste the wallet address to which you will recieve payment referenced to the coin you selected above (Confirm the wallet address to make sure it is correct) ",
use_aliases=True
)
)
question = question.wait()
bot.register_next_step_handler(question, process_trade)
def process_trade(msg):
"""
Assigning of trade wallet
"""
wallet = msg.text
add_wallet(
user=msg.from_user,
address=wallet
)
trade = get_recent_trade(msg.from_user)
bot.send_message(
trade.seller,
emoji.emojize(
f"""
:memo: <b>Trade Details</b> :memo:
-----------------------
:beginner: <b>ID --> {trade.id}</b>
:beginner: <b>Price --> {trade.price} {trade.currency}</b>
:beginner: <b>Preferred method of payment --> {trade.coin}</b>
:beginner: <b>Created on --> {trade.created_at}</b>
Share only the trade ID with your customer to allow his/her join the trade. They would receive all the related information when they join.
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML,
)
#############APPROVING PAYMENTS
def validate_pay(msg):
"Receives the transaction hash for checking"
trade = get_recent_trade(msg.from_user)
trade_hash = msg.text
status = check_payment(trade, trade_hash)
if status == "Approved":
##SEND CONFIRMATION TO SELLER
bot.send_message(
trade.seller,
emoji.emojize(
f"""
:memo: <b>TRADE ID - {trade.id}</b> :memo:
------------------------------------
<b>Buyer Payment Confirmed Successfully :white_check_mark: . Please release the goods to the buyer before being paid</b>
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML
)
##SEND CONFIRMATION TO BUYER
bot.send_message(
trade.buyer,
emoji.emojize(
f"""
:memo: <b>TRADE ID - {trade.id}</b> :memo:
------------------------------------
<b>Payment Confirmed Sucessfully :white_check_mark: . Seller has been instructed to release the goods to you.</b>
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML,
reply_markup=confirm_goods()
)
else:
##SEND ALERT TO SELLER
bot.send_message(
trade.buyer,
emoji.emojize(
f"""
:memo: <b>TRADE ID - {trade.id}</b> :memo:
------------------------------------
<b>Payment Still Pending! :heavy_exclamation_mark: Please cross check the transaction hash and try again.</b>
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML
)
bot.delete_message(msg.chat.id, msg.message_id)
##REFUND PROCESS FOR BUYER
def refund_to_buyer(msg):
"Refund Coins Back To Buyer"
trade = get_recent_trade(msg)
if trade.payment_status == True:
question = bot.send_message(
trade.buyer,
f"A refund was requested for your funds on trade {trade.id}. Please paste a wallet address to receive in {trade.coin}"
)
question = question.wait()
bot.register_next_step_handler(question, refund_coins)
else:
bot.send_message(
msg.id,
emoji.emojize(
":warning: Buyer Has Not Made Payments Yet!!",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML
)
def refund_coins(msg):
"Payout refund"
wallet = msg.text
trade = get_recent_trade(msg.from_user)
pay_to_buyer(trade, wallet)
bot.send_message(
ADMIN_ID,
emoji.emojize(
"""
<b>Refunds Paid</b> :heavy_check_mark:
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML,
)
##REFUND PROCES SELLER TO RECEIVE FUNDS
def refund_to_seller(msg):
"Refund Coins Back To Buyer"
trade = get_recent_trade(msg)
confirm_pay(trade)
if trade.payment_status == True:
pay_funds_to_seller(trade)
bot.send_message(
ADMIN_ID,
emoji.emojize(
"""
<b>Paid To Seller</b> :heavy_check_mark:
""",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML,
)
else:
bot.send_message(
msg.id,
emoji.emojize(
":warning: Buyer Has Not Made Payments Yet!!",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML
)
####CLOSE TRADE WITH NO PAYOUTS
def close_dispute_trade(msg):
"Close Order After Dispute & No Body Has Paid"
trade = get_recent_trade(msg)
close_trade(trade)
users = [trade.seller, trade.buyer]
for user in users:
bot.send_message(
user,
emoji.emojize(
f"<b>Trade {trade.id} Closed</b> :mailbox_closed: ",
use_aliases=True
),
parse_mode=telegram.ParseMode.HTML,
)