-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYamiManager.py
More file actions
163 lines (137 loc) · 7.46 KB
/
YamiManager.py
File metadata and controls
163 lines (137 loc) · 7.46 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
import telethon
from telethon.types import Message
from .. import loader, utils
from ..inline.types import InlineCall
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
import asyncio
import random
from telethon.errors.common import AlreadyInConversationError
"""
███ ███ ██ ██ ██████ ██ ██ ██ ██████ ███████ ███████
████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ████ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ███████ █████
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██ ██ ██████ ███████ ██████ ███████ ███████
YamiManager
📜 Licensed under the GNU AGPLv3
"""
# meta banner: https://0x0.st/HYVA.jpg
# meta desc: desc
# meta developer: @BruhHikkaModules
@loader.tds
class YamiManager(loader.Module):
"""Module for @YamiChat_bot """
strings = {
"name": "YamiManager",
"timeout-error": "🚫 <b>The bot did not respond within three minutes, it is disabled or you asked it too complex request in /img</b>",
"wait": "<i>Waiting...</i>\n\nInteresting fact! If the bot doesn't respond within three minutes, there will be an error",
"alive": "💖 Bot is alive",
"dead": "💔 Bot is dead...",
"answer": "🔀 <b>Bot answer</b>:\n\n{}",
"aleardyconv": "⛔ You can't execute more than one command",
"genimgdisabled": "At the moment generate images disabled:\n\n{}",
"sub-req": "Subscription is required for yami work, otherwise the module will not be removed and will not work before subscription",
"copyright": "Result from <a href='tg://resolve?domain=YamiChat_bot'>Yami's bot 💘</a>",
}
strings_ru = {
"timeout-error": "🚫 <b>Бот не ответил в течении трёх минут, он отключён либо же вы задали ему слишком сложный запрос в /img</b>",
"wait": "<i>Ожидаю...</i>\n\nИнтересный факт! Если бот не ответит в течении трёх минут, то будет ошибка",
"alive": "💖 Бот жив!",
"dead": "💔 Бот мёртв...",
"answer": "🔀 <b>Ответ бота</b>:\n\n{}",
"aleardyconv": "⛔ Нельзя выполнять больше одной команды",
"genimgdisabled": "В данный момент генерация изображений отключена:\n\n{}",
"sub-req": "Подписка необходима для работы ями, иначе модуль не будет удалён и не будет работать до подписки",
"copyright": "Результат из <a href='tg://resolve?domain=YamiChat_bot'>бота Ями 💘</a>",
"_cls_doc": "Модуль для @YamiChat_bot",
}
def __init__(self):
self.bot = "YamiChat_bot"
@loader.command(
ru_doc=" [команда] [запрос] - Отправить команду Ями бот\nПример: .scmmnd /img аргументы с запросом"
)
async def scmmnd(self, message: Message):
"""[cmd] [request] - Send command to Yami bot\nExample: .scmmnd /img arguments with req"""
args = utils.get_args_raw(message).split()
req = " ".join(args[1:])
await utils.answer(message, f"☁ {self.strings['wait']}")
try:
async with self.client.conversation(self.bot, timeout=180) as conv:
try:
await conv.send_message(f"{args[0]} {req}")
res = await conv.get_response()
if "❌ Чтобы использовать эту функцию, подпишись на мой канал @YamiSpace! ><" in res.raw_text:
await utils.answer(
message, f"Check @{self.inline.bot_username}"
)
return await self.yami_request_join()
if (
"✅ Запрос принят"
in res.raw_text
):
await asyncio.sleep(10)
res = await conv.get_response()
elif (
"❌ Технические работы. Попробуй позже.."
in res.raw_text
):
return await utils.answer(
message, self.strings["genimgdisabled"].format(res.text)
)
await conv.mark_read()
except asyncio.TimeoutError:
return await utils.answer(message, self.strings["timeout-error"])
except AlreadyInConversationError:
return await utils.answer(message, self.strings["aleardyconv"])
if res.media is not None:
return await utils.answer(
message,
res.media,
caption=self.strings["answer"].format(res.text)
+ (
("\n\n") + self.strings["copyright"]
if random.randint(0, 10) <= 5
else ""
),
as_file=True,
)
else:
return await utils.answer(
message,
self.strings["answer"].format(res.text)
+ (
("\n\n") + self.strings["copyright"]
if random.randint(0, 10) <= 5
else ""
),
)
@loader.command(ru_doc=" - Проверьте, жив ли бот")
async def chalive(self, message: Message):
"""- Check, to see if the bot is alive"""
try:
async with self.client.conversation(self.bot, timeout=10) as conv:
try:
await conv.send_message("/start")
except asyncio.TimeoutError:
return await utils.answer(message, self.strings["dead"])
finally:
conv.cancel()
except AlreadyInConversationError:
return await utils.answer(message, self.strings["aleardyconv"])
await utils.answer(message, self.strings["alive"])
async def yami_request_join(self):
reply_markup = InlineKeyboardMarkup()
reply_markup.add(InlineKeyboardButton(text="✅ Approve", callback_data="approve"))
reply_markup.add(InlineKeyboardButton(text="❌ Decline", callback_data="decline"))
await self.inline.bot.send_message(self.tg_id, self.strings["sub-req"], reply_markup=reply_markup)
async def yami_sub_callback_handler(self, call: InlineCall):
if call.data == 'decline':
await call.answer('❌')
await self.invoke("unloadmod", "YamiManager", call.message.chat.id)
await call.message.delete()
elif call.data == 'approve':
await self.client(telethon.tl.functions.channels.JoinChannelRequest(
channel='YamiSpace'
))
await call.answer('✅')
await call.message.delete()