-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToTHosting.py
More file actions
236 lines (174 loc) · 8.17 KB
/
ToTHosting.py
File metadata and controls
236 lines (174 loc) · 8.17 KB
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
from telethon.types import Message
from telethon.tl.types import DocumentAttributeFilename
from .. import loader, utils
import logging
import aiohttp
"""
███ ███ ██ ██ ██████ ██ ██ ██ ██████ ███████ ███████
████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ███████ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██ ██ ██████ ███████ ██████ ███████ ███████
Module Name
"""
# scopes:
# 🔒 Licensed under the GNU AGPLv3
# meta banner: link
# meta desc: desc
# meta developer: @BruhHikkaModules
logger = logging.getLogger(__name__)
class UserInfo:
def __init__(self, userbots, regdate, balance):
self.userbots = userbots
self.regdate = regdate
self.balance = balance
def __repr__(self):
return f"UserInfo(userbots={self.userbots}, regdate={self.regdate}, balance={self.balance})"
class UserbotInfo:
def __init__(self, name, emojistatus, status, serveremoji, server, time):
self.name = name
self.emojistatus = emojistatus
self.status = status
self.serveremoji = serveremoji
self.server = server
self.time = time
def __repr__(self):
return f"UserbotInfo(name={self.name}, emojistatus={self.emojistatus}, status={self.status}, serveremoji={self.serveremoji}, server={self.server}, time={self.time})"
class TothostAPI:
def __init__(self, token):
self._token = token
async def logs(self, ub_id):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.tothost.live/api/v1/userbot/get_logs?userbotID={ub_id}&token={self._token}") as response:
return bytes(await response.text(), encoding='utf-8')
async def userbotstatus(self, ub_id):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.tothost.live/api/v1/userbot/status?userbotID={ub_id}&token={self._token}") as response:
if dict(await response.json())['status'] == "active":
return True
else:
return False
async def userbotinfo(self, ub_id):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.tothost.live/api/v1/userbot/userbot_info?userbotID={ub_id}&token={self._token}") as response:
data = await response.json()
ubstatus = await self.userbotstatus(ub_id)
enddate = data['endDate']
name = data['name']
emojistatus = "🟢" if ubstatus else "🔴"
status ="Включен" if ubstatus else "Выключен"
serveremoji = data['server']['emoji']
server = data['server']['text']
time = f"{enddate['year']}-{enddate['month']}-{enddate['day']} {enddate['hour']}:{enddate['minute']}:{enddate['second']}"
return UserbotInfo(name, emojistatus, status, serveremoji, server, time)
async def restart(self, ub_id):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.tothost.live/api/v1/userbot/restart?userbotID={ub_id}&token={self._token}"):
return True
async def userinfo(self):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.tothost.live/api/v1/user/user_info?token={self._token}") as response:
data = await response.json()
userbots = [str(userbot['userbotID']) for userbot in data['userbots']]
regdate = data['registeredDate'][:10]
balance = data['balance']
return UserInfo(userbots, regdate, balance)
@loader.tds
class ToTHosting(loader.Module):
"""Module for interaction with ToTHosting API (obviously) """
strings = {
"name": "ToTHosting",
"userbot_info": (
"<blockquote><b>🌟Информация о юзерботе🌟</b></blockquote>"
"\n"
"<blockquote><b>🤖 Юзербот: {}</b></blockquote>"
"\n"
"<blockquote><b>{} Статус: {}</b></blockquote>"
"\n"
"<blockquote><b>{} Сервер: {}</b></blockquote>"
"\n"
"<blockquote><b>⏰ Подписка истекает: <code>{}</code></b></blockquote>"
),
"wait": "<emoji document_id=6334358870701376795>⌛️</emoji> Подождите пожалуйста",
"userinfo": (
"<blockquote><b>🌟 Информация о юзере 🌟</b></blockquote>"
"\n"
"<blockquote><b>🤖 Юзерботы: {}</b></blockquote>"
"\n"
"<blockquote><b>💸 Баланс: <code>{}</code></b></blockquote>"
"\n"
"<blockquote><b>🎂 Дата регистрации: {}</b></blockquote>"
)
}
def __init__(self):
self.config = loader.ModuleConfig(
loader.ConfigValue(
"token",
"None",
lambda: "Получите ваш токен в: https://t.me/ToThosTing_bot (/get_token)",
validator=loader.validators.Hidden()
),
loader.ConfigValue(
"defaultid",
123,
lambda: "Айди по-умолчанию",
validator=loader.validators.Hidden(loader.validators.Integer())
)
)
@loader.loop(interval=5, autostart=True)
async def autoupdatetoken(self):
self.api = TothostAPI(token=self.config['token'])
# async def client_ready(self, client, db):
# self.get("token_ready", False) soon
@loader.command()
async def tinfocmd(self, message: Message):
""" [id/None] - Get info about your userbot"""
args = utils.get_args_raw(message)
if not args:
args = self.config['defaultid']
await utils.answer(message, self.strings["wait"])
data = await self.api.userbotinfo(ub_id=args)
await utils.answer(
message,
self.strings['userbot_info'].format(
data.name,
data.emojistatus,
data.status,
data.serveremoji,
data.server,
data.time
)
)
@loader.command()
async def tlogscmd(self, message: Message):
''' [id/None] - Get logs of your userbot'''
args = utils.get_args_raw(message)
if not args:
args = self.config['defaultid']
await utils.answer(message, self.strings["wait"])
logs = await self.api.logs(ub_id=args)
attributes = [
DocumentAttributeFilename("logs.html")
]
await utils.answer_file(message, logs,"<emoji document_id=5226512880362332956>📖</emoji> Here you go!", attributes=attributes)
@loader.command()
async def trestartcmd(self, message: Message):
''' [id/None] - Restart the userbot'''
args = utils.get_args_raw(message)
if not args:
args = self.config['defaultid']
await utils.answer(message, self.strings["wait"])
await self.api.restart(args)
@loader.command()
async def tuserinfo(self, message: Message):
''' - Info about user'''
await utils.answer(message, self.strings["wait"])
userinfo = await self.api.userinfo()
await utils.answer(
message,
self.strings["userinfo"].format(
' '.join(userinfo.userbots),
userinfo.balance,
userinfo.regdate
)
)