Some necessary modules
This commit is contained in:
273
modules/notes.py
Normal file
273
modules/notes.py
Normal file
@@ -0,0 +1,273 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pyrogram import Client, filters, errors
|
||||
from pyrogram.types import (
|
||||
Message,
|
||||
InputMediaPhoto,
|
||||
InputMediaVideo,
|
||||
InputMediaAudio,
|
||||
InputMediaDocument,
|
||||
)
|
||||
|
||||
from utils.db import db
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
# from utils.scripts import with_reply
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["save"], prefix) & filters.me)
|
||||
async def save_note(client: Client, message: Message):
|
||||
await message.edit("<b>Loading...</b>")
|
||||
|
||||
try:
|
||||
chat = await client.get_chat(db.get("core.notes", "chat_id", 0))
|
||||
except (errors.RPCError, ValueError, KeyError):
|
||||
# group is not accessible or isn't created
|
||||
chat = await client.create_supergroup(
|
||||
"Moon_Userbot_Notes_Filters", "Don't touch this group, please"
|
||||
)
|
||||
db.set("core.notes", "chat_id", chat.id)
|
||||
|
||||
chat_id = chat.id
|
||||
|
||||
if message.reply_to_message and len(message.text.split()) >= 2:
|
||||
note_name = message.text.split(maxsplit=1)[1]
|
||||
if message.reply_to_message.media_group_id:
|
||||
checking_note = db.get("core.notes", f"note{note_name}", False)
|
||||
if not checking_note:
|
||||
get_media_group = [
|
||||
_.message_id
|
||||
for _ in await client.get_media_group(
|
||||
message.chat.id, message.reply_to_message.message_id
|
||||
)
|
||||
]
|
||||
try:
|
||||
message_id = await client.forward_messages(
|
||||
chat_id, message.chat.id, get_media_group
|
||||
)
|
||||
except errors.ChatForwardsRestricted:
|
||||
await message.edit(
|
||||
"<b>Forwarding messages is restricted by chat admins</b>"
|
||||
)
|
||||
return
|
||||
note = {
|
||||
"MESSAGE_ID": str(message_id[1].message_id),
|
||||
"MEDIA_GROUP": True,
|
||||
"CHAT_ID": str(chat_id),
|
||||
}
|
||||
db.set("core.notes", f"note{note_name}", note)
|
||||
await message.edit(f"<b>Note {note_name} saved</b>")
|
||||
else:
|
||||
await message.edit("<b>This note already exists</b>")
|
||||
else:
|
||||
checking_note = db.get("core.notes", f"note{note_name}", False)
|
||||
if not checking_note:
|
||||
try:
|
||||
message_id = await message.reply_to_message.forward(chat_id)
|
||||
except errors.ChatForwardsRestricted:
|
||||
if message.reply_to_message.text:
|
||||
# manual copy
|
||||
message_id = await client.send_message(
|
||||
chat_id, message.reply_to_message.text
|
||||
)
|
||||
else:
|
||||
await message.edit(
|
||||
"<b>Forwarding messages is restricted by chat admins</b>"
|
||||
)
|
||||
return
|
||||
note = {
|
||||
"MEDIA_GROUP": False,
|
||||
"MESSAGE_ID": str(message_id.message_id),
|
||||
"CHAT_ID": str(chat_id),
|
||||
}
|
||||
db.set("core.notes", f"note{note_name}", note)
|
||||
await message.edit(f"<b>Note {note_name} saved</b>")
|
||||
else:
|
||||
await message.edit("<b>This note already exists</b>")
|
||||
elif len(message.text.split()) >= 3:
|
||||
note_name = message.text.split(maxsplit=1)[1].split()[0]
|
||||
checking_note = db.get("core.notes", f"note{note_name}", False)
|
||||
if not checking_note:
|
||||
message_id = await client.send_message(
|
||||
chat_id, message.text.split(note_name)[1].strip()
|
||||
)
|
||||
note = {
|
||||
"MEDIA_GROUP": False,
|
||||
"MESSAGE_ID": str(message_id.message_id),
|
||||
"CHAT_ID": str(chat_id),
|
||||
}
|
||||
db.set("core.notes", f"note{note_name}", note)
|
||||
await message.edit(f"<b>Note {note_name} saved</b>")
|
||||
else:
|
||||
await message.edit("<b>This note already exists</b>")
|
||||
else:
|
||||
await message.edit(f"<b>Example: <code>{prefix}save note_name</code></b>")
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["note"], prefix) & filters.me)
|
||||
async def note_send(client: Client, message: Message):
|
||||
if len(message.text.split()) >= 2:
|
||||
await message.edit("<b>Loading...</b>")
|
||||
|
||||
note_name = f"{message.text.split(maxsplit=1)[1]}"
|
||||
find_note = db.get("core.notes", f"note{note_name}", False)
|
||||
if find_note:
|
||||
try:
|
||||
await client.get_messages(
|
||||
int(find_note["CHAT_ID"]), int(find_note["MESSAGE_ID"])
|
||||
)
|
||||
except errors.RPCError:
|
||||
await message.edit(
|
||||
"<b>Sorry, but this note is unavaliable.\n\n"
|
||||
f"You can delete this note with "
|
||||
f"<code>{prefix}clear {note_name}</code></b>"
|
||||
)
|
||||
return
|
||||
|
||||
if find_note.get("MEDIA_GROUP"):
|
||||
messages_grouped = await client.get_media_group(
|
||||
int(find_note["CHAT_ID"]), int(find_note["MESSAGE_ID"])
|
||||
)
|
||||
media_grouped_list = []
|
||||
for _ in messages_grouped:
|
||||
if _.photo:
|
||||
if _.caption:
|
||||
media_grouped_list.append(
|
||||
InputMediaPhoto(
|
||||
_.photo.file_id, _.caption.markdown)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaPhoto(_.photo.file_id))
|
||||
elif _.video:
|
||||
if _.caption:
|
||||
if _.video.thumbs:
|
||||
media_grouped_list.append(
|
||||
InputMediaVideo(
|
||||
_.video.file_id,
|
||||
_.video.thumbs[0].file_id,
|
||||
_.caption.markdown,
|
||||
)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaVideo(
|
||||
_.video.file_id, _.caption.markdown)
|
||||
)
|
||||
elif _.video.thumbs:
|
||||
media_grouped_list.append(
|
||||
InputMediaVideo(
|
||||
_.video.file_id, _.video.thumbs[0].file_id
|
||||
)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaVideo(_.video.file_id))
|
||||
elif _.audio:
|
||||
if _.caption:
|
||||
media_grouped_list.append(
|
||||
InputMediaAudio(
|
||||
_.audio.file_id, _.caption.markdown)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaAudio(_.audio.file_id))
|
||||
elif _.document:
|
||||
if _.caption:
|
||||
if _.document.thumbs:
|
||||
media_grouped_list.append(
|
||||
InputMediaDocument(
|
||||
_.document.file_id,
|
||||
_.document.thumbs[0].file_id,
|
||||
_.caption.markdown,
|
||||
)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaDocument(
|
||||
_.document.file_id, _.caption.markdown
|
||||
)
|
||||
)
|
||||
elif _.document.thumbs:
|
||||
media_grouped_list.append(
|
||||
InputMediaDocument(
|
||||
_.document.file_id, _.document.thumbs[0].file_id
|
||||
)
|
||||
)
|
||||
else:
|
||||
media_grouped_list.append(
|
||||
InputMediaDocument(_.document.file_id)
|
||||
)
|
||||
if message.reply_to_message:
|
||||
await client.send_media_group(
|
||||
message.chat.id,
|
||||
media_grouped_list,
|
||||
reply_to_message_id=message.reply_to_message.message_id,
|
||||
)
|
||||
else:
|
||||
await client.send_media_group(message.chat.id, media_grouped_list)
|
||||
elif message.reply_to_message:
|
||||
await client.copy_message(
|
||||
message.chat.id,
|
||||
int(find_note["CHAT_ID"]),
|
||||
int(find_note["MESSAGE_ID"]),
|
||||
reply_to_message_id=message.reply_to_message.message_id,
|
||||
)
|
||||
else:
|
||||
await client.copy_message(
|
||||
message.chat.id,
|
||||
int(find_note["CHAT_ID"]),
|
||||
int(find_note["MESSAGE_ID"]),
|
||||
)
|
||||
await message.delete()
|
||||
else:
|
||||
await message.edit("<b>There is no such note</b>")
|
||||
else:
|
||||
await message.edit(f"<b>Example: <code>{prefix}note note_name</code></b>")
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["notes"], prefix) & filters.me)
|
||||
async def notes(_, message: Message):
|
||||
await message.edit("<b>Loading...</b>")
|
||||
text = "Available notes:\n\n"
|
||||
collection = db.get_collection("core.notes")
|
||||
for note in collection.keys():
|
||||
if note[:4] == "note":
|
||||
text += f"<code>{note[4:]}</code>\n"
|
||||
await message.edit(text)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["clear"], prefix) & filters.me)
|
||||
async def clear_note(_, message: Message):
|
||||
if len(message.text.split()) >= 2:
|
||||
note_name = message.text.split(maxsplit=1)[1]
|
||||
find_note = db.get("core.notes", f"note{note_name}", False)
|
||||
if find_note:
|
||||
db.remove("core.notes", f"note{note_name}")
|
||||
await message.edit(f"<b>Note {note_name} deleted</b>")
|
||||
else:
|
||||
await message.edit("<b>There is no such note</b>")
|
||||
else:
|
||||
await message.edit(f"<b>Example: <code>{prefix}clear note_name</code></b>")
|
||||
|
||||
|
||||
modules_help["notes"] = {
|
||||
"save [name]*": "Save note",
|
||||
"note [name]*": "Get saved note",
|
||||
"notes": "Get note list",
|
||||
"clear [name]*": "Delete note",
|
||||
}
|
||||
35
modules/ping.py
Normal file
35
modules/ping.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from time import perf_counter
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["ping", "p"], prefix) & filters.me)
|
||||
async def ping(_, message: Message):
|
||||
start = perf_counter()
|
||||
await message.edit("<b>Pong!</b>")
|
||||
end = perf_counter()
|
||||
await message.edit(f"<b>Pong! {round(end - start, 3)}s</b>")
|
||||
|
||||
|
||||
modules_help["ping"] = {
|
||||
"ping": "Check ping to Telegram servers",
|
||||
}
|
||||
41
modules/prefix.py
Normal file
41
modules/prefix.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.db import db
|
||||
from utils.scripts import restart
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
filters.command(["sp", "setprefix", "setprefix_Moon"], prefix) & filters.me
|
||||
)
|
||||
async def setprefix(_, message: Message):
|
||||
if len(message.command) > 1:
|
||||
pref = message.command[1]
|
||||
db.set("core.main", "prefix", pref)
|
||||
await message.edit(f"<b>Prefix [ <code>{pref}</code> ] is set!</b>")
|
||||
restart()
|
||||
else:
|
||||
await message.edit("<b>The prefix must not be empty!</b>")
|
||||
|
||||
|
||||
modules_help["prefix"] = {
|
||||
"setprefix [prefix]": "Set custom prefix",
|
||||
"setprefix_Moon [prefix]": "Set custom prefix",
|
||||
}
|
||||
53
modules/purge.py
Normal file
53
modules/purge.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 asyncio
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import with_reply
|
||||
|
||||
|
||||
@Client.on_message(filters.command("del", prefix) & filters.me)
|
||||
async def del_msg(_, message: Message):
|
||||
await message.delete()
|
||||
await message.reply_to_message.delete()
|
||||
|
||||
|
||||
@Client.on_message(filters.command("purge", prefix) & filters.me)
|
||||
@with_reply
|
||||
async def purge(client: Client, message: Message):
|
||||
chunk = []
|
||||
async for msg in client.iter_history(
|
||||
chat_id=message.chat.id,
|
||||
offset_id=message.reply_to_message.message_id,
|
||||
reverse=True,
|
||||
):
|
||||
chunk.append(msg.message_id)
|
||||
if len(chunk) >= 100:
|
||||
await client.delete_messages(message.chat.id, chunk)
|
||||
chunk = []
|
||||
await asyncio.sleep(1)
|
||||
|
||||
if len(chunk) > 0:
|
||||
await client.delete_messages(message.chat.id, chunk)
|
||||
|
||||
|
||||
modules_help["purge"] = {
|
||||
"purge [reply]": "Purge (delete all messages) chat from replied message to last",
|
||||
"del [reply]": "Delete replied message",
|
||||
}
|
||||
91
modules/python.py
Normal file
91
modules/python.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from io import StringIO
|
||||
from contextlib import redirect_stdout
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
from utils.db import db
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@Client.on_message(
|
||||
filters.command(["ex", "exec", "py", "exnoedit"], prefix) & filters.me
|
||||
)
|
||||
def user_exec(client: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
message.edit("<b>Code to execute isn't provided</b>")
|
||||
return
|
||||
|
||||
reply = message.reply_to_message
|
||||
|
||||
code = message.text.split(maxsplit=1)[1]
|
||||
stdout = StringIO()
|
||||
|
||||
message.edit("<b>Executing...</b>")
|
||||
|
||||
try:
|
||||
with redirect_stdout(stdout):
|
||||
exec(code)
|
||||
text = (
|
||||
"<b>Code:</b>\n"
|
||||
f"<code>{code}</code>\n\n"
|
||||
"<b>Result</b>:\n"
|
||||
f"<code>{stdout.getvalue()}</code>"
|
||||
)
|
||||
if message.command[0] == "exnoedit":
|
||||
message.reply(text)
|
||||
else:
|
||||
message.edit(text)
|
||||
except Exception as e:
|
||||
message.edit(format_exc(e))
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@Client.on_message(filters.command(["ev", "eval"], prefix) & filters.me)
|
||||
def user_eval(client: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
message.edit("<b>Code to eval isn't provided</b>")
|
||||
return
|
||||
|
||||
reply = message.reply_to_message
|
||||
|
||||
code = message.text.split(maxsplit=1)[1]
|
||||
|
||||
try:
|
||||
result = eval(code)
|
||||
message.edit(
|
||||
"<b>Expression:</b>\n"
|
||||
f"<code>{code}</code>\n\n"
|
||||
"<b>Result</b>:\n"
|
||||
f"<code>{result}</code>"
|
||||
)
|
||||
except Exception as e:
|
||||
message.edit(format_exc(e))
|
||||
|
||||
|
||||
modules_help["python"] = {
|
||||
"ex [python code]": "Execute Python code",
|
||||
"exnoedit [python code]": "Execute Python code and return result with reply",
|
||||
"eval [python code]": "Eval Python code",
|
||||
}
|
||||
33
modules/say.py
Normal file
33
modules/say.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["say", "s"], prefix) & filters.me)
|
||||
async def say(_, message: Message):
|
||||
if len(message.command) == 1:
|
||||
return
|
||||
command = " ".join(message.command[1:])
|
||||
await message.edit(f"<code>{command}</code>")
|
||||
|
||||
|
||||
modules_help["say"] = {
|
||||
"say [command]*": "Send message that won't be interpreted by userbot",
|
||||
}
|
||||
58
modules/sendmod.py
Normal file
58
modules/sendmod.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 os
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc, format_module_help, format_small_module_help
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["sendmod", "sm"], prefix) & filters.me)
|
||||
async def sendmod(client: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
await message.edit("<b>Module name to send is not provided</b>")
|
||||
return
|
||||
|
||||
await message.edit("<b>Dispatching...</b>")
|
||||
try:
|
||||
module_name = message.command[1].lower()
|
||||
if module_name in modules_help:
|
||||
text = format_module_help(module_name)
|
||||
if len(text) >= 1024:
|
||||
text = format_small_module_help(module_name)
|
||||
if os.path.isfile(f"modules/{module_name}.py"):
|
||||
await client.send_document(
|
||||
message.chat.id, f"modules/{module_name}.py", caption=text
|
||||
)
|
||||
elif os.path.isfile(f"modules/custom_modules/{module_name.lower()}.py"):
|
||||
await client.send_document(
|
||||
message.chat.id,
|
||||
f"modules/custom_modules/{module_name}.py",
|
||||
caption=text,
|
||||
)
|
||||
await message.delete()
|
||||
else:
|
||||
await message.edit(f"<b>Module {module_name} not found!</b>")
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
|
||||
|
||||
modules_help["sendmod"] = {
|
||||
"sendmod [module_name]": "Send module to interlocutor",
|
||||
}
|
||||
124
modules/sessionkiller.py
Normal file
124
modules/sessionkiller.py
Normal file
@@ -0,0 +1,124 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 time
|
||||
from datetime import datetime
|
||||
from html import escape
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram import ContinuePropagation
|
||||
from pyrogram.errors import RPCError
|
||||
from pyrogram.raw.functions.account import GetAuthorizations, ResetAuthorization
|
||||
from pyrogram.raw.types import UpdateServiceNotification
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.db import db
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
auth_hashes = db.get("core.sessionkiller", "auths_hashes", [])
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["sessionkiller", "sk"], prefix) & filters.me)
|
||||
async def sessionkiller(client: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
if db.get("core.sessionkiller", "enabled", False):
|
||||
await message.edit(
|
||||
"<b>Sessionkiller status: enabled\n"
|
||||
f"You can disable it with <code>{prefix}sessionkiller disable</code></b>"
|
||||
)
|
||||
else:
|
||||
await message.edit(
|
||||
"<b>Sessionkiller status: disabled\n"
|
||||
f"You can enable it with <code>{prefix}sessionkiller enable</code></b>"
|
||||
)
|
||||
elif message.command[1] in ["enable", "on", "1", "yes", "true"]:
|
||||
db.set("core.sessionkiller", "enabled", True)
|
||||
await message.edit("<b>Sessionkiller enabled!</b>")
|
||||
|
||||
db.set(
|
||||
"core.sessionkiller",
|
||||
"auths_hashes",
|
||||
[
|
||||
auth["hash"]
|
||||
for auth in (await client.send(GetAuthorizations()))["authorizations"]
|
||||
],
|
||||
)
|
||||
elif message.command[1] in ["disable", "off", "0", "no", "false"]:
|
||||
db.set("core.sessionkiller", "enabled", False)
|
||||
await message.edit("<b>Sessionkiller disabled!</b>")
|
||||
else:
|
||||
await message.edit(f"<b>Usage: {prefix}sessionkiller [enable|disable]</b>")
|
||||
|
||||
|
||||
@Client.on_raw_update()
|
||||
async def check_new_login(client: Client, update: UpdateServiceNotification, _, __):
|
||||
if not isinstance(update, UpdateServiceNotification) or not update.type.startswith(
|
||||
"auth"
|
||||
):
|
||||
raise ContinuePropagation
|
||||
if not db.get("core.sessionkiller", "enabled", False):
|
||||
raise ContinuePropagation
|
||||
authorizations = (await client.send(GetAuthorizations()))["authorizations"]
|
||||
for auth in authorizations:
|
||||
if auth.current:
|
||||
continue
|
||||
if auth["hash"] not in auth_hashes:
|
||||
# found new unexpected login
|
||||
try:
|
||||
await client.send(ResetAuthorization(hash=auth.hash))
|
||||
except RPCError:
|
||||
info_text = (
|
||||
"Someone tried to log in to your account. You can see this report because you"
|
||||
"turned on this feature. But I couldn't terminate attacker's session and "
|
||||
"⚠ <b>you must reset it manually</b>. You should change your 2FA password "
|
||||
"(if enabled), or set it.\n"
|
||||
)
|
||||
else:
|
||||
info_text = (
|
||||
"Someone tried to log in to your account. Since you have enabled "
|
||||
"this feature, I deleted the attacker's session from your account. "
|
||||
"You should change your 2FA password (if enabled), or set it.\n"
|
||||
)
|
||||
logined_time = datetime.utcfromtimestamp(auth.date_created).strftime(
|
||||
"%d-%m-%Y %H-%M-%S UTC"
|
||||
)
|
||||
full_report = (
|
||||
"<b>!!! ACTION REQUIRED !!!</b>\n"
|
||||
+ info_text
|
||||
+ "Below is the information about the attacker that I got.\n\n"
|
||||
f"Unique authorization hash: <code>{auth.hash}</code> (not valid anymore)\n"
|
||||
f"Device model: <code>{escape(auth.device_model)}</code>\n"
|
||||
f"Platform: <code>{escape(auth.platform)}</code>\n"
|
||||
f"API ID: <code>{auth.api_id}</code>\n"
|
||||
f"App name: <code>{escape(auth.app_name)}</code>\n"
|
||||
f"App version: <code>{auth.app_version}</code>\n"
|
||||
f"Logined at: <code>{logined_time}</code>\n"
|
||||
f"IP: <code>{auth.ip}</code>\n"
|
||||
f"Country: <code>{auth.country}</code>\n"
|
||||
f'Official app: <b>{"yes" if auth.official_app else "no"}</b>\n\n'
|
||||
f"<b>It is you? Type <code>{prefix}sk off</code> and try logging "
|
||||
f"in again.</b>"
|
||||
)
|
||||
# schedule sending report message so user will get notification
|
||||
schedule_date = int(time.time() + 3)
|
||||
await client.send_message("me", full_report, schedule_date=schedule_date)
|
||||
return
|
||||
|
||||
|
||||
modules_help["sessionkiller"] = {
|
||||
"sessionkiller [enable|disable]": "When enabled, every new session will be terminated.\n"
|
||||
"Useful for additional protection for your account"
|
||||
}
|
||||
60
modules/shell.py
Normal file
60
modules/shell.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from subprocess import Popen, PIPE, TimeoutExpired
|
||||
import os
|
||||
from time import perf_counter
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["shell", "sh"], prefix) & filters.me)
|
||||
async def shell(_, message: Message):
|
||||
if len(message.command) < 2:
|
||||
return await message.edit("<b>Specify the command in message text</b>")
|
||||
cmd_text = message.text.split(maxsplit=1)[1]
|
||||
cmd_obj = Popen(
|
||||
cmd_text,
|
||||
shell=True,
|
||||
stdout=PIPE,
|
||||
stderr=PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
char = "#" if os.getuid() == 0 else "$"
|
||||
text = f"<b>{char}</b> <code>{cmd_text}</code>\n\n"
|
||||
|
||||
await message.edit(text + "<b>Running...</b>")
|
||||
try:
|
||||
start_time = perf_counter()
|
||||
stdout, stderr = cmd_obj.communicate(timeout=60)
|
||||
except TimeoutExpired:
|
||||
text += "<b>Timeout expired (60 seconds)</b>"
|
||||
else:
|
||||
stop_time = perf_counter()
|
||||
if stdout:
|
||||
text += "<b>Output:</b>\n" f"<code>{stdout}</code>\n\n"
|
||||
if stderr:
|
||||
text += "<b>Error:</b>\n" f"<code>{stderr}</code>\n\n"
|
||||
text += f"<b>Completed in {round(stop_time - start_time, 5)} seconds with code {cmd_obj.returncode}</b>"
|
||||
await message.edit(text)
|
||||
cmd_obj.kill()
|
||||
|
||||
|
||||
modules_help["shell"] = {"sh [command]*": "Execute command in shell"}
|
||||
54
modules/spam.py
Normal file
54
modules/spam.py
Normal file
@@ -0,0 +1,54 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 asyncio
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
commands = ["spam", "statspam", "slowspam", "fastspam"]
|
||||
|
||||
|
||||
@Client.on_message(filters.command(commands, prefix) & filters.me)
|
||||
async def spam(client: Client, message: Message):
|
||||
amount = int(message.command[1])
|
||||
text = " ".join(message.command[2:])
|
||||
|
||||
cooldown = {"spam": 0.15, "statspam": 0.1, "slowspam": 0.9, "fastspam": 0}
|
||||
|
||||
await message.delete()
|
||||
|
||||
for msg in range(amount):
|
||||
if message.reply_to_message:
|
||||
sent = await message.reply_to_message.reply(text)
|
||||
else:
|
||||
sent = await client.send_message(message.chat.id, text)
|
||||
|
||||
if message.command[0] == "statspam":
|
||||
await asyncio.sleep(0.1)
|
||||
await sent.delete()
|
||||
|
||||
await asyncio.sleep(cooldown[message.command[0]])
|
||||
|
||||
|
||||
modules_help["spam"] = {
|
||||
"spam [amount] [text]": "Start spam",
|
||||
"statspam [amount] [text]": "Send and delete",
|
||||
"fastspam [amount] [text]": "Start fast spam",
|
||||
"slowspam [amount] [text]": "Start slow spam",
|
||||
}
|
||||
419
modules/squotes.py
Normal file
419
modules/squotes.py
Normal file
@@ -0,0 +1,419 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 base64
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import requests
|
||||
from pyrogram import Client, filters, errors, types
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import with_reply, format_exc, resize_image
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["q", "quote"], prefix) & filters.me)
|
||||
@with_reply
|
||||
async def quote_cmd(client: Client, message: types.Message):
|
||||
if len(message.command) > 1 and message.command[1].isdigit():
|
||||
count = int(message.command[1])
|
||||
if count < 1:
|
||||
count = 1
|
||||
elif count > 15:
|
||||
count = 15
|
||||
else:
|
||||
count = 1
|
||||
|
||||
is_png = "!png" in message.command or "!file" in message.command
|
||||
send_for_me = "!me" in message.command or "!ls" in message.command
|
||||
no_reply = "!noreply" in message.command or "!nr" in message.command
|
||||
|
||||
messages = []
|
||||
|
||||
async for msg in client.iter_history(
|
||||
message.chat.id, offset_id=message.reply_to_message.message_id, reverse=True
|
||||
):
|
||||
if msg.empty:
|
||||
continue
|
||||
if msg.message_id >= message.message_id:
|
||||
break
|
||||
if no_reply:
|
||||
msg.reply_to_message = None
|
||||
|
||||
messages.append(msg)
|
||||
|
||||
if len(messages) >= count:
|
||||
break
|
||||
|
||||
if send_for_me:
|
||||
await message.delete()
|
||||
message = await client.send_message("me", "<b>Generating...</b>")
|
||||
else:
|
||||
await message.edit("<b>Generating...</b>")
|
||||
|
||||
url = "https://quotes.fl1yd.su/generate"
|
||||
params = {
|
||||
"messages": [
|
||||
await render_message(client, msg) for msg in messages if not msg.empty
|
||||
],
|
||||
"quote_color": "#162330",
|
||||
"text_color": "#fff",
|
||||
}
|
||||
|
||||
response = requests.post(url, json=params)
|
||||
if not response.ok:
|
||||
return await message.edit(
|
||||
f"<b>Quotes API error!</b>\n" f"<code>{response.text}</code>"
|
||||
)
|
||||
|
||||
resized = resize_image(
|
||||
BytesIO(response.content), img_type="PNG" if is_png else "WEBP"
|
||||
)
|
||||
await message.edit("<b>Sending...</b>")
|
||||
|
||||
try:
|
||||
func = client.send_document if is_png else client.send_sticker
|
||||
chat_id = "me" if send_for_me else message.chat.id
|
||||
await func(chat_id, resized)
|
||||
except errors.RPCError as e: # no rights to send stickers, etc
|
||||
await message.edit(format_exc(e))
|
||||
else:
|
||||
await message.delete()
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["fq", "fakequote"], prefix) & filters.me)
|
||||
@with_reply
|
||||
async def fake_quote_cmd(client: Client, message: types.Message):
|
||||
is_png = "!png" in message.command or "!file" in message.command
|
||||
send_for_me = "!me" in message.command or "!ls" in message.command
|
||||
no_reply = "!noreply" in message.command or "!nr" in message.command
|
||||
|
||||
fake_quote_text = " ".join(
|
||||
[
|
||||
arg
|
||||
for arg in message.command[1:]
|
||||
if arg not in ["!png", "!file", "!me", "!ls", "!noreply", "!nr"]
|
||||
] # remove some special arg words
|
||||
)
|
||||
|
||||
if not fake_quote_text:
|
||||
return await message.edit("<b>Fake quote text is empty</b>")
|
||||
|
||||
q_message = await client.get_messages(
|
||||
message.chat.id, message.reply_to_message.message_id
|
||||
)
|
||||
q_message.text = fake_quote_text
|
||||
q_message.entities = None
|
||||
if no_reply:
|
||||
q_message.reply_to_message = None
|
||||
|
||||
if send_for_me:
|
||||
await message.delete()
|
||||
message = await client.send_message("me", "<b>Generating...</b>")
|
||||
else:
|
||||
await message.edit("<b>Generating...</b>")
|
||||
|
||||
url = "https://quotes.fl1yd.su/generate"
|
||||
params = {
|
||||
"messages": [await render_message(client, q_message)],
|
||||
"quote_color": "#162330",
|
||||
"text_color": "#fff",
|
||||
}
|
||||
|
||||
response = requests.post(url, json=params)
|
||||
if not response.ok:
|
||||
return await message.edit(
|
||||
f"<b>Quotes API error!</b>\n" f"<code>{response.text}</code>"
|
||||
)
|
||||
|
||||
resized = resize_image(
|
||||
BytesIO(response.content), img_type="PNG" if is_png else "WEBP"
|
||||
)
|
||||
await message.edit("<b>Sending...</b>")
|
||||
|
||||
try:
|
||||
func = client.send_document if is_png else client.send_sticker
|
||||
chat_id = "me" if send_for_me else message.chat.id
|
||||
await func(chat_id, resized)
|
||||
except errors.RPCError as e: # no rights to send stickers, etc
|
||||
await message.edit(format_exc(e))
|
||||
else:
|
||||
await message.delete()
|
||||
|
||||
|
||||
files_cache = {}
|
||||
|
||||
|
||||
async def render_message(app: Client, message: types.Message) -> dict:
|
||||
async def get_file(file_id) -> str:
|
||||
if file_id in files_cache:
|
||||
return files_cache[file_id]
|
||||
|
||||
file_name = await app.download_media(file_id)
|
||||
with open(file_name, "rb") as f:
|
||||
content = f.read()
|
||||
os.remove(file_name)
|
||||
data = base64.b64encode(content).decode()
|
||||
files_cache[file_id] = data
|
||||
return data
|
||||
|
||||
# text
|
||||
if message.photo:
|
||||
text = message.caption if message.caption else ""
|
||||
elif message.poll:
|
||||
text = get_poll_text(message.poll)
|
||||
elif message.sticker:
|
||||
text = ""
|
||||
else:
|
||||
text = get_reply_text(message)
|
||||
|
||||
# media
|
||||
if message.photo:
|
||||
media = await get_file(message.photo.file_id)
|
||||
elif message.sticker:
|
||||
media = await get_file(message.sticker.file_id)
|
||||
else:
|
||||
media = ""
|
||||
|
||||
# entities
|
||||
entities = []
|
||||
if message.entities:
|
||||
for entity in message.entities:
|
||||
entities.append(
|
||||
{
|
||||
"offset": entity.offset,
|
||||
"length": entity.length,
|
||||
"type": entity.type,
|
||||
}
|
||||
)
|
||||
|
||||
def move_forwards(msg: types.Message):
|
||||
if msg.forward_from:
|
||||
msg.from_user = msg.forward_from
|
||||
if msg.forward_sender_name:
|
||||
msg.from_user.id = 0
|
||||
msg.from_user.first_name = msg.forward_sender_name
|
||||
msg.from_user.last_name = ""
|
||||
if msg.forward_from_chat:
|
||||
msg.sender_chat = msg.forward_from_chat
|
||||
msg.from_user.id = 0
|
||||
if msg.forward_signature:
|
||||
msg.author_signature = msg.forward_signature
|
||||
|
||||
move_forwards(message)
|
||||
|
||||
# author
|
||||
author = {}
|
||||
if message.from_user and message.from_user.id != 0:
|
||||
from_user = message.from_user
|
||||
|
||||
author["id"] = from_user.id
|
||||
author["name"] = get_full_name(from_user)
|
||||
if message.author_signature:
|
||||
author["rank"] = message.author_signature
|
||||
elif message.chat.type != "supergroup" or message.forward_date:
|
||||
author["rank"] = ""
|
||||
else:
|
||||
try:
|
||||
member = await message.chat.get_member(from_user.id)
|
||||
except errors.UserNotParticipant:
|
||||
author["rank"] = ""
|
||||
else:
|
||||
author["rank"] = getattr(member, "title", "") or (
|
||||
"owner"
|
||||
if member.status == "creator"
|
||||
else "admin"
|
||||
if member.status == "administrator"
|
||||
else ""
|
||||
)
|
||||
|
||||
if from_user.photo:
|
||||
author["avatar"] = await get_file(from_user.photo.big_file_id)
|
||||
elif not from_user.photo and from_user.username:
|
||||
# may be user blocked us, we will try to get avatar via t.me
|
||||
t_me_page = requests.get(f"https://t.me/{from_user.username}").text
|
||||
sub = '<meta property="og:image" content='
|
||||
index = t_me_page.find(sub)
|
||||
if index != -1:
|
||||
link = t_me_page[index + 35:].split('"')
|
||||
if (
|
||||
len(link) > 0
|
||||
and link[0]
|
||||
and link[0] != "https://telegram.org/img/t_logo.png"
|
||||
):
|
||||
# found valid link
|
||||
avatar = requests.get(link[0]).content
|
||||
author["avatar"] = base64.b64encode(avatar).decode()
|
||||
else:
|
||||
author["avatar"] = ""
|
||||
else:
|
||||
author["avatar"] = ""
|
||||
else:
|
||||
author["avatar"] = ""
|
||||
elif message.from_user and message.from_user.id == 0:
|
||||
author["id"] = 0
|
||||
author["name"] = message.from_user.first_name
|
||||
author["rank"] = ""
|
||||
else:
|
||||
author["id"] = message.sender_chat.id
|
||||
author["name"] = message.sender_chat.title
|
||||
author["rank"] = "channel" if message.sender_chat.type == "channel" else ""
|
||||
|
||||
if message.sender_chat.photo:
|
||||
author["avatar"] = await get_file(message.sender_chat.photo.big_file_id)
|
||||
else:
|
||||
author["avatar"] = ""
|
||||
author["via_bot"] = message.via_bot.username if message.via_bot else ""
|
||||
|
||||
# reply
|
||||
reply = {}
|
||||
reply_msg = message.reply_to_message
|
||||
if reply_msg and not reply_msg.empty:
|
||||
move_forwards(reply_msg)
|
||||
|
||||
if reply_msg.from_user:
|
||||
reply["id"] = reply_msg.from_user.id
|
||||
reply["name"] = get_full_name(reply_msg.from_user)
|
||||
else:
|
||||
reply["id"] = reply_msg.sender_chat.id
|
||||
reply["name"] = reply_msg.sender_chat.title
|
||||
|
||||
reply["text"] = get_reply_text(reply_msg)
|
||||
|
||||
return {
|
||||
"text": text,
|
||||
"media": media,
|
||||
"entities": entities,
|
||||
"author": author,
|
||||
"reply": reply,
|
||||
}
|
||||
|
||||
|
||||
def get_audio_text(audio: types.Audio) -> str:
|
||||
if audio.title and audio.performer:
|
||||
return f" ({audio.title} — {audio.performer})"
|
||||
elif audio.title:
|
||||
return f" ({audio.title})"
|
||||
elif audio.performer:
|
||||
return f" ({audio.performer})"
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
def get_reply_text(reply: types.Message) -> str:
|
||||
return (
|
||||
"📷 Photo" + ("\n" + reply.caption if reply.caption else "")
|
||||
if reply.photo
|
||||
else get_reply_poll_text(reply.poll)
|
||||
if reply.poll
|
||||
else "📍 Location"
|
||||
if reply.location or reply.venue
|
||||
else "👤 Contact"
|
||||
if reply.contact
|
||||
else "🖼 GIF"
|
||||
if reply.animation
|
||||
else "🎧 Music" + get_audio_text(reply.audio)
|
||||
if reply.audio
|
||||
else "📹 Video"
|
||||
if reply.video
|
||||
else "📹 Videomessage"
|
||||
if reply.video_note
|
||||
else "🎵 Voice"
|
||||
if reply.voice
|
||||
else (reply.sticker.emoji + " " if reply.sticker.emoji else "") + "Sticker"
|
||||
if reply.sticker
|
||||
else "💾 File " + reply.document.file_name
|
||||
if reply.document
|
||||
else "🎮 Game"
|
||||
if reply.game
|
||||
else "🎮 set new record"
|
||||
if reply.game_high_score
|
||||
else f"{reply.dice.emoji} - {reply.dice.value}"
|
||||
if reply.dice
|
||||
else (
|
||||
"👤 joined the group"
|
||||
if reply.new_chat_members[0].id == reply.from_user.id
|
||||
else "👤 invited %s to the group"
|
||||
% (get_full_name(reply.new_chat_members[0]))
|
||||
)
|
||||
if reply.new_chat_members
|
||||
else (
|
||||
"👤 left the group"
|
||||
if reply.left_chat_member.id == reply.from_user.id
|
||||
else "👤 removed %s" % (get_full_name(reply.left_chat_member))
|
||||
)
|
||||
if reply.left_chat_member
|
||||
else f"✏ changed group name to {reply.new_chat_title}"
|
||||
if reply.new_chat_title
|
||||
else "🖼 changed group photo"
|
||||
if reply.new_chat_photo
|
||||
else "🖼 removed group photo"
|
||||
if reply.delete_chat_photo
|
||||
else "📍 pinned message"
|
||||
if reply.pinned_message
|
||||
else "🎤 started a new video chat"
|
||||
if reply.voice_chat_started
|
||||
else "🎤 ended the video chat"
|
||||
if reply.voice_chat_ended
|
||||
else "🎤 invited participants to the video chat"
|
||||
if reply.voice_chat_members_invited
|
||||
else "👥 created the group"
|
||||
if reply.group_chat_created or reply.supergroup_chat_created
|
||||
else "👥 created the channel"
|
||||
if reply.channel_chat_created
|
||||
else reply.text or "unsupported message"
|
||||
)
|
||||
|
||||
|
||||
def get_poll_text(poll: types.Poll) -> str:
|
||||
text = get_reply_poll_text(poll) + "\n"
|
||||
|
||||
text += poll.question + "\n"
|
||||
for option in poll.options:
|
||||
text += f"- {option.text}"
|
||||
if option.voter_count > 0:
|
||||
text += f" ({option.voter_count} voted)"
|
||||
text += "\n"
|
||||
|
||||
text += f"Total: {poll.total_voter_count} voted"
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def get_reply_poll_text(poll: types.Poll) -> str:
|
||||
if poll.is_anonymous:
|
||||
text = "📊 Anonymous poll" if poll.type == "regular" else "📊 Anonymous quiz"
|
||||
else:
|
||||
text = "📊 Poll" if poll.type == "regular" else "📊 Quiz"
|
||||
if poll.is_closed:
|
||||
text += " (closed)"
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def get_full_name(user: types.User) -> str:
|
||||
name = user.first_name
|
||||
if user.last_name:
|
||||
name += " " + user.last_name
|
||||
return name
|
||||
|
||||
|
||||
modules_help["squotes"] = {
|
||||
"q [reply]* [count 1-15] [!png] [!me] [!noreply]": "Generate a quote\n"
|
||||
"Available options: !png — send as PNG, !me — send quote to"
|
||||
"saved messages, !noreply — generate quote without reply",
|
||||
"fq [reply]* [!png] [!me] [!noreply] [text]*": "Generate a fake quote",
|
||||
}
|
||||
132
modules/stickers.py
Normal file
132
modules/stickers.py
Normal file
@@ -0,0 +1,132 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 os
|
||||
from io import BytesIO
|
||||
|
||||
from pyrogram import Client, filters, types
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import (
|
||||
with_reply,
|
||||
interact_with,
|
||||
interact_with_to_delete,
|
||||
format_exc,
|
||||
resize_image,
|
||||
)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("kang", prefix) & filters.me)
|
||||
@with_reply
|
||||
async def kang(client: Client, message: types.Message):
|
||||
await message.edit("<b>Please wait...</b>")
|
||||
|
||||
if len(message.command) < 2:
|
||||
await message.edit(
|
||||
"<b>No arguments provided\n"
|
||||
f"Usage: <code>{prefix}kang [pack]* [emoji]</code></b>"
|
||||
)
|
||||
return
|
||||
|
||||
pack = message.command[1]
|
||||
if len(message.command) >= 3:
|
||||
emoji = message.command[2]
|
||||
else:
|
||||
emoji = "✨"
|
||||
|
||||
await client.unblock_user("@stickers")
|
||||
await interact_with(await client.send_message("@stickers", "/cancel"))
|
||||
await interact_with(await client.send_message("@stickers", "/addsticker"))
|
||||
|
||||
result = await interact_with(await client.send_message("@stickers", pack))
|
||||
if ".TGS" in result.text:
|
||||
await message.edit("<b>Animated packs aren't supported</b>")
|
||||
return
|
||||
if "StickerExample.psd" not in result.text:
|
||||
await message.edit(
|
||||
"<b>Stickerpack doesn't exitst. Create it using @Stickers bot (via /newpack command)</b>"
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
path = await message.reply_to_message.download()
|
||||
except ValueError:
|
||||
await message.edit(
|
||||
"<b>Replied message doesn't contain any downloadable media</b>"
|
||||
)
|
||||
return
|
||||
|
||||
resized = resize_image(path)
|
||||
os.remove(path)
|
||||
|
||||
await interact_with(await client.send_document("@stickers", resized))
|
||||
response = await interact_with(await client.send_message("@stickers", emoji))
|
||||
if "/done" in response.text:
|
||||
# ok
|
||||
await interact_with(await client.send_message("@stickers", "/done"))
|
||||
await client.delete_messages("@stickers", interact_with_to_delete)
|
||||
await message.edit(
|
||||
f"<b>Sticker added to <a href=https://t.me/addstickers/{pack}>pack</a></b>"
|
||||
)
|
||||
else:
|
||||
await message.edit("<b>Something went wrong. Check history with @stickers</b>")
|
||||
interact_with_to_delete.clear()
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["stp", "s2p", "stick2png"], prefix) & filters.me)
|
||||
@with_reply
|
||||
async def stick2png(client: Client, message: types.Message):
|
||||
try:
|
||||
await message.edit("<b>Downloading...</b>")
|
||||
|
||||
path = await message.reply_to_message.download()
|
||||
with open(path, "rb") as f:
|
||||
content = f.read()
|
||||
os.remove(path)
|
||||
|
||||
file_io = BytesIO(content)
|
||||
file_io.name = "sticker.png"
|
||||
|
||||
await client.send_document(message.chat.id, file_io)
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
else:
|
||||
await message.delete()
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["resize"], prefix) & filters.me)
|
||||
@with_reply
|
||||
async def resize_cmd(client: Client, message: types.Message):
|
||||
try:
|
||||
await message.edit("<b>Downloading...</b>")
|
||||
|
||||
path = await message.reply_to_message.download()
|
||||
resized = resize_image(path)
|
||||
resized.name = "image.png"
|
||||
os.remove(path)
|
||||
|
||||
await client.send_document(message.chat.id, resized)
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
else:
|
||||
await message.delete()
|
||||
|
||||
|
||||
modules_help["stickers"] = {
|
||||
"kang [reply]* [pack]* [emoji]": "Add sticker to defined pack",
|
||||
"stp [reply]*": "Convert replied sticker to PNG",
|
||||
"resize [reply]*": "Resize replied image to 512xN format",
|
||||
}
|
||||
90
modules/support.py
Normal file
90
modules/support.py
Normal file
@@ -0,0 +1,90 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
import random
|
||||
import datetime
|
||||
|
||||
from utils.misc import modules_help, prefix, userbot_version, python_version, gitrepo
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["support", "repo"], prefix) & filters.me)
|
||||
async def support(_, message: Message):
|
||||
devs = ["@Qbtaumai", "@moonub_chat"]
|
||||
random.shuffle(devs)
|
||||
|
||||
commands_count = 0.0
|
||||
for module in modules_help:
|
||||
for cmd in module:
|
||||
commands_count += 1
|
||||
|
||||
await message.edit(
|
||||
f"<b>Moon-Userbot\n\n"
|
||||
"GitHub: <a href=https://github.com/The-MoonTg-project/Moon-Userbot>Moon-Userbot/Moon-Userbot</a>\n"
|
||||
"Custom modules repository: <a href=https://github.com/The-MoonTg-project/custom_modules>"
|
||||
"Moon-Userbot/custom_modules</a>\n"
|
||||
"License: <a href=https://github.com/The-MoonTg-project/Moon-Userbot/blob/master/LICENSE>GNU GPL v3</a>\n\n"
|
||||
"Channel: @moonuserbot\n"
|
||||
"Custom modules: @moonub_modules\n"
|
||||
"Chat [RU]: @moonub_chat\n"
|
||||
f"Main developers: {', '.join(devs)}\n\n"
|
||||
f"Python version: {python_version}\n"
|
||||
f"Modules count: {len(modules_help) / 1}\n"
|
||||
f"Commands count: {commands_count}</b>",
|
||||
disable_web_page_preview=True,
|
||||
)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["version", "ver"], prefix) & filters.me)
|
||||
async def version(client: Client, message: Message):
|
||||
changelog = ""
|
||||
ub_version = ".".join(userbot_version.split(".")[:2])
|
||||
async for m in client.search_messages(
|
||||
"Moon_uB_cHaNgElOg", query=ub_version + "."
|
||||
):
|
||||
if ub_version in m.text:
|
||||
changelog = m.message_id
|
||||
|
||||
await message.delete()
|
||||
|
||||
remote_url = list(gitrepo.remote().urls)[0]
|
||||
commit_time = (
|
||||
datetime.datetime.fromtimestamp(gitrepo.head.commit.committed_date)
|
||||
.astimezone(datetime.timezone.utc)
|
||||
.strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||
)
|
||||
|
||||
await message.reply(
|
||||
f"<b>Moon Userbot version: {userbot_version}\n"
|
||||
f"Changelog </b><i><a href=https://t.me/moonuserbot/{changelog}>in channel</a></i>.<b>\n"
|
||||
f"Changelog written by </b><i>"
|
||||
f"<a href=tg://user?id=5254194517>\u2060</a>"
|
||||
f"<a href=https://t.me/Qbtaumai>♿️</a></i>\n\n"
|
||||
+ (
|
||||
f"<b>Branch: <a href={remote_url}/tree/{gitrepo.active_branch}>{gitrepo.active_branch}</a>\n"
|
||||
if gitrepo.active_branch != "master"
|
||||
else ""
|
||||
)
|
||||
+ f"Commit: <a href={remote_url}/commit/{gitrepo.head.commit.hexsha}>"
|
||||
f"{gitrepo.head.commit.hexsha[:7]}</a> by {gitrepo.head.commit.author.name}\n"
|
||||
f"Commit time: {commit_time}</b>",
|
||||
)
|
||||
|
||||
|
||||
modules_help["support"] = {
|
||||
"support": "Information about userbot",
|
||||
"version": "Check userbot version",
|
||||
}
|
||||
51
modules/switch.py
Normal file
51
modules/switch.py
Normal file
@@ -0,0 +1,51 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
ru_keys = (
|
||||
"""ёйцукенгшщзхъфывапролджэячсмитьбю.Ё"№;%:?ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ/ЯЧСМИТЬБЮ,"""
|
||||
)
|
||||
en_keys = (
|
||||
"""`qwertyuiop[]asdfghjkl;'zxcvbnm,./~@#$%^&QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?"""
|
||||
)
|
||||
table = str.maketrans(ru_keys + en_keys, en_keys + ru_keys)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["switch", "sw"], prefix) & filters.me)
|
||||
async def switch(client: Client, message: Message):
|
||||
if len(message.command) == 1:
|
||||
if message.reply_to_message:
|
||||
text = message.reply_to_message.text
|
||||
else:
|
||||
history = await client.get_history(message.chat.id, limit=2)
|
||||
if history and history[1].from_user.is_self and history[1].text:
|
||||
text = history[1].text
|
||||
else:
|
||||
await message.edit("<b>Text to switch not found</b>")
|
||||
return
|
||||
else:
|
||||
text = message.text.split(maxsplit=1)[1]
|
||||
|
||||
await message.edit(str.translate(text, table))
|
||||
|
||||
|
||||
modules_help["switch"] = {
|
||||
"sw [reply/text for switch]*": "Useful when tou forgot to change the keyboard layout",
|
||||
}
|
||||
75
modules/updater.py
Normal file
75
modules/updater.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix, requirements_list
|
||||
from utils.scripts import format_exc
|
||||
|
||||
|
||||
def restart(message: Message, restart_type):
|
||||
text = "1" if restart_type == "update" else "2"
|
||||
os.execvp(
|
||||
sys.executable,
|
||||
[
|
||||
sys.executable,
|
||||
"main.py",
|
||||
f"{message.chat.id}",
|
||||
f" {message.message_id}",
|
||||
f"{text}",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("restart", prefix) & filters.me)
|
||||
async def restart_cmd(_, message: Message):
|
||||
await message.edit("<b>Restarting...</b>")
|
||||
restart(message, "restart")
|
||||
|
||||
|
||||
@Client.on_message(filters.command("update", prefix) & filters.me)
|
||||
async def update(_, message: Message):
|
||||
try:
|
||||
await message.edit("<b>Updating: 1/4 (updating pip)</b>")
|
||||
subprocess.run([sys.executable, "-m", "pip", "install", "-U", "pip"])
|
||||
await message.edit("<b>Updating: 2/4 (git pull)</b>")
|
||||
subprocess.run(["git", "pull"])
|
||||
await message.edit("<b>Updating: 3/4 (updating libs from requirements.txt)</b>")
|
||||
subprocess.run(
|
||||
[sys.executable, "-m", "pip", "install", "-U", "-r", "requirements.txt"]
|
||||
)
|
||||
await message.edit(
|
||||
"<b>Updating: 4/4 (updating libs from requirements_list)</b>"
|
||||
)
|
||||
subprocess.run(
|
||||
[sys.executable, "-m", "pip", "install", "-U", *requirements_list]
|
||||
)
|
||||
await message.edit("<b>Updating: done! Restarting...</b>")
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
else:
|
||||
restart(message, "update")
|
||||
|
||||
|
||||
modules_help["updater"] = {
|
||||
"update": "Update the userbot. If new core modules are avaliable, they will be installed",
|
||||
"restart": "Restart userbot",
|
||||
}
|
||||
137
modules/url.py
Normal file
137
modules/url.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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 os
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.types import Message
|
||||
import requests
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc
|
||||
|
||||
|
||||
@Client.on_message(filters.command("short", prefix) & filters.me)
|
||||
async def short(_, message: Message):
|
||||
if len(message.command) > 1:
|
||||
link = message.text.split(maxsplit=1)[1]
|
||||
elif message.reply_to_message:
|
||||
link = message.reply_to_message.text
|
||||
else:
|
||||
await message.edit(f"<b>Usage: </b><code>{prefix}short [url to short]</code>")
|
||||
return
|
||||
|
||||
shortened = requests.get("https://clck.ru/--", data={"url": link}).text
|
||||
|
||||
await message.edit(shortened.replace("https://", ""), disable_web_page_preview=True)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("urldl", prefix) & filters.me)
|
||||
async def urldl(client: Client, message: Message):
|
||||
if len(message.command) > 1:
|
||||
link = message.text.split(maxsplit=1)[1]
|
||||
elif message.reply_to_message:
|
||||
link = message.reply_to_message.text
|
||||
else:
|
||||
await message.edit(
|
||||
f"<b>Usage: </b><code>{prefix}urldl [url to download]</code>"
|
||||
)
|
||||
return
|
||||
|
||||
await message.edit("<b>Downloading...</b>")
|
||||
file_name = "downloads/" + link.split("/")[-1]
|
||||
|
||||
try:
|
||||
resp = requests.get(link)
|
||||
resp.raise_for_status()
|
||||
|
||||
with open(file_name, "wb") as f:
|
||||
for chunk in resp.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
await message.edit("<b>Uploading...</b>")
|
||||
await client.send_document(message.chat.id, file_name)
|
||||
await message.delete()
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
finally:
|
||||
os.remove(file_name)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("upload", prefix) & filters.me)
|
||||
async def upload_cmd(_, message: Message):
|
||||
max_size = 512 * 1024 * 1024
|
||||
max_size_mb = 512
|
||||
|
||||
min_file_age = 31
|
||||
max_file_age = 180
|
||||
|
||||
await message.edit("<b>Downloading...</b>")
|
||||
|
||||
try:
|
||||
file_name = await message.download()
|
||||
except ValueError:
|
||||
try:
|
||||
file_name = await message.reply_to_message.download()
|
||||
except ValueError:
|
||||
await message.edit("<b>File to upload not found</b>")
|
||||
return
|
||||
|
||||
if os.path.getsize(file_name) > max_size:
|
||||
await message.edit(f"<b>Files longer than {max_size_mb}MB isn't supported</b>")
|
||||
os.remove(file_name)
|
||||
return
|
||||
|
||||
await message.edit("<b>Uploading...</b>")
|
||||
with open(file_name, "rb") as f:
|
||||
response = requests.post(
|
||||
"https://x0.at",
|
||||
files={"file": f},
|
||||
)
|
||||
|
||||
if response.ok:
|
||||
file_size_mb = os.path.getsize(file_name) / 1024 / 1024
|
||||
file_age = int(
|
||||
min_file_age
|
||||
+ (max_file_age - min_file_age) *
|
||||
((1 - (file_size_mb / max_size_mb)) ** 2)
|
||||
)
|
||||
url = response.text.replace("https://", "")
|
||||
await message.edit(
|
||||
f"<b>Your URL: {url}\nYour file will live {file_age} days</b>",
|
||||
disable_web_page_preview=True,
|
||||
)
|
||||
else:
|
||||
await message.edit(f"<b>API returned an error!\n" f"{response.text}</b>")
|
||||
|
||||
os.remove(file_name)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("webshot", prefix) & filters.me)
|
||||
async def webshot(client: Client, message: Message):
|
||||
try:
|
||||
user_link = message.command[1]
|
||||
await message.delete()
|
||||
full_link = f"https://webshot.deam.io/{user_link}/?delay=2000"
|
||||
await client.send_document(message.chat.id, full_link, caption=f"{user_link}")
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
|
||||
|
||||
modules_help["url"] = {
|
||||
"short [url]*": "short url",
|
||||
"urldl [url]*": "download url content",
|
||||
"upload [file|reply]*": "upload file to internet",
|
||||
"webshot [link]*": "Screenshot of web page",
|
||||
}
|
||||
115
modules/user_info.py
Normal file
115
modules/user_info.py
Normal file
@@ -0,0 +1,115 @@
|
||||
# Moon-Userbot - telegram userbot
|
||||
# Copyright (C) 2020-present Moon Userbot Organization
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.raw import functions
|
||||
from pyrogram.types import Message
|
||||
|
||||
from utils.misc import modules_help, prefix
|
||||
from utils.scripts import format_exc, interact_with, interact_with_to_delete
|
||||
|
||||
|
||||
@Client.on_message(filters.command("inf", prefix) & filters.me)
|
||||
async def get_user_inf(client: Client, message: Message):
|
||||
if len(message.command) >= 2:
|
||||
peer = await client.resolve_peer(message.command[1])
|
||||
elif message.reply_to_message and message.reply_to_message.from_user:
|
||||
peer = await client.resolve_peer(message.reply_to_message.from_user.id)
|
||||
else:
|
||||
peer = await client.resolve_peer("me")
|
||||
|
||||
response = await client.send(functions.users.GetFullUser(id=peer))
|
||||
|
||||
user = response.users[0]
|
||||
full_user = response.full_user
|
||||
|
||||
if user.username is None:
|
||||
username = "None"
|
||||
else:
|
||||
username = f"@{user.username}"
|
||||
about = "None" if full_user.about is None else full_user.about
|
||||
|
||||
user_info = f"""|=<b>Username: {username}
|
||||
|-Id: <code>{user.id}</code>
|
||||
|-Bot: <code>{user.bot}</code>
|
||||
|-Scam: <code>{user.scam}</code>
|
||||
|-Name: <code>{user.first_name}</code>
|
||||
|-Deleted: <code>{user.deleted}</code>
|
||||
|-BIO: <code>{about}</code>
|
||||
</b>"""
|
||||
await message.edit(user_info)
|
||||
|
||||
|
||||
@Client.on_message(filters.command("inffull", prefix) & filters.me)
|
||||
async def get_full_user_inf(client: Client, message: Message):
|
||||
await message.edit("<b>Receiving the information...</b>")
|
||||
|
||||
try:
|
||||
if len(message.command) >= 2:
|
||||
peer = await client.resolve_peer(message.command[1])
|
||||
elif message.reply_to_message and message.reply_to_message.from_user:
|
||||
peer = await client.resolve_peer(message.reply_to_message.from_user.id)
|
||||
else:
|
||||
peer = await client.resolve_peer("me")
|
||||
|
||||
response = await client.send(functions.users.GetFullUser(id=peer))
|
||||
|
||||
user = response.users[0]
|
||||
full_user = response.full_user
|
||||
|
||||
await client.unblock_user("@creationdatebot")
|
||||
try:
|
||||
response = await interact_with(
|
||||
await client.send_message("creationdatebot", f"/id {user.id}")
|
||||
)
|
||||
except RuntimeError:
|
||||
creation_date = "None"
|
||||
else:
|
||||
creation_date = response.text
|
||||
# await client.delete_messages("@creationdatebot", interact_with_to_delete)
|
||||
interact_with_to_delete.clear()
|
||||
|
||||
if user.username is None:
|
||||
username = "None"
|
||||
else:
|
||||
username = f"@{user.username}"
|
||||
about = "None" if full_user.about is None else full_user.about
|
||||
user_info = f"""|=<b>Username: {username}
|
||||
|-Id: <code>{user.id}</code>
|
||||
|-Account creation date: <code>{creation_date}</code>
|
||||
|-Bot: <code>{user.bot}</code>
|
||||
|-Scam: <code>{user.scam}</code>
|
||||
|-Name: <code>{user.first_name}</code>
|
||||
|-Deleted: <code>{user.deleted}</code>
|
||||
|-BIO: <code>{about}</code>
|
||||
|-Contact: <code>{user.contact}</code>
|
||||
|-Can pin message: <code>{full_user.can_pin_message}</code>
|
||||
|-Mutual contact: <code>{user.mutual_contact}</code>
|
||||
|-Access hash: <code>{user.access_hash}</code>
|
||||
|-Restricted: <code>{user.restricted}</code>
|
||||
|-Verified: <code>{user.verified}</code>
|
||||
|-Phone calls available: <code>{full_user.phone_calls_available}</code>
|
||||
|-Phone calls private: <code>{full_user.phone_calls_private}</code>
|
||||
|-Blocked: <code>{full_user.blocked}</code></b>"""
|
||||
await message.edit(user_info)
|
||||
except Exception as e:
|
||||
await message.edit(format_exc(e))
|
||||
|
||||
|
||||
modules_help["user_info"] = {
|
||||
"inf [reply|id|username]": "Get brief information about user",
|
||||
"inffull [reply|id|username": "Get full information about user",
|
||||
}
|
||||
Reference in New Issue
Block a user