-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxrocket.py
152 lines (105 loc) · 5.01 KB
/
xrocket.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
# █▀▀ ▄▀█ █▀▄▀█ █▀█ █▀▄ █▀
# █▀░ █▀█ █░▀░█ █▄█ █▄▀ ▄█
# https://t.me/famods
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# ---------------------------------------------------------------------------------
# Name: xRocket
# Description: Автоматизация базового функционала @xRocket
# meta developer: @FAmods
# meta banner: https://github.com/FajoX1/FAmods/blob/main/assets/banners/xrocket.png?raw=true
# ---------------------------------------------------------------------------------
import hikkatl
import asyncio
import logging
from .. import loader, utils
logger = logging.getLogger(__name__)
@loader.tds
class xRocket(loader.Module):
"""Автоматизация базового функционала @xRocket"""
strings = {
"name": "xRocket",
"no_args": "<emoji document_id=5440381017384822513>❌</emoji> <b>Нужно <code>{}{}</code></b>",
"creating": "<emoji document_id=5334904192622403796>🔄</emoji> <b>Создаю {}...</b>",
"checking_wallet": "<emoji document_id=5334885140147479028>🔄</emoji> <b>Смотрю кошелёк...</b>",
"no_money": "<emoji document_id=5440381017384822513>❌</emoji> <b>Не достаточно денег</b>",
"invoice": """<b>💵 Счёт на <code>{} {}</code>
🔗 <a href='{}'>Оплатить</a></b>""",
"check": """<b>💵 Чек на <code>{} {}</code> {}
🔗 <a href='{}'>Получить</a></b>""",
}
def __init__(self):
self.config = loader.ModuleConfig(
loader.ConfigValue(
"testnet",
False,
lambda: "Use testnet version of @xRocket",
validator=loader.validators.Boolean()
),
)
xrocket_bot = "@xrocket"
xrocket_testnetbot = "@ton_rocket_test_bot"
async def client_ready(self, client, db):
self.db = db
self._client = client
def bot(self):
return self.xrocket_bot if not self.config['testnet'] else self.xrocket_testnetbot
async def _create_invoice(self, amount, crypt):
q = await self._client.inline_query(self.bot(), f"{amount} {crypt}")
result = await q[0].click("me")
await result.delete()
link = result.reply_markup.rows[0].buttons[0].url
return link
async def _create_check(self, amount, crypt, user):
q = await self._client.inline_query(self.bot(), f"{amount} {crypt} {user}")
result = await q[0].click("me")
await result.delete()
if "Счёт" in result.message:
return "no_money"
link = result.reply_markup.rows[0].buttons[0].url
return link
async def _get_wallet(self):
while True:
try:
async with self._client.conversation(self.bot()) as conv:
msg = await conv.send_message("/wallet")
r = await conv.get_response()
await msg.delete()
await r.delete()
return r
except hikkatl.errors.common.AlreadyInConversationError:
await asyncio.sleep(5.67)
@loader.command()
async def xwallet(self, message):
"""Посмотреть кошелёк"""
await utils.answer(message, self.strings['checking_wallet'])
wm = await self._get_wallet()
return await utils.answer(message, wm.text)
@loader.command()
async def xinvoice(self, message):
"""Создать счёт"""
args = utils.get_args_raw(message)
try:
amount, crypt = args.split(" ")
except:
return await utils.answer(message, self.strings['no_args'].format(self.get_prefix(), 'xinvoice [сумма] [криптовалюта]'))
await utils.answer(message, self.strings['creating'].format("счёт"))
link = await self._create_invoice(amount, crypt)
return await utils.answer(message, self.strings['invoice'].format(amount, crypt, link))
@loader.command()
async def xcheck(self, message):
"""Создать чек"""
args = utils.get_args_raw(message)
user = ""
try:
try:
amount, crypt, user = args.split(" ")
except:
amount, crypt = args.split(" ")
except:
return await utils.answer(message, self.strings['no_args'].format(self.get_prefix(), 'xcheck [сумма] [криптовалюта] [пользователь(не обязательно)]'))
await utils.answer(message, self.strings['creating'].format("чек"))
link = await self._create_check(amount, crypt, user)
if "no_money" in link:
return await utils.answer(message, self.strings['no_money'])
return await utils.answer(message, self.strings['check'].format(amount, crypt, (f"для {user}" if user else ""), link))