Skip to content

Commit

Permalink
+модули
Browse files Browse the repository at this point in the history
  • Loading branch information
Fl1yd committed Apr 24, 2022
1 parent 7d92dd4 commit 1a45ded
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 36 deletions.
3 changes: 3 additions & 0 deletions all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ kickall
moduleslink
notes
quotes
randomreact
reverse
saver
speedtest
tagall
userdata
64 changes: 34 additions & 30 deletions chattools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<b>[ChatTools]</b> Это не чат!")

reply = message.reply_to_message

if not (args or reply):
return await utils.answer(
message, "Нет аргументов или реплая")
message, "<b>[ChatTools]</b> Нет аргументов или реплая")

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, "<b>[ChatTools]</b> Невзаимный контакт")
except (errors.RPCError, Exception) as error:
return await utils.answer(
message, f"Не удалось пригласить. Ошибка: {error}")
message, f"<b>[ChatTools]</b> Не удалось пригласить. Ошибка: {error}")

return await utils.answer(
message, "Пользователь приглашен успешно")
message, "<b>[ChatTools]</b> Пользователь приглашен успешно")

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, "<b>[ChatTools]</b> Это не чат!")

m = await utils.answer(
message, "Загружаю...")
message, "<b>[ChatTools]</b> Загружаю...")

msg = [
(
"Удалённый аккаунт" if user.user.is_deleted
else user.user.mention
) + f" | <code>{user.user.id}</code>"
async for user in chat.iter_members(query=args.replace("!doc", ""))
"Удалённый аккаунт" if member.user.is_deleted
else member.user.mention
) + f" | <code>{member.user.id}</code>"
async for member in chat.iter_members(query=args.replace("!doc", ""))
]
text = (
f"Пользователи в \"{chat.title}\"" + (
f"<b>[ChatTools]</b> Пользователи в \"{chat.title}\"" + (
f" по запросу \"{args.replace('!doc', '')}\"" if args
else ""
) + f": {len(msg)}"
Expand All @@ -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, "<b>[ChatTools]</b> Слишком много пользователей. Загружаю в файл...")

file = io.BytesIO(bytes(f"{text}\n\n{msg}"))
file.name = f"users-{chat.id}.html"
Expand All @@ -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, "<b>[ChatTools]</b> Это не чат!")

m = await utils.answer(
message, "Загружаю...")
message, "<b>[ChatTools]</b> Загружаю...")

msg = [
(
"Удалённый аккаунт" if user.user.is_deleted
else user.user.mention
) + f" | {user.title or 'admin'} | <code>{user.user.id}</code>"
async for user in chat.iter_members(
"Удалённый аккаунт" if member.user.is_deleted
else member.user.mention
) + f" | {member.title or 'admin'} | <code>{member.user.id}</code>"
async for member in chat.iter_members(
query=args.replace("!doc", ""), filter="administrators")
]
text = (
f"Админы в \"{chat.title}\"" + (
f"<b>[ChatTools]</b> Админы в \"{chat.title}\"" + (
f" по запросу \"{args.replace('!doc', '')}\"" if args
else ""
) + f": {len(msg)}"
Expand All @@ -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, "<b>[ChatTools]</b> Загружаю в файл...")

file = io.BytesIO(bytes(f"{text}\n\n{msg}"))
file.name = f"admins-{chat.id}.html"
Expand All @@ -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, "<b>[ChatTools]</b> Это не чат!")

m = await utils.answer(
message, "Загружаю...")
message, "<b>[ChatTools]</b> Загружаю...")

msg = [
(
"Удалённый аккаунт" if user.user.is_deleted
else user.user.mention
) + f" | <code>{user.user.id}</code>"
async for user in chat.iter_members(
"Удалённый аккаунт" if member.user.is_deleted
else member.user.mention
) + f" | <code>{member.user.id}</code>"
async for member in chat.iter_members(
query = args.replace("!doc", ""), filter = "bots")
]
text = (
f"Боты в \"{chat.title}\"" + (
f"<b>[ChatTools]</b> Боты в \"{chat.title}\"" + (
f" по запросу \"{args.replace('!doc', '')}\"" if args
else ""
) + f": {len(msg)}"
Expand All @@ -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, "<b>[ChatTools]</b> Загружаю в файл...")

file = io.BytesIO(bytes(f"{text}\n\n{msg}"))
file.name = f"bots-{chat.id}.html"
Expand Down
6 changes: 3 additions & 3 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]
Expand All @@ -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"Запрос был <code>{args}</code>"
f"Запрос был <code>{args}</code>"
)

file = args
Expand Down
6 changes: 3 additions & 3 deletions notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down Expand Up @@ -95,9 +95,9 @@ async def notes_cmd(self, app: Client, message: types.Message):
return await utils.answer(
message, "Список заметок нет")

list_ = "\n".join(f"• <code>{note}</code>" for note in notes)
text = "\n".join(map("• <code>{}</code>".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 <название>"""
Expand Down
81 changes: 81 additions & 0 deletions randomreact.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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, "❌ <b>Это не чат</b>")

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"👍🏿 <b>Автоматическое выставление реакций включено!</b>\n"
f"Шанс срабатывания: <b>{chance}</b>%"
)

del chats[str(chat.id)]
self.db.set("RandomReact", "chats", chats)
return await utils.answer(
message, "👎 <b>Автоматическое выставление реакций отключено</b>")

@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)
48 changes: 48 additions & 0 deletions speedtest.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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, "<b>Запускаем тест...</b>")

result = speed_test()
text = (
f"<b>Результаты теста:</b>\n\n"
f"<b>Скачивание:</b> <code>{round(result['download'] / 2 ** 20 / 8, 2)}</code> <b>мб/с</b>\n"
f"<b>Загрузка:</b> <code>{round(result['upload'] / 2 ** 20 / 8, 2)}</code> <b>мб/c</b>\n"
f"<b>Задержка:</b> <code>{round(result['ping'], 2)}</code> <b>мc</b>"
)
return await utils.answer(
message, text)
46 changes: 46 additions & 0 deletions tagall.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

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"<a href=\"tg://user?id={member.user.id}\">\u2060</a>"
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

0 comments on commit 1a45ded

Please sign in to comment.