From 1a45ded71575f97f71c3e3479e495b0b1c024f14 Mon Sep 17 00:00:00 2001 From: Stanislaw Date: Sun, 24 Apr 2022 22:32:28 +0600 Subject: [PATCH] =?UTF-8?q?+=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all.txt | 3 ++ chattools.py | 64 ++++++++++++++++++++------------------- downloader.py | 6 ++-- notes.py | 6 ++-- randomreact.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ speedtest.py | 48 ++++++++++++++++++++++++++++++ tagall.py | 46 ++++++++++++++++++++++++++++ 7 files changed, 218 insertions(+), 36 deletions(-) create mode 100644 randomreact.py create mode 100644 speedtest.py create mode 100644 tagall.py diff --git a/all.txt b/all.txt index cead4d2..9a3d6e2 100644 --- a/all.txt +++ b/all.txt @@ -7,6 +7,9 @@ kickall moduleslink notes quotes +randomreact reverse saver +speedtest +tagall userdata \ No newline at end of file diff --git a/chattools.py b/chattools.py index 8961860..998b835 100644 --- a/chattools.py +++ b/chattools.py @@ -46,44 +46,48 @@ async def who_cmd(self, app: Client, message: types.Message, args: str): async def invite_cmd(self, app: Client, message: types.Message, args: str): """Пригласить пользователя. Использование: invite <@ или ID или реплай>""" - reply = message.reply_to_message + if chat.type == "private": + return await utils.answer( + message, "[ChatTools] Это не чат!") + reply = message.reply_to_message + if not (args or reply): return await utils.answer( - message, "Нет аргументов или реплая") + message, "[ChatTools] Нет аргументов или реплая") try: - await message.chat.add_members( + await chat.add_members( args.split() if args else reply.from_user.id) except errors.UserNotMutualContact: return await utils.answer( - message, "Невзаимный контакт") + message, "[ChatTools] Невзаимный контакт") except (errors.RPCError, Exception) as error: return await utils.answer( - message, f"Не удалось пригласить. Ошибка: {error}") + message, f"[ChatTools] Не удалось пригласить. Ошибка: {error}") return await utils.answer( - message, "Пользователь приглашен успешно") + message, "[ChatTools] Пользователь приглашен успешно") async def users_cmd(self, app: Client, message: types.Message, args: str): """Показать список пользователей. Использование: users [имя] [!doc]>""" chat = message.chat if chat.type == "private": return await utils.answer( - message, "Это не чат!") + message, "[ChatTools] Это не чат!") m = await utils.answer( - message, "Загружаю...") + message, "[ChatTools] Загружаю...") msg = [ ( - "Удалённый аккаунт" if user.user.is_deleted - else user.user.mention - ) + f" | {user.user.id}" - async for user in chat.iter_members(query=args.replace("!doc", "")) + "Удалённый аккаунт" if member.user.is_deleted + else member.user.mention + ) + f" | {member.user.id}" + async for member in chat.iter_members(query=args.replace("!doc", "")) ] text = ( - f"Пользователи в \"{chat.title}\"" + ( + f"[ChatTools] Пользователи в \"{chat.title}\"" + ( f" по запросу \"{args.replace('!doc', '')}\"" if args else "" ) + f": {len(msg)}" @@ -95,7 +99,7 @@ async def users_cmd(self, app: Client, message: types.Message, args: str): m, text + f"\n\n{msg}") m = await utils.answer( - m, "Слишком много пользователей. Загружаю в файл...") + m, "[ChatTools] Слишком много пользователей. Загружаю в файл...") file = io.BytesIO(bytes(f"{text}\n\n{msg}")) file.name = f"users-{chat.id}.html" @@ -110,21 +114,21 @@ async def admins_cmd(self, app: Client, message: types.Message, args: str): chat = message.chat if chat.type == "private": return await utils.answer( - message, "Это не чат!") + message, "[ChatTools] Это не чат!") m = await utils.answer( - message, "Загружаю...") + message, "[ChatTools] Загружаю...") msg = [ ( - "Удалённый аккаунт" if user.user.is_deleted - else user.user.mention - ) + f" | {user.title or 'admin'} | {user.user.id}" - async for user in chat.iter_members( + "Удалённый аккаунт" if member.user.is_deleted + else member.user.mention + ) + f" | {member.title or 'admin'} | {member.user.id}" + async for member in chat.iter_members( query=args.replace("!doc", ""), filter="administrators") ] text = ( - f"Админы в \"{chat.title}\"" + ( + f"[ChatTools] Админы в \"{chat.title}\"" + ( f" по запросу \"{args.replace('!doc', '')}\"" if args else "" ) + f": {len(msg)}" @@ -136,7 +140,7 @@ async def admins_cmd(self, app: Client, message: types.Message, args: str): m, text + f"\n\n{msg}") m = await utils.answer( - m, "Загружаю в файл...") + m, "[ChatTools] Загружаю в файл...") file = io.BytesIO(bytes(f"{text}\n\n{msg}")) file.name = f"admins-{chat.id}.html" @@ -151,21 +155,21 @@ async def bots_cmd(self, app: Client, message: types.Message, args: str): chat = message.chat if chat.type == "private": return await utils.answer( - message, "Это не чат!") + message, "[ChatTools] Это не чат!") m = await utils.answer( - message, "Загружаю...") + message, "[ChatTools] Загружаю...") msg = [ ( - "Удалённый аккаунт" if user.user.is_deleted - else user.user.mention - ) + f" | {user.user.id}" - async for user in chat.iter_members( + "Удалённый аккаунт" if member.user.is_deleted + else member.user.mention + ) + f" | {member.user.id}" + async for member in chat.iter_members( query = args.replace("!doc", ""), filter = "bots") ] text = ( - f"Боты в \"{chat.title}\"" + ( + f"[ChatTools] Боты в \"{chat.title}\"" + ( f" по запросу \"{args.replace('!doc', '')}\"" if args else "" ) + f": {len(msg)}" @@ -177,7 +181,7 @@ async def bots_cmd(self, app: Client, message: types.Message, args: str): m, text + f"\n\n{msg}") m = await utils.answer( - m, "Загружаю в файл...") + m, "[ChatTools] Загружаю в файл...") file = io.BytesIO(bytes(f"{text}\n\n{msg}")) file.name = f"bots-{chat.id}.html" diff --git a/downloader.py b/downloader.py index 9616378..ea5d487 100644 --- a/downloader.py +++ b/downloader.py @@ -56,7 +56,7 @@ async def dlr_cmd(self, app: Client, message: types.Message, args: str): ) async def ulf_cmd(self, app: Client, message: types.Message, args: str): - """Выгрузить файл (по ссылке тоже). Использование: ulf <название или путь до файла>""" + """Выгрузить файл (по ссылке тоже). Использование: ulf <ссылка или путь до файла>""" reply = message.reply_to_message if not (args or reply): return await utils.answer( @@ -74,7 +74,7 @@ async def ulf_cmd(self, app: Client, message: types.Message, args: str): r = await utils.run_sync(requests.get, args) if r.status_code != 200: return await utils.answer( - message, "Не удалось запрос к сайту") + message, "Не удалось сделать запрос к сайту") file = io.BytesIO(r.content) file.name = args.split("/")[-1] @@ -87,7 +87,7 @@ async def ulf_cmd(self, app: Client, message: types.Message, args: str): if not os.path.exists(args): return await utils.answer( message, f"Такого файла не существует\n" - f"Запрос был {args}" + f"Запрос был {args}" ) file = args diff --git a/notes.py b/notes.py index 732e2eb..456dade 100644 --- a/notes.py +++ b/notes.py @@ -36,7 +36,7 @@ async def note_cmd(self, app: Client, message: types.Message, args: str): msg = await self.db.get_data(notes[args]) await msg.copy( - message.chat.id, reply_to_message_id = ( + message.chat.id, reply_to_message_id=( reply.message_id if reply else None) ) @@ -95,9 +95,9 @@ async def notes_cmd(self, app: Client, message: types.Message): return await utils.answer( message, "Список заметок нет") - list_ = "\n".join(f"• {note}" for note in notes) + text = "\n".join(map("• {}".format, notes)) return await utils.answer( - message, f"Список заметок:\n{list_}") + message, f"Список заметок:\n{text}") async def findnote_cmd(self, app: Client, message: types.Message, args: str): """Найти ссылку на заметку по названию. Использование: findnote <название>""" diff --git a/randomreact.py b/randomreact.py new file mode 100644 index 0000000..81a6c09 --- /dev/null +++ b/randomreact.py @@ -0,0 +1,81 @@ +# Sh1t-UB (telegram userbot by sh1tn3t) +# Copyright (C) 2021-2022 Sh1tN3t + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import logging +import random + +from pyrogram import Client, types, filters, errors +from .. import loader, utils + + +@loader.module("RandomReact", "sh1tn3t") +class RandomReactMod(loader.Module): + """Ставит реакции рандомные реакции""" + + async def react_cmd(self, app: Client, message: types.Message, args: str): + """Включить/выключить рандомные реакции. Использование: react [шанс (в %, от 1 до 100)]""" + chat = message.chat + if chat.type not in ["group", "supergroup"]: + return await utils.answer( + message, "❌ Это не чат") + + chats = self.db.get("RandomReact", "chats", {}) + if args or not chats.get(str(chat.id)): + chance = ( + int(args) if args.isdigit() and 0 < int(args) <= 100 + else 30 + ) + chats[str(chat.id)] = { + "on": True, + "chance": chance, + "reactions": (await app.get_chat(chat.id)).available_reactions + } + + self.db.set("RandomReact", "chats", chats) + return await utils.answer( + message, f"👍🏿 Автоматическое выставление реакций включено!\n" + f"Шанс срабатывания: {chance}%" + ) + + del chats[str(chat.id)] + self.db.set("RandomReact", "chats", chats) + return await utils.answer( + message, "👎 Автоматическое выставление реакций отключено") + + @loader.on(filters.outgoing & filters.group) + async def watcher(self, app: Client, message: types.Message): + """Ставит реакции""" + chat = message.chat + + chats = self.db.get("RandomReact", "chats", {}) + if not (current_chat := chats.get(str(chat.id))): + return + + chance = current_chat["chance"] + if random.randint(0, 100) >= chance: + return + + reactions = current_chat["reactions"] + if not reactions: + return + + try: + await app.send_reaction( + chat.id, message.message_id, + random.choice(reactions) + ) + except errors.RPCError as error: + logging.exception(error) diff --git a/speedtest.py b/speedtest.py new file mode 100644 index 0000000..f4e5635 --- /dev/null +++ b/speedtest.py @@ -0,0 +1,48 @@ +# Sh1t-UB (telegram userbot by sh1tn3t) +# Copyright (C) 2021-2022 Sh1tN3t + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import speedtest + +from pyrogram import Client, types +from .. import loader, utils + + +def speed_test(): + tester = speedtest.Speedtest() + tester.get_best_server() + tester.download() + tester.upload() + return tester.results.dict() + + +@loader.module(name="SpeedTest", author="sh1tn3t") +class SpeedTestMod(loader.Module): + """Тест интернет-соединения""" + + async def speedtest_cmd(self, app: Client, message: types.Message): + """Запускает тест скорости. Использование: speedtest""" + await utils.answer( + message, "Запускаем тест...") + + result = speed_test() + text = ( + f"Результаты теста:\n\n" + f"Скачивание: {round(result['download'] / 2 ** 20 / 8, 2)} мб/с\n" + f"Загрузка: {round(result['upload'] / 2 ** 20 / 8, 2)} мб/c\n" + f"Задержка: {round(result['ping'], 2)} мc" + ) + return await utils.answer( + message, text) diff --git a/tagall.py b/tagall.py new file mode 100644 index 0000000..8f20309 --- /dev/null +++ b/tagall.py @@ -0,0 +1,46 @@ +# Sh1t-UB (telegram userbot by sh1tn3t) +# Copyright (C) 2021-2022 Sh1tN3t + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import random + +from pyrogram import Client, types +from .. import loader, utils + + +@loader.module("TagAll", "sh1tn3t") +class TagAllMod(loader.Module): + """Тегает всех в чате""" + + async def tagall_cmd(self, app: Client, message: types.Message, args: str): + """Начинает всех тегать. Использование: tagall [текст]""" + args = args or "говно залупное\n пашет." + + users = [ + f"\u2060" + async for member in message.chat.iter_members() + if not (member.user.is_bot or member.user.is_deleted) + ] + + random.shuffle(users) + await message.delete() + + for output in [ + users[i: i + 5] + for i in range(0, len(users), 5) + ]: + await message.reply(args + "\u2060".join(output)) + + return