diff --git a/.env b/.env
deleted file mode 100644
index 3589dc4b7cc2701bc6f573854a915ccbcdbf7862..0000000000000000000000000000000000000000
--- a/.env
+++ /dev/null
@@ -1,12 +0,0 @@
-API_ID = 28238386
-API_HASH = b466f3f2023129c2737f6af0f5a59efa
-BOT_TOKEN = 7872827994:AAE21CqczkEldf1IzCHn45tentXskDiS4Es
-ULOG_CHANNEL = -1002340006444
-FLOG_CHANNEL = -1002340006444
-DATABASE_URL = mongodb+srv://harshkr0095:Harsh8083@cluster0.bnqjd.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
-FQDN = 192.168.27.1
-HAS_SSL = False
-#MULTI_TOKEN1 = 12345678:bot_token_multi_client_1
-#MULTI_TOKEN2 = 12345678:bot_token_multi_client_2
-OWNER_ID = 987456321
-PORT = 8080
\ No newline at end of file
diff --git a/.gitattributes b/.gitattributes
index a6344aac8c09253b3b630fb776ae94478aa0275b..8dcc84f077d564e94703e7c59dbab6af184a3be3 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
+*.jpg filter=lfs diff=lfs merge=lfs -text
+*.otf filter=lfs diff=lfs merge=lfs -text
+*.ttf filter=lfs diff=lfs merge=lfs -text
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000000000000000000000000000000000000..fabd8716071171936b76c41aca01f38437559ab0
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,128 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+We as members, contributors, and leaders pledge to make participation in our
+community a harassment-free experience for everyone, regardless of age, body
+size, visible or invisible disability, ethnicity, sex characteristics, gender
+identity and expression, level of experience, education, socio-economic status,
+nationality, personal appearance, race, religion, or sexual identity
+and orientation.
+
+We pledge to act and interact in ways that contribute to an open, welcoming,
+diverse, inclusive, and healthy community.
+
+## Our Standards
+
+Examples of behavior that contributes to a positive environment for our
+community include:
+
+* Demonstrating empathy and kindness toward other people
+* Being respectful of differing opinions, viewpoints, and experiences
+* Giving and gracefully accepting constructive feedback
+* Accepting responsibility and apologizing to those affected by our mistakes,
+ and learning from the experience
+* Focusing on what is best not just for us as individuals, but for the
+ overall community
+
+Examples of unacceptable behavior include:
+
+* The use of sexualized language or imagery, and sexual attention or
+ advances of any kind
+* Trolling, insulting or derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or email
+ address, without their explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+ professional setting
+
+## Enforcement Responsibilities
+
+Community leaders are responsible for clarifying and enforcing our standards of
+acceptable behavior and will take appropriate and fair corrective action in
+response to any behavior that they deem inappropriate, threatening, offensive,
+or harmful.
+
+Community leaders have the right and responsibility to remove, edit, or reject
+comments, commits, code, wiki edits, issues, and other contributions that are
+not aligned to this Code of Conduct, and will communicate reasons for moderation
+decisions when appropriate.
+
+## Scope
+
+This Code of Conduct applies within all community spaces, and also applies when
+an individual is officially representing the community in public spaces.
+Examples of representing our community include using an official e-mail address,
+posting via an official social media account, or acting as an appointed
+representative at an online or offline event.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported to the community leaders responsible for enforcement at
+teamultroid@ultroid.tech.
+All complaints will be reviewed and investigated promptly and fairly.
+
+All community leaders are obligated to respect the privacy and security of the
+reporter of any incident.
+
+## Enforcement Guidelines
+
+Community leaders will follow these Community Impact Guidelines in determining
+the consequences for any action they deem in violation of this Code of Conduct:
+
+### 1. Correction
+
+**Community Impact**: Use of inappropriate language or other behavior deemed
+unprofessional or unwelcome in the community.
+
+**Consequence**: A private, written warning from community leaders, providing
+clarity around the nature of the violation and an explanation of why the
+behavior was inappropriate. A public apology may be requested.
+
+### 2. Warning
+
+**Community Impact**: A violation through a single incident or series
+of actions.
+
+**Consequence**: A warning with consequences for continued behavior. No
+interaction with the people involved, including unsolicited interaction with
+those enforcing the Code of Conduct, for a specified period of time. This
+includes avoiding interactions in community spaces as well as external channels
+like social media. Violating these terms may lead to a temporary or
+permanent ban.
+
+### 3. Temporary Ban
+
+**Community Impact**: A serious violation of community standards, including
+sustained inappropriate behavior.
+
+**Consequence**: A temporary ban from any sort of interaction or public
+communication with the community for a specified period of time. No public or
+private interaction with the people involved, including unsolicited interaction
+with those enforcing the Code of Conduct, is allowed during this period.
+Violating these terms may lead to a permanent ban.
+
+### 4. Permanent Ban
+
+**Community Impact**: Demonstrating a pattern of violation of community
+standards, including sustained inappropriate behavior, harassment of an
+individual, or aggression toward or disparagement of classes of individuals.
+
+**Consequence**: A permanent ban from any sort of public interaction within
+the community.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage],
+version 2.0, available at
+https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
+
+Community Impact Guidelines were inspired by [Mozilla's code of conduct
+enforcement ladder](https://github.com/mozilla/diversity).
+
+[homepage]: https://www.contributor-covenant.org
+
+For answers to common questions about this code of conduct, see the FAQ at
+https://www.contributor-covenant.org/faq. Translations are available at
+https://www.contributor-covenant.org/translations.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000000000000000000000000000000000000..a69d36986aa278af32dd2c262b039c5f9b358072
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,23 @@
+# Welcome To Contributing Guide
+Any contribution done to this repository will be appreciated! đ
+
+### About Ultroid
+- **Ultroid** is Telegram Userbot, which allow you to perform many task easily.
+- It's base core is a pip package named [`pyUltroid`](https://GitHub.com/TeamUltroid/pyUltroid).
+- This repository, contains Ultroid's official plugin files.
+- moreover, Ultroid User also have an option to get more plugins available at [`UltroidAddons`](https://github.com/TeamUltroid/UltroidAddons)
+
+### Issues
+- Search for existing Similar issues.
+- You can open a issue first before contributing, If it contain some major changes like `bug fixes` or `feature addition`.
+- If you are busy or getting trouble while making changes, you can just open the issue (explaining it).
+
+### Contributing
+- You can [fork](https://github.com/TeamUltroid/Ultroid/fork) this repository.
+- You can commits your changes now.
+- You can [Git-Squash](https://docs.github.com/en/get-started/using-git/about-git-rebase) your commits, if they are more. [Optional]
+- At last, You are ready to [`make a Pull Request`](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
+- Make sure that, your `Pull Request` contain an explaining title and issue number if it closes any open issue.
+
+### Thanks
+- Congrats! đŤ you have successfully made your Contribution to Ultroid.
diff --git a/Dockerfile b/Dockerfile
index 2ce9ad4f4e740fcefc63e54fc79536171857407a..482018ca5ca839e10aa3c8edd075f59fbf38f99c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,22 +1,63 @@
-# Use a minimal base image
-FROM ghcr.io/wolfi-dev/alpine-base
+FROM python:3.9.5-buster
-# Set environment variables
-ENV OLLAMA_VERSION=1.0.0
+# Fix apt sources for old Buster release
+RUN sed -i 's|deb.debian.org|archive.debian.org|g' /etc/apt/sources.list && \
+ sed -i 's|security.debian.org|archive.debian.org|g' /etc/apt/sources.list && \
+ sed -i '/stretch-updates/d' /etc/apt/sources.list && \
+ echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until
+
-# Install necessary packages
-RUN apk add --no-cache \
- curl \
- ca-certificates
+# Set timezone
+ENV TZ=Asia/Kolkata
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
-# Download and install Ollama
-RUN curl -L https://ollama.com/download/$OLLAMA_VERSION/ollama-linux-amd64.tar.gz | tar -xz -C /usr/local/bin
-# Create a directory for Ollama data
-RUN mkdir -p /root/.ollama
+# Install dependencies
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends \
+ neofetch \
+ git \
+ curl \
+ wget \
+ mediainfo \
+ ffmpeg && \
+ apt-get autoremove --purge -y && \
+ rm -rf /var/lib/apt/lists/*
-# Expose the default Ollama port
-EXPOSE 11434
+# Set working directory
+WORKDIR /Ult
-# Set the entry point
-ENTRYPOINT ["ollama", "serve"]
+# Copy the application code
+COPY . .
+
+RUN pip3 install --no-cache-dir -r reqs.txt
+RUN pip3 install -U pip
+RUN pip3 install -U redis
+
+RUN pip3 install --no-cache-dir -r addons.txt
+RUN pip3 install --no-cache-dir -r requirements.txt
+RUN pip3 install --no-cache-dir -r res*/st*/op*
+
+# Set appropriate permissions
+RUN chown -R 1000:0 /Ult \
+ && chown -R 1000:0 . \
+ && chmod 777 . \
+ && chmod 777 /usr \
+ && chown -R 1000:0 /usr \
+ && chmod -R 755 /Ult \
+ && chmod +x /Ult/start.sh
+
+# Install FFmpeg
+RUN wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz && \
+ wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz.md5 && \
+ md5sum -c ffmpeg-git-amd64-static.tar.xz.md5 && \
+ tar xvf ffmpeg-git-amd64-static.tar.xz && \
+ mv ffmpeg-git*/ffmpeg ffmpeg-git*/ffprobe /usr/local/bin/
+
+
+
+# Expose port
+EXPOSE 7860
+
+# Start the application
+CMD ["bash", "-c", "python3 server.py & python3 -m pyUltroid"]
\ No newline at end of file
diff --git a/FileStream/__init__.py b/FileStream/__init__.py
deleted file mode 100644
index 66d212f8d3b69767cadf0d22812d04f71e4d55ec..0000000000000000000000000000000000000000
--- a/FileStream/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-import time
-
-__version__ = "1.1.0"
-StartTime = time.time()
-
diff --git a/FileStream/__main__.py b/FileStream/__main__.py
deleted file mode 100644
index b010a886f27f14d1ef7e539584abffda32647a70..0000000000000000000000000000000000000000
--- a/FileStream/__main__.py
+++ /dev/null
@@ -1,77 +0,0 @@
-import sys
-import asyncio
-import logging
-import traceback
-import logging.handlers as handlers
-from FileStream.config import Telegram, Server
-from aiohttp import web
-from pyrogram import idle
-
-from FileStream.bot import FileStream
-from FileStream.server import web_server
-from FileStream.bot.clients import initialize_clients
-
-logging.basicConfig(
- level=logging.INFO,
- datefmt="%d/%m/%Y %H:%M:%S",
- format='[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s',
- handlers=[logging.StreamHandler(stream=sys.stdout),
- handlers.RotatingFileHandler("streambot.log", mode="a", maxBytes=104857600, backupCount=2, encoding="utf-8")],)
-
-logging.getLogger("aiohttp").setLevel(logging.ERROR)
-logging.getLogger("pyrogram").setLevel(logging.ERROR)
-logging.getLogger("aiohttp.web").setLevel(logging.ERROR)
-
-server = web.AppRunner(web_server())
-
-loop = asyncio.get_event_loop()
-
-async def start_services():
- print()
- if Telegram.SECONDARY:
- print("------------------ Starting as Secondary Server ------------------")
- else:
- print("------------------- Starting as Primary Server -------------------")
- print()
- print("-------------------- Initializing Telegram Bot --------------------")
-
-
- await FileStream.start()
- bot_info = await FileStream.get_me()
- FileStream.id = bot_info.id
- FileStream.username = bot_info.username
- FileStream.fname=bot_info.first_name
- print("------------------------------ DONE ------------------------------")
- print()
- print("---------------------- Initializing Clients ----------------------")
- await initialize_clients()
- print("------------------------------ DONE ------------------------------")
- print()
- print("--------------------- Initializing Web Server ---------------------")
- await server.setup()
- await web.TCPSite(server, Server.BIND_ADDRESS, Server.PORT).start()
- print("------------------------------ DONE ------------------------------")
- print()
- print("------------------------- Service Started -------------------------")
- print(" bot =>> {}".format(bot_info.first_name))
- if bot_info.dc_id:
- print(" DC ID =>> {}".format(str(bot_info.dc_id)))
- print(" URL =>> {}".format(Server.URL))
- print("------------------------------------------------------------------")
- await idle()
-
-async def cleanup():
- await server.cleanup()
- await FileStream.stop()
-
-if __name__ == "__main__":
- try:
- loop.run_until_complete(start_services())
- except KeyboardInterrupt:
- pass
- except Exception as err:
- logging.error(traceback.format_exc())
- finally:
- loop.run_until_complete(cleanup())
- loop.stop()
- print("------------------------ Stopped Services ------------------------")
\ No newline at end of file
diff --git a/FileStream/bot/__init__.py b/FileStream/bot/__init__.py
deleted file mode 100644
index bef7291172b036b5bbb70aaf6172085f32d0783d..0000000000000000000000000000000000000000
--- a/FileStream/bot/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from ..config import Telegram
-from pyrogram import Client
-
-if Telegram.SECONDARY:
- plugins=None
- no_updates=True
-else:
- plugins={"root": "FileStream/bot/plugins"}
- no_updates=None
-
-FileStream = Client(
- name="FileStream",
- api_id=Telegram.API_ID,
- api_hash=Telegram.API_HASH,
- workdir="FileStream",
- plugins=plugins,
- bot_token=Telegram.BOT_TOKEN,
- sleep_threshold=Telegram.SLEEP_THRESHOLD,
- workers=Telegram.WORKERS,
- no_updates=no_updates
-)
-
-multi_clients = {}
-work_loads = {}
-
diff --git a/FileStream/bot/clients.py b/FileStream/bot/clients.py
deleted file mode 100644
index 9dd0761aa14e707b4834aaa21a1471b4ad3d0486..0000000000000000000000000000000000000000
--- a/FileStream/bot/clients.py
+++ /dev/null
@@ -1,59 +0,0 @@
-import asyncio
-import logging
-from os import environ
-from ..config import Telegram
-from pyrogram import Client
-from . import multi_clients, work_loads, FileStream
-
-
-async def initialize_clients():
- all_tokens = dict(
- (c + 1, t)
- for c, (_, t) in enumerate(
- filter(
- lambda n: n[0].startswith("MULTI_TOKEN"), sorted(environ.items())
- )
- )
- )
- if not all_tokens:
- multi_clients[0] = FileStream
- work_loads[0] = 0
- print("No additional clients found, using default client")
- return
-
- async def start_client(client_id, token):
- try:
- if len(token) >= 100:
- session_string=token
- bot_token=None
- print(f'Starting Client - {client_id} Using Session String')
- else:
- session_string=None
- bot_token=token
- print(f'Starting Client - {client_id} Using Bot Token')
- if client_id == len(all_tokens):
- await asyncio.sleep(2)
- print("This will take some time, please wait...")
- client = await Client(
- name=str(client_id),
- api_id=Telegram.API_ID,
- api_hash=Telegram.API_HASH,
- bot_token=bot_token,
- sleep_threshold=Telegram.SLEEP_THRESHOLD,
- no_updates=True,
- session_string=session_string,
- in_memory=True,
- ).start()
- client.id = (await client.get_me()).id
- work_loads[client_id] = 0
- return client_id, client
- except Exception:
- logging.error(f"Failed starting Client - {client_id} Error:", exc_info=True)
-
- clients = await asyncio.gather(*[start_client(i, token) for i, token in all_tokens.items()])
- multi_clients.update(dict(clients))
- if len(multi_clients) != 1:
- Telegram.MULTI_CLIENT = True
- print("Multi-Client Mode Enabled")
- else:
- print("No additional clients were initialized, using default client")
diff --git a/FileStream/bot/plugins/admin.py b/FileStream/bot/plugins/admin.py
deleted file mode 100644
index cda3d035555a54c9f2943a556622c887f33b2498..0000000000000000000000000000000000000000
--- a/FileStream/bot/plugins/admin.py
+++ /dev/null
@@ -1,160 +0,0 @@
-import os
-import time
-import string
-import random
-import asyncio
-import aiofiles
-import datetime
-
-from FileStream.utils.broadcast_helper import send_msg
-from FileStream.utils.database import Database
-from FileStream.bot import FileStream
-from FileStream.server.exceptions import FIleNotFound
-from FileStream.config import Telegram, Server
-from pyrogram import filters, Client
-from pyrogram.types import Message
-from pyrogram.enums.parse_mode import ParseMode
-
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-broadcast_ids = {}
-
-
-@FileStream.on_message(filters.command("status") & filters.private & filters.user(Telegram.OWNER_ID))
-async def sts(c: Client, m: Message):
- await m.reply_text(text=f"""**Total Users in DB:** `{await db.total_users_count()}`
-**Banned Users in DB:** `{await db.total_banned_users_count()}`
-**Total Links Generated: ** `{await db.total_files()}`"""
- , parse_mode=ParseMode.MARKDOWN, quote=True)
-
-
-@FileStream.on_message(filters.command("ban") & filters.private & filters.user(Telegram.OWNER_ID))
-async def sts(b, m: Message):
- id = m.text.split("/ban ")[-1]
- if not await db.is_user_banned(int(id)):
- try:
- await db.ban_user(int(id))
- await db.delete_user(int(id))
- await m.reply_text(text=f"`{id}`** is Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
- if not str(id).startswith('-100'):
- await b.send_message(
- chat_id=id,
- text="**Your Banned to Use The Bot**",
- parse_mode=ParseMode.MARKDOWN,
- disable_web_page_preview=True
- )
- except Exception as e:
- await m.reply_text(text=f"**something went wrong: {e}** ", parse_mode=ParseMode.MARKDOWN, quote=True)
- else:
- await m.reply_text(text=f"`{id}`** is Already Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
-
-
-@FileStream.on_message(filters.command("unban") & filters.private & filters.user(Telegram.OWNER_ID))
-async def sts(b, m: Message):
- id = m.text.split("/unban ")[-1]
- if await db.is_user_banned(int(id)):
- try:
- await db.unban_user(int(id))
- await m.reply_text(text=f"`{id}`** is Unbanned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
- if not str(id).startswith('-100'):
- await b.send_message(
- chat_id=id,
- text="**Your Unbanned now Use can use The Bot**",
- parse_mode=ParseMode.MARKDOWN,
- disable_web_page_preview=True
- )
- except Exception as e:
- await m.reply_text(text=f"** something went wrong: {e}**", parse_mode=ParseMode.MARKDOWN, quote=True)
- else:
- await m.reply_text(text=f"`{id}`** is not Banned** ", parse_mode=ParseMode.MARKDOWN, quote=True)
-
-
-@FileStream.on_message(filters.command("broadcast") & filters.private & filters.user(Telegram.OWNER_ID) & filters.reply)
-async def broadcast_(c, m):
- all_users = await db.get_all_users()
- broadcast_msg = m.reply_to_message
- while True:
- broadcast_id = ''.join([random.choice(string.ascii_letters) for i in range(3)])
- if not broadcast_ids.get(broadcast_id):
- break
- out = await m.reply_text(
- text=f"Broadcast initiated! You will be notified with log file when all the users are notified."
- )
- start_time = time.time()
- total_users = await db.total_users_count()
- done = 0
- failed = 0
- success = 0
- broadcast_ids[broadcast_id] = dict(
- total=total_users,
- current=done,
- failed=failed,
- success=success
- )
- async with aiofiles.open('broadcast.txt', 'w') as broadcast_log_file:
- async for user in all_users:
- sts, msg = await send_msg(
- user_id=int(user['id']),
- message=broadcast_msg
- )
- if msg is not None:
- await broadcast_log_file.write(msg)
- if sts == 200:
- success += 1
- else:
- failed += 1
- if sts == 400:
- await db.delete_user(user['id'])
- done += 1
- if broadcast_ids.get(broadcast_id) is None:
- break
- else:
- broadcast_ids[broadcast_id].update(
- dict(
- current=done,
- failed=failed,
- success=success
- )
- )
- try:
- await out.edit_text(f"Broadcast Status\n\ncurrent: {done}\nfailed:{failed}\nsuccess: {success}")
- except:
- pass
- if broadcast_ids.get(broadcast_id):
- broadcast_ids.pop(broadcast_id)
- completed_in = datetime.timedelta(seconds=int(time.time() - start_time))
- await asyncio.sleep(3)
- await out.delete()
- if failed == 0:
- await m.reply_text(
- text=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
- quote=True
- )
- else:
- await m.reply_document(
- document='broadcast.txt',
- caption=f"broadcast completed in `{completed_in}`\n\nTotal users {total_users}.\nTotal done {done}, {success} success and {failed} failed.",
- quote=True
- )
- os.remove('broadcast.txt')
-
-
-@FileStream.on_message(filters.command("del") & filters.private & filters.user(Telegram.OWNER_ID))
-async def sts(c: Client, m: Message):
- file_id = m.text.split(" ")[-1]
- try:
- file_info = await db.get_file(file_id)
- except FIleNotFound:
- await m.reply_text(
- text=f"**ę°ÉŞĘá´ á´ĘĘá´á´á´
Ę á´
á´Ęá´á´á´á´
**",
- quote=True
- )
- return
- await db.delete_one_file(file_info['_id'])
- await db.count_links(file_info['user_id'], "-")
- await m.reply_text(
- text=f"**FÉŞĘá´ Dá´Ęá´á´á´á´
Sá´á´á´á´ssŇá´ĘĘĘ !** ",
- quote=True
- )
-
-
-
diff --git a/FileStream/bot/plugins/callback.py b/FileStream/bot/plugins/callback.py
deleted file mode 100644
index 4040a4d697a6f5e25efc6756daf06cd3235069d3..0000000000000000000000000000000000000000
--- a/FileStream/bot/plugins/callback.py
+++ /dev/null
@@ -1,198 +0,0 @@
-import datetime
-import math
-from FileStream import __version__
-from FileStream.bot import FileStream
-from FileStream.config import Telegram, Server
-from FileStream.utils.translation import LANG, BUTTON
-from FileStream.utils.bot_utils import gen_link
-from FileStream.utils.database import Database
-from FileStream.utils.human_readable import humanbytes
-from FileStream.server.exceptions import FIleNotFound
-from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
-from pyrogram.file_id import FileId, FileType, PHOTO_TYPES
-from pyrogram.enums.parse_mode import ParseMode
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-#---------------------[ START CMD ]---------------------#
-@FileStream.on_callback_query()
-async def cb_data(bot, update: CallbackQuery):
- usr_cmd = update.data.split("_")
- if usr_cmd[0] == "home":
- await update.message.edit_text(
- text=LANG.START_TEXT.format(update.from_user.mention, FileStream.username),
- disable_web_page_preview=True,
- reply_markup=BUTTON.START_BUTTONS
- )
- elif usr_cmd[0] == "help":
- await update.message.edit_text(
- text=LANG.HELP_TEXT.format(Telegram.OWNER_ID),
- disable_web_page_preview=True,
- reply_markup=BUTTON.HELP_BUTTONS
- )
- elif usr_cmd[0] == "about":
- await update.message.edit_text(
- text=LANG.ABOUT_TEXT.format(FileStream.fname, __version__),
- disable_web_page_preview=True,
- reply_markup=BUTTON.ABOUT_BUTTONS
- )
-
- #---------------------[ MY FILES CMD ]---------------------#
-
- elif usr_cmd[0] == "N/A":
- await update.answer("N/A", True)
- elif usr_cmd[0] == "close":
- await update.message.delete()
- elif usr_cmd[0] == "msgdelete":
- await update.message.edit_caption(
- caption= "**Cá´É´ŇÉŞĘá´ Ęá´á´ á´Ąá´É´á´ á´á´ á´
á´Ęá´á´á´ á´Ęá´ FÉŞĘá´**\n\n",
- reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Ęá´s", callback_data=f"msgdelyes_{usr_cmd[1]}_{usr_cmd[2]}"), InlineKeyboardButton("É´á´", callback_data=f"myfile_{usr_cmd[1]}_{usr_cmd[2]}")]])
- )
- elif usr_cmd[0] == "msgdelyes":
- await delete_user_file(usr_cmd[1], int(usr_cmd[2]), update)
- return
- elif usr_cmd[0] == "msgdelpvt":
- await update.message.edit_caption(
- caption= "**Cá´É´ŇÉŞĘá´ Ęá´á´ á´Ąá´É´á´ á´á´ á´
á´Ęá´á´á´ á´Ęá´ FÉŞĘá´**\n\n",
- reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Ęá´s", callback_data=f"msgdelpvtyes_{usr_cmd[1]}"), InlineKeyboardButton("É´á´", callback_data=f"mainstream_{usr_cmd[1]}")]])
- )
- elif usr_cmd[0] == "msgdelpvtyes":
- await delete_user_filex(usr_cmd[1], update)
- return
-
- elif usr_cmd[0] == "mainstream":
- _id = usr_cmd[1]
- reply_markup, stream_text = await gen_link(_id=_id)
- await update.message.edit_text(
- text=stream_text,
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True,
- reply_markup=reply_markup,
- )
-
- elif usr_cmd[0] == "userfiles":
- file_list, total_files = await gen_file_list_button(int(usr_cmd[1]), update.from_user.id)
- await update.message.edit_caption(
- caption="Total files: {}".format(total_files),
- reply_markup=InlineKeyboardMarkup(file_list)
- )
- elif usr_cmd[0] == "myfile":
- await gen_file_menu(usr_cmd[1], usr_cmd[2], update)
- return
- elif usr_cmd[0] == "sendfile":
- myfile = await db.get_file(usr_cmd[1])
- file_name = myfile['file_name']
- await update.answer(f"Sending File {file_name}")
- await update.message.reply_cached_media(myfile['file_id'], caption=f'**{file_name}**')
- else:
- await update.message.delete()
-
-
-
- #---------------------[ MY FILES FUNC ]---------------------#
-
-async def gen_file_list_button(file_list_no: int, user_id: int):
-
- file_range=[file_list_no*10-10+1, file_list_no*10]
- user_files, total_files=await db.find_files(user_id, file_range)
-
- file_list=[]
- async for x in user_files:
- file_list.append([InlineKeyboardButton(x["file_name"], callback_data=f"myfile_{x['_id']}_{file_list_no}")])
- if total_files > 10:
- file_list.append(
- [InlineKeyboardButton("â", callback_data="{}".format("userfiles_"+str(file_list_no-1) if file_list_no > 1 else 'N/A')),
- InlineKeyboardButton(f"{file_list_no}/{math.ceil(total_files/10)}", callback_data="N/A"),
- InlineKeyboardButton("âş", callback_data="{}".format("userfiles_"+str(file_list_no+1) if total_files > file_list_no*10 else 'N/A'))]
- )
- if not file_list:
- file_list.append(
- [InlineKeyboardButton("á´á´á´á´Ę", callback_data="N/A")])
- file_list.append([InlineKeyboardButton("á´Ęá´sá´", callback_data="close")])
- return file_list, total_files
-
-async def gen_file_menu(_id, file_list_no, update: CallbackQuery):
- try:
- myfile_info=await db.get_file(_id)
- except FIleNotFound:
- await update.answer("File Not Found")
- return
-
- file_id=FileId.decode(myfile_info['file_id'])
-
- if file_id.file_type in PHOTO_TYPES:
- file_type = "Image"
- elif file_id.file_type == FileType.VOICE:
- file_type = "Voice"
- elif file_id.file_type in (FileType.VIDEO, FileType.ANIMATION, FileType.VIDEO_NOTE):
- file_type = "Video"
- elif file_id.file_type == FileType.DOCUMENT:
- file_type = "Document"
- elif file_id.file_type == FileType.STICKER:
- file_type = "Sticker"
- elif file_id.file_type == FileType.AUDIO:
- file_type = "Audio"
- else:
- file_type = "Unknown"
-
- page_link = f"{Server.URL}watch/{myfile_info['_id']}"
- stream_link = f"{Server.URL}dl/{myfile_info['_id']}"
- if "video" in file_type.lower():
- MYFILES_BUTTONS = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("sá´Ęá´á´á´", url=page_link), InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)],
- [InlineKeyboardButton("ɢá´á´ ŇÉŞĘá´", callback_data=f"sendfile_{myfile_info['_id']}"),
- InlineKeyboardButton("Ęá´á´ á´á´á´ ŇÉŞĘá´", callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")],
- [InlineKeyboardButton("Ęá´á´á´", callback_data="userfiles_{}".format(file_list_no))]
- ]
- )
- else:
- MYFILES_BUTTONS = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)],
- [InlineKeyboardButton("ɢá´á´ ŇÉŞĘá´", callback_data=f"sendfile_{myfile_info['_id']}"),
- InlineKeyboardButton("Ęá´á´ á´á´á´ ŇÉŞĘá´", callback_data=f"msgdelete_{myfile_info['_id']}_{file_list_no}")],
- [InlineKeyboardButton("Ęá´á´á´", callback_data="userfiles_{}".format(file_list_no))]
- ]
- )
-
- TiMe = myfile_info['time']
- if type(TiMe) == float:
- date = datetime.datetime.fromtimestamp(TiMe)
- await update.edit_message_caption(
- caption="**File Name :** `{}`\n**File Size :** `{}`\n**File Type :** `{}`\n**Created On :** `{}`".format(myfile_info['file_name'],
- humanbytes(int(myfile_info['file_size'])),
- file_type,
- TiMe if isinstance(TiMe,str) else date.date()),
- reply_markup=MYFILES_BUTTONS )
-
-
-async def delete_user_file(_id, file_list_no: int, update:CallbackQuery):
-
- try:
- myfile_info=await db.get_file(_id)
- except FIleNotFound:
- await update.answer("File Already Deleted")
- return
-
- await db.delete_one_file(myfile_info['_id'])
- await db.count_links(update.from_user.id, "-")
- await update.message.edit_caption(
- caption= "**FÉŞĘá´ Dá´Ęá´á´á´á´
Sá´á´á´á´ssŇá´ĘĘĘ !**" + update.message.caption.replace("Cá´É´ŇÉŞĘá´ Ęá´á´ á´Ąá´É´á´ á´á´ á´
á´Ęá´á´á´ á´Ęá´ FÉŞĘá´", ""),
- reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Ęá´á´á´", callback_data=f"userfiles_1")]])
- )
-
-async def delete_user_filex(_id, update:CallbackQuery):
-
- try:
- myfile_info=await db.get_file(_id)
- except FIleNotFound:
- await update.answer("File Already Deleted")
- return
-
- await db.delete_one_file(myfile_info['_id'])
- await db.count_links(update.from_user.id, "-")
- await update.message.edit_caption(
- caption= "**FÉŞĘá´ Dá´Ęá´á´á´á´
Sá´á´á´á´ssŇá´ĘĘĘ !**\n\n",
- reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("á´Ęá´sá´", callback_data=f"close")]])
- )
-
diff --git a/FileStream/bot/plugins/start.py b/FileStream/bot/plugins/start.py
deleted file mode 100644
index 14da30dde441c7ae6149e01114669a30e5a7a730..0000000000000000000000000000000000000000
--- a/FileStream/bot/plugins/start.py
+++ /dev/null
@@ -1,149 +0,0 @@
-import logging
-import math
-from FileStream import __version__
-from FileStream.bot import FileStream
-from FileStream.server.exceptions import FIleNotFound
-from FileStream.utils.bot_utils import gen_linkx, verify_user
-from FileStream.config import Telegram
-from FileStream.utils.database import Database
-from FileStream.utils.translation import LANG, BUTTON
-from pyrogram import filters, Client
-from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
-from pyrogram.enums.parse_mode import ParseMode
-import asyncio
-
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-@FileStream.on_message(filters.command('start') & filters.private)
-async def start(bot: Client, message: Message):
- if not await verify_user(bot, message):
- return
- usr_cmd = message.text.split("_")[-1]
-
- if usr_cmd == "/start":
- if Telegram.START_PIC:
- await message.reply_photo(
- photo=Telegram.START_PIC,
- caption=LANG.START_TEXT.format(message.from_user.mention, FileStream.username),
- parse_mode=ParseMode.HTML,
- reply_markup=BUTTON.START_BUTTONS
- )
- else:
- await message.reply_text(
- text=LANG.START_TEXT.format(message.from_user.mention, FileStream.username),
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True,
- reply_markup=BUTTON.START_BUTTONS
- )
- else:
- if "stream_" in message.text:
- try:
- file_check = await db.get_file(usr_cmd)
- file_id = str(file_check['_id'])
- if file_id == usr_cmd:
- reply_markup, stream_text = await gen_linkx(m=message, _id=file_id,
- name=[FileStream.username, FileStream.fname])
- await message.reply_text(
- text=stream_text,
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True,
- reply_markup=reply_markup,
- quote=True
- )
-
- except FIleNotFound as e:
- await message.reply_text("File Not Found")
- except Exception as e:
- await message.reply_text("Something Went Wrong")
- logging.error(e)
-
- elif "file_" in message.text:
- try:
- file_check = await db.get_file(usr_cmd)
- db_id = str(file_check['_id'])
- file_id = file_check['file_id']
- file_name = file_check['file_name']
- if db_id == usr_cmd:
- filex = await message.reply_cached_media(file_id=file_id, caption=f'**{file_name}**')
- await asyncio.sleep(3600)
- try:
- await filex.delete()
- await message.delete()
- except Exception:
- pass
-
- except FIleNotFound as e:
- await message.reply_text("**File Not Found**")
- except Exception as e:
- await message.reply_text("Something Went Wrong")
- logging.error(e)
-
- else:
- await message.reply_text(f"**Invalid Command**")
-
-@FileStream.on_message(filters.private & filters.command(["about"]))
-async def start(bot, message):
- if not await verify_user(bot, message):
- return
- if Telegram.START_PIC:
- await message.reply_photo(
- photo=Telegram.START_PIC,
- caption=LANG.ABOUT_TEXT.format(FileStream.fname, __version__),
- parse_mode=ParseMode.HTML,
- reply_markup=BUTTON.ABOUT_BUTTONS
- )
- else:
- await message.reply_text(
- text=LANG.ABOUT_TEXT.format(FileStream.fname, __version__),
- disable_web_page_preview=True,
- reply_markup=BUTTON.ABOUT_BUTTONS
- )
-
-@FileStream.on_message((filters.command('help')) & filters.private)
-async def help_handler(bot, message):
- if not await verify_user(bot, message):
- return
- if Telegram.START_PIC:
- await message.reply_photo(
- photo=Telegram.START_PIC,
- caption=LANG.HELP_TEXT.format(Telegram.OWNER_ID),
- parse_mode=ParseMode.HTML,
- reply_markup=BUTTON.HELP_BUTTONS
- )
- else:
- await message.reply_text(
- text=LANG.HELP_TEXT.format(Telegram.OWNER_ID),
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True,
- reply_markup=BUTTON.HELP_BUTTONS
- )
-
-# ---------------------------------------------------------------------------------------------------
-
-@FileStream.on_message(filters.command('files') & filters.private)
-async def my_files(bot: Client, message: Message):
- if not await verify_user(bot, message):
- return
- user_files, total_files = await db.find_files(message.from_user.id, [1, 10])
-
- file_list = []
- async for x in user_files:
- file_list.append([InlineKeyboardButton(x["file_name"], callback_data=f"myfile_{x['_id']}_{1}")])
- if total_files > 10:
- file_list.append(
- [
- InlineKeyboardButton("â", callback_data="N/A"),
- InlineKeyboardButton(f"1/{math.ceil(total_files / 10)}", callback_data="N/A"),
- InlineKeyboardButton("âş", callback_data="userfiles_2")
- ],
- )
- if not file_list:
- file_list.append(
- [InlineKeyboardButton("á´á´á´á´Ę", callback_data="N/A")],
- )
- file_list.append([InlineKeyboardButton("á´Ęá´sá´", callback_data="close")])
- await message.reply_photo(photo=Telegram.FILE_PIC,
- caption="Total files: {}".format(total_files),
- reply_markup=InlineKeyboardMarkup(file_list))
-
-
diff --git a/FileStream/bot/plugins/stream.py b/FileStream/bot/plugins/stream.py
deleted file mode 100644
index d405131d5338d43189fa11378c2cc4a258d40a67..0000000000000000000000000000000000000000
--- a/FileStream/bot/plugins/stream.py
+++ /dev/null
@@ -1,96 +0,0 @@
-
-import asyncio
-from FileStream.bot import FileStream, multi_clients
-from FileStream.utils.bot_utils import is_user_banned, is_user_exist, is_user_joined, gen_link, is_channel_banned, is_channel_exist, is_user_authorized
-from FileStream.utils.database import Database
-from FileStream.utils.file_properties import get_file_ids, get_file_info
-from FileStream.config import Telegram
-from pyrogram import filters, Client
-from pyrogram.errors import FloodWait
-from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
-from pyrogram.enums.parse_mode import ParseMode
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-@FileStream.on_message(
- filters.private
- & (
- filters.document
- | filters.video
- | filters.video_note
- | filters.audio
- | filters.voice
- | filters.animation
- | filters.photo
- ),
- group=4,
-)
-async def private_receive_handler(bot: Client, message: Message):
- if not await is_user_authorized(message):
- return
- if await is_user_banned(message):
- return
-
- await is_user_exist(bot, message)
- if Telegram.FORCE_SUB:
- if not await is_user_joined(bot, message):
- return
- try:
- inserted_id = await db.add_file(get_file_info(message))
- await get_file_ids(False, inserted_id, multi_clients, message)
- reply_markup, stream_text = await gen_link(_id=inserted_id)
- await message.reply_text(
- text=stream_text,
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True,
- reply_markup=reply_markup,
- quote=True
- )
- except FloodWait as e:
- print(f"Sleeping for {str(e.value)}s")
- await asyncio.sleep(e.value)
- await bot.send_message(chat_id=Telegram.ULOG_CHANNEL,
- text=f"Gá´á´ FĘá´á´á´
Wá´ÉŞá´ á´Ň {str(e.value)}s ŇĘá´á´ [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n\n**á´sá´Ę ÉŞá´
:** `{str(message.from_user.id)}`",
- disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN)
-
-
-@FileStream.on_message(
- filters.channel
- & ~filters.forwarded
- & ~filters.media_group
- & (
- filters.document
- | filters.video
- | filters.video_note
- | filters.audio
- | filters.voice
- | filters.photo
- )
-)
-async def channel_receive_handler(bot: Client, message: Message):
- if await is_channel_banned(bot, message):
- return
- await is_channel_exist(bot, message)
-
- try:
- inserted_id = await db.add_file(get_file_info(message))
- await get_file_ids(False, inserted_id, multi_clients, message)
- reply_markup, stream_link = await gen_link(_id=inserted_id)
- await bot.edit_message_reply_markup(
- chat_id=message.chat.id,
- message_id=message.id,
- reply_markup=InlineKeyboardMarkup(
- [[InlineKeyboardButton("Dá´á´ĄÉ´Ęá´á´á´
ĘÉŞÉ´á´ đĽ",
- url=f"https://t.me/{FileStream.username}?start=stream_{str(inserted_id)}")]])
- )
-
- except FloodWait as w:
- print(f"Sleeping for {str(w.x)}s")
- await asyncio.sleep(w.x)
- await bot.send_message(chat_id=Telegram.ULOG_CHANNEL,
- text=f"ɢá´á´ ŇĘá´á´á´
á´Ąá´ÉŞá´ á´Ň {str(w.x)}s ŇĘá´á´ {message.chat.title}\n\n**á´Ęá´É´É´á´Ę ÉŞá´
:** `{str(message.chat.id)}`",
- disable_web_page_preview=True)
- except Exception as e:
- await bot.send_message(chat_id=Telegram.ULOG_CHANNEL, text=f"**#EĘĘá´ĘTĘá´á´á´á´Ęá´á´á´:** `{e}`",
- disable_web_page_preview=True)
- print(f"Cá´É´'á´ Eá´
ÉŞá´ BĘá´á´á´
á´á´sá´ Má´ssá´É˘á´!\nEĘĘá´Ę: **GÉŞá´ á´ á´á´ á´á´
ÉŞá´ á´á´Ęá´ÉŞssÉŞá´É´ ÉŞÉ´ á´á´á´
á´á´á´s á´É´á´
ĘÉŞÉ´ CĘá´É´É´á´Ę!{e}**")
-
diff --git a/FileStream/config.py b/FileStream/config.py
deleted file mode 100644
index 48c49c815cc8fc3e579053723b094da275dbd342..0000000000000000000000000000000000000000
--- a/FileStream/config.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from os import environ as env
-from dotenv import load_dotenv
-
-load_dotenv()
-
-class Telegram:
- API_ID = int(env.get("API_ID"))
- API_HASH = str(env.get("API_HASH"))
- BOT_TOKEN = str(env.get("BOT_TOKEN"))
- OWNER_ID = int(env.get('OWNER_ID', '7978482443'))
- WORKERS = int(env.get("WORKERS", "6")) # 6 workers = 6 commands at once
- DATABASE_URL = str(env.get('DATABASE_URL'))
- UPDATES_CHANNEL = str(env.get('UPDATES_CHANNEL', "Telegram"))
- SESSION_NAME = str(env.get('SESSION_NAME', 'FileStream'))
- FORCE_SUB_ID = env.get('FORCE_SUB_ID', None)
- FORCE_SUB = env.get('FORCE_UPDATES_CHANNEL', False)
- FORCE_SUB = True if str(FORCE_SUB).lower() == "true" else False
- SLEEP_THRESHOLD = int(env.get("SLEEP_THRESHOLD", "60"))
- FILE_PIC = env.get('FILE_PIC', "https://graph.org/file/5bb9935be0229adf98b73.jpg")
- START_PIC = env.get('START_PIC', "https://graph.org/file/290af25276fa34fa8f0aa.jpg")
- VERIFY_PIC = env.get('VERIFY_PIC', "https://graph.org/file/736e21cc0efa4d8c2a0e4.jpg")
- MULTI_CLIENT = False
- FLOG_CHANNEL = int(env.get("FLOG_CHANNEL", None)) # Logs channel for file logs
- ULOG_CHANNEL = int(env.get("ULOG_CHANNEL", None)) # Logs channel for user logs
- MODE = env.get("MODE", "primary")
- SECONDARY = True if MODE.lower() == "secondary" else False
- AUTH_USERS = list(set(int(x) for x in str(env.get("AUTH_USERS", "")).split()))
-
-class Server:
- PORT = int(env.get("PORT", 8080))
- BIND_ADDRESS = str(env.get("BIND_ADDRESS", "0.0.0.0"))
- PING_INTERVAL = int(env.get("PING_INTERVAL", "1200"))
- HAS_SSL = str(env.get("HAS_SSL", "0").lower()) in ("1", "true", "t", "yes", "y")
- NO_PORT = str(env.get("NO_PORT", "0").lower()) in ("1", "true", "t", "yes", "y")
- FQDN = str(env.get("FQDN", BIND_ADDRESS))
- URL = "http{}://{}{}/".format(
- "s" if HAS_SSL else "", FQDN, "" if NO_PORT else ":" + str(PORT)
- )
-
-
-
diff --git a/FileStream/server/__init__.py b/FileStream/server/__init__.py
deleted file mode 100644
index 41a657fa38f43f8828e87e75e54713081e1049a2..0000000000000000000000000000000000000000
--- a/FileStream/server/__init__.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from aiohttp import web
-from .stream_routes import routes
-
-def web_server():
- web_app = web.Application(client_max_size=30000000)
- web_app.add_routes(routes)
- return web_app
diff --git a/FileStream/server/exceptions.py b/FileStream/server/exceptions.py
deleted file mode 100644
index 80e981e5ec4b371b1215140903ecd2e63158a0c2..0000000000000000000000000000000000000000
--- a/FileStream/server/exceptions.py
+++ /dev/null
@@ -1,5 +0,0 @@
-class InvalidHash(Exception):
- message = "Invalid hash"
-
-class FIleNotFound(Exception):
- message = "File not found"
\ No newline at end of file
diff --git a/FileStream/server/stream_routes.py b/FileStream/server/stream_routes.py
deleted file mode 100644
index a16d34e27ef1bc9d550dfbe2af5860ce3efc8728..0000000000000000000000000000000000000000
--- a/FileStream/server/stream_routes.py
+++ /dev/null
@@ -1,136 +0,0 @@
-import time
-import math
-import logging
-import mimetypes
-import traceback
-from aiohttp import web
-from aiohttp.http_exceptions import BadStatusLine
-from FileStream.bot import multi_clients, work_loads, FileStream
-from FileStream.config import Telegram, Server
-from FileStream.server.exceptions import FIleNotFound, InvalidHash
-from FileStream import utils, StartTime, __version__
-from FileStream.utils.render_template import render_page
-
-routes = web.RouteTableDef()
-
-@routes.get("/status", allow_head=True)
-async def root_route_handler(_):
- return web.json_response(
- {
- "server_status": "running",
- "uptime": utils.get_readable_time(time.time() - StartTime),
- "telegram_bot": "@" + FileStream.username,
- "connected_bots": len(multi_clients),
- "loads": dict(
- ("bot" + str(c + 1), l)
- for c, (_, l) in enumerate(
- sorted(work_loads.items(), key=lambda x: x[1], reverse=True)
- )
- ),
- "version": __version__,
- }
- )
-
-@routes.get("/watch/{path}", allow_head=True)
-async def stream_handler(request: web.Request):
- try:
- path = request.match_info["path"]
- return web.Response(text=await render_page(path), content_type='text/html')
- except InvalidHash as e:
- raise web.HTTPForbidden(text=e.message)
- except FIleNotFound as e:
- raise web.HTTPNotFound(text=e.message)
- except (AttributeError, BadStatusLine, ConnectionResetError):
- pass
-
-
-@routes.get("/dl/{path}", allow_head=True)
-async def stream_handler(request: web.Request):
- try:
- path = request.match_info["path"]
- return await media_streamer(request, path)
- except InvalidHash as e:
- raise web.HTTPForbidden(text=e.message)
- except FIleNotFound as e:
- raise web.HTTPNotFound(text=e.message)
- except (AttributeError, BadStatusLine, ConnectionResetError):
- pass
- except Exception as e:
- traceback.print_exc()
- logging.critical(e.with_traceback(None))
- logging.debug(traceback.format_exc())
- raise web.HTTPInternalServerError(text=str(e))
-
-class_cache = {}
-
-async def media_streamer(request: web.Request, db_id: str):
- range_header = request.headers.get("Range", 0)
-
- index = min(work_loads, key=work_loads.get)
- faster_client = multi_clients[index]
-
- if Telegram.MULTI_CLIENT:
- logging.info(f"Client {index} is now serving {request.headers.get('X-FORWARDED-FOR',request.remote)}")
-
- if faster_client in class_cache:
- tg_connect = class_cache[faster_client]
- logging.debug(f"Using cached ByteStreamer object for client {index}")
- else:
- logging.debug(f"Creating new ByteStreamer object for client {index}")
- tg_connect = utils.ByteStreamer(faster_client)
- class_cache[faster_client] = tg_connect
- logging.debug("before calling get_file_properties")
- file_id = await tg_connect.get_file_properties(db_id, multi_clients)
- logging.debug("after calling get_file_properties")
-
- file_size = file_id.file_size
-
- if range_header:
- from_bytes, until_bytes = range_header.replace("bytes=", "").split("-")
- from_bytes = int(from_bytes)
- until_bytes = int(until_bytes) if until_bytes else file_size - 1
- else:
- from_bytes = request.http_range.start or 0
- until_bytes = (request.http_range.stop or file_size) - 1
-
- if (until_bytes > file_size) or (from_bytes < 0) or (until_bytes < from_bytes):
- return web.Response(
- status=416,
- body="416: Range not satisfiable",
- headers={"Content-Range": f"bytes */{file_size}"},
- )
-
- chunk_size = 1024 * 1024
- until_bytes = min(until_bytes, file_size - 1)
-
- offset = from_bytes - (from_bytes % chunk_size)
- first_part_cut = from_bytes - offset
- last_part_cut = until_bytes % chunk_size + 1
-
- req_length = until_bytes - from_bytes + 1
- part_count = math.ceil(until_bytes / chunk_size) - math.floor(offset / chunk_size)
- body = tg_connect.yield_file(
- file_id, index, offset, first_part_cut, last_part_cut, part_count, chunk_size
- )
-
- mime_type = file_id.mime_type
- file_name = utils.get_name(file_id)
- disposition = "attachment"
-
- if not mime_type:
- mime_type = mimetypes.guess_type(file_name)[0] or "application/octet-stream"
-
- # if "video/" in mime_type or "audio/" in mime_type:
- # disposition = "inline"
-
- return web.Response(
- status=206 if range_header else 200,
- body=body,
- headers={
- "Content-Type": f"{mime_type}",
- "Content-Range": f"bytes {from_bytes}-{until_bytes}/{file_size}",
- "Content-Length": str(req_length),
- "Content-Disposition": f'{disposition}; filename="{file_name}"',
- "Accept-Ranges": "bytes",
- },
- )
diff --git a/FileStream/template/dl.html b/FileStream/template/dl.html
deleted file mode 100644
index 2dce4871cf273ce1f35f805fc5dfd4c59f612820..0000000000000000000000000000000000000000
--- a/FileStream/template/dl.html
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
- {{file_name}}
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/FileStream/template/play.html b/FileStream/template/play.html
deleted file mode 100644
index 949a1cd43183e633754533fbe8b72c3705dd5db0..0000000000000000000000000000000000000000
--- a/FileStream/template/play.html
+++ /dev/null
@@ -1,171 +0,0 @@
-
-
-
-
-
-
- FileStreamBot | {{file_name}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
File Name:
-
{{file_name}}
-
File Size:
-
{{file_size}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
WELCOME TO OUR FILE STREAM BOT
-
- This is a Telegram Bot to Stream Movies and Series directly on
- Telegram. You can also
- download them if you want. This bot is developed by Avi
-
If you like this bot, then don't
- forget to share it with your friends and family.
-
-
-
-
-
JOIN OUR TELEGRAM CHANNELS
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/FileStream/utils/__init__.py b/FileStream/utils/__init__.py
deleted file mode 100644
index 93653aa7a72fa1133ab0892343b3e57a0acc9fb5..0000000000000000000000000000000000000000
--- a/FileStream/utils/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from .time_format import get_readable_time
-from .file_properties import get_name, get_file_ids
-from .custom_dl import ByteStreamer
\ No newline at end of file
diff --git a/FileStream/utils/bot_utils.py b/FileStream/utils/bot_utils.py
deleted file mode 100644
index e40d7f6c3f7c6a7d91e06fa0b54b8c732017f9fb..0000000000000000000000000000000000000000
--- a/FileStream/utils/bot_utils.py
+++ /dev/null
@@ -1,216 +0,0 @@
-from pyrogram.errors import UserNotParticipant, FloodWait
-from pyrogram.enums.parse_mode import ParseMode
-from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
-from FileStream.utils.translation import LANG
-from FileStream.utils.database import Database
-from FileStream.utils.human_readable import humanbytes
-from FileStream.config import Telegram, Server
-from FileStream.bot import FileStream
-import asyncio
-from typing import (
- Union
-)
-
-
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-async def get_invite_link(bot, chat_id: Union[str, int]):
- try:
- invite_link = await bot.create_chat_invite_link(chat_id=chat_id)
- return invite_link
- except FloodWait as e:
- print(f"Sleep of {e.value}s caused by FloodWait ...")
- await asyncio.sleep(e.value)
- return await get_invite_link(bot, chat_id)
-
-async def is_user_joined(bot, message: Message):
- if Telegram.FORCE_SUB_ID and Telegram.FORCE_SUB_ID.startswith("-100"):
- channel_chat_id = int(Telegram.FORCE_SUB_ID) # When id startswith with -100
- elif Telegram.FORCE_SUB_ID and (not Telegram.FORCE_SUB_ID.startswith("-100")):
- channel_chat_id = Telegram.FORCE_SUB_ID # When id not startswith -100
- else:
- return 200
- try:
- user = await bot.get_chat_member(chat_id=channel_chat_id, user_id=message.from_user.id)
- if user.status == "BANNED":
- await message.reply_text(
- text=LANG.BAN_TEXT.format(Telegram.OWNER_ID),
- parse_mode=ParseMode.MARKDOWN,
- disable_web_page_preview=True
- )
- return False
- except UserNotParticipant:
- invite_link = await get_invite_link(bot, chat_id=channel_chat_id)
- if Telegram.VERIFY_PIC:
- ver = await message.reply_photo(
- photo=Telegram.VERIFY_PIC,
- caption="Já´ÉŞÉ´ á´Ę á´á´á´
á´á´á´ á´Ęá´É´É´á´Ę á´á´ á´sá´ á´á´ đ",
- parse_mode=ParseMode.HTML,
- reply_markup=InlineKeyboardMarkup(
- [[
- InlineKeyboardButton("â Já´ÉŞÉ´ Oá´Ę CĘá´É´É´á´Ę â", url=invite_link.invite_link)
- ]]
- )
- )
- else:
- ver = await message.reply_text(
- text = "Já´ÉŞÉ´ á´Ę á´á´á´
á´á´á´ á´Ęá´É´É´á´Ę á´á´ á´sá´ á´á´ đ",
- reply_markup=InlineKeyboardMarkup(
- [[
- InlineKeyboardButton("â Já´ÉŞÉ´ Oá´Ę CĘá´É´É´á´Ę â", url=invite_link.invite_link)
- ]]
- ),
- parse_mode=ParseMode.HTML
- )
- await asyncio.sleep(30)
- try:
- await ver.delete()
- await message.delete()
- except Exception:
- pass
- return False
- except Exception:
- await message.reply_text(
- text = f"Sá´á´á´á´Ęɪɴɢ á´ĄĘá´É´É˘ á´á´É´á´á´á´á´ á´Ę á´
á´á´ á´Ęá´á´á´Ę [ á´ĘÉŞá´á´ Ęá´Ęá´ ]",
- parse_mode=ParseMode.HTML,
- disable_web_page_preview=True)
- return False
- return True
-
-#---------------------[ PRIVATE GEN LINK + CALLBACK ]---------------------#
-
-async def gen_link(_id):
- file_info = await db.get_file(_id)
- file_name = file_info['file_name']
- file_size = humanbytes(file_info['file_size'])
- mime_type = file_info['mime_type']
-
- page_link = f"{Server.URL}watch/{_id}"
- stream_link = f"{Server.URL}dl/{_id}"
- file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
-
- if "video" in mime_type:
- stream_text = LANG.STREAM_TEXT.format(file_name, file_size, stream_link, page_link, file_link)
- reply_markup = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("sá´Ęá´á´á´", url=page_link), InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)],
- [InlineKeyboardButton("ɢá´á´ ŇÉŞĘá´", url=file_link), InlineKeyboardButton("Ęá´á´ á´á´á´ ŇÉŞĘá´", callback_data=f"msgdelpvt_{_id}")],
- [InlineKeyboardButton("á´Ęá´sá´", callback_data="close")]
- ]
- )
- else:
- stream_text = LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link, file_link)
- reply_markup = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)],
- [InlineKeyboardButton("ɢá´á´ ŇÉŞĘá´", url=file_link), InlineKeyboardButton("Ęá´á´ á´á´á´ ŇÉŞĘá´", callback_data=f"msgdelpvt_{_id}")],
- [InlineKeyboardButton("á´Ęá´sá´", callback_data="close")]
- ]
- )
- return reply_markup, stream_text
-
-#---------------------[ GEN STREAM LINKS FOR CHANNEL ]---------------------#
-
-async def gen_linkx(m:Message , _id, name: list):
- file_info = await db.get_file(_id)
- file_name = file_info['file_name']
- mime_type = file_info['mime_type']
- file_size = humanbytes(file_info['file_size'])
-
- page_link = f"{Server.URL}watch/{_id}"
- stream_link = f"{Server.URL}dl/{_id}"
- file_link = f"https://t.me/{FileStream.username}?start=file_{_id}"
-
- if "video" in mime_type:
- stream_text= LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link, page_link)
- reply_markup = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("sá´Ęá´á´á´", url=page_link), InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)]
- ]
- )
- else:
- stream_text= LANG.STREAM_TEXT_X.format(file_name, file_size, stream_link, file_link)
- reply_markup = InlineKeyboardMarkup(
- [
- [InlineKeyboardButton("á´
á´á´ĄÉ´Ęá´á´á´
", url=stream_link)]
- ]
- )
- return reply_markup, stream_text
-
-#---------------------[ USER BANNED ]---------------------#
-
-async def is_user_banned(message):
- if await db.is_user_banned(message.from_user.id):
- await message.reply_text(
- text=LANG.BAN_TEXT.format(Telegram.OWNER_ID),
- parse_mode=ParseMode.MARKDOWN,
- disable_web_page_preview=True
- )
- return True
- return False
-
-#---------------------[ CHANNEL BANNED ]---------------------#
-
-async def is_channel_banned(bot, message):
- if await db.is_user_banned(message.chat.id):
- await bot.edit_message_reply_markup(
- chat_id=message.chat.id,
- message_id=message.id,
- reply_markup=InlineKeyboardMarkup([[
- InlineKeyboardButton(f"á´Ęá´É´É´á´Ę ÉŞs Ęá´É´É´á´á´
", callback_data="N/A")]])
- )
- return True
- return False
-
-#---------------------[ USER AUTH ]---------------------#
-
-async def is_user_authorized(message):
- if hasattr(Telegram, 'AUTH_USERS') and Telegram.AUTH_USERS:
- user_id = message.from_user.id
-
- if user_id == Telegram.OWNER_ID:
- return True
-
- if not (user_id in Telegram.AUTH_USERS):
- await message.reply_text(
- text="Yá´á´ á´Ęá´ É´á´á´ á´á´á´Ęá´ĘÉŞá´˘á´á´
á´á´ á´sá´ á´ĘÉŞs Ęá´á´.",
- parse_mode=ParseMode.MARKDOWN,
- disable_web_page_preview=True
- )
- return False
-
- return True
-
-#---------------------[ USER EXIST ]---------------------#
-
-async def is_user_exist(bot, message):
- if not bool(await db.get_user(message.from_user.id)):
- await db.add_user(message.from_user.id)
- await bot.send_message(
- Telegram.ULOG_CHANNEL,
- f"**#Ná´á´ĄUsá´Ę**\n**⏊ á´sá´Ę É´á´á´á´ :** [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n**⏊ á´sá´Ę ÉŞá´
:** `{message.from_user.id}`"
- )
-
-async def is_channel_exist(bot, message):
- if not bool(await db.get_user(message.chat.id)):
- await db.add_user(message.chat.id)
- members = await bot.get_chat_members_count(message.chat.id)
- await bot.send_message(
- Telegram.ULOG_CHANNEL,
- f"**#Ná´á´ĄCĘá´É´É´á´Ę** \n**⏊ á´Ęá´á´ É´á´á´á´ :** `{message.chat.title}`\n**⏊ á´Ęá´á´ ÉŞá´
:** `{message.chat.id}`\n**⏊ á´á´á´á´Ę á´á´á´Ęá´Ęs :** `{members}`"
- )
-
-async def verify_user(bot, message):
- if not await is_user_authorized(message):
- return False
-
- if await is_user_banned(message):
- return False
-
- await is_user_exist(bot, message)
-
- if Telegram.FORCE_SUB:
- if not await is_user_joined(bot, message):
- return False
-
- return True
diff --git a/FileStream/utils/broadcast_helper.py b/FileStream/utils/broadcast_helper.py
deleted file mode 100644
index 6b9914920a5bdccdc5eff0c2196ce6ac82ea68c4..0000000000000000000000000000000000000000
--- a/FileStream/utils/broadcast_helper.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import asyncio
-import traceback
-from pyrogram.errors import FloodWait, InputUserDeactivated, UserIsBlocked, PeerIdInvalid
-
-async def send_msg(user_id, message):
- try:
- await message.copy(chat_id=user_id)
- return 200, None
- except FloodWait as e:
- await asyncio.sleep(e.value)
- return send_msg(user_id, message)
- except InputUserDeactivated:
- return 400, f"{user_id} : deactivated\n"
- except UserIsBlocked:
- return 400, f"{user_id} : blocked the bot\n"
- except PeerIdInvalid:
- return 400, f"{user_id} : user id invalid\n"
- except Exception as e:
- return 500, f"{user_id} : {traceback.format_exc()}\n"
diff --git a/FileStream/utils/custom_dl.py b/FileStream/utils/custom_dl.py
deleted file mode 100644
index e78887f5cc80a57a1d0cabe12374994e61e99192..0000000000000000000000000000000000000000
--- a/FileStream/utils/custom_dl.py
+++ /dev/null
@@ -1,214 +0,0 @@
-import asyncio
-import logging
-from typing import Dict, Union
-from FileStream.bot import work_loads
-from pyrogram import Client, utils, raw
-from .file_properties import get_file_ids
-from pyrogram.session import Session, Auth
-from pyrogram.errors import AuthBytesInvalid
-from pyrogram.file_id import FileId, FileType, ThumbnailSource
-from pyrogram.types import Message
-
-class ByteStreamer:
- def __init__(self, client: Client):
- self.clean_timer = 30 * 60
- self.client: Client = client
- self.cached_file_ids: Dict[str, FileId] = {}
- asyncio.create_task(self.clean_cache())
-
- async def get_file_properties(self, db_id: str, multi_clients) -> FileId:
- """
- Returns the properties of a media of a specific message in a FIleId class.
- if the properties are cached, then it'll return the cached results.
- or it'll generate the properties from the Message ID and cache them.
- """
- if not db_id in self.cached_file_ids:
- logging.debug("Before Calling generate_file_properties")
- await self.generate_file_properties(db_id, multi_clients)
- logging.debug(f"Cached file properties for file with ID {db_id}")
- return self.cached_file_ids[db_id]
-
- async def generate_file_properties(self, db_id: str, multi_clients) -> FileId:
- """
- Generates the properties of a media file on a specific message.
- returns ths properties in a FIleId class.
- """
- logging.debug("Before calling get_file_ids")
- file_id = await get_file_ids(self.client, db_id, multi_clients, Message)
- logging.debug(f"Generated file ID and Unique ID for file with ID {db_id}")
- self.cached_file_ids[db_id] = file_id
- logging.debug(f"Cached media file with ID {db_id}")
- return self.cached_file_ids[db_id]
-
- async def generate_media_session(self, client: Client, file_id: FileId) -> Session:
- """
- Generates the media session for the DC that contains the media file.
- This is required for getting the bytes from Telegram servers.
- """
-
- media_session = client.media_sessions.get(file_id.dc_id, None)
-
- if media_session is None:
- if file_id.dc_id != await client.storage.dc_id():
- media_session = Session(
- client,
- file_id.dc_id,
- await Auth(
- client, file_id.dc_id, await client.storage.test_mode()
- ).create(),
- await client.storage.test_mode(),
- is_media=True,
- )
- await media_session.start()
-
- for _ in range(6):
- exported_auth = await client.invoke(
- raw.functions.auth.ExportAuthorization(dc_id=file_id.dc_id)
- )
-
- try:
- await media_session.invoke(
- raw.functions.auth.ImportAuthorization(
- id=exported_auth.id, bytes=exported_auth.bytes
- )
- )
- break
- except AuthBytesInvalid:
- logging.debug(
- f"Invalid authorization bytes for DC {file_id.dc_id}"
- )
- continue
- else:
- await media_session.stop()
- raise AuthBytesInvalid
- else:
- media_session = Session(
- client,
- file_id.dc_id,
- await client.storage.auth_key(),
- await client.storage.test_mode(),
- is_media=True,
- )
- await media_session.start()
- logging.debug(f"Created media session for DC {file_id.dc_id}")
- client.media_sessions[file_id.dc_id] = media_session
- else:
- logging.debug(f"Using cached media session for DC {file_id.dc_id}")
- return media_session
-
-
- @staticmethod
- async def get_location(file_id: FileId) -> Union[raw.types.InputPhotoFileLocation,
- raw.types.InputDocumentFileLocation,
- raw.types.InputPeerPhotoFileLocation,]:
- """
- Returns the file location for the media file.
- """
- file_type = file_id.file_type
-
- if file_type == FileType.CHAT_PHOTO:
- if file_id.chat_id > 0:
- peer = raw.types.InputPeerUser(
- user_id=file_id.chat_id, access_hash=file_id.chat_access_hash
- )
- else:
- if file_id.chat_access_hash == 0:
- peer = raw.types.InputPeerChat(chat_id=-file_id.chat_id)
- else:
- peer = raw.types.InputPeerChannel(
- channel_id=utils.get_channel_id(file_id.chat_id),
- access_hash=file_id.chat_access_hash,
- )
-
- location = raw.types.InputPeerPhotoFileLocation(
- peer=peer,
- volume_id=file_id.volume_id,
- local_id=file_id.local_id,
- big=file_id.thumbnail_source == ThumbnailSource.CHAT_PHOTO_BIG,
- )
- elif file_type == FileType.PHOTO:
- location = raw.types.InputPhotoFileLocation(
- id=file_id.media_id,
- access_hash=file_id.access_hash,
- file_reference=file_id.file_reference,
- thumb_size=file_id.thumbnail_size,
- )
- else:
- location = raw.types.InputDocumentFileLocation(
- id=file_id.media_id,
- access_hash=file_id.access_hash,
- file_reference=file_id.file_reference,
- thumb_size=file_id.thumbnail_size,
- )
- return location
-
- async def yield_file(
- self,
- file_id: FileId,
- index: int,
- offset: int,
- first_part_cut: int,
- last_part_cut: int,
- part_count: int,
- chunk_size: int,
- ) -> Union[str, None]:
- """
- Custom generator that yields the bytes of the media file.
- Modded from
- Thanks to Eyaadh
- """
- client = self.client
- work_loads[index] += 1
- logging.debug(f"Starting to yielding file with client {index}.")
- media_session = await self.generate_media_session(client, file_id)
-
- current_part = 1
-
- location = await self.get_location(file_id)
-
- try:
- r = await media_session.invoke(
- raw.functions.upload.GetFile(
- location=location, offset=offset, limit=chunk_size
- ),
- )
- if isinstance(r, raw.types.upload.File):
- while True:
- chunk = r.bytes
- if not chunk:
- break
- elif part_count == 1:
- yield chunk[first_part_cut:last_part_cut]
- elif current_part == 1:
- yield chunk[first_part_cut:]
- elif current_part == part_count:
- yield chunk[:last_part_cut]
- else:
- yield chunk
-
- current_part += 1
- offset += chunk_size
-
- if current_part > part_count:
- break
-
- r = await media_session.invoke(
- raw.functions.upload.GetFile(
- location=location, offset=offset, limit=chunk_size
- ),
- )
- except (TimeoutError, AttributeError):
- pass
- finally:
- logging.debug(f"Finished yielding file with {current_part} parts.")
- work_loads[index] -= 1
-
-
- async def clean_cache(self) -> None:
- """
- function to clean the cache to reduce memory usage
- """
- while True:
- await asyncio.sleep(self.clean_timer)
- self.cached_file_ids.clear()
- logging.debug("Cleaned the cache")
diff --git a/FileStream/utils/database.py b/FileStream/utils/database.py
deleted file mode 100644
index bd90cd915e67396ee608b04b62423c2e40d18a38..0000000000000000000000000000000000000000
--- a/FileStream/utils/database.py
+++ /dev/null
@@ -1,134 +0,0 @@
-import pymongo
-import time
-import motor.motor_asyncio
-from bson.objectid import ObjectId
-from bson.errors import InvalidId
-from FileStream.server.exceptions import FIleNotFound
-
-class Database:
- def __init__(self, uri, database_name):
- self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
- self.db = self._client[database_name]
- self.col = self.db.users
- self.black = self.db.blacklist
- self.file = self.db.file
-
-#---------------------[ NEW USER ]---------------------#
- def new_user(self, id):
- return dict(
- id=id,
- join_date=time.time(),
- Links=0
- )
-
-# ---------------------[ ADD USER ]---------------------#
- async def add_user(self, id):
- user = self.new_user(id)
- await self.col.insert_one(user)
-
-# ---------------------[ GET USER ]---------------------#
- async def get_user(self, id):
- user = await self.col.find_one({'id': int(id)})
- return user
-
-# ---------------------[ CHECK USER ]---------------------#
- async def total_users_count(self):
- count = await self.col.count_documents({})
- return count
-
- async def get_all_users(self):
- all_users = self.col.find({})
- return all_users
-
-# ---------------------[ REMOVE USER ]---------------------#
- async def delete_user(self, user_id):
- await self.col.delete_many({'id': int(user_id)})
-
-# ---------------------[ BAN, UNBAN USER ]---------------------#
- def black_user(self, id):
- return dict(
- id=id,
- ban_date=time.time()
- )
-
- async def ban_user(self, id):
- user = self.black_user(id)
- await self.black.insert_one(user)
-
- async def unban_user(self, id):
- await self.black.delete_one({'id': int(id)})
-
- async def is_user_banned(self, id):
- user = await self.black.find_one({'id': int(id)})
- return True if user else False
-
- async def total_banned_users_count(self):
- count = await self.black.count_documents({})
- return count
-
-# ---------------------[ ADD FILE TO DB ]---------------------#
- async def add_file(self, file_info):
- file_info["time"] = time.time()
- fetch_old = await self.get_file_by_fileuniqueid(file_info["user_id"], file_info["file_unique_id"])
- if fetch_old:
- return fetch_old["_id"]
- await self.count_links(file_info["user_id"], "+")
- return (await self.file.insert_one(file_info)).inserted_id
-
-# ---------------------[ FIND FILE IN DB ]---------------------#
- async def find_files(self, user_id, range):
- user_files=self.file.find({"user_id": user_id})
- user_files.skip(range[0] - 1)
- user_files.limit(range[1] - range[0] + 1)
- user_files.sort('_id', pymongo.DESCENDING)
- total_files = await self.file.count_documents({"user_id": user_id})
- return user_files, total_files
-
- async def get_file(self, _id):
- try:
- file_info=await self.file.find_one({"_id": ObjectId(_id)})
- if not file_info:
- raise FIleNotFound
- return file_info
- except InvalidId:
- raise FIleNotFound
-
- async def get_file_by_fileuniqueid(self, id, file_unique_id, many=False):
- if many:
- return self.file.find({"file_unique_id": file_unique_id})
- else:
- file_info=await self.file.find_one({"user_id": id, "file_unique_id": file_unique_id})
- if file_info:
- return file_info
- return False
-
-# ---------------------[ TOTAL FILES ]---------------------#
- async def total_files(self, id=None):
- if id:
- return await self.file.count_documents({"user_id": id})
- return await self.file.count_documents({})
-
-# ---------------------[ DELETE FILES ]---------------------#
- async def delete_one_file(self, _id):
- await self.file.delete_one({'_id': ObjectId(_id)})
-
-# ---------------------[ UPDATE FILES ]---------------------#
- async def update_file_ids(self, _id, file_ids: dict):
- await self.file.update_one({"_id": ObjectId(_id)}, {"$set": {"file_ids": file_ids}})
-
-# ---------------------[ PAID SYS ]---------------------#
-# async def link_available(self, id):
-# user = await self.col.find_one({"id": id})
-# if user.get("Plan") == "Plus":
-# return "Plus"
-# elif user.get("Plan") == "Free":
-# files = await self.file.count_documents({"user_id": id})
-# if files < 11:
-# return True
-# return False
-
- async def count_links(self, id, operation: str):
- if operation == "-":
- await self.col.update_one({"id": id}, {"$inc": {"Links": -1}})
- elif operation == "+":
- await self.col.update_one({"id": id}, {"$inc": {"Links": 1}})
\ No newline at end of file
diff --git a/FileStream/utils/file_properties.py b/FileStream/utils/file_properties.py
deleted file mode 100644
index 49dcc09155967fbdcb76bcca2cf778efaefc59f5..0000000000000000000000000000000000000000
--- a/FileStream/utils/file_properties.py
+++ /dev/null
@@ -1,144 +0,0 @@
-from __future__ import annotations
-import logging
-from datetime import datetime
-from pyrogram import Client
-from typing import Any, Optional
-
-from pyrogram.enums import ParseMode, ChatType
-from pyrogram.types import Message
-from pyrogram.file_id import FileId
-from FileStream.bot import FileStream
-from FileStream.utils.database import Database
-from FileStream.config import Telegram, Server
-
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-
-async def get_file_ids(client: Client | bool, db_id: str, multi_clients, message) -> Optional[FileId]:
- logging.debug("Starting of get_file_ids")
- file_info = await db.get_file(db_id)
- if (not "file_ids" in file_info) or not client:
- logging.debug("Storing file_id of all clients in DB")
- log_msg = await send_file(FileStream, db_id, file_info['file_id'], message)
- await db.update_file_ids(db_id, await update_file_id(log_msg.id, multi_clients))
- logging.debug("Stored file_id of all clients in DB")
- if not client:
- return
- file_info = await db.get_file(db_id)
-
- file_id_info = file_info.setdefault("file_ids", {})
- if not str(client.id) in file_id_info:
- logging.debug("Storing file_id in DB")
- log_msg = await send_file(FileStream, db_id, file_info['file_id'], message)
- msg = await client.get_messages(Telegram.FLOG_CHANNEL, log_msg.id)
- media = get_media_from_message(msg)
- file_id_info[str(client.id)] = getattr(media, "file_id", "")
- await db.update_file_ids(db_id, file_id_info)
- logging.debug("Stored file_id in DB")
-
- logging.debug("Middle of get_file_ids")
- file_id = FileId.decode(file_id_info[str(client.id)])
- setattr(file_id, "file_size", file_info['file_size'])
- setattr(file_id, "mime_type", file_info['mime_type'])
- setattr(file_id, "file_name", file_info['file_name'])
- setattr(file_id, "unique_id", file_info['file_unique_id'])
- logging.debug("Ending of get_file_ids")
- return file_id
-
-
-def get_media_from_message(message: "Message") -> Any:
- media_types = (
- "audio",
- "document",
- "photo",
- "sticker",
- "animation",
- "video",
- "voice",
- "video_note",
- )
- for attr in media_types:
- media = getattr(message, attr, None)
- if media:
- return media
-
-
-def get_media_file_size(m):
- media = get_media_from_message(m)
- return getattr(media, "file_size", "None")
-
-
-def get_name(media_msg: Message | FileId) -> str:
- if isinstance(media_msg, Message):
- media = get_media_from_message(media_msg)
- file_name = getattr(media, "file_name", "")
-
- elif isinstance(media_msg, FileId):
- file_name = getattr(media_msg, "file_name", "")
-
- if not file_name:
- if isinstance(media_msg, Message) and media_msg.media:
- media_type = media_msg.media.value
- elif media_msg.file_type:
- media_type = media_msg.file_type.name.lower()
- else:
- media_type = "file"
-
- formats = {
- "photo": "jpg", "audio": "mp3", "voice": "ogg",
- "video": "mp4", "animation": "mp4", "video_note": "mp4",
- "sticker": "webp"
- }
-
- ext = formats.get(media_type)
- ext = "." + ext if ext else ""
-
- date = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
- file_name = f"{media_type}-{date}{ext}"
-
- return file_name
-
-
-def get_file_info(message):
- media = get_media_from_message(message)
- if message.chat.type == ChatType.PRIVATE:
- user_idx = message.from_user.id
- else:
- user_idx = message.chat.id
- return {
- "user_id": user_idx,
- "file_id": getattr(media, "file_id", ""),
- "file_unique_id": getattr(media, "file_unique_id", ""),
- "file_name": get_name(message),
- "file_size": getattr(media, "file_size", 0),
- "mime_type": getattr(media, "mime_type", "None/unknown")
- }
-
-
-async def update_file_id(msg_id, multi_clients):
- file_ids = {}
- for client_id, client in multi_clients.items():
- log_msg = await client.get_messages(Telegram.FLOG_CHANNEL, msg_id)
- media = get_media_from_message(log_msg)
- file_ids[str(client.id)] = getattr(media, "file_id", "")
-
- return file_ids
-
-
-async def send_file(client: Client, db_id, file_id: str, message):
- file_caption = getattr(message, 'caption', None) or get_name(message)
- log_msg = await client.send_cached_media(chat_id=Telegram.FLOG_CHANNEL, file_id=file_id,
- caption=f'**{file_caption}**')
-
- if message.chat.type == ChatType.PRIVATE:
- await log_msg.reply_text(
- text=f"**Rá´Qá´á´ęąá´á´á´
ĘĘ :** [{message.from_user.first_name}](tg://user?id={message.from_user.id})\n**Uęąá´Ę ÉŞá´
:** `{message.from_user.id}`\n**FÉŞĘá´ ÉŞá´
:** `{db_id}`",
- disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN, quote=True)
- else:
- await log_msg.reply_text(
- text=f"**Rá´Qá´á´ęąá´á´á´
ĘĘ :** {message.chat.title} \n**CĘá´É´É´á´Ę ÉŞá´
:** `{message.chat.id}`\n**FÉŞĘá´ ÉŞá´
:** `{db_id}`",
- disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN, quote=True)
-
- return log_msg
- # return await client.send_cached_media(Telegram.BIN_CHANNEL, file_id)
-
diff --git a/FileStream/utils/human_readable.py b/FileStream/utils/human_readable.py
deleted file mode 100644
index 9298de483c2c819527d6bef8272586df026963da..0000000000000000000000000000000000000000
--- a/FileStream/utils/human_readable.py
+++ /dev/null
@@ -1,10 +0,0 @@
-def humanbytes(size):
- if not size:
- return ""
- power = 2**10
- n = 0
- Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'}
- while size > power:
- size /= power
- n += 1
- return str(round(size, 2)) + " " + Dic_powerN[n] + 'B'
diff --git a/FileStream/utils/render_template.py b/FileStream/utils/render_template.py
deleted file mode 100644
index c853da60b5f3370fdb4da0c44dd7ad86a1358272..0000000000000000000000000000000000000000
--- a/FileStream/utils/render_template.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import aiohttp
-import jinja2
-import urllib.parse
-from FileStream.config import Telegram, Server
-from FileStream.utils.database import Database
-from FileStream.utils.human_readable import humanbytes
-db = Database(Telegram.DATABASE_URL, Telegram.SESSION_NAME)
-
-async def render_page(db_id):
- file_data=await db.get_file(db_id)
- src = urllib.parse.urljoin(Server.URL, f'dl/{file_data["_id"]}')
- file_size = humanbytes(file_data['file_size'])
- file_name = file_data['file_name'].replace("_", " ")
-
- if str((file_data['mime_type']).split('/')[0].strip()) == 'video':
- template_file = "FileStream/template/play.html"
- else:
- template_file = "FileStream/template/dl.html"
- async with aiohttp.ClientSession() as s:
- async with s.get(src) as u:
- file_size = humanbytes(int(u.headers.get('Content-Length')))
-
- with open(template_file) as f:
- template = jinja2.Template(f.read())
-
- return template.render(
- file_name=file_name,
- file_url=src,
- file_size=file_size
- )
diff --git a/FileStream/utils/time_format.py b/FileStream/utils/time_format.py
deleted file mode 100644
index 78537ca0798e0dc21f76a95d56e0e7ae49231ce2..0000000000000000000000000000000000000000
--- a/FileStream/utils/time_format.py
+++ /dev/null
@@ -1,22 +0,0 @@
-def get_readable_time(seconds: int) -> str:
- count = 0
- readable_time = ""
- time_list = []
- time_suffix_list = ["s", "m", "h", " days"]
- while count < 4:
- count += 1
- if count < 3:
- remainder, result = divmod(seconds, 60)
- else:
- remainder, result = divmod(seconds, 24)
- if seconds == 0 and remainder == 0:
- break
- time_list.append(int(result))
- seconds = int(remainder)
- for x in range(len(time_list)):
- time_list[x] = str(time_list[x]) + time_suffix_list[x]
- if len(time_list) == 4:
- readable_time += time_list.pop() + ", "
- time_list.reverse()
- readable_time += ": ".join(time_list)
- return readable_time
diff --git a/FileStream/utils/translation.py b/FileStream/utils/translation.py
deleted file mode 100644
index 7cf48df7950e2f90c866642393da69855b5905c4..0000000000000000000000000000000000000000
--- a/FileStream/utils/translation.py
+++ /dev/null
@@ -1,72 +0,0 @@
-from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
-from FileStream.config import Telegram
-
-class LANG(object):
-
- START_TEXT = """
-đ Há´Ę, {}\n
-I'á´ á´á´Ęá´É˘Ęá´á´ ŇÉŞĘá´s sá´Ęá´á´á´ÉŞÉ´É˘ Ęá´á´ á´s á´Ąá´ĘĘ á´
ÉŞĘá´á´á´ ĘÉŞÉ´á´s ɢá´É´á´Ęá´á´á´Ę\n
-á´Ąá´Ęá´ÉŞÉ´É˘ á´É´ á´Ęá´É´É´á´Ęs á´É´á´
á´ĘÉŞá´ á´á´á´ á´Ęá´á´\n
-đ @{}\n"""
-
- HELP_TEXT = """
-- á´á´
á´
á´á´ á´s á´É´ á´á´
á´ÉŞÉ´ á´É´ á´Ęá´ á´Ęá´É´É´á´Ę
-- sá´É´á´
á´á´ á´É´Ę á´
á´á´á´á´á´É´á´ á´Ę á´á´á´
ÉŞá´
-- ÉŞ'ĘĘ á´Ęá´á´ ÉŞá´
á´ sá´Ęá´á´á´á´ĘĘá´ ĘÉŞÉ´á´\n
-đ á´á´
á´Ęá´ á´á´É´á´á´É´á´ sá´ĘÉŞá´á´ĘĘ á´Ęá´ĘÉŞĘÉŞá´á´á´
.\n
- Ęá´á´á´Ęá´ Ęá´É˘s á´á´ á´
á´á´ á´Ęá´á´á´Ę"""
-
- ABOUT_TEXT = """
-â á´Ę É´á´á´á´ : {}\n
-⌠ᴠá´ĘsÉŞá´É´ : {}
-⌠á´á´á´
á´á´á´á´
á´É´ : 06-January-2024
-⌠á´
á´á´ á´Ęá´á´á´Ę : Avishkar Patil\n
-"""
-
- STREAM_TEXT = """
-đŹđźđđż đđśđťđ¸ đđ˛đťđ˛đżđŽđđ˛đą !\n
-đ FÉŞĘá´ É´á´á´á´ : {}\n
-đŚ FÉŞĘá´ ęąÉŞá´˘á´ : {}\n
-đĽ Dá´á´ĄÉ´Ęá´á´á´
: {}\n
-đĽ Wá´á´á´Ę : {}\n
-đ SĘá´Ęá´ : {}\n"""
-
- STREAM_TEXT_X = """
-đŹđźđđż đđśđťđ¸ đđ˛đťđ˛đżđŽđđ˛đą !\n
-đ FÉŞĘá´ É´á´á´á´ : {}\n
-đŚ FÉŞĘá´ ęąÉŞá´˘á´ : {}\n
-đĽ Dá´á´ĄÉ´Ęá´á´á´
: {}\n
-đ SĘá´Ęá´ : {}\n"""
-
-
- BAN_TEXT = "__Sá´ĘĘĘ SÉŞĘ, Yá´á´ á´Ęá´ Bá´É´É´á´á´
á´á´ á´sá´ á´á´.__\n\n**[Cá´É´á´á´á´á´ Dá´á´ á´Ęá´á´á´Ę](tg://user?id={}) TĘá´Ę WÉŞĘĘ Há´Ęá´ Yá´á´**"
-
-
-class BUTTON(object):
- START_BUTTONS = InlineKeyboardMarkup(
- [[
- InlineKeyboardButton('Ęá´Ęá´', callback_data='help'),
- InlineKeyboardButton('á´Ęá´á´á´', callback_data='about'),
- InlineKeyboardButton('á´Ęá´sá´', callback_data='close')
- ],
- [InlineKeyboardButton("đ˘ á´á´á´
á´á´á´ á´Ęá´É´É´á´Ę", url=f'https://t.me/{Telegram.UPDATES_CHANNEL}')]
- ]
- )
- HELP_BUTTONS = InlineKeyboardMarkup(
- [[
- InlineKeyboardButton('Ęá´á´á´', callback_data='home'),
- InlineKeyboardButton('á´Ęá´á´á´', callback_data='about'),
- InlineKeyboardButton('á´Ęá´sá´', callback_data='close'),
- ],
- [InlineKeyboardButton("đ˘ á´á´á´
á´á´á´ á´Ęá´É´É´á´Ę", url=f'https://t.me/{Telegram.UPDATES_CHANNEL}')]
- ]
- )
- ABOUT_BUTTONS = InlineKeyboardMarkup(
- [[
- InlineKeyboardButton('Ęá´á´á´', callback_data='home'),
- InlineKeyboardButton('Ęá´Ęá´', callback_data='help'),
- InlineKeyboardButton('á´Ęá´sá´', callback_data='close'),
- ],
- [InlineKeyboardButton("đ˘ á´á´á´
á´á´á´ á´Ęá´É´É´á´Ę", url=f'https://t.me/{Telegram.UPDATES_CHANNEL}')]
- ]
- )
diff --git a/FileStreamBot b/FileStreamBot
deleted file mode 160000
index 1068087588910dc4095952e5159b97ff8f5cf86e..0000000000000000000000000000000000000000
--- a/FileStreamBot
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 1068087588910dc4095952e5159b97ff8f5cf86e
diff --git a/Filer b/Filer
new file mode 160000
index 0000000000000000000000000000000000000000..a7e554d4bd09fe3349e988e498f2413e4c3dc4aa
--- /dev/null
+++ b/Filer
@@ -0,0 +1 @@
+Subproject commit a7e554d4bd09fe3349e988e498f2413e4c3dc4aa
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000000000000000000000000000000..be3f7b28e564e7dd05eaf59d64adba1a4065ac0e
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,661 @@
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+ A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+ The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+ An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU Affero General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Remote Network Interaction; Use with the GNU General Public License.
+
+ Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+.
diff --git a/Procfile b/Procfile
deleted file mode 100644
index c1411fe83fadd8a2edbd155b860bd2bd0cb7c4d1..0000000000000000000000000000000000000000
--- a/Procfile
+++ /dev/null
@@ -1 +0,0 @@
-web: python -m FileStream
\ No newline at end of file
diff --git a/addons.txt b/addons.txt
new file mode 100644
index 0000000000000000000000000000000000000000..0c2c8289aeb8d2a998292fb16302454447985772
--- /dev/null
+++ b/addons.txt
@@ -0,0 +1,19 @@
+covid
+emoji
+fonttools
+gtts
+# gingerit
+jikanpy
+git+https://github.com/New-dev0/AsyncLyricsExtractor.git
+git+https://github.com/ufoptg/drawHub.git
+pokedex.py
+pyfiglet
+pygments
+pyjokes
+quotefancy
+shazamio
+speechrecognition
+speedtest-cli
+textblob
+wikipedia
+https://github.com/ufoptg/google_trans_new/archive/refs/tags/1.2.0.zip
diff --git a/app.json b/app.json
deleted file mode 100644
index 3f5d59bab65b620e011765cf19ef1037d98dd058..0000000000000000000000000000000000000000
--- a/app.json
+++ /dev/null
@@ -1,117 +0,0 @@
-{
- "name": "FileStreamBot",
- "description": "A Telegram Bot to Convert Telegram Files To Direct & Streamable Links.",
- "keywords": [
- "telegram",
- "files",
- "stream"
- ],
- "repository": "https://github.com/avipatilpro/FileStreamBot/",
- "success_url": "/",
- "logo": "https://i.ibb.co/ZJzJ9Hq/link-3x.png",
- "env": {
- "ENV": {
- "description": "Set this to True if you don't want to crash the bot",
- "value": "True"
- },
- "API_ID": {
- "description": "Get this value from https://my.telegram.org"
- },
- "API_HASH": {
- "description": "Get this value from https://my.telegram.org"
- },
- "BOT_TOKEN": {
- "description": "Get this value from @BotFather"
- },
- "FLOG_CHANNEL": {
- "description": "ID of Channel Where store files sent by users. Read the readme for more info about this var"
- },
- "ULOG_CHANNEL": {
- "description": "ID of Channel Where store New Users data. Read the readme for more info about this var"
- },
- "OWNER_ID": {
- "description": "Your Telegram User ID as Owner"
- },
- "DATABASE_URL": {
- "description": "MongoDB URI for saving User Data and Files List created by user."
- },
- "AUTH_USERS": {
- "description": "Put IDs of Auth Usrs where bot will work. You can add multiple IDs & separate with Space.",
- "required": false
- },
- "UPDATES_CHANNEL": {
- "description": "Channel Username without `@` to set channel as Update Channel",
- "required": false
- },
- "FORCE_SUB_ID": {
- "description": "Channel ID starts with -100 to set channel as Force Sub Channel",
- "required": false
- },
- "FORCE_SUB": {
- "description": "Set to True, so every user have to Join update channel to use the bot.",
- "required": false
- },
- "SLEEP_THRESHOLD": {
- "description": "Set global flood wait threshold, auto-retry requests under 60s. ",
- "required": false
- },
- "WORKERS": {
- "description": "No. of workers that is to be assigned.",
- "required": false
- },
- "PORT": {
- "description": "The port that you want your webapp to be listened to",
- "required": false
- },
- "NO_PORT": {
- "description": "If you don't want your port to be displayed. Set True or False",
- "value": "True",
- "required": false
- },
- "HAS_SSL": {
- "description": "(can be either True or False) If you want the generated links in https format.",
- "value": "True",
- "required": false
- },
- "BIND_ADDRESS": {
- "description": "Your server bind address. default to 0.0.0.0",
- "required": false
- },
- "FQDN": {
- "description": "Heroku app Link without http/s://, you can set later. its required",
- "required": false
- },
- "SESSION_NAME": {
- "description": "Name for the Database created on your MongoDB. Defaults to FileStream",
- "required": false
- },
- "FILE_PIC": {
- "description": "To set Image at /files command. Defaults to pre-set image.",
- "required": false
- },
- "START_PIC": {
- "description": "To set Image at /start command. Defaults to pre-set image.",
- "required": false
- },
- "VERIFY_PIC": {
- "description": "To set Image at Force Subscribe Verify. Defaults to pre-set image.",
- "required": false
- },
- "MODE": {
- "description": "Should be set to `secondary` if you only want to use the server for serving files.",
- "required": false
- }
- },
- "buildpacks": [
- {
- "url": "heroku/python"
- }
- ],
- "stack": "heroku-22",
- "formation": {
- "web": {
- "quantity": 1,
- "size": "eco"
- }
- }
-}
diff --git a/assistant/__init__.py b/assistant/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..cba67e1dc985e53c5c2ce2b2d005a0135dcb96d4
--- /dev/null
+++ b/assistant/__init__.py
@@ -0,0 +1,34 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from telethon import Button, custom
+
+from plugins import ATRA_COL, InlinePlugin
+from pyUltroid import *
+from pyUltroid import _ult_cache
+from pyUltroid._misc import owner_and_sudos
+from pyUltroid._misc._assistant import asst_cmd, callback, in_pattern
+from pyUltroid.fns.helper import *
+from pyUltroid.fns.tools import get_stored_file
+from strings import get_languages, get_string
+
+OWNER_NAME = ultroid_bot.full_name
+OWNER_ID = ultroid_bot.uid
+
+AST_PLUGINS = {}
+
+
+async def setit(event, name, value):
+ try:
+ udB.set_key(name, value)
+ except BaseException as er:
+ LOGS.exception(er)
+ return await event.edit("`Something Went Wrong`")
+
+
+def get_back_button(name):
+ return [Button.inline("ÂŤ Bá´á´á´", data=f"{name}")]
diff --git a/assistant/callbackstuffs.py b/assistant/callbackstuffs.py
new file mode 100644
index 0000000000000000000000000000000000000000..955892949562b2d64d7e170cabe8a37d7bb84297
--- /dev/null
+++ b/assistant/callbackstuffs.py
@@ -0,0 +1,1325 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import ast
+import asyncio
+import re
+import sys
+import time
+from asyncio.exceptions import TimeoutError as AsyncTimeOut
+from os import execl, remove
+from random import choice
+
+from bs4 import BeautifulSoup as bs
+
+try:
+ from pyUltroid.fns.gDrive import GDriveManager
+except ImportError:
+ GDriveManager = None
+from telegraph import upload_file as upl
+from telethon import Button, events
+from telethon.tl.types import MessageMediaWebPage
+from telethon.utils import get_peer_id
+
+from pyUltroid.fns.helper import fast_download, progress
+from pyUltroid.fns.tools import Carbon, async_searcher, get_paste, telegraph_client
+from pyUltroid.startup.loader import Loader
+
+from . import *
+
+# --------------------------------------------------------------------#
+telegraph = telegraph_client()
+GDrive = GDriveManager() if GDriveManager else None
+# --------------------------------------------------------------------#
+
+
+def text_to_url(event):
+ """function to get media url (with|without) Webpage"""
+ if isinstance(event.media, MessageMediaWebPage):
+ webpage = event.media.webpage
+ if not isinstance(webpage, types.WebPageEmpty) and webpage.type in ["photo"]:
+ return webpage.display_url
+ return event.text
+
+
+# --------------------------------------------------------------------#
+
+_buttons = {
+ "otvars": {
+ "text": "Other Variables to set for @TeamUltroid:",
+ "buttons": [
+ [
+ Button.inline("Tá´É˘ Lá´É˘É˘á´Ę", data="taglog"),
+ Button.inline("Sá´á´á´ĘFĘá´É´", data="cbs_sfban"),
+ ],
+ [
+ Button.inline("Sá´á´
á´ Má´á´
á´", data="sudo"),
+ Button.inline("Há´É´á´
Ęá´Ę", data="hhndlr"),
+ ],
+ [
+ Button.inline("Exá´Ęá´ PĘá´É˘ÉŞÉ´s", data="plg"),
+ Button.inline("Aá´
á´
á´É´s", data="eaddon"),
+ ],
+ [
+ Button.inline("Eá´á´á´ÉŞ ÉŞÉ´ Há´Ęá´", data="emoj"),
+ Button.inline("Sá´á´ ɢDĘÉŞá´ á´", data="gdrive"),
+ ],
+ [
+ Button.inline("IÉ´ĘÉŞÉ´á´ PÉŞá´", data="inli_pic"),
+ Button.inline("Sá´á´
á´ HNDLR", data="shndlr"),
+ ],
+ [Button.inline("Dá´á´Ę Má´á´
á´", "cbs_oofdm")],
+ [Button.inline("ÂŤ Bá´á´á´", data="setter")],
+ ],
+ },
+ "sfban": {
+ "text": "SuperFban Settings:",
+ "buttons": [
+ [Button.inline("FBá´É´ GĘá´á´á´", data="sfgrp")],
+ [Button.inline("Exá´Ęá´á´
á´ Fá´á´
s", data="abs_sfexf")],
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_otvars")],
+ ],
+ },
+ "apauto": {
+ "text": "This'll auto approve on outgoing messages",
+ "buttons": [
+ [Button.inline("Aá´á´á´ Aá´á´Ęá´á´ á´ ON", data="apon")],
+ [Button.inline("Aá´á´á´ Aá´á´Ęá´á´ á´ OFF", data="apof")],
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_pmcstm")],
+ ],
+ },
+ "alvcstm": {
+ "text": f"Customise your {HNDLR}alive. Choose from the below options -",
+ "buttons": [
+ [Button.inline("AĘÉŞá´ á´ Tá´xá´", data="abs_alvtx")],
+ [Button.inline("AĘÉŞá´ á´ á´á´á´
ÉŞá´", data="alvmed")],
+ [Button.inline("Dá´Ęá´á´á´ AĘÉŞá´ á´ Má´á´
ÉŞá´", data="delmed")],
+ [Button.inline("ÂŤ Bá´á´á´", data="setter")],
+ ],
+ },
+ "pmcstm": {
+ "text": "Customise your PMPERMIT Settings -",
+ "buttons": [
+ [
+ Button.inline("Pá´ Tá´xá´", data="pmtxt"),
+ Button.inline("Pá´ Má´á´
ÉŞá´", data="pmmed"),
+ ],
+ [
+ Button.inline("Aá´á´á´ Aá´á´Ęá´á´ á´", data="cbs_apauto"),
+ Button.inline("PMLOGGER", data="pml"),
+ ],
+ [
+ Button.inline("Sá´á´ Wá´ĘÉ´s", data="swarn"),
+ Button.inline("Dá´Ęá´á´á´ Pá´ Má´á´
ÉŞá´", data="delpmmed"),
+ ],
+ [Button.inline("PMPermit Type", data="cbs_pmtype")],
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_ppmset")],
+ ],
+ },
+ "pmtype": {
+ "text": "Select the type of PMPermit needed.",
+ "buttons": [
+ [Button.inline("Inline", data="inpm_in")],
+ [Button.inline("Normal", data="inpm_no")],
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_pmcstm")],
+ ],
+ },
+ "ppmset": {
+ "text": "PMPermit Settings:",
+ "buttons": [
+ [Button.inline("Tá´ĘÉ´ PMPá´Ęá´ÉŞá´ OÉ´", data="pmon")],
+ [Button.inline("Tá´ĘÉ´ PMPá´Ęá´ÉŞá´ OŇŇ", data="pmoff")],
+ [Button.inline("Cá´sá´á´á´ÉŞá´˘á´ PMPá´Ęá´ÉŞá´", data="cbs_pmcstm")],
+ [Button.inline("ÂŤ Bá´á´á´", data="setter")],
+ ],
+ },
+ "chatbot": {
+ "text": "From This Feature U can chat with ppls Via ur Assistant Bot.\n[More info](https://t.me/UltroidUpdates/2)",
+ "buttons": [
+ [
+ Button.inline("CĘá´á´ Bá´á´ OÉ´", data="onchbot"),
+ Button.inline("CĘá´á´ Bá´á´ OŇŇ", data="ofchbot"),
+ ],
+ [
+ Button.inline("Bá´á´ Wá´Ęá´á´á´á´", data="bwel"),
+ Button.inline("Bá´á´ Wá´Ęá´á´á´á´ Má´á´
ÉŞá´", data="botmew"),
+ ],
+ [Button.inline("Bá´á´ IÉ´Ňá´ Tá´xá´", data="botinfe")],
+ [Button.inline("Fá´Ęá´á´ Sá´Ęsá´ĘÉŞĘá´", data="pmfs")],
+ [Button.inline("ÂŤ Bá´á´á´", data="setter")],
+ ],
+ },
+ "vcb": {
+ "text": "From This Feature U can play songs in group voice chat\n\n[moreinfo](https://t.me/UltroidUpdates/4)",
+ "buttons": [
+ [Button.inline("VC Sá´ssÉŞá´É´", data="abs_vcs")],
+ [Button.inline("ÂŤ Bá´á´á´", data="setter")],
+ ],
+ },
+ "oofdm": {
+ "text": "About [Dual Mode](https://t.me/UltroidUpdates/18)",
+ "buttons": [
+ [
+ Button.inline("Dá´á´Ę Má´á´
á´ OÉ´", "dmof"),
+ Button.inline("Dá´á´Ę Má´á´
á´ OŇŇ", "dmof"),
+ ],
+ [Button.inline("Dá´á´Ę Má´á´
á´ HÉ´á´
ĘĘ", "dmhn")],
+ [Button.inline("ÂŤ Back", data="cbs_otvars")],
+ ],
+ },
+ "apiset": {
+ "text": get_string("ast_1"),
+ "buttons": [
+ [Button.inline("Remove.bg API", data="abs_rmbg")],
+ [Button.inline("DEEP API", data="abs_dapi")],
+ [Button.inline("OCR API", data="abs_oapi")],
+ [Button.inline("SERP API", data="abs_sapi")],
+ [Button.inline("ÂŤ Back", data="setter")],
+ ],
+ },
+}
+
+_convo = {
+ "rmbg": {
+ "var": "RMBG_API",
+ "name": "Remove.bg API Key",
+ "text": get_string("ast_2"),
+ "back": "cbs_apiset",
+ },
+ "dapi": {
+ "var": "DEEP_AI",
+ "name": "Deep AI Api Key",
+ "text": "Get Your Deep Api from deepai.org and send here.",
+ "back": "cbs_apiset",
+ },
+ "oapi": {
+ "var": "OCR_API",
+ "name": "Ocr Api Key",
+ "text": "Get Your OCR api from ocr.space and send that Here.",
+ "back": "cbs_apiset",
+ },
+ "sapi": {
+ "var": "SERPAPI",
+ "name": "Serp Api Key",
+ "text": "Get Your SERP api from https://serpapi.com/users/sign_in and send that Here.",
+ "back": "cbs_apiset",
+ },
+ "pmlgg": {
+ "var": "PMLOGGROUP",
+ "name": "Pm Log Group",
+ "text": "Send chat id of chat which you want to save as Pm log Group.",
+ "back": "pml",
+ },
+ "vcs": {
+ "var": "VC_SESSION",
+ "name": "Vc Session",
+ "text": "**Vc session**\nEnter the New session u generated for vc bot.\n\nUse /cancel to terminate the operation.",
+ "back": "cbs_vcb",
+ },
+ "settag": {
+ "var": "TAG_LOG",
+ "name": "Tag Log Group",
+ "text": f"Make a group, add your assistant and make it admin.\nGet the `{HNDLR}id` of that group and send it here for tag logs.\n\nUse /cancel to cancel.",
+ "back": "taglog",
+ },
+ "alvtx": {
+ "var": "ALIVE_TEXT",
+ "name": "Alive Text",
+ "text": "**Alive Text**\nEnter the new alive text.\n\nUse /cancel to terminate the operation.",
+ "back": "cbs_alvcstm",
+ },
+ "sfexf": {
+ "var": "EXCLUDE_FED",
+ "name": "Excluded Fed",
+ "text": "Send the Fed IDs you want to exclude in the ban. Split by a space.\neg`id1 id2 id3`\nSet is as `None` if you dont want any.\nUse /cancel to go back.",
+ "back": "cbs_sfban",
+ },
+}
+
+
+TOKEN_FILE = "resources/auths/auth_token.txt"
+
+
+@callback(
+ re.compile(
+ "sndplug_(.*)",
+ ),
+ owner=True,
+)
+async def send(eve):
+ key, name = (eve.data_match.group(1)).decode("UTF-8").split("_")
+ thumb = "resources/extras/inline.jpg"
+ await eve.answer("â Sending â ")
+ data = f"uh_{key}_"
+ index = None
+ if "|" in name:
+ name, index = name.split("|")
+ key = "plugins" if key == "Official" else key.lower()
+ plugin = f"{key}/{name}.py"
+ _ = f"pasta-{plugin}"
+ if index is not None:
+ data += f"|{index}"
+ _ += f"|{index}"
+ buttons = [
+ [
+ Button.inline(
+ "ÂŤ Pá´sá´á´ Âť",
+ data=_,
+ )
+ ],
+ [
+ Button.inline("ÂŤ Bá´á´á´", data=data),
+ ],
+ ]
+ try:
+ await eve.edit(file=plugin, thumb=thumb, buttons=buttons)
+ except Exception as er:
+ await eve.answer(str(er), alert=True)
+
+
+heroku_api, app_name = Var.HEROKU_API, Var.HEROKU_APP_NAME
+
+
+@callback("updatenow", owner=True)
+async def update(eve):
+ repo = Repo()
+ ac_br = repo.active_branch
+ ups_rem = repo.remote("upstream")
+ if heroku_api:
+ import heroku3
+
+ try:
+ heroku = heroku3.from_key(heroku_api)
+ heroku_app = None
+ heroku_applications = heroku.apps()
+ except BaseException as er:
+ LOGS.exception(er)
+ return await eve.edit("`Wrong HEROKU_API.`")
+ for app in heroku_applications:
+ if app.name == app_name:
+ heroku_app = app
+ if not heroku_app:
+ await eve.edit("`Wrong HEROKU_APP_NAME.`")
+ repo.__del__()
+ return
+ await eve.edit(get_string("clst_1"))
+ ups_rem.fetch(ac_br)
+ repo.git.reset("--hard", "FETCH_HEAD")
+ heroku_git_url = heroku_app.git_url.replace(
+ "https://", f"https://api:{heroku_api}@"
+ )
+
+ if "heroku" in repo.remotes:
+ remote = repo.remote("heroku")
+ remote.set_url(heroku_git_url)
+ else:
+ remote = repo.create_remote("heroku", heroku_git_url)
+ try:
+ remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True)
+ except GitCommandError as error:
+ await eve.edit(f"`Here is the error log:\n{error}`")
+ repo.__del__()
+ return
+ await eve.edit("`Successfully Updated!\nRestarting, please wait...`")
+ else:
+ await eve.edit(get_string("clst_1"))
+ call_back()
+ await bash("git pull && pip3 install -r requirements.txt")
+ execl(sys.executable, sys.executable, "-m", "pyUltroid")
+
+
+@callback(re.compile("changes(.*)"), owner=True)
+async def changes(okk):
+ match = okk.data_match.group(1).decode("utf-8")
+ await okk.answer(get_string("clst_3"))
+ repo = Repo.init()
+ button = [[Button.inline("Update Now", data="updatenow")]]
+ changelog, tl_chnglog = await gen_chlog(
+ repo, f"HEAD..upstream/{repo.active_branch}"
+ )
+ cli = "\n\nClick the below button to update!"
+ if not match:
+ try:
+ if len(tl_chnglog) > 700:
+ tl_chnglog = f"{tl_chnglog[:700]}..."
+ button.append([Button.inline("View Complete", "changesall")])
+ await okk.edit("⢠Writing Changelogs đ â˘")
+ img = await Carbon(
+ file_name="changelog",
+ code=tl_chnglog,
+ backgroundColor=choice(ATRA_COL),
+ language="md",
+ )
+ return await okk.edit(
+ f"**⢠Ultroid Userbot â˘**{cli}", file=img, buttons=button
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ changelog_str = changelog + cli
+ if len(changelog_str) > 1024:
+ await okk.edit(get_string("upd_4"))
+ await asyncio.sleep(2)
+ with open("ultroid_updates.txt", "w+") as file:
+ file.write(tl_chnglog)
+ await okk.edit(
+ get_string("upd_5"),
+ file="ultroid_updates.txt",
+ buttons=button,
+ )
+ remove("ultroid_updates.txt")
+ return
+ await okk.edit(
+ changelog_str,
+ buttons=button,
+ parse_mode="html",
+ )
+
+
+@callback(
+ re.compile(
+ "pasta-(.*)",
+ ),
+ owner=True,
+)
+async def _(e):
+ ok = (e.data_match.group(1)).decode("UTF-8")
+ index = None
+ if "|" in ok:
+ ok, index = ok.split("|")
+ with open(ok, "r") as hmm:
+ _, key = await get_paste(hmm.read())
+ link = f"https://spaceb.in/{key}"
+ raw = f"https://spaceb.in/api/v1/documents/{key}/raw"
+ if not _:
+ return await e.answer(key[:30], alert=True)
+ if ok.startswith("addons"):
+ key = "Addons"
+ elif ok.startswith("vcbot"):
+ key = "VCBot"
+ else:
+ key = "Official"
+ data = f"uh_{key}_"
+ if index is not None:
+ data += f"|{index}"
+ await e.edit(
+ "",
+ buttons=[
+ [Button.url("LÉŞÉ´á´", link), Button.url("Rá´á´Ą", raw)],
+ [Button.inline("ÂŤ Bá´á´á´", data=data)],
+ ],
+ )
+
+
+@callback(re.compile("cbs_(.*)"), owner=True)
+async def _edit_to(event):
+ match = event.data_match.group(1).decode("utf-8")
+ data = _buttons.get(match)
+ if not data:
+ return
+ await event.edit(data["text"], buttons=data["buttons"], link_preview=False)
+
+
+@callback(re.compile("abs_(.*)"), owner=True)
+async def convo_handler(event: events.CallbackQuery):
+ match = event.data_match.group(1).decode("utf-8")
+ if not _convo.get(match):
+ return
+ await event.delete()
+ get_ = _convo[match]
+ back = get_["back"]
+ async with event.client.conversation(event.sender_id) as conv:
+ await conv.send_message(get_["text"])
+ response = await conv.get_response()
+ themssg = response.message
+ try:
+ themssg = ast.literal_eval(themssg)
+ except Exception:
+ pass
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button(back),
+ )
+ await setit(event, get_["var"], themssg)
+ await conv.send_message(
+ f"{get_['name']} changed to `{themssg}`",
+ buttons=get_back_button(back),
+ )
+
+
+@callback("authorise", owner=True)
+async def _(e):
+ if not e.is_private:
+ return
+ url = GDrive._create_token_file()
+ await e.edit("Go to the below link and send the code!")
+ async with asst.conversation(e.sender_id) as conv:
+ await conv.send_message(url)
+ code = await conv.get_response()
+ if GDrive._create_token_file(code=code.text):
+ await conv.send_message(
+ "`Success!\nYou are all set to use Google Drive with Ultroid Userbot.`",
+ buttons=Button.inline("Main Menu", data="setter"),
+ )
+ else:
+ await conv.send_message("Wrong code! Click authorise again.")
+
+
+@callback("folderid", owner=True, func=lambda x: x.is_private)
+async def _(e):
+ if not e.is_private:
+ return
+ msg = (
+ "Send your FOLDER ID\n\n"
+ + "For FOLDER ID:\n"
+ + "1. Open Google Drive App.\n"
+ + "2. Create Folder.\n"
+ + "3. Make that folder public.\n"
+ + "4. Send link of that folder."
+ )
+ await e.delete()
+ async with asst.conversation(e.sender_id, timeout=150) as conv:
+ await conv.send_message(msg)
+ repl = await conv.get_response()
+ id = repl.text
+ if id.startswith("https"):
+ id = id.split("?id=")[-1]
+ udB.set_key("GDRIVE_FOLDER_ID", id)
+ await repl.reply(
+ "`Success.`",
+ buttons=get_back_button("gdrive"),
+ )
+
+
+@callback("gdrive", owner=True)
+async def _(e):
+ if not e.is_private:
+ return
+ await e.edit(
+ "Click Authorise and send the code.\n\nYou can use your own CLIENT ID and SECRET by [this](https://t.me/UltroidUpdates/37)",
+ buttons=[
+ [
+ Button.inline("Folder ID", data="folderid"),
+ Button.inline("Authorise", data="authorise"),
+ ],
+ [Button.inline("ÂŤ Back", data="cbs_otvars")],
+ ],
+ link_preview=False,
+ )
+
+
+@callback("dmof", owner=True)
+async def rhwhe(e):
+ if udB.get_key("DUAL_MODE"):
+ udB.del_key("DUAL_MODE")
+ key = "Off"
+ else:
+ udB.set_key("DUAL_MODE", "True")
+ key = "On"
+ Msg = f"Dual Mode : {key}"
+ await e.edit(Msg, buttons=get_back_button("cbs_otvars"))
+
+
+@callback("dmhn", owner=True)
+async def hndlrr(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "DUAL_HNDLR"
+ name = "Dual Handler"
+ CH = udB.get_key(var) or "/"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ f"Send The Symbol Which u want as Handler/Trigger to use your Assistant bot\nUr Current Handler is [ `{CH}` ]\n\n use /cancel to cancel.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif len(themssg) > 1:
+ await conv.send_message(
+ "Incorrect Handler",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ else:
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}",
+ buttons=get_back_button("cbs_otvars"),
+ )
+
+
+@callback("emoj", owner=True)
+async def emoji(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "EMOJI_IN_HELP"
+ name = f"Emoji in `{HNDLR}help` menu"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message("Send emoji u want to set đ.\n\nUse /cancel to cancel.")
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif themssg.startswith(("/", HNDLR)):
+ await conv.send_message(
+ "Incorrect Emoji",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ else:
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}\n",
+ buttons=get_back_button("cbs_otvars"),
+ )
+
+
+@callback("plg", owner=True)
+async def pluginch(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "PLUGIN_CHANNEL"
+ name = "Plugin Channel"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "Send id or username of a channel from where u want to install all plugins\n\nOur Channel~ @ultroidplugins\n\nUse /cancel to cancel.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif themssg.startswith(("/", HNDLR)):
+ await conv.send_message(
+ "Incorrect channel",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ else:
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}\n After Setting All Things Do Restart",
+ buttons=get_back_button("cbs_otvars"),
+ )
+
+
+@callback("hhndlr", owner=True)
+async def hndlrr(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "HNDLR"
+ name = "Handler/ Trigger"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ f"Send The Symbol Which u want as Handler/Trigger to use bot\nUr Current Handler is [ `{HNDLR}` ]\n\n use /cancel to cancel.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif len(themssg) > 1:
+ await conv.send_message(
+ "Incorrect Handler",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif themssg.startswith(("/", "#", "@")):
+ await conv.send_message(
+ "This cannot be used as handler",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ else:
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}",
+ buttons=get_back_button("cbs_otvars"),
+ )
+
+
+@callback("shndlr", owner=True)
+async def hndlrr(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "SUDO_HNDLR"
+ name = "Sudo Handler"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "Send The Symbol Which u want as Sudo Handler/Trigger to use bot\n\n use /cancel to cancel."
+ )
+
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif len(themssg) > 1:
+ await conv.send_message(
+ "Incorrect Handler",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ elif themssg.startswith(("/", "#", "@")):
+ await conv.send_message(
+ "This cannot be used as handler",
+ buttons=get_back_button("cbs_otvars"),
+ )
+ else:
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}",
+ buttons=get_back_button("cbs_otvars"),
+ )
+
+
+@callback("taglog", owner=True)
+async def tagloggrr(e):
+ BUTTON = [
+ [Button.inline("SET TAG LOG", data="abs_settag")],
+ [Button.inline("DELETE TAG LOG", data="deltag")],
+ get_back_button("cbs_otvars"),
+ ]
+ await e.edit(
+ "Choose Options",
+ buttons=BUTTON,
+ )
+
+
+@callback("deltag", owner=True)
+async def _(e):
+ udB.del_key("TAG_LOG")
+ await e.answer("Done!!! Tag Logger has been turned Off")
+
+
+@callback("eaddon", owner=True)
+async def pmset(event):
+ BT = (
+ [Button.inline("Aá´
á´
á´É´s OŇŇ", data="edof")]
+ if udB.get_key("ADDONS")
+ else [Button.inline("Aá´
á´
á´É´s OÉ´", data="edon")]
+ )
+
+ await event.edit(
+ "ADDONS~ Extra Plugins:",
+ buttons=[
+ BT,
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_otvars")],
+ ],
+ )
+
+
+@callback("edon", owner=True)
+async def eddon(event):
+ var = "ADDONS"
+ await setit(event, var, "True")
+ await event.edit(
+ "Done! ADDONS has been turned on!!\n\n After Setting All Things Do Restart",
+ buttons=get_back_button("eaddon"),
+ )
+
+
+@callback("edof", owner=True)
+async def eddof(event):
+ udB.set_key("ADDONS", "False")
+ await event.edit(
+ "Done! ADDONS has been turned off!! After Setting All Things Do Restart",
+ buttons=get_back_button("eaddon"),
+ )
+
+
+@callback("sudo", owner=True)
+async def pmset(event):
+ BT = (
+ [Button.inline("Sá´á´
á´ Má´á´
á´ OŇŇ", data="ofsudo")]
+ if udB.get_key("SUDO")
+ else [Button.inline("Sá´á´
á´ Má´á´
á´ OÉ´", data="onsudo")]
+ )
+
+ await event.edit(
+ f"SUDO MODE ~ Some peoples can use ur Bot which u selected. To know More use `{HNDLR}help sudo`",
+ buttons=[
+ BT,
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_otvars")],
+ ],
+ )
+
+
+@callback("onsudo", owner=True)
+async def eddon(event):
+ var = "SUDO"
+ await setit(event, var, "True")
+ await event.edit(
+ "Done! SUDO MODE has been turned on!!\n\n After Setting All Things Do Restart",
+ buttons=get_back_button("sudo"),
+ )
+
+
+@callback("ofsudo", owner=True)
+async def eddof(event):
+ var = "SUDO"
+ await setit(event, var, "False")
+ await event.edit(
+ "Done! SUDO MODE has been turned off!! After Setting All Things Do Restart",
+ buttons=get_back_button("sudo"),
+ )
+
+
+@callback("sfgrp", owner=True)
+async def sfgrp(event):
+ await event.delete()
+ name = "FBan Group ID"
+ var = "FBAN_GROUP_ID"
+ pru = event.sender_id
+ async with asst.conversation(pru) as conv:
+ await conv.send_message(
+ f"Make a group, add @MissRose_Bot, send `{HNDLR}id`, copy that and send it here.\nUse /cancel to go back.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_sfban"),
+ )
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}",
+ buttons=get_back_button("cbs_sfban"),
+ )
+
+
+@callback("alvmed", owner=True)
+async def media(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "ALIVE_PIC"
+ name = "Alive Media"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "**Alive Media**\nSend me a pic/gif/media to set as alive media.\n\nUse /cancel to terminate the operation.",
+ )
+ response = await conv.get_response()
+ try:
+ themssg = response.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Operation cancelled!!",
+ buttons=get_back_button("cbs_alvcstm"),
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ if (
+ not (response.text).startswith("/")
+ and response.text != ""
+ and (not response.media or isinstance(response.media, MessageMediaWebPage))
+ ):
+ url = text_to_url(response)
+ elif response.sticker:
+ url = response.file.id
+ else:
+ media = await event.client.download_media(response, "alvpc")
+ try:
+ x = upl(media)
+ url = f"https://graph.org/{x[0]}"
+ remove(media)
+ except BaseException as er:
+ LOGS.exception(er)
+ return await conv.send_message(
+ "Terminated.",
+ buttons=get_back_button("cbs_alvcstm"),
+ )
+ await setit(event, var, url)
+ await conv.send_message(
+ f"{name} has been set.",
+ buttons=get_back_button("cbs_alvcstm"),
+ )
+
+
+@callback("delmed", owner=True)
+async def dell(event):
+ try:
+ udB.del_key("ALIVE_PIC")
+ return await event.edit(
+ get_string("clst_5"), buttons=get_back_button("cbs_alabs_vcstm")
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ return await event.edit(
+ get_string("clst_4"),
+ buttons=get_back_button("cbs_alabs_vcstm"),
+ )
+
+
+@callback("inpm_in", owner=True)
+async def inl_on(event):
+ var = "INLINE_PM"
+ await setit(event, var, "True")
+ await event.edit(
+ "Done!! PMPermit type has been set to inline!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_pmtype")]],
+ )
+
+
+@callback("inpm_no", owner=True)
+async def inl_on(event):
+ var = "INLINE_PM"
+ await setit(event, var, "False")
+ await event.edit(
+ "Done!! PMPermit type has been set to normal!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_pmtype")]],
+ )
+
+
+@callback("pmtxt", owner=True)
+async def name(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "PM_TEXT"
+ name = "PM Text"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "**PM Text**\nEnter the new Pmpermit text.\n\nu can use `{name}` `{fullname}` `{count}` `{mention}` `{username}` to get this from user Too\n\nUse /cancel to terminate the operation.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+ if len(themssg) > 4090:
+ return await conv.send_message(
+ "Message too long!\nGive a shorter message please!!",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}\n\nAfter Setting All Things Do restart",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+
+
+@callback("swarn", owner=True)
+async def name(event):
+ m = range(1, 10)
+ tultd = [Button.inline(f"{x}", data=f"wrns_{x}") for x in m]
+ lst = list(zip(tultd[::3], tultd[1::3], tultd[2::3]))
+ lst.append([Button.inline("ÂŤ Bá´á´á´", data="cbs_pmcstm")])
+ await event.edit(
+ "Select the number of warnings for a user before getting blocked in PMs.",
+ buttons=lst,
+ )
+
+
+@callback(re.compile(b"wrns_(.*)"), owner=True)
+async def set_wrns(event):
+ value = int(event.data_match.group(1).decode("UTF-8"))
+ if dn := udB.set_key("PMWARNS", value):
+ await event.edit(
+ f"PM Warns Set to {value}.\nNew users will have {value} chances in PMs before getting banned.",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+ else:
+ await event.edit(
+ f"Something went wrong, please check your {HNDLR}logs!",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+
+
+@callback("pmmed", owner=True)
+async def media(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "PMPIC"
+ name = "PM Media"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "**PM Media**\nSend me a pic/gif/sticker/link to set as pmpermit media.\n\nUse /cancel to terminate the operation.",
+ )
+ response = await conv.get_response()
+ try:
+ themssg = response.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Operation cancelled!!",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ media = await event.client.download_media(response, "pmpc")
+ if (
+ not (response.text).startswith("/")
+ and response.text != ""
+ and (not response.media or isinstance(response.media, MessageMediaWebPage))
+ ):
+ url = text_to_url(response)
+ elif response.sticker:
+ url = response.file.id
+ else:
+ try:
+ x = upl(media)
+ url = f"https://graph.org/{x[0]}"
+ remove(media)
+ except BaseException as er:
+ LOGS.exception(er)
+ return await conv.send_message(
+ "Terminated.",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+ await setit(event, var, url)
+ await conv.send_message(
+ f"{name} has been set.",
+ buttons=get_back_button("cbs_pmcstm"),
+ )
+
+
+@callback("delpmmed", owner=True)
+async def dell(event):
+ try:
+ udB.del_key("PMPIC")
+ return await event.edit(
+ get_string("clst_5"), buttons=get_back_button("cbs_pmcstm")
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ return await event.edit(
+ get_string("clst_4"),
+ buttons=[[Button.inline("ÂŤ Sá´á´á´ÉŞÉ´É˘s", data="setter")]],
+ )
+
+
+@callback("apon", owner=True)
+async def apon(event):
+ var = "AUTOAPPROVE"
+ await setit(event, var, "True")
+ await event.edit(
+ "Done!! AUTOAPPROVE Started!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_apauto")]],
+ )
+
+
+@callback("apof", owner=True)
+async def apof(event):
+ try:
+ udB.set_key("AUTOAPPROVE", "False")
+ return await event.edit(
+ "Done! AUTOAPPROVE Stopped!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_apauto")]],
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ return await event.edit(
+ get_string("clst_4"),
+ buttons=[[Button.inline("ÂŤ Sá´á´á´ÉŞÉ´É˘s", data="setter")]],
+ )
+
+
+@callback("pml", owner=True)
+async def l_vcs(event):
+ BT = (
+ [Button.inline("PMLOGGER OFF", data="pmlogof")]
+ if udB.get_key("PMLOG")
+ else [Button.inline("PMLOGGER ON", data="pmlog")]
+ )
+
+ await event.edit(
+ "PMLOGGER This Will Forward Ur Pm to Ur Private Group -",
+ buttons=[
+ BT,
+ [Button.inline("Pá´Lá´É˘É˘á´Ę GĘá´á´á´", "abs_pmlgg")],
+ [Button.inline("ÂŤ Bá´á´á´", data="cbs_pmcstm")],
+ ],
+ )
+
+
+@callback("pmlog", owner=True)
+async def pmlog(event):
+ await setit(event, "PMLOG", "True")
+ await event.edit(
+ "Done!! PMLOGGER Started!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="pml")]],
+ )
+
+
+@callback("pmlogof", owner=True)
+async def pmlogof(event):
+ try:
+ udB.del_key("PMLOG")
+ return await event.edit(
+ "Done! PMLOGGER Stopped!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="pml")]],
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ return await event.edit(
+ get_string("clst_4"),
+ buttons=[[Button.inline("ÂŤ Sá´á´á´ÉŞÉ´É˘s", data="setter")]],
+ )
+
+
+@callback("pmon", owner=True)
+async def pmonn(event):
+ var = "PMSETTING"
+ await setit(event, var, "True")
+ await event.edit(
+ "Done! PMPermit has been turned on!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_ppmset")]],
+ )
+
+
+@callback("pmoff", owner=True)
+async def pmofff(event):
+ var = "PMSETTING"
+ await setit(event, var, "False")
+ await event.edit(
+ "Done! PMPermit has been turned off!!",
+ buttons=[[Button.inline("ÂŤ Bá´á´á´", data="cbs_ppmset")]],
+ )
+
+
+@callback("botmew", owner=True)
+async def hhh(e):
+ async with e.client.conversation(e.chat_id) as conv:
+ await conv.send_message("Send Any Media to keep at your Bot's welcome ")
+ msg = await conv.get_response()
+ if not msg.media or msg.text.startswith("/"):
+ return await conv.send_message(
+ "Terminated!", buttons=get_back_button("cbs_chatbot")
+ )
+ udB.set_key("STARTMEDIA", msg.file.id)
+ await conv.send_message("Done!", buttons=get_back_button("cbs_chatbot"))
+
+
+@callback("botinfe", owner=True)
+async def hhh(e):
+ async with e.client.conversation(e.chat_id) as conv:
+ await conv.send_message(
+ "Send message to set to Display, when user Press Info button in Bot Welcome!\n\nsend `False` to completely remove that button.."
+ )
+ msg = await conv.get_response()
+ if msg.media or msg.text.startswith("/"):
+ return await conv.send_message(
+ "Terminated!", buttons=get_back_button("cbs_chatbot")
+ )
+ udB.set_key("BOT_INFO_START", msg.text)
+ await conv.send_message("Done!", buttons=get_back_button("cbs_chatbot"))
+
+
+@callback("pmfs", owner=True)
+async def heheh(event):
+ Ll = []
+ err = ""
+ async with event.client.conversation(event.chat_id) as conv:
+ await conv.send_message(
+ "⢠Send The Chat Id(s), which you want user to Join Before using Chat/Pm Bot\n\n⢠Send /clear to disable PmBot Force sub..\n⢠⢠Send /cancel to stop this process.."
+ )
+ await conv.send_message(
+ "Example : \n`-1001234567\n-100778888`\n\nFor Multiple Chat(s)."
+ )
+ try:
+ msg = await conv.get_response()
+ except AsyncTimeOut:
+ return await conv.send_message("**⢠TimeUp!**\nStart from /start back.")
+ if not msg.text or msg.text.startswith("/"):
+ timyork = "Cancelled!"
+ if msg.text == "/clear":
+ udB.del_key("PMBOT_FSUB")
+ timyork = "Done! Force Subscribe Stopped\nRestart your Bot!"
+ return await conv.send_message(
+ "Cancelled!", buttons=get_back_button("cbs_chatbot")
+ )
+ for chat in msg.message.split("\n"):
+ if chat.startswith("-") or chat.isdigit():
+ chat = int(chat)
+ try:
+ CHSJSHS = await event.client.get_entity(chat)
+ Ll.append(get_peer_id(CHSJSHS))
+ except Exception as er:
+ err += f"**{chat}** : {er}\n"
+ if err:
+ return await conv.send_message(err)
+ udB.set_key("PMBOT_FSUB", str(Ll))
+ await conv.send_message(
+ "Done!\nRestart Your Bot.", buttons=get_back_button("cbs_chatbot")
+ )
+
+
+@callback("bwel", owner=True)
+async def name(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "STARTMSG"
+ name = "Bot Welcome Message:"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "**BOT WELCOME MSG**\nEnter the msg which u want to show when someone start your assistant Bot.\nYou Can use `{me}` , `{mention}` Parameters Too\nUse /cancel to terminate the operation.",
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("cbs_chatbot"),
+ )
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}",
+ buttons=get_back_button("cbs_chatbot"),
+ )
+
+
+@callback("onchbot", owner=True)
+async def chon(event):
+ var = "PMBOT"
+ await setit(event, var, "True")
+ Loader(path="assistant/pmbot.py", key="PM Bot").load()
+ if AST_PLUGINS.get("pmbot"):
+ for i, e in AST_PLUGINS["pmbot"]:
+ event.client.remove_event_handler(i)
+ for i, e in AST_PLUGINS["pmbot"]:
+ event.client.add_event_handler(i, events.NewMessage(**e))
+ await event.edit(
+ "Done! Now u Can Chat With People Via This Bot",
+ buttons=[Button.inline("ÂŤ Bá´á´á´", data="cbs_chatbot")],
+ )
+
+
+@callback("ofchbot", owner=True)
+async def chon(event):
+ var = "PMBOT"
+ await setit(event, var, "False")
+ if AST_PLUGINS.get("pmbot"):
+ for i, e in AST_PLUGINS["pmbot"]:
+ event.client.remove_event_handler(i)
+ await event.edit(
+ "Done! Chat People Via This Bot Stopped.",
+ buttons=[Button.inline("ÂŤ Bá´á´á´", data="cbs_chatbot")],
+ )
+
+
+@callback("inli_pic", owner=True)
+async def media(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "INLINE_PIC"
+ name = "Inline Media"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "**Inline Media**\nSend me a pic/gif/ or link to set as inline media.\n\nUse /cancel to terminate the operation.",
+ )
+ response = await conv.get_response()
+ try:
+ themssg = response.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Operation cancelled!!",
+ buttons=get_back_button("setter"),
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ media = await event.client.download_media(response, "inlpic")
+ if (
+ not (response.text).startswith("/")
+ and response.text != ""
+ and (not response.media or isinstance(response.media, MessageMediaWebPage))
+ ):
+ url = text_to_url(response)
+ else:
+ try:
+ x = upl(media)
+ url = f"https://graph.org/{x[0]}"
+ remove(media)
+ except BaseException as er:
+ LOGS.exception(er)
+ return await conv.send_message(
+ "Terminated.",
+ buttons=get_back_button("setter"),
+ )
+ await setit(event, var, url)
+ await conv.send_message(
+ f"{name} has been set.",
+ buttons=get_back_button("setter"),
+ )
+
+
+FD_MEDIA = {}
+
+
+@callback(re.compile("fd(.*)"), owner=True)
+async def fdroid_dler(event):
+ uri = event.data_match.group(1).decode("utf-8")
+ if FD_MEDIA.get(uri):
+ return await event.edit(file=FD_MEDIA[uri])
+ await event.answer("⢠Starting Download â˘", alert=True)
+ await event.edit("⢠Downloading.. â˘")
+ URL = f"https://f-droid.org/packages/{uri}"
+ conte = await async_searcher(URL, re_content=True)
+ BSC = bs(conte, "html.parser", from_encoding="utf-8")
+ dl_ = BSC.find("p", "package-version-download").find("a")["href"]
+ title = BSC.find("h3", "package-name").text.strip()
+ thumb = BSC.find("img", "package-icon")["src"]
+ if thumb.startswith("/"):
+ thumb = f"https://f-droid.org{thumb}"
+ thumb, _ = await fast_download(thumb, filename=f"{uri}.png")
+ s_time = time.time()
+ file, _ = await fast_download(
+ dl_,
+ filename=f"{title}.apk",
+ progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
+ progress(
+ d,
+ t,
+ event,
+ s_time,
+ "Downloading...",
+ )
+ ),
+ )
+
+ time.time()
+ n_file = await event.client.fast_uploader(
+ file, show_progress=True, event=event, message="Uploading...", to_delete=True
+ )
+ buttons = Button.switch_inline("Search Back", query="fdroid", same_peer=True)
+ try:
+ msg = await event.edit(
+ f"**⢠[{title}]({URL}) â˘**", file=n_file, thumb=thumb, buttons=buttons
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ try:
+ msg = await event.client.edit_message(
+ await event.get_input_chat(),
+ event.message_id,
+ f"**⢠[{title}]({URL}) â˘**",
+ buttons=buttons,
+ thumb=thumb,
+ file=n_file,
+ )
+ except Exception as er:
+ os.remove(thumb)
+ LOGS.exception(er)
+ return await event.edit(f"**ERROR**: `{er}`", buttons=buttons)
+ if msg and hasattr(msg, "media"):
+ FD_MEDIA.update({uri: msg.media})
+ os.remove(thumb)
diff --git a/assistant/games.py b/assistant/games.py
new file mode 100644
index 0000000000000000000000000000000000000000..85ea88ebf6676d216b67bb972d8ad2a257c172ba
--- /dev/null
+++ b/assistant/games.py
@@ -0,0 +1,317 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2024 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+"""
+⢠`{i}akinator` | `/akinator`
+ Start akinator game from Userbot/Assistant
+
+⢠`/startgame`
+ Open Portal for Games
+"""
+
+import asyncio
+import re
+
+from akipy.async_akipy import Akinator, akipyLOGS
+from telethon.errors.rpcerrorlist import BotMethodInvalidError
+from telethon.events import Raw
+from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, UpdateMessagePollVote
+
+from pyUltroid._misc._decorators import ultroid_cmd
+from pyUltroid.fns.helper import inline_mention
+from pyUltroid.fns.tools import async_searcher
+
+from . import * # Ensure this import matches your project structure
+
+games = {}
+aki_photo = "https://graph.org/file/3cc8825c029fd0cab9edc.jpg"
+
+
+@ultroid_cmd(pattern="akinator")
+async def akina(e):
+ sta = Akinator()
+ games[e.chat_id] = {e.id: sta}
+ LOGS.info(f"Game started for chat {e.chat_id} with ID {e.id}.")
+ try:
+ m = await e.client.inline_query(asst.me.username, f"aki_{e.chat_id}_{e.id}")
+ await m[0].click(e.chat_id)
+ akipyLOGS.info(f"Clicked inline result for chat {e.chat_id}")
+ except BotMethodInvalidError as err:
+ akipyLOGS.error(f"BotMethodInvalidError: {err}")
+ await asst.send_file(
+ e.chat_id,
+ aki_photo,
+ buttons=Button.inline(get_string("aki_2"), data=f"aki_{e.chat_id}_{e.id}"),
+ )
+ except Exception as er:
+ akipyLOGS.error(f"Unexpected error: {er}")
+ return await e.eor(f"ERROR : {er}")
+ if e.out:
+ await e.delete()
+
+
+@asst_cmd(pattern="akinator", owner=True)
+async def _akokk(e):
+ await akina(e)
+
+
+@callback(re.compile("aki_(.*)"), owner=True)
+async def doai(e):
+ adt = e.pattern_match.group(1).strip().decode("utf-8")
+ dt = adt.split("_")
+ ch = int(dt[0])
+ mid = int(dt[1])
+ await e.edit(get_string("com_1"))
+ try:
+ await games[ch][mid].start_game(child_mode=False)
+ bts = [Button.inline(o, f"aka_{adt}_{o}") for o in ["Yes", "No", "Idk"]]
+ cts = [Button.inline(o, f"aka_{adt}_{o}") for o in ["Probably", "Probably Not"]]
+ bts = [bts, cts]
+ await e.edit(f"Q. {games[ch][mid].question}", buttons=bts)
+ except KeyError:
+ return await e.answer(get_string("aki_1"), alert=True)
+
+
+@callback(re.compile("aka_(.*)"), owner=True)
+async def okah(e):
+ try:
+ mk = e.pattern_match.group(1).decode("utf-8").split("_")
+ #akipyLOGS.info(f"Parsed values: {mk}")
+
+ if len(mk) < 3:
+ akipyLOGS.error("Pattern match did not return enough parts.")
+ return await e.answer("Invalid data received.", alert=True)
+
+ ch = int(mk[0])
+ mid = int(mk[1])
+ ans = mk[2]
+
+ gm = games[ch][mid]
+ await gm.answer(ans)
+
+ # Check for the final guess in the API response
+ if gm.name_proposition and gm.description_proposition:
+ gm.win = True
+ text = f"It's {gm.name_proposition}\n{gm.description_proposition}"
+ await e.edit(text, file=gm.photo)
+ else:
+ # Game is not won yet, continue asking questions
+ buttons = [
+ [Button.inline(o, f"aka_{ch}_{mid}_{o}") for o in ["Yes", "No", "Idk"]],
+ [Button.inline(o, f"aka_{ch}_{mid}_{o}") for o in ["Probably", "Probably Not"]],
+ ]
+ await e.edit(gm.question, buttons=buttons)
+
+ except KeyError:
+ await e.answer(get_string("aki_3"))
+ except Exception as ex:
+ akipyLOGS.error(f"An unexpected error occurred: {ex}")
+
+
+@in_pattern(re.compile("aki_?(.*)"), owner=True)
+async def eiagx(e):
+ bts = Button.inline(get_string("aki_2"), data=e.text)
+ ci = types.InputWebDocument(aki_photo, 0, "image/jpeg", [])
+ ans = [
+ await e.builder.article(
+ "Akinator",
+ type="photo",
+ content=ci,
+ text="Akinator",
+ thumb=ci,
+ buttons=bts,
+ include_media=True,
+ )
+ ]
+ await e.answer(ans)
+
+
+# ----------------------- Main Command ------------------- #
+
+GIMAGES = [
+ "https://graph.org/file/1c51015bae5205a65fd69.jpg",
+ "https://imgwhale.xyz/3xyr322l64j9590",
+]
+
+
+@asst_cmd(pattern="startgame", owner=True)
+async def magic(event):
+ buttons = [
+ [Button.inline("Trivia Quiz", "trzia")],
+ [Button.inline("Cancel â", "delit")],
+ ]
+ await event.reply(
+ get_string("games_1"),
+ file=choice(GIMAGES),
+ buttons=buttons,
+ )
+
+
+# -------------------------- Trivia ----------------------- #
+
+TR_BTS = {}
+DIFI_KEYS = ["Easy", "Medium", "Hard"]
+TRIVIA_CHATS = {}
+POLLS = {}
+CONGO_STICKER = [
+ "CAADAgADSgIAAladvQrJasZoYBh68AI",
+ "CAADAgADXhIAAuyZKUl879mlR_dkOwI",
+ "CAADAgADpQAD9wLID-xfZCDwOI5LAg",
+ "CAADAgADjAADECECEFZM-SrKO9GgAg",
+ "CAADAgADSwIAAj-VzArAzNCDiGWAHAI",
+ "CAADAgADhQADwZxgDIuMHR9IU10iAg",
+ "CAADAgADiwMAAsSraAuoe2BwYu1sdQI",
+]
+
+
+@callback("delit", owner=True)
+async def delete_it(event):
+ await event.delete()
+
+
+@callback(re.compile("ctdown(.*)"), owner=True)
+async def ct_spam(e):
+ n = e.data_match.group(1).decode("utf-8")
+ await e.answer(f"Wait {n} seconds..", alert=True)
+
+
+@callback(re.compile("trzia(.*)"), owner=True)
+async def choose_cata(event):
+ match = event.data_match.group(1).decode("utf-8")
+ if not match:
+ if TR_BTS.get("category"):
+ buttons = TR_BTS["category"]
+ else:
+ req = (
+ await async_searcher(
+ "https://opentdb.com/api_category.php", re_json=True
+ )
+ )["trivia_categories"]
+ btt = []
+ for i in req:
+ name = i["name"]
+ if ":" in name:
+ name = name.split(":")[1]
+ btt.append(Button.inline(name, f"trziad_{i['id']}"))
+ buttons = list(zip(btt[::2], btt[1::2]))
+ if len(btt) % 2 == 1:
+ buttons.append((btt[-1],))
+ buttons.append([Button.inline("Cancel â", "delit")])
+ TR_BTS.update({"category": buttons})
+ text = get_string("games_2")
+ elif match[0] == "d":
+ cat = match[1:]
+ buttons = [[Button.inline(i, f"trziac{cat}_{i}") for i in DIFI_KEYS]]
+ buttons.append(get_back_button("trzia"))
+ text = get_string("games_3")
+ elif match[0] == "c":
+ m = match[1:]
+ buttons = [[Button.inline(str(i), f"trziat{m}_{i}") for i in range(10, 70, 20)]]
+ text = get_string("games_4")
+ elif match[0] == "t":
+ m_ = match[1:]
+ buttons = [
+ [Button.inline(str(i), f"trzias{m_}_{i}") for i in [10, 30, 60, 120]]
+ ]
+ text = get_string("games_5")
+ elif match[0] == "s":
+ chat = event.chat_id
+ cat, le, nu, in_ = match[2:].split("_")
+ msg = await event.edit(get_string("games_6").format(le, nu))
+ for i in reversed(range(5)):
+ msg = await msg.edit(buttons=Button.inline(f"{i} â°", f"ctdown{i}"))
+ await asyncio.sleep(1)
+ await msg.edit(
+ msg.text + "\n\n⢠Send /cancel to stop the Quiz...", buttons=None
+ )
+ qsss = await async_searcher(
+ f"https://opentdb.com/api.php?amount={nu}&category={cat}&difficulty={le.lower()}",
+ re_json=True,
+ )
+ qs = qsss["results"]
+ if not qs:
+ await event.respond("Sorry, No Question Found for the given Criteria..")
+ await event.delete()
+ return
+ TRIVIA_CHATS.update({chat: {}})
+ for copper, q in enumerate(qs):
+ if TRIVIA_CHATS[chat].get("cancel") is not None:
+ break
+ ansi = str(uuid.uuid1()).split("-")[0].encode()
+ opts = [PollAnswer(unescape(q["correct_answer"]), ansi)]
+ [
+ opts.append(
+ PollAnswer(unescape(a), str(uuid.uuid1()).split("-")[0].encode())
+ )
+ for a in q["incorrect_answers"]
+ ]
+ shuffle(opts)
+ poll = InputMediaPoll(
+ Poll(
+ 0,
+ f"[{copper+1}]. " + unescape(q["question"]),
+ answers=opts,
+ public_voters=True,
+ quiz=True,
+ close_period=int(in_),
+ ),
+ correct_answers=[ansi],
+ solution="Join @TeamUltroid",
+ solution_entities=[],
+ )
+ m_ = await event.client.send_message(chat, file=poll)
+ POLLS.update({m_.poll.poll.id: {"chat": m_.chat_id, "answer": ansi}})
+ await asyncio.sleep(int(in_))
+ if not TRIVIA_CHATS[chat]:
+ await event.respond(
+ "No-One Got Any Score in the Quiz!\nBetter Luck Next Time!"
+ )
+ else:
+ try:
+ await event.respond(file=choice(CONGO_STICKER))
+ except ChatSendStickersForbiddenError:
+ pass
+ LBD = "đŻ **Scoreboard of the Quiz.**\n\n"
+ TRC = TRIVIA_CHATS[chat]
+ if "cancel" in TRC.keys():
+ del TRC["cancel"]
+ for userid, user_score in dict(
+ sorted(TRC.items(), key=operator.itemgetter(1), reverse=True)
+ ).items():
+ user = inline_mention(await event.client.get_entity(userid))
+ LBD += f"â˘â˘â˘ {user} - {user_score}\n"
+ await event.respond(LBD)
+ del TRIVIA_CHATS[chat]
+ list_ = list(POLLS.copy().keys())
+ for key in list_:
+ if POLLS[key]["chat"] == chat:
+ del POLLS[key]
+ return
+ await event.edit(text, buttons=buttons)
+
+
+@asst.on(
+ Raw(UpdateMessagePollVote, func=lambda x: TRIVIA_CHATS and POLLS.get(x.poll_id))
+)
+async def pollish(eve):
+ if POLLS.get(eve.poll_id)["chat"] not in TRIVIA_CHATS.keys():
+ return
+ if POLLS[eve.poll_id]["answer"] != eve.options[0]:
+ return
+ chat = POLLS.get(eve.poll_id)["chat"]
+ user = eve.user_id
+ if not TRIVIA_CHATS.get(chat, {}).get(user):
+ TRIVIA_CHATS[chat][user] = 1
+ else:
+ TRIVIA_CHATS[chat][user] += 1
+
+
+@asst_cmd("cancel", owner=True, func=lambda x: TRIVIA_CHATS.get(x.chat_id))
+async def cancelish(event):
+ chat = TRIVIA_CHATS.get(event.chat_id)
+ chat.update({"cancel": True})
+ await event.respond("Cancelled!")
diff --git a/assistant/initial.py b/assistant/initial.py
new file mode 100644
index 0000000000000000000000000000000000000000..eb57a0308c7b1a74f4cb5f5bdb9e8f8fcdb6067c
--- /dev/null
+++ b/assistant/initial.py
@@ -0,0 +1,84 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import re
+
+from . import *
+
+STRINGS = {
+ 1: """đ **Thanks for Deploying Ultroid Userbot!**
+
+⢠Here, are the Some Basic stuff from, where you can Know, about its Usage.""",
+ 2: """đ** About Ultroid**
+
+đ§ż Ultroid is Pluggable and powerful Telethon Userbot, made in Python from Scratch. It is Aimed to Increase Security along with Addition of Other Useful Features.
+
+⣠Made by **@TeamUltroid**""",
+ 3: """**đĄâ˘ FAQs â˘**
+
+-> [Username Tracker](https://t.me/UltroidUpdates/24)
+-> [Keeping Custom Addons Repo](https://t.me/UltroidUpdates/28)
+-> [Disabling Deploy message](https://t.me/UltroidUpdates/27)
+-> [Setting up TimeZone](https://t.me/UltroidUpdates/22)
+-> [About Inline PmPermit](https://t.me/UltroidUpdates/21)
+-> [About Dual Mode](https://t.me/UltroidUpdates/18)
+-> [Custom Thumbnail](https://t.me/UltroidUpdates/13)
+-> [About FullSudo](https://t.me/UltroidUpdates/11)
+-> [Setting Up PmBot](https://t.me/UltroidUpdates/2)
+-> [Also Check](https://t.me/UltroidUpdates/14)
+
+**⢠To Know About Updates**
+ - Join @TeamUltroid.""",
+ 4: f"""⢠`To Know All Available Commands`
+
+ - `{HNDLR}help`
+ - `{HNDLR}cmds`""",
+ 5: """⢠**For Any Other Query or Suggestion**
+ - Move to **@UltroidSupportChat**.
+
+⢠Thanks for Reaching till END.""",
+}
+
+
+@callback(re.compile("initft_(\\d+)"))
+async def init_depl(e):
+ CURRENT = int(e.data_match.group(1))
+ if CURRENT == 5:
+ return await e.edit(
+ STRINGS[5],
+ buttons=Button.inline("<< Back", "initbk_4"),
+ link_preview=False,
+ )
+
+ await e.edit(
+ STRINGS[CURRENT],
+ buttons=[
+ Button.inline("<<", f"initbk_{str(CURRENT - 1)}"),
+ Button.inline(">>", f"initft_{str(CURRENT + 1)}"),
+ ],
+ link_preview=False,
+ )
+
+
+@callback(re.compile("initbk_(\\d+)"))
+async def ineiq(e):
+ CURRENT = int(e.data_match.group(1))
+ if CURRENT == 1:
+ return await e.edit(
+ STRINGS[1],
+ buttons=Button.inline("Start Back >>", "initft_2"),
+ link_preview=False,
+ )
+
+ await e.edit(
+ STRINGS[CURRENT],
+ buttons=[
+ Button.inline("<<", f"initbk_{str(CURRENT - 1)}"),
+ Button.inline(">>", f"initft_{str(CURRENT + 1)}"),
+ ],
+ link_preview=False,
+ )
diff --git a/assistant/inlinestuff.py b/assistant/inlinestuff.py
new file mode 100644
index 0000000000000000000000000000000000000000..16a45f522b6abbe8a51c275ca4a16d4723231276
--- /dev/null
+++ b/assistant/inlinestuff.py
@@ -0,0 +1,623 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import base64
+import inspect
+from datetime import datetime
+from html import unescape
+from random import choice
+from re import compile as re_compile
+
+from bs4 import BeautifulSoup as bs
+from telethon import Button
+from telethon.tl.alltlobjects import LAYER, tlobjects
+from telethon.tl.types import DocumentAttributeAudio as Audio
+from telethon.tl.types import InputWebDocument as wb
+
+from pyUltroid.fns.misc import google_search
+from pyUltroid.fns.tools import (
+ _webupload_cache,
+ async_searcher,
+ get_ofox,
+ saavn_search,
+ webuploader,
+)
+
+from . import *
+from . import _ult_cache
+
+SUP_BUTTONS = [
+ [
+ Button.url("⢠Repo â˘", url="https://github.com/TeamUltroid/Ultroid"),
+ Button.url("⢠Support â˘", url="t.me/UltroidSupportChat"),
+ ],
+]
+
+ofox = "https://graph.org/file/231f0049fcd722824f13b.jpg"
+gugirl = "https://graph.org/file/0df54ae4541abca96aa11.jpg"
+ultpic = "https://graph.org/file/4136aa1650bc9d4109cc5.jpg"
+
+apis = [
+ "QUl6YVN5QXlEQnNZM1dSdEI1WVBDNmFCX3c4SkF5NlpkWE5jNkZV",
+ "QUl6YVN5QkYwenhMbFlsUE1wOXh3TVFxVktDUVJxOERnZHJMWHNn",
+ "QUl6YVN5RGRPS253blB3VklRX2xiSDVzWUU0Rm9YakFLSVFWMERR",
+]
+
+
+@in_pattern("ofox", owner=True)
+async def _(e):
+ try:
+ match = e.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ kkkk = e.builder.article(
+ title="Enter Device Codename",
+ thumb=wb(ofox, 0, "image/jpeg", []),
+ text="**OFá´xđŚRá´á´á´á´ á´ĘĘ**\n\nYou didn't search anything",
+ buttons=Button.switch_inline("Sá´á´Ęá´Ę Aɢá´ÉŞÉ´", query="ofox ", same_peer=True),
+ )
+ return await e.answer([kkkk])
+ device, releases = await get_ofox(match)
+ if device.get("detail") is None:
+ fox = []
+ fullname = device["full_name"]
+ codename = device["codename"]
+ str(device["supported"])
+ maintainer = device["maintainer"]["name"]
+ link = f"https://orangefox.download/device/{codename}"
+ for data in releases["data"]:
+ release = data["type"]
+ version = data["version"]
+ size = humanbytes(data["size"])
+ release_date = datetime.utcfromtimestamp(data["date"]).strftime("%Y-%m-%d")
+ text = f"[\xad]({ofox})**OĘá´É´É˘á´Fá´x Rá´á´á´á´ á´ĘĘ Fá´Ę**\n\n"
+ text += f"` Fá´ĘĘ Ná´á´á´: {fullname}`\n"
+ text += f"` Cá´á´
á´É´á´á´á´: {codename}`\n"
+ text += f"` Má´ÉŞÉ´á´á´ÉŞÉ´á´Ę: {maintainer}`\n"
+ text += f"` Bá´ÉŞĘá´
TĘá´á´: {release}`\n"
+ text += f"` Vá´ĘsÉŞá´É´: {version}`\n"
+ text += f"` SÉŞá´˘á´: {size}`\n"
+ text += f"` Bá´ÉŞĘá´
Dá´á´á´: {release_date}`"
+ fox.append(
+ await e.builder.article(
+ title=f"{fullname}",
+ description=f"{version}\n{release_date}",
+ text=text,
+ thumb=wb(ofox, 0, "image/jpeg", []),
+ link_preview=True,
+ buttons=[
+ Button.url("Dá´á´ĄÉ´Ęá´á´á´
", url=f"{link}"),
+ Button.switch_inline(
+ "Sá´á´Ęá´Ę Aɢá´ÉŞÉ´", query="ofox ", same_peer=True
+ ),
+ ],
+ )
+ )
+ await e.answer(
+ fox, switch_pm="OrangeFox Recovery Search.", switch_pm_param="start"
+ )
+ else:
+ await e.answer(
+ [], switch_pm="OrangeFox Recovery Search.", switch_pm_param="start"
+ )
+
+
+@in_pattern("fl2lnk ?(.*)", owner=True)
+async def _(e):
+ match = e.pattern_match.group(1)
+ chat_id, msg_id = match.split(":")
+ filename = _webupload_cache[int(chat_id)][int(msg_id)]
+ if "/" in filename:
+ filename = filename.split("/")[-1]
+ __cache = f"{chat_id}:{msg_id}"
+ buttons = [
+ [
+ Button.inline("anonfiles", data=f"flanonfiles//{__cache}"),
+ Button.inline("transfer", data=f"fltransfer//{__cache}"),
+ ],
+ [
+ Button.inline("bayfiles", data=f"flbayfiles//{__cache}"),
+ Button.inline("x0.at", data=f"flx0.at//{__cache}"),
+ ],
+ [
+ Button.inline("file.io", data=f"flfile.io//{__cache}"),
+ Button.inline("siasky", data=f"flsiasky//{__cache}"),
+ ],
+ ]
+ try:
+ lnk = [
+ await e.builder.article(
+ title=f"Upload {filename}",
+ text=f"**File:**\n{filename}",
+ buttons=buttons,
+ )
+ ]
+ except BaseException as er:
+ LOGS.exception(er)
+ lnk = [
+ await e.builder.article(
+ title="fl2lnk",
+ text="File not found",
+ )
+ ]
+ await e.answer(lnk, switch_pm="File to Link.", switch_pm_param="start")
+
+
+@callback(
+ re_compile(
+ "fl(.*)",
+ ),
+ owner=True,
+)
+async def _(e):
+ t = (e.data).decode("UTF-8")
+ data = t[2:]
+ host = data.split("//")[0]
+ chat_id, msg_id = data.split("//")[1].split(":")
+ filename = _webupload_cache[int(chat_id)][int(msg_id)]
+ if "/" in filename:
+ filename = filename.split("/")[-1]
+ await e.edit(f"Uploading `{filename}` on {host}")
+ link = (await webuploader(chat_id, msg_id, host)).strip().replace("\n", "")
+ await e.edit(f"Uploaded `{filename}` on {host}.", buttons=Button.url("View", link))
+
+
+@in_pattern("repo", owner=True)
+async def repo(e):
+ res = [
+ await e.builder.article(
+ title="Ultroid Userbot",
+ description="Userbot | Telethon",
+ thumb=wb(ultpic, 0, "image/jpeg", []),
+ text="⢠**ULTROID USERBOT** â˘",
+ buttons=SUP_BUTTONS,
+ ),
+ ]
+ await e.answer(res, switch_pm="Ultroid Repo.", switch_pm_param="start")
+
+
+@in_pattern("go", owner=True)
+async def gsearch(q_event):
+ try:
+ match = q_event.text.split(maxsplit=1)[1]
+ except IndexError:
+ return await q_event.answer(
+ [], switch_pm="Google Search. Enter a query!", switch_pm_param="start"
+ )
+ searcher = []
+ gresults = await google_search(match)
+ for i in gresults:
+ try:
+ title = i["title"]
+ link = i["link"]
+ desc = i["description"]
+ searcher.append(
+ await q_event.builder.article(
+ title=title,
+ description=desc,
+ thumb=wb(gugirl, 0, "image/jpeg", []),
+ text=f"**Gá´á´É˘Ęá´ Sá´á´Ęá´Ę**\n\n**â˘â˘TÉŞá´Ęá´â˘â˘**\n`{title}`\n\n**â˘â˘Dá´sá´ĘÉŞá´á´ÉŞá´É´â˘â˘**\n`{desc}`",
+ link_preview=False,
+ buttons=[
+ [Button.url("LÉŞÉ´á´", url=f"{link}")],
+ [
+ Button.switch_inline(
+ "Sá´á´Ęá´Ę Aɢá´ÉŞÉ´",
+ query="go ",
+ same_peer=True,
+ ),
+ Button.switch_inline(
+ "SĘá´Ęá´",
+ query=f"go {match}",
+ same_peer=False,
+ ),
+ ],
+ ],
+ ),
+ )
+ except IndexError:
+ break
+ await q_event.answer(searcher, switch_pm="Google Search.", switch_pm_param="start")
+
+
+@in_pattern("mods", owner=True)
+async def _(e):
+ try:
+ quer = e.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ return await e.answer(
+ [], switch_pm="Mod Apps Search. Enter app name!", switch_pm_param="start"
+ )
+ start = 0 * 3 + 1
+ da = base64.b64decode(choice(apis)).decode("ascii")
+ url = f"https://www.googleapis.com/customsearch/v1?key={da}&cx=25b3b50edb928435b&q={quer}&start={start}"
+ data = await async_searcher(url, re_json=True)
+ search_items = data.get("items", [])
+ modss = []
+ for a in search_items:
+ title = a.get("title")
+ desc = a.get("snippet")
+ link = a.get("link")
+ text = f"**â˘â˘TÉŞá´Ęá´â˘â˘** `{title}`\n\n"
+ text += f"**Dá´sá´ĘÉŞá´á´ÉŞá´É´** `{desc}`"
+ modss.append(
+ await e.builder.article(
+ title=title,
+ description=desc,
+ text=text,
+ link_preview=True,
+ buttons=[
+ [Button.url("Dá´á´ĄÉ´Ęá´á´á´
", url=f"{link}")],
+ [
+ Button.switch_inline(
+ "Má´Ęá´ Má´á´
s",
+ query="mods ",
+ same_peer=True,
+ ),
+ Button.switch_inline(
+ "SĘá´Ęá´",
+ query=f"mods {quer}",
+ same_peer=False,
+ ),
+ ],
+ ],
+ ),
+ )
+ await e.answer(modss, switch_pm="Search Mod Applications.", switch_pm_param="start")
+
+
+APP_CACHE = {}
+RECENTS = {}
+PLAY_API = "https://googleplay.onrender.com/api/apps?q="
+
+
+@in_pattern("app", owner=True)
+async def _(e):
+ try:
+ f = e.text.split(maxsplit=1)[1].lower()
+ except IndexError:
+ get_string("instu_1")
+ res = []
+ if APP_CACHE and RECENTS.get(e.sender_id):
+ res.extend(
+ APP_CACHE[a][0] for a in RECENTS[e.sender_id] if APP_CACHE.get(a)
+ )
+ return await e.answer(
+ res, switch_pm=get_string("instu_2"), switch_pm_param="start"
+ )
+ try:
+ return await e.answer(
+ APP_CACHE[f], switch_pm="Application Searcher.", switch_pm_param="start"
+ )
+ except KeyError:
+ pass
+ foles = []
+ url = PLAY_API + f.replace(" ", "+")
+ aap = await async_searcher(url, re_json=True)
+ for z in aap["results"][:50]:
+ url = "https://play.google.com/store/apps/details?id=" + z["appId"]
+ name = z["title"]
+ desc = unescape(z["summary"])[:300].replace("
", "\n") + "..."
+ dev = z["developer"]["devId"]
+ text = f"**â˘â˘Aá´á´ Ná´á´á´â˘â˘** [{name}]({url})\n"
+ text += f"**â˘â˘Dá´á´ á´Ęá´á´á´Ęâ˘â˘** `{dev}`\n"
+ text += f"**â˘â˘Dá´sá´ĘÉŞá´á´ÉŞá´É´â˘â˘**\n`{desc}`"
+ foles.append(
+ await e.builder.article(
+ title=name,
+ description=dev,
+ thumb=wb(z["icon"], 0, "image/jpeg", []),
+ text=text,
+ link_preview=True,
+ buttons=[
+ [Button.url("LÉŞÉ´á´", url=url)],
+ [
+ Button.switch_inline(
+ "Má´Ęá´ Aá´á´s",
+ query="app ",
+ same_peer=True,
+ ),
+ Button.switch_inline(
+ "SĘá´Ęá´",
+ query=f"app {f}",
+ same_peer=False,
+ ),
+ ],
+ ],
+ ),
+ )
+ APP_CACHE.update({f: foles})
+ if RECENTS.get(e.sender_id):
+ RECENTS[e.sender_id].append(f)
+ else:
+ RECENTS.update({e.sender_id: [f]})
+ await e.answer(foles, switch_pm="Application Searcher.", switch_pm_param="start")
+
+
+PISTON_URI = "https://emkc.org/api/v2/piston/"
+PISTON_LANGS = {}
+
+
+@in_pattern("run", owner=True)
+async def piston_run(event):
+ try:
+ lang = event.text.split()[1]
+ code = event.text.split(maxsplit=2)[2]
+ except IndexError:
+ result = await event.builder.article(
+ title="Bad Query",
+ description="Usage: [Language] [code]",
+ thumb=wb(
+ "https://graph.org/file/e33c57fc5f1044547e4d8.jpg", 0, "image/jpeg", []
+ ),
+ text=f'**Inline Usage**\n\n`@{asst.me.username} run python print("hello world")`\n\n[Language List](https://graph.org/Ultroid-09-01-6)',
+ )
+ return await event.answer([result])
+ if not PISTON_LANGS:
+ se = await async_searcher(f"{PISTON_URI}runtimes", re_json=True)
+ PISTON_LANGS.update({lang.pop("language"): lang for lang in se})
+ if lang in PISTON_LANGS.keys():
+ version = PISTON_LANGS[lang]["version"]
+ else:
+ result = await event.builder.article(
+ title="Unsupported Language",
+ description="Usage: [Language] [code]",
+ thumb=wb(
+ "https://graph.org/file/e33c57fc5f1044547e4d8.jpg", 0, "image/jpeg", []
+ ),
+ text=f'**Inline Usage**\n\n`@{asst.me.username} run python print("hello world")`\n\n[Language List](https://graph.org/Ultroid-09-01-6)',
+ )
+ return await event.answer([result])
+ output = await async_searcher(
+ f"{PISTON_URI}execute",
+ post=True,
+ json={
+ "language": lang,
+ "version": version,
+ "files": [{"content": code}],
+ },
+ re_json=True,
+ )
+
+ output = output["run"]["output"] or get_string("instu_4")
+ if len(output) > 3000:
+ output = f"{output[:3000]}..."
+ result = await event.builder.article(
+ title="Result",
+ description=output,
+ text=f"⢠**Language:**\n`{lang}`\n\n⢠**Code:**\n`{code}`\n\n⢠**Result:**\n`{output}`",
+ thumb=wb(
+ "https://graph.org/file/871ee4a481f58117dccc4.jpg", 0, "image/jpeg", []
+ ),
+ buttons=Button.switch_inline("Fork", query=event.text, same_peer=True),
+ )
+ await event.answer([result], switch_pm="⢠Piston â˘", switch_pm_param="start")
+
+
+FDROID_ = {}
+
+
+@in_pattern("fdroid", owner=True)
+async def do_magic(event):
+ try:
+ match = event.text.split(" ", maxsplit=1)[1].lower()
+ except IndexError:
+ return await event.answer(
+ [], switch_pm="Enter Query to Search", switch_pm_param="start"
+ )
+ if FDROID_.get(match):
+ return await event.answer(
+ FDROID_[match], switch_pm=f"⢠Results for {match}", switch_pm_param="start"
+ )
+ link = "https://search.f-droid.org/?q=" + match.replace(" ", "+")
+ content = await async_searcher(link, re_content=True)
+ BSC = bs(content, "html.parser", from_encoding="utf-8")
+ ress = []
+ for dat in BSC.find_all("a", "package-header")[:10]:
+ image = dat.find("img", "package-icon")["src"]
+ if image.endswith("/"):
+ image = "https://graph.org/file/a8dd4a92c5a53a89d0eff.jpg"
+ title = dat.find("h4", "package-name").text.strip()
+ desc = dat.find("span", "package-summary").text.strip()
+ text = f"⢠**Name :** `{title}`\n\n"
+ text += f"⢠**Description :** `{desc}`\n"
+ text += f"⢠**License :** `{dat.find('span', 'package-license').text.strip()}`"
+ imga = wb(image, 0, "image/jpeg", [])
+ ress.append(
+ await event.builder.article(
+ title=title,
+ type="photo",
+ description=desc,
+ text=text,
+ content=imga,
+ thumb=imga,
+ include_media=True,
+ buttons=[
+ Button.inline(
+ "⢠Download â˘", "fd" + dat["href"].split("packages/")[-1]
+ ),
+ Button.switch_inline("⢠Share â˘", query=event.text),
+ ],
+ )
+ )
+ msg = f"Showing {len(ress)} Results!" if ress else "No Results Found"
+ FDROID_.update({match: ress})
+ await event.answer(ress, switch_pm=msg, switch_pm_param="start")
+
+
+# Thanks to OpenSource
+_bearer_collected = [
+ "AAAAAAAAAAAAAAAAAAAAALIKKgEAAAAA1DRuS%2BI7ZRKiagD6KHYmreaXomo%3DP5Vaje4UTtEkODg0fX7nCh5laSrchhtLxeyEqxXpv0w9ZKspLD",
+ "AAAAAAAAAAAAAAAAAAAAAL5iUAEAAAAAmo6FYRjqdKlI3cNziIm%2BHUQB9Xs%3DS31pj0mxARMTOk2g9dvQ1yP9wknvY4FPBPUlE00smJcncw4dPR",
+ "AAAAAAAAAAAAAAAAAAAAAN6sVgEAAAAAMMjMMWrwgGyv7YQOWN%2FSAsO5SGM%3Dg8MG9Jq93Rlllaok6eht7HvRCruN4Vpzp4NaVsZaaHHWSTzKI8",
+]
+
+
+@in_pattern("twitter", owner=True)
+async def twitter_search(event):
+ try:
+ match = event.text.split(maxsplit=1)[1].lower()
+ except IndexError:
+ return await event.answer(
+ [], switch_pm="Enter Query to Search", switch_pm_param="start"
+ )
+ try:
+ return await event.answer(
+ _ult_cache["twitter"][match],
+ switch_pm="⢠Twitter Search â˘",
+ switch_pm_param="start",
+ )
+ except KeyError:
+ pass
+ headers = {"Authorization": f"bearer {choice(_bearer_collected)}"}
+ res = await async_searcher(
+ f"https://api.twitter.com/1.1/users/search.json?q={match}",
+ headers=headers,
+ re_json=True,
+ )
+ reso = []
+ for user in res:
+ thumb = wb(user["profile_image_url_https"], 0, "image/jpeg", [])
+ if user.get("profile_banner_url"):
+ url = user["profile_banner_url"]
+ text = f"[\xad]({url})⢠**Name :** `{user['name']}`\n"
+ else:
+ text = f"⢠**Name :** `{user['name']}`\n"
+ text += f"⢠**Description :** `{user['description']}`\n"
+ text += f"⢠**Username :** `@{user['screen_name']}`\n"
+ text += f"⢠**Followers :** `{user['followers_count']}` ⢠**Following :** `{user['friends_count']}`\n"
+ pro_ = "https://twitter.com/" + user["screen_name"]
+ text += f"⢠**Link :** [Click Here]({pro_})\n_"
+ reso.append(
+ await event.builder.article(
+ title=user["name"],
+ description=user["description"],
+ url=pro_,
+ text=text,
+ thumb=thumb,
+ )
+ )
+ swi_ = f"đŚ Showing {len(reso)} Results!" if reso else "No User Found :("
+ await event.answer(reso, switch_pm=swi_, switch_pm_param="start")
+ if _ult_cache.get("twitter"):
+ _ult_cache["twitter"].update({match: reso})
+ else:
+ _ult_cache.update({"twitter": {match: reso}})
+
+
+_savn_cache = {}
+
+
+@in_pattern("saavn", owner=True)
+async def savn_s(event):
+ try:
+ query = event.text.split(maxsplit=1)[1].lower()
+ except IndexError:
+ return await event.answer(
+ [], switch_pm="Enter Query to search đ", switch_pm_param="start"
+ )
+ if query in _savn_cache:
+ return await event.answer(
+ _savn_cache[query],
+ switch_pm=f"Showing Results for {query}",
+ switch_pm_param="start",
+ )
+ results = await saavn_search(query)
+ swi = "đľ Saavn Search" if results else "No Results Found!"
+ res = []
+ for song in results:
+ thumb = wb(song["image"], 0, "image/jpeg", [])
+ text = f"⢠**Title :** {song['title']}"
+ text += f"\n⢠**Year :** {song['year']}"
+ text += f"\n⢠**Lang :** {song['language']}"
+ text += f"\n⢠**Artist :** {song['artists']}"
+ text += f"\n⢠**Release Date :** {song['release_date']}"
+ res.append(
+ await event.builder.article(
+ title=song["title"],
+ description=song["artists"],
+ type="audio",
+ text=text,
+ include_media=True,
+ buttons=Button.switch_inline(
+ "Search Again đ", query="saavn", same_peer=True
+ ),
+ thumb=thumb,
+ content=wb(
+ song["url"],
+ 0,
+ "audio/mp4",
+ [
+ Audio(
+ title=song["title"],
+ duration=int(song["duration"]),
+ performer=song["artists"],
+ )
+ ],
+ ),
+ )
+ )
+ await event.answer(res, switch_pm=swi, switch_pm_param="start")
+ _savn_cache.update({query: res})
+
+
+@in_pattern("tl", owner=True)
+async def inline_tl(ult):
+ try:
+ match = ult.text.split(maxsplit=1)[1]
+ except IndexError:
+ text = f"**Telegram TlObjects Searcher.**\n__(Don't use if you don't know what it is!)__\n\n⢠Example Usage\n`@{asst.me.username} tl GetFullUserRequest`"
+ return await ult.answer(
+ [
+ await ult.builder.article(
+ title="How to Use?",
+ description="Tl Searcher by Ultroid",
+ url="https://t.me/TeamUltroid",
+ text=text,
+ )
+ ],
+ switch_pm="Tl Search đ",
+ switch_pm_param="start",
+ )
+ res = []
+ for key in tlobjects.values():
+ if match.lower() in key.__name__.lower():
+ tyyp = "Function" if "tl.functions." in str(key) else "Type"
+ text = f"**Name:** `{key.__name__}`\n"
+ text += f"**Category:** `{tyyp}`\n"
+ text += f"\n`from {key.__module__} import {key.__name__}`\n\n"
+ if args := str(inspect.signature(key))[1:][:-1]:
+ text += "**Parameter:**\n"
+ for para in args.split(","):
+ text += " " * 4 + "`" + para + "`\n"
+ text += f"\n**Layer:** `{LAYER}`"
+ res.append(
+ await ult.builder.article(
+ title=key.__name__,
+ description=tyyp,
+ url="https://t.me/TeamUltroid",
+ text=text[:4000],
+ )
+ )
+ mo = f"Showing {len(res)} results!" if res else f"No Results for {match}!"
+ await ult.answer(res[:50], switch_pm=mo, switch_pm_param="start")
+
+
+InlinePlugin.update(
+ {
+ "PĘá´Ę Sá´á´Ęá´ Aá´á´s": "app telegram",
+ "Má´á´
á´
á´á´
Aá´á´s": "mods minecraft",
+ "Sá´á´Ęá´Ę OÉ´ Gá´á´É˘Ęá´": "go TeamUltroid",
+ "WĘÉŞSá´á´Ę": "wspr @username Hellođ",
+ "Yá´á´Tá´Ęá´ Dá´á´ĄÉ´Ęá´á´á´
á´Ę": "yt Ed Sheeran Perfect",
+ "Piston Eval": "run javascript console.log('Hello Ultroid')",
+ "OĘá´É´É˘á´Fá´xđŚ": "ofox beryllium",
+ "Tá´ĄÉŞá´á´á´Ę Usá´Ę": "twitter theultroid",
+ "Fá´
Ęá´ÉŞá´
Sá´á´Ęá´Ę": "fdroid telegram",
+ "Sá´á´á´ É´ sá´á´Ęá´Ę": "saavn",
+ "TĘ Sá´á´Ęá´Ę": "tl",
+ }
+)
diff --git a/assistant/localization.py b/assistant/localization.py
new file mode 100644
index 0000000000000000000000000000000000000000..0fc8538cdbeace2d08d13080f29dad4b224918d8
--- /dev/null
+++ b/assistant/localization.py
@@ -0,0 +1,47 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import re
+
+from . import (
+ Button,
+ ULTConfig,
+ callback,
+ get_back_button,
+ get_languages,
+ get_string,
+ udB,
+)
+
+
+@callback("lang", owner=True)
+async def setlang(event):
+ languages = get_languages()
+ tultd = [
+ Button.inline(
+ f"{languages[ult]['natively']} [{ult.lower()}]",
+ data=f"set_{ult}",
+ )
+ for ult in languages
+ ]
+ buttons = list(zip(tultd[::2], tultd[1::2]))
+ if len(tultd) % 2 == 1:
+ buttons.append((tultd[-1],))
+ buttons.append([Button.inline("ÂŤ Back", data="mainmenu")])
+ await event.edit(get_string("ast_4"), buttons=buttons)
+
+
+@callback(re.compile(b"set_(.*)"), owner=True)
+async def settt(event):
+ lang = event.data_match.group(1).decode("UTF-8")
+ languages = get_languages()
+ ULTConfig.lang = lang
+ udB.del_key("language") if lang == "en" else udB.set_key("language", lang)
+ await event.edit(
+ f"Your language has been set to {languages[lang]['natively']} [{lang}].",
+ buttons=get_back_button("lang"),
+ )
diff --git a/assistant/manager/__init__.py b/assistant/manager/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..69b49061e9f70567985b423c8d29e1b6c21e332d
--- /dev/null
+++ b/assistant/manager/__init__.py
@@ -0,0 +1,11 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from pyUltroid._misc._decorators import ultroid_cmd
+from pyUltroid.fns.helper import inline_mention
+
+from .. import *
diff --git a/assistant/manager/_help.py b/assistant/manager/_help.py
new file mode 100644
index 0000000000000000000000000000000000000000..f071301e91f9deacd358ae443ef069bb0978f0c6
--- /dev/null
+++ b/assistant/manager/_help.py
@@ -0,0 +1,134 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import *
+
+START = """
+đŞ
**Help Menu** đŞ
+
+â /start : Check I am Alive or not.
+â /help : Get This Message.
+â /repo : Get Bot's Repo..
+
+đ§âđť Join **@TeamUltroid**
+"""
+
+ADMINTOOLS = """â **AdminTools** â
+
+⢠/pin : Pins the Replied Message
+⢠/pinned : Get Pinned message in chat.
+⢠/unpin : Unpin the Replied message
+⢠/unpin all : Unpin all Pinned Messages.
+
+⢠/ban (username/id/reply) : Ban the User
+⢠/unban (username/id/reply) : UnBan the User.
+
+⢠/mute (username/id/reply) : Mute the User.
+⢠/unmute (username/id/reply) : Unmute the User.
+
+⢠/tban (username/id/reply) (time) : Temporary ban a user
+⢠/tmute (username/id/reply) (time) : temporary Mutes a User.
+
+⢠/purge (purge messages)
+
+⢠/setgpic (reply photo) : keep Chat Photo of Group.
+⢠/delgpic : remove current chat Photo."""
+
+UTILITIES = """
+â ** Utilities ** â
+
+⢠/info (reply/username/id) : get detailed info of user.
+⢠/id : get chat/user id.
+⢠/tr : Translate Languages..
+⢠/q : Create Quotes.
+
+⢠/paste (reply file/text) : paste content on Spaceb.in
+⢠/meaning (text) : Get Meaning of that Word.
+⢠/google (query) : Search Something on Google..
+
+⢠/suggest (query/reply) : Creates a Yes / No Poll.
+"""
+
+LOCKS = """
+â ** Locks ** â
+
+⢠/lock (query) : lock particular content in chat.
+⢠/unlock (query) : Unlock some content.
+
+⢠All Queries
+- `msgs` : for messages.
+- `inlines` : for inline queries.
+- `media` : for all medias.
+- `games` : for games.
+- `sticker` : for stickers.
+- `polls` : for polls.
+- `gif` : for gifs.
+- `pin` : for pins.
+- `changeinfo` : for change info right.
+"""
+
+MISC = """
+â **Misc** â
+
+⢠/joke : Get Random Jokes.
+⢠/decide : Decide Something..
+
+**â Stickertools â**
+⢠/kang : add sticker to your pack.
+⢠/listpack : get all of yours pack..
+"""
+
+STRINGS = {"Admintools": ADMINTOOLS, "locks": LOCKS, "Utils": UTILITIES, "Misc": MISC}
+
+MNGE = udB.get_key("MNGR_EMOJI") or "â˘"
+
+
+def get_buttons():
+ BTTS = []
+ keys = STRINGS.copy()
+ while keys:
+ BT = []
+ for i in list(keys)[:2]:
+ text = f"{MNGE} {i} {MNGE}"
+ BT.append(Button.inline(text, f"hlp_{i}"))
+ del keys[i]
+ BTTS.append(BT)
+ url = f"https://t.me/{asst.me.username}?startgroup=true"
+ BTTS.append([Button.url("Add me to Group", url)])
+ return BTTS
+
+
+@asst_cmd(pattern="help")
+async def helpish(event):
+ if not event.is_private:
+ url = f"https://t.me/{asst.me.username}?start=start"
+ return await event.reply(
+ "Contact me in PM for help!", buttons=Button.url("Click me for Help", url)
+ )
+ if str(event.sender_id) in owner_and_sudos() and (
+ udB.get_key("DUAL_MODE") and (udB.get_key("DUAL_HNDLR") == "/")
+ ):
+ return
+ await event.reply(START, buttons=get_buttons())
+
+
+@callback("mngbtn", owner=True)
+async def ehwhshd(e):
+ buttons = get_buttons()
+ buttons.append([Button.inline("<< Back", "open")])
+ await e.edit(buttons=buttons)
+
+
+@callback("mnghome")
+async def home_aja(e):
+ await e.edit(START, buttons=get_buttons())
+
+
+@callback(re.compile("hlp_(.*)"))
+async def do_something(event):
+ match = event.pattern_match.group(1).strip().decode("utf-8")
+ await event.edit(STRINGS[match], buttons=Button.inline("<< Back", "mnghome"))
diff --git a/assistant/manager/_on_adds.py b/assistant/manager/_on_adds.py
new file mode 100644
index 0000000000000000000000000000000000000000..c54cf1444275c4f4c205924f173cc417c663c17a
--- /dev/null
+++ b/assistant/manager/_on_adds.py
@@ -0,0 +1,23 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from telethon import events
+
+from . import *
+
+
+@asst.on(events.ChatAction(func=lambda x: x.user_added))
+async def dueha(e):
+ user = await e.get_user()
+ if not user.is_self:
+ return
+ sm = udB.get_key("ON_MNGR_ADD")
+ if sm == "OFF":
+ return
+ if not sm:
+ sm = "Thanks for Adding me :)"
+ await e.reply(sm, link_preview=False)
diff --git a/assistant/manager/admins.py b/assistant/manager/admins.py
new file mode 100644
index 0000000000000000000000000000000000000000..168e14e6801887a9e9e3c01c010c9649ff61d883
--- /dev/null
+++ b/assistant/manager/admins.py
@@ -0,0 +1,50 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import re
+
+from telethon.errors.rpcerrorlist import UserNotParticipantError
+
+from pyUltroid import _ult_cache
+
+from . import *
+
+
+@ultroid_cmd(pattern="d(kick|ban)", manager=True, require="ban_users")
+async def dowj(e):
+ replied = await e.get_reply_message()
+ if replied:
+ user = replied.sender_id
+ else:
+ return await e.eor("Reply to a message...")
+ try:
+ await replied.delete()
+ if e.pattern_match.group(1).strip() == "kick":
+ await e.client.kick_participant(e.chat_id, user)
+ te = "Kicked"
+ else:
+ await e.client.edit_permissions(e.chat_id, user, view_messages=False)
+ te = "Banned"
+ await e.eor(f"{te} Successfully!")
+ except Exception as E:
+ await e.eor(str(E))
+
+
+@callback(re.compile("cc_(.*)"), func=_ult_cache.get("admin_callback"))
+async def callback_(event):
+ data = event.data_match.group(1).decode("utf-8")
+ if data not in _ult_cache.get("admin_callback", {}):
+ return
+ try:
+ perm = await event.client.get_permissions(event.chat_id, event.sender_id)
+ except UserNotParticipantError:
+ return await event.answer("Join the Group First!", alert=True)
+ if not perm.is_admin:
+ return await event.answer("You are not an Admin!", alert=True)
+ _ult_cache["admin_callback"].update({data: (event.sender, perm)})
+ await event.answer("Verification Done!")
+ await event.delete()
diff --git a/assistant/manager/afk.py b/assistant/manager/afk.py
new file mode 100644
index 0000000000000000000000000000000000000000..ceb45a3fd2362f00af9f7f20687a1fbe599b9f47
--- /dev/null
+++ b/assistant/manager/afk.py
@@ -0,0 +1,110 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from datetime import datetime as dt
+
+from telethon.events import NewMessage
+from telethon.tl.types import (
+ Message,
+ MessageEntityMention,
+ MessageEntityMentionName,
+ User,
+)
+from telethon.utils import get_display_name
+
+from pyUltroid.fns.helper import inline_mention, time_formatter
+
+from . import asst, asst_cmd
+
+AFK = {}
+
+
+@asst_cmd(pattern="afk", func=lambda x: not x.is_private)
+async def go_afk(event):
+ sender = await event.get_sender()
+ if (not isinstance(sender, User)) or sender.bot:
+ return
+ try:
+ reason = event.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ reason = None
+ if event.is_reply and not reason:
+ replied = await event.get_reply_message()
+ if not reason and replied.text and not replied.media:
+ reason = replied.text
+ else:
+ reason = replied
+ time_ = dt.now()
+ if AFK.get(event.chat_id):
+ AFK[event.chat_id].update({event.sender_id: {"reason": reason, "time": time_}})
+ else:
+ AFK.update(
+ {event.chat_id: {event.sender_id: {"reason": reason, "time": time_}}}
+ )
+ mention = inline_mention(sender)
+ msg = f"**{mention} went AFK Now!**"
+ if reason and not isinstance(reason, str):
+ await event.reply(reason)
+ else:
+ msg += f"\n\n**Reason : ** `{reason}`"
+ await event.reply(msg)
+
+
+@asst.on(NewMessage(func=lambda x: AFK.get(x.chat_id) and not x.is_private))
+async def make_change(event):
+ if event.text.startswith("/afk"):
+ return
+ sender = await event.get_sender()
+ if (not isinstance(sender, User)) or sender.bot:
+ return
+ chat_ = AFK[event.chat_id]
+ if event.sender_id in chat_.keys():
+ name = get_display_name(event.sender)
+ cha_send = chat_[event.sender_id]
+ time_ = time_formatter((dt.now() - cha_send["time"]).seconds * 1000)
+ msg = f"**{name}** is No Longer AFK!\n**Was AFK for** {time_}"
+ await event.reply(msg)
+ del chat_[event.sender_id]
+ if not chat_:
+ del AFK[event.chat_id]
+ ST_SPAM = []
+ replied = await event.get_reply_message()
+ if replied:
+ name = get_display_name(replied.sender)
+ if replied.sender_id in chat_.keys():
+ s_der = chat_[replied.sender_id]
+ res_ = s_der["reason"]
+ time_ = time_formatter((dt.now() - s_der["time"]).seconds * 1000)
+ msg = f"**{name}** is AFK Currently!\n**From :** {time_}"
+ if res_ and isinstance(res_, str):
+ msg += f"\n**Reason :** {res_}"
+ elif res_ and isinstance(res_, Message):
+ await event.reply(res_)
+ await event.reply(msg)
+ ST_SPAM.append(replied.sender_id)
+ for ent, text in event.get_entities_text():
+ dont_send, entity = None, None
+ if isinstance(ent, MessageEntityMentionName):
+ c_id = ent.user_id
+ elif isinstance(ent, MessageEntityMention):
+ c_id = text
+ else:
+ c_id = None
+ if c_id:
+ entity = await event.client.get_entity(c_id)
+ if entity and entity.id in chat_.keys() and entity.id not in ST_SPAM:
+ ST_SPAM.append(entity.id)
+ s_der = chat_[entity.id]
+ name = get_display_name(entity)
+ res_ = s_der["reason"]
+ time_ = time_formatter((dt.now() - s_der["time"]).seconds * 1000)
+ msg = f"**{name}** is AFK Currently!\n**From :** {time_}"
+ if res_ and isinstance(res_, str):
+ msg += f"\n**Reason :** {res_}"
+ elif res_ and isinstance(res_, Message):
+ await event.reply(res_)
+ await event.reply(msg)
diff --git a/assistant/manager/misc.py b/assistant/manager/misc.py
new file mode 100644
index 0000000000000000000000000000000000000000..093c9c74384b53d06a013f342e9251156af07d01
--- /dev/null
+++ b/assistant/manager/misc.py
@@ -0,0 +1,64 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+import random
+
+import aiohttp
+
+from pyUltroid.dB import DEVLIST
+from pyUltroid.fns.admins import admin_check
+
+from . import *
+
+
+@asst_cmd(pattern="decide")
+async def dheh(e):
+ text = ["Yes", "NoU", "Maybe", "IDK"]
+ text = random.choice(text)
+ ri = e.reply_to_msg_id or e.id
+ await e.client.send_message(e.chat_id, text, reply_to=ri)
+
+
+@asst_cmd(pattern="echo( (.*)|$)")
+async def oqha(e):
+ if not await admin_check(e):
+ return
+ if match := e.pattern_match.group(1).strip():
+ text = match
+ reply_to = e
+ elif e.is_reply:
+ text = (await e.get_reply_message()).text
+ reply_to = e.reply_to_msg_id
+ else:
+ return await e.eor("What to Echo?", time=5)
+ try:
+ await e.delete()
+ except BaseException as ex:
+ LOGS.error(ex)
+ await e.client.send_message(e.chat_id, text, reply_to=reply_to)
+
+
+@asst_cmd(pattern="kickme$")
+async def doit(e):
+ if e.sender_id in DEVLIST:
+ return await eod(e, "`I will Not Kick You, my Developer..`")
+ try:
+ await e.client.kick_participant(e.chat_id, e.sender_id)
+ except Exception as Fe:
+ return await e.eor(str(Fe), time=5)
+ await e.eor("Yes, You are right, get out.", time=5)
+
+
+@asst_cmd(pattern="joke$")
+async def do_joke(e):
+ e = await e.get_reply_message() if e.is_reply else e
+ link = "https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist,sexist,explicit&type=single"
+ async with aiohttp.ClientSession() as ses:
+ async with ses.get(link) as out:
+ out = await out.json()
+ await e.reply(out["joke"])
diff --git a/assistant/manager/stickermanager.py b/assistant/manager/stickermanager.py
new file mode 100644
index 0000000000000000000000000000000000000000..18529bb34df8c63b5b1132f178b275de9308cd56
--- /dev/null
+++ b/assistant/manager/stickermanager.py
@@ -0,0 +1,180 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import random
+
+from telethon import errors
+from telethon.errors.rpcerrorlist import StickersetInvalidError
+from telethon.tl.functions.messages import GetStickerSetRequest as GetSticker
+from telethon.tl.functions.messages import UploadMediaRequest
+from telethon.tl.functions.stickers import AddStickerToSetRequest as AddSticker
+from telethon.tl.functions.stickers import CreateStickerSetRequest
+from telethon.tl.types import InputPeerSelf
+from telethon.tl.types import InputStickerSetItem as SetItem
+from telethon.tl.types import InputStickerSetShortName, User
+from telethon.utils import get_display_name, get_input_document
+
+from pyUltroid.fns.misc import Quotly
+from pyUltroid.fns.tools import TgConverter
+
+from . import LOGS, asst, asst_cmd, udB
+
+
+@asst_cmd(
+ pattern="kang",
+)
+async def kang_cmd(ult):
+ sender = await ult.get_sender()
+ if not isinstance(sender, User):
+ return
+ if not ult.is_reply:
+ return await ult.eor("`Reply to a sticker/photo..`", time=5)
+ reply = await ult.get_reply_message()
+ if sender.username:
+ pre = sender.username[:4]
+ else:
+ pre = random.random_string(length=3)
+ animated, dl, video = None, None, None
+ try:
+ emoji = ult.text.split(maxsplit=1)[1]
+ except IndexError:
+ emoji = None
+ if reply.sticker:
+ file = get_input_document(reply.sticker)
+ emoji = emoji or reply.file.emoji
+ name = reply.file.name
+ if name.endswith(".tgs"):
+ animated = True
+ dl = await reply.download_media()
+ elif name.endswith(".webm"):
+ video = True
+ dl = await reply.download_media()
+ elif reply.photo:
+ dl = await reply.download_media()
+ name = "sticker.webp"
+ image = TgConverter.resize_photo_sticker(dl)
+ image.save(name, "WEBP")
+ elif reply.text:
+ dl = await Quotly().create_quotly(reply)
+ else:
+ return await ult.eor("`Reply to sticker or text to add it in your pack...`")
+ if not emoji:
+ emoji = "đľ"
+ if dl:
+ upl = await ult.client.upload_file(dl)
+ file = get_input_document(
+ await ult.client(UploadMediaRequest(InputPeerSelf(), upl))
+ )
+ get_ = udB.get_key("STICKERS") or {}
+ type_ = "anim" if animated else "static"
+ if not get_.get(ult.sender_id) or not get_.get(ult.sender_id, {}).get(type_):
+ sn = f"{pre}_{ult.sender_id}"
+ title = f"{get_display_name(sender)}'s Kang Pack"
+ if animated:
+ type_ = "anim"
+ sn += "_anim"
+ title += " (Animated)"
+ elif video:
+ type_ = "vid"
+ sn += "_vid"
+ title += " (Video)"
+ sn += f"_by_{asst.me.username}"
+ try:
+ await asst(GetSticker(InputStickerSetShortName(sn), hash=0))
+ sn = sn.replace(str(ult.sender_id), f"{ult.sender_id}_{ult.id}")
+ except StickersetInvalidError:
+ pass
+ try:
+ pack = await ult.client(
+ CreateStickerSetRequest(
+ user_id=sender.id,
+ title=title,
+ short_name=sn,
+ stickers=[SetItem(file, emoji=emoji)],
+ videos=video,
+ animated=animated,
+ software="@TeamUltroid",
+ )
+ )
+ except Exception as er:
+ return await ult.eor(str(er))
+ sn = pack.set.short_name
+ if not get_.get(ult.sender_id):
+ get_.update({ult.sender_id: {type_: [sn]}})
+ else:
+ get_[ult.sender_id].update({type_: [sn]})
+ udB.set_key("STICKERS", get_)
+ return await ult.reply(
+ f"**Kanged Successfully!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})"
+ )
+ name = get_[ult.sender_id][type_][-1]
+ try:
+ await asst(GetSticker(InputStickerSetShortName(name), hash=0))
+ except StickersetInvalidError:
+ get_[ult.sender_id][type_].remove(name)
+ try:
+ await asst(
+ AddSticker(InputStickerSetShortName(name), SetItem(file, emoji=emoji))
+ )
+ except (errors.StickerpackStickersTooMuchError, errors.StickersTooMuchError):
+ sn = f"{pre}{ult.sender_id}_{ult.id}"
+ title = f"{get_display_name(sender)}'s Kang Pack"
+ if animated:
+ sn += "_anim"
+ title += " (Animated)"
+ elif video:
+ sn += "_vid"
+ title += "(Video)"
+ sn += f"_by_{asst.me.username}"
+ try:
+ pack = await ult.client(
+ CreateStickerSetRequest(
+ user_id=sender.id,
+ title=title,
+ short_name=sn,
+ stickers=[SetItem(file, emoji=emoji)],
+ animated=animated,
+ )
+ )
+ except Exception as er:
+ return await ult.eor(str(er))
+ get_[ult.sender_id][type_].append(pack.set.short_name)
+ udB.set_key("STICKERS", get_)
+ return await ult.reply(
+ f"**Created New Kang Pack!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})"
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ return await ult.reply(str(er))
+ await ult.reply(
+ f"Sticker Added to Pack Successfully\n**Link :** [Click Here](https://t.me/addstickers/{name})"
+ )
+
+
+@asst_cmd(pattern="listpack")
+async def do_magic(ult):
+ ko = udB.get_key("STICKERS") or {}
+ if not ko.get(ult.sender_id):
+ return await ult.reply("No Sticker Pack Found!")
+ al_ = []
+ ul = ko[ult.sender_id]
+ for _ in ul.keys():
+ al_.extend(ul[_])
+ msg = "⢠**Stickers Owned by You!**\n\n"
+ for _ in al_:
+ try:
+ pack = await ult.client(GetSticker(InputStickerSetShortName(_), hash=0))
+ msg += f"⢠[{pack.set.title}](https://t.me/addstickers/{_})\n"
+ except StickerSetInvalidError:
+ if ul.get("anim") and _ in ul["anim"]:
+ ul["anim"].remove(_)
+ elif ul.get("vid") and _ in ul["vid"]:
+ ul["vid"].remove(_)
+ else:
+ ul["static"].remove(_)
+ udB.set_key("STICKERS", ko)
+ await ult.reply(msg)
diff --git a/assistant/pmbot.py b/assistant/pmbot.py
new file mode 100644
index 0000000000000000000000000000000000000000..316f8eae6d09b1878882356bad6986d6f6580534
--- /dev/null
+++ b/assistant/pmbot.py
@@ -0,0 +1,150 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+# https://github.com/xditya/TeleBot/blob/master/telebot/plugins/mybot/pmbot/incoming.py
+
+# --------------------------------------- Imports -------------------------------------------- #
+
+import os
+
+from telethon.errors.rpcerrorlist import UserNotParticipantError
+from telethon.tl.custom import Button
+from telethon.tl.functions.channels import GetFullChannelRequest
+from telethon.tl.functions.messages import GetFullChatRequest
+from telethon.tl.types import Channel, Chat
+from telethon.utils import get_display_name
+
+from pyUltroid.dB.base import KeyManager
+from pyUltroid.dB.botchat_db import *
+from pyUltroid.fns.helper import inline_mention
+
+from . import *
+
+botb = KeyManager("BOTBLS", cast=list)
+FSUB = udB.get_key("PMBOT_FSUB")
+CACHE = {}
+# --------------------------------------- Incoming -------------------------------------------- #
+
+
+@asst_cmd(
+ load=AST_PLUGINS,
+ incoming=True,
+ func=lambda e: e.is_private and not botb.contains(e.sender_id),
+)
+async def on_new_mssg(event):
+ who = event.sender_id
+ # doesn't reply to that user anymore
+ if event.text.startswith("/") or who == OWNER_ID:
+ return
+ if FSUB:
+ MSG = ""
+ BTTS = []
+ for chat in FSUB:
+ try:
+ await event.client.get_permissions(chat, event.sender_id)
+ except UserNotParticipantError:
+ if not MSG:
+ MSG += get_string("pmbot_1")
+ try:
+ uri = ""
+ TAHC_ = await event.client.get_entity(chat)
+ if hasattr(TAHC_, "username") and TAHC_.username:
+ uri = f"t.me/{TAHC_.username}"
+ elif CACHE.get(chat):
+ uri = CACHE[chat]
+ else:
+ if isinstance(TAHC_, Channel):
+ FUGB = await event.client(GetFullChannelRequest(chat))
+ elif isinstance(TAHC_, Chat):
+ FUGB = await event.client(GetFullChatRequest(chat))
+ else:
+ return
+ if FUGB.full_chat.exported_invite:
+ CACHE[chat] = FUGB.full_chat.exported_invite.link
+ uri = CACHE[chat]
+ BTTS.append(Button.url(get_display_name(TAHC_), uri))
+ except Exception as er:
+ LOGS.exception(f"Error On PmBot Force Sub!\n - {chat} \n{er}")
+ if MSG and BTTS:
+ return await event.reply(MSG, buttons=BTTS)
+ xx = await event.forward_to(OWNER_ID)
+ if event.fwd_from:
+ await xx.reply(f"From {inline_mention(event.sender)} [`{event.sender_id}`]")
+ add_stuff(xx.id, who)
+
+
+# --------------------------------------- Outgoing -------------------------------------------- #
+
+
+@asst_cmd(
+ load=AST_PLUGINS,
+ from_users=[OWNER_ID],
+ incoming=True,
+ func=lambda e: e.is_private and e.is_reply,
+)
+async def on_out_mssg(event):
+ x = event.reply_to_msg_id
+ to_user = get_who(x)
+ if event.text.startswith("/who"):
+ try:
+ k = await asst.get_entity(to_user)
+ photu = await event.client.download_profile_photo(k.id)
+ await event.reply(
+ f"⢠**Name :** {get_display_name(k)}\n⢠**ID :** `{k.id}`\n⢠**Link :** {inline_mention(k)}",
+ file=photu,
+ )
+ if photu:
+ os.remove(photu)
+ return
+ except BaseException as er:
+ return await event.reply(f"**ERROR : **{str(er)}")
+ elif event.text.startswith("/"):
+ return
+ if to_user:
+ await asst.send_message(to_user, event.message)
+
+
+# --------------------------------------- Ban/Unban -------------------------------------------- #
+
+
+@asst_cmd(
+ pattern="ban",
+ load=AST_PLUGINS,
+ from_users=[OWNER_ID],
+ func=lambda x: x.is_private,
+)
+async def banhammer(event):
+ if not event.is_reply:
+ return await event.reply(get_string("pmbot_2"))
+ target = get_who(event.reply_to_msg_id)
+ if botb.contains(target):
+ return await event.reply(get_string("pmbot_3"))
+
+ botb.add(target)
+ await event.reply(f"#BAN\nUser : {target}")
+ await asst.send_message(target, get_string("pmbot_4"))
+
+
+@asst_cmd(
+ pattern="unban",
+ load=AST_PLUGINS,
+ from_users=[OWNER_ID],
+ func=lambda x: x.is_private,
+)
+async def unbanhammer(event):
+ if not event.is_reply:
+ return await event.reply(get_string("pmbot_5"))
+ target = get_who(event.reply_to_msg_id)
+ if not botb.contains(target):
+ return await event.reply(get_string("pmbot_6"))
+
+ botb.remove(target)
+ await event.reply(f"#UNBAN\nUser : {target}")
+ await asst.send_message(target, get_string("pmbot_7"))
+
+
+# --------------------------------------- END -------------------------------------------- #
diff --git a/assistant/start.py b/assistant/start.py
new file mode 100644
index 0000000000000000000000000000000000000000..6eac6a29b5e10051c4dadea23d69c2a2cc1e5fd9
--- /dev/null
+++ b/assistant/start.py
@@ -0,0 +1,240 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from datetime import datetime
+
+from pytz import timezone as tz
+from telethon import Button, events
+from telethon.errors.rpcerrorlist import MessageDeleteForbiddenError
+from telethon.utils import get_display_name
+
+from pyUltroid._misc import SUDO_M, owner_and_sudos
+from pyUltroid.dB.base import KeyManager
+from pyUltroid.fns.helper import inline_mention
+from strings import get_string
+
+from . import *
+
+Owner_info_msg = udB.get_key("BOT_INFO_START")
+custom_info = True
+if Owner_info_msg is None:
+ custom_info = False
+ Owner_info_msg = f"""
+**Owner** - {OWNER_NAME}
+**OwnerID** - `{OWNER_ID}`
+
+**Message Forwards** - {udB.get_key("PMBOT")}
+
+**Ultroid [v{ultroid_version}](https://github.com/TeamUltroid/Ultroid), powered by @TeamUltroid**
+"""
+
+
+_settings = [
+ [
+ Button.inline("API Ká´Ęs", data="cbs_apiset"),
+ Button.inline("Pá´ Bá´á´", data="cbs_chatbot"),
+ ],
+ [
+ Button.inline("AĘÉŞá´ á´", data="cbs_alvcstm"),
+ Button.inline("Pá´Pá´Ęá´ÉŞá´", data="cbs_ppmset"),
+ ],
+ [
+ Button.inline("Fá´á´á´á´Ęá´s", data="cbs_otvars"),
+ Button.inline("VC Sá´É´É˘ Bá´á´", data="cbs_vcb"),
+ ],
+ [Button.inline("ÂŤ Bá´á´á´", data="mainmenu")],
+]
+
+_start = [
+ [
+ Button.inline("Lá´É´É˘á´á´É˘á´ đ", data="lang"),
+ Button.inline("Sá´á´á´ÉŞÉ´É˘s âď¸", data="setter"),
+ ],
+ [
+ Button.inline("Sá´á´á´s â¨", data="stat"),
+ Button.inline("BĘá´á´á´
á´á´sá´ đť", data="bcast"),
+ ],
+ [Button.inline("TÉŞá´á´Zá´É´á´ đ", data="tz")],
+]
+
+
+@callback("ownerinfo")
+async def own(event):
+ msg = Owner_info_msg.format(
+ mention=inline_mention(event.sender), me=inline_mention(ultroid_bot.me)
+ )
+ if custom_info:
+ msg += "\n\n⢠Powered by **@TeamUltroid**"
+ await event.edit(
+ msg,
+ buttons=[Button.inline("Close", data="closeit")],
+ link_preview=False,
+ )
+
+
+@callback("closeit")
+async def closet(lol):
+ try:
+ await lol.delete()
+ except MessageDeleteForbiddenError:
+ await lol.answer("MESSAGE_TOO_OLD", alert=True)
+
+
+@asst_cmd(pattern="start( (.*)|$)", forwards=False, func=lambda x: not x.is_group)
+async def ultroid(event):
+ args = event.pattern_match.group(1).strip()
+ keym = KeyManager("BOT_USERS", cast=list)
+ if not keym.contains(event.sender_id) and event.sender_id not in owner_and_sudos():
+ keym.add(event.sender_id)
+ kak_uiw = udB.get_key("OFF_START_LOG")
+ if not kak_uiw or kak_uiw != True:
+ msg = f"{inline_mention(event.sender)} `[{event.sender_id}]` started your [Assistant bot](@{asst.me.username})."
+ buttons = [[Button.inline("Info", "itkkstyo")]]
+ if event.sender.username:
+ buttons[0].append(
+ Button.mention(
+ "User", await event.client.get_input_entity(event.sender_id)
+ )
+ )
+ await event.client.send_message(
+ udB.get_key("LOG_CHANNEL"), msg, buttons=buttons
+ )
+ if event.sender_id not in SUDO_M.fullsudos:
+ ok = ""
+ me = inline_mention(ultroid_bot.me)
+ mention = inline_mention(event.sender)
+ if args and args != "set":
+ await get_stored_file(event, args)
+ if not udB.get_key("STARTMSG"):
+ if udB.get_key("PMBOT"):
+ ok = "You can contact my master using this bot!!\n\nSend your Message, I will Deliver it To Master."
+ await event.reply(
+ f"Hey there {mention}, this is Ultroid Assistant of {me}!\n\n{ok}",
+ file=udB.get_key("STARTMEDIA"),
+ buttons=[Button.inline("Info.", data="ownerinfo")]
+ if Owner_info_msg
+ else None,
+ )
+ else:
+ await event.reply(
+ udB.get_key("STARTMSG").format(me=me, mention=mention),
+ file=udB.get_key("STARTMEDIA"),
+ buttons=[Button.inline("Info.", data="ownerinfo")]
+ if Owner_info_msg
+ else None,
+ )
+ else:
+ name = get_display_name(event.sender)
+ if args == "set":
+ await event.reply(
+ "Choose from the below options -",
+ buttons=_settings,
+ )
+ elif args:
+ await get_stored_file(event, args)
+ else:
+ await event.reply(
+ get_string("ast_3").format(name),
+ buttons=_start,
+ )
+
+
+@callback("itkkstyo", owner=True)
+async def ekekdhdb(e):
+ text = f"When New Visitor will visit your Assistant Bot. You will get this log message!\n\nTo Disable : {HNDLR}setdb OFF_START_LOG True"
+ await e.answer(text, alert=True)
+
+
+@callback("mainmenu", owner=True, func=lambda x: not x.is_group)
+async def ultroid(event):
+ await event.edit(
+ get_string("ast_3").format(OWNER_NAME),
+ buttons=_start,
+ )
+
+
+@callback("stat", owner=True)
+async def botstat(event):
+ ok = len(udB.get_key("BOT_USERS") or [])
+ msg = """Ultroid Assistant - Stats
+Total Users - {}""".format(
+ ok,
+ )
+ await event.answer(msg, cache_time=0, alert=True)
+
+
+@callback("bcast", owner=True)
+async def bdcast(event):
+ keym = KeyManager("BOT_USERS", cast=list)
+ total = keym.count()
+ await event.edit(f"⢠Broadcast to {total} users.")
+ async with event.client.conversation(OWNER_ID) as conv:
+ await conv.send_message(
+ "Enter your broadcast message.\nUse /cancel to stop the broadcast.",
+ )
+ response = await conv.get_response()
+ if response.message == "/cancel":
+ return await conv.send_message("Cancelled!!")
+ success = 0
+ fail = 0
+ await conv.send_message(f"Starting a broadcast to {total} users...")
+ start = datetime.now()
+ for i in keym.get():
+ try:
+ await asst.send_message(int(i), response)
+ success += 1
+ except BaseException:
+ fail += 1
+ end = datetime.now()
+ time_taken = (end - start).seconds
+ await conv.send_message(
+ f"""
+**Broadcast completed in {time_taken} seconds.**
+Total Users in Bot - {total}
+**Sent to** : `{success} users.`
+**Failed for** : `{fail} user(s).`""",
+ )
+
+
+@callback("setter", owner=True)
+async def setting(event):
+ await event.edit(
+ "Choose from the below options -",
+ buttons=_settings,
+ )
+
+
+@callback("tz", owner=True)
+async def timezone_(event):
+ await event.delete()
+ pru = event.sender_id
+ var = "TIMEZONE"
+ name = "Timezone"
+ async with event.client.conversation(pru) as conv:
+ await conv.send_message(
+ "Send Your TimeZone From This List [Check From Here](http://www.timezoneconverter.com/cgi-bin/findzone.tzc)"
+ )
+ response = conv.wait_event(events.NewMessage(chats=pru))
+ response = await response
+ themssg = response.message.message
+ if themssg == "/cancel":
+ return await conv.send_message(
+ "Cancelled!!",
+ buttons=get_back_button("mainmenu"),
+ )
+ try:
+ tz(themssg)
+ await setit(event, var, themssg)
+ await conv.send_message(
+ f"{name} changed to {themssg}\n",
+ buttons=get_back_button("mainmenu"),
+ )
+ except BaseException:
+ await conv.send_message(
+ "Wrong TimeZone, Try again",
+ buttons=get_back_button("mainmenu"),
+ )
diff --git a/assistant/ytdl.py b/assistant/ytdl.py
new file mode 100644
index 0000000000000000000000000000000000000000..a858aabe159d271da948d4b43b479e41e0b646b2
--- /dev/null
+++ b/assistant/ytdl.py
@@ -0,0 +1,325 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+import os
+import re
+
+try:
+ from PIL import Image
+except ImportError:
+ Image = None
+from telethon import Button
+from telethon.errors.rpcerrorlist import FilePartLengthInvalidError, MediaEmptyError
+from telethon.tl.types import DocumentAttributeAudio, DocumentAttributeVideo
+from telethon.tl.types import InputWebDocument as wb
+
+from pyUltroid.fns.helper import (
+ bash,
+ fast_download,
+ humanbytes,
+ numerize,
+ time_formatter,
+)
+from pyUltroid.fns.ytdl import dler, get_buttons, get_formats
+
+from . import LOGS, asst, callback, in_pattern, udB
+
+try:
+ from youtubesearchpython import VideosSearch
+except ImportError:
+ LOGS.info("'youtubesearchpython' not installed!")
+ VideosSearch = None
+
+
+ytt = "https://graph.org/file/afd04510c13914a06dd03.jpg"
+_yt_base_url = "https://www.youtube.com/watch?v="
+BACK_BUTTON = {}
+
+
+@in_pattern("yt", owner=True)
+async def _(event):
+ try:
+ string = event.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ fuk = event.builder.article(
+ title="Search Something",
+ thumb=wb(ytt, 0, "image/jpeg", []),
+ text="**Yá´á´Tá´Ęá´ Sá´á´Ęá´Ę**\n\nYou didn't search anything",
+ buttons=Button.switch_inline(
+ "Sá´á´Ęá´Ę Aɢá´ÉŞÉ´",
+ query="yt ",
+ same_peer=True,
+ ),
+ )
+ await event.answer([fuk])
+ return
+ results = []
+ search = VideosSearch(string, limit=50)
+ nub = search.result()
+ nibba = nub["result"]
+ for v in nibba:
+ ids = v["id"]
+ link = _yt_base_url + ids
+ title = v["title"]
+ duration = v["duration"]
+ views = v["viewCount"]["short"]
+ publisher = v["channel"]["name"]
+ published_on = v["publishedTime"]
+ description = (
+ v["descriptionSnippet"][0]["text"]
+ if v.get("descriptionSnippet")
+ and len(v["descriptionSnippet"][0]["text"]) < 500
+ else "None"
+ )
+ thumb = f"https://i.ytimg.com/vi/{ids}/hqdefault.jpg"
+ text = f"**Title: [{title}]({link})**\n\n"
+ text += f"`Description: {description}\n\n"
+ text += f"ă Duration: {duration} ă\n"
+ text += f"ă Views: {views} ă\n"
+ text += f"ă Publisher: {publisher} ă\n"
+ text += f"ă Published on: {published_on} ă`"
+ desc = f"{title}\n{duration}"
+ file = wb(thumb, 0, "image/jpeg", [])
+ buttons = [
+ [
+ Button.inline("Audio", data=f"ytdl:audio:{ids}"),
+ Button.inline("Video", data=f"ytdl:video:{ids}"),
+ ],
+ [
+ Button.switch_inline(
+ "Sá´á´Ęá´Ę Aɢá´ÉŞÉ´",
+ query="yt ",
+ same_peer=True,
+ ),
+ Button.switch_inline(
+ "SĘá´Ęá´",
+ query=f"yt {string}",
+ same_peer=False,
+ ),
+ ],
+ ]
+ BACK_BUTTON.update({ids: {"text": text, "buttons": buttons}})
+ results.append(
+ await event.builder.article(
+ type="photo",
+ title=title,
+ description=desc,
+ thumb=file,
+ content=file,
+ text=text,
+ include_media=True,
+ buttons=buttons,
+ ),
+ )
+ await event.answer(results[:50])
+
+
+@callback(
+ re.compile(
+ "ytdl:(.*)",
+ ),
+ owner=True,
+)
+async def _(e):
+ _e = e.pattern_match.group(1).strip().decode("UTF-8")
+ _lets_split = _e.split(":")
+ _ytdl_data = await dler(e, _yt_base_url + _lets_split[1])
+ _data = get_formats(_lets_split[0], _lets_split[1], _ytdl_data)
+ _buttons = get_buttons(_data)
+ _text = (
+ "`Select Your Format.`"
+ if _buttons
+ else "`Error downloading from YouTube.\nTry Restarting your bot.`"
+ )
+ await e.edit(_text, buttons=_buttons)
+
+
+@callback(
+ re.compile(
+ "ytdownload:(.*)",
+ ),
+ owner=True,
+)
+async def _(event):
+ url = event.pattern_match.group(1).strip().decode("UTF-8")
+ lets_split = url.split(":")
+ vid_id = lets_split[2]
+ link = _yt_base_url + vid_id
+ format = lets_split[1]
+ try:
+ ext = lets_split[3]
+ except IndexError:
+ ext = "mp3"
+
+ # Define download options based on audio or video type
+ if lets_split[0] == "audio":
+ opts = {
+ "format": "bestaudio",
+ "addmetadata": True,
+ "key": "FFmpegMetadata",
+ "prefer_ffmpeg": True,
+ "geo_bypass": True,
+ "outtmpl": f"%(id)s.{ext}",
+ "logtostderr": False,
+ "postprocessors": [
+ {
+ "key": "FFmpegExtractAudio",
+ "preferredcodec": ext,
+ "preferredquality": format,
+ },
+ {"key": "FFmpegMetadata"},
+ ],
+ "cookiefile": "cookies.txt",
+ }
+
+ ytdl_data = await dler(event, link, opts, True)
+ title = ytdl_data["title"]
+ artist = ytdl_data.get("artist") or ytdl_data.get("creator") or ytdl_data.get("channel")
+ views = numerize(ytdl_data.get("view_count")) or 0
+ thumb, _ = await fast_download(ytdl_data["thumbnail"], filename=f"{vid_id}.jpg")
+
+ likes = numerize(ytdl_data.get("like_count")) or 0
+ duration = ytdl_data.get("duration") or 0
+ description = (
+ ytdl_data["description"][:100]
+ if ytdl_data["description"] and len(ytdl_data["description"]) >= 100
+ else ytdl_data.get("description", "None")
+ )
+
+ filepath = f"{vid_id}.{ext}"
+ if not os.path.exists(filepath):
+ filepath = f"{filepath}.{ext}"
+ if os.path.exists(filepath):
+ size = os.path.getsize(filepath)
+ else:
+ LOGS.error(f"File not found: {filepath}")
+ await event.edit("`Error: File not found after download.`")
+ return
+
+ file, _ = await event.client.fast_uploader(
+ filepath,
+ filename=f"{title}.{ext}",
+ show_progress=True,
+ event=event,
+ to_delete=True,
+ )
+
+ attributes = [
+ DocumentAttributeAudio(
+ duration=int(duration),
+ title=title,
+ performer=artist,
+ ),
+ ]
+
+ elif lets_split[0] == "video":
+ opts = {
+ "format": str(format),
+ "addmetadata": True,
+ "key": "FFmpegMetadata",
+ "prefer_ffmpeg": True,
+ "geo_bypass": True,
+ "outtmpl": f"%(id)s.{ext}",
+ "logtostderr": False,
+ "postprocessors": [{"key": "FFmpegMetadata"}],
+ "cookiefile": "cookies.txt",
+ }
+
+ ytdl_data = await dler(event, link, opts, True)
+ title = ytdl_data["title"]
+ artist = ytdl_data.get("artist") or ytdl_data.get("creator") or ytdl_data.get("channel")
+ views = numerize(ytdl_data.get("view_count")) or 0
+ thumb, _ = await fast_download(ytdl_data["thumbnail"], filename=f"{vid_id}.jpg")
+ description = (
+ ytdl_data.get("description", "None")
+ if ytdl_data.get("description") and len(ytdl_data["description"]) < 100
+ else (ytdl_data["description"][:100] if ytdl_data.get("description") else "None")
+ )
+
+ try:
+ Image.open(thumb).save(thumb, "JPEG")
+ except Exception as er:
+ LOGS.exception(er)
+ thumb = None
+
+ likes = numerize(ytdl_data.get("like_count")) or 0
+ hi, wi = ytdl_data.get("height") or 720, ytdl_data.get("width") or 1280
+ duration = ytdl_data.get("duration") or 0
+ filepath = f"{vid_id}.mkv"
+ if not os.path.exists(filepath):
+ filepath = f"{filepath}.webm"
+ if os.path.exists(filepath):
+ size = os.path.getsize(filepath)
+ if not os.path.exists(filepath):
+ filepath = f"{vid_id}.mp4.webm"
+ if os.path.exists(filepath):
+ size = os.path.getsize(filepath)
+ if not os.path.exists(filepath):
+ filepath = f"{vid_id}.mp4.mkv"
+ if os.path.exists(filepath):
+ size = os.path.getsize(filepath)
+ else:
+ LOGS.error(f"File not found: {filepath}")
+ await event.edit("`Error: File not found after download.`")
+ return
+
+ file, _ = await event.client.fast_uploader(
+ filepath,
+ filename=f"{title}.mkv",
+ show_progress=True,
+ event=event,
+ to_delete=True,
+ )
+
+ attributes = [
+ DocumentAttributeVideo(
+ duration=int(duration),
+ w=wi,
+ h=hi,
+ supports_streaming=True,
+ ),
+ ]
+
+ description = description if description != "" else "None"
+ text = f"**Title: [{title}]({_yt_base_url}{vid_id})**\n\n"
+ text += f"`đ Description: {description}\n\n"
+ text += f"ă Duration: {time_formatter(int(duration)*1000)} ă\n"
+ text += f"ă Artist: {artist} ă\n"
+ text += f"ă Views: {views} ă\n"
+ text += f"ă Likes: {likes} ă\n"
+ text += f"ă Size: {humanbytes(size)} ă`"
+ button = Button.switch_inline("Search More", query="yt ", same_peer=True)
+
+ try:
+ await event.edit(
+ text,
+ file=file,
+ buttons=button,
+ attributes=attributes,
+ thumb=thumb,
+ )
+ except (FilePartLengthInvalidError, MediaEmptyError):
+ file = await asst.send_message(
+ udB.get_key("LOG_CHANNEL"),
+ text,
+ file=file,
+ buttons=button,
+ attributes=attributes,
+ thumb=thumb,
+ )
+ await event.edit(text, file=file.media, buttons=button)
+
+ await bash(f"rm {vid_id}.jpg")
+
+
+@callback(re.compile("ytdl_back:(.*)"), owner=True)
+async def ytdl_back(event):
+ id_ = event.data_match.group(1).decode("utf-8")
+ if not BACK_BUTTON.get(id_):
+ return await event.answer("Query Expired! Search again đ")
+ await event.edit(**BACK_BUTTON[id_])
\ No newline at end of file
diff --git a/cookies.txt b/cookies.txt
new file mode 100644
index 0000000000000000000000000000000000000000..314638764bf75143677fd0e09652dbede7bd9700
--- /dev/null
+++ b/cookies.txt
@@ -0,0 +1,42 @@
+# Netscape HTTP Cookie File
+
+#HttpOnly_.youtube.com TRUE / TRUE 1746001205 VISITOR_INFO1_LIVE JzkiGVgHdxs
+#HttpOnly_.youtube.com TRUE / TRUE 1746001205 VISITOR_PRIVACY_METADATA CgJJThIEGgAgPg%3D%3D
+.youtube.com TRUE / TRUE 1765872096 PREF f6=40000000&tz=Asia.Kolkata&f7=100
+#HttpOnly_.youtube.com TRUE / TRUE 1730649729 YTSESSION-rvkia ANPz9Kiz+w+HZes55sKK7pCuEovAWHcXOk37Q0agDWJm/apfN4Vh8Ftll+/LLymwYzS3hG+8MKthM7g2ME+R/dAxYG4vJTwhMhqVuvUaIi9NUvQWkM6nln3Sm2g84UiOME3KjeoLHiTkAu6bscjJwXEUlzCcAiAA9NqNMP+aaYtJJIcQ0jwONZ3zM+xtiEkwvBjkTyKKqKO8bS1es5SLnfccSc3v0DrCraeNTrblOWvfzRPnnV53QbxDEPSs32vPtWeMeQu4m1TATvK+D9x6pMsXuVRMmnqaXmvgqOtjxh8mU9QRGyTzwTKehJqIxWYp3tHEAcZLxjmVKxhlEu2rmnQQL8ZQTSeHEMaMwnjtPCg=
+.youtube.com TRUE / FALSE 1730650255 ST-1niaixf csn=cswKjmrMw8VB5Z1b&itct=CFIQh_YEGAAiEwjbvIDJxsCJAxVD20wCHSfHMKBaD0ZFd2hhdF90b193YXRjaJoBBQgkEI4e
+.youtube.com TRUE / FALSE 1730650257 ST-1gh2pue csn=cswKjmrMw8VB5Z1b&itct=CFAQh_YEGAEiEwjbvIDJxsCJAxVD20wCHSfHMKBaD0ZFd2hhdF90b193YXRjaJoBBQgkEI4e
+.youtube.com TRUE / FALSE 1730650259 ST-s99c5j csn=cswKjmrMw8VB5Z1b&itct=CCsQ_FoiEwjbvIDJxsCJAxVD20wCHSfHMKAyBmctaGlnaFoPRkV3aGF0X3RvX3dhdGNomgEGEI4eGIAK
+.youtube.com TRUE / FALSE 1730650259 ST-vq8erx csn=cswKjmrMw8VB5Z1b&itct=CAoQ_FoiEwiwlbnLxsCJAxWFSfUFHdBqEnMyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+.youtube.com TRUE / FALSE 1730650260 ST-16p99kj csn=cswKjmrMw8VB5Z1b&itct=CAQQ_FoiEwiwlbnLxsCJAxWFSfUFHdBqEnMyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+.youtube.com TRUE / FALSE 1730650444 ST-1622lmp csn=fi1SuwtAPZ_X96Gg&itct=CGoQ_FoiEwiE3eObx8CJAxVQdp0JHZleF5cyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+.youtube.com TRUE / FALSE 1730650444 ST-xe5mcv csn=fi1SuwtAPZ_X96Gg&itct=CGEQh_YEGAEiEwiE3eObx8CJAxVQdp0JHZleF5daD0ZFd2hhdF90b193YXRjaJoBBQgkEI4e
+.youtube.com TRUE / FALSE 1731310795 ST-t94cx csn=TgXFmi3VemchnwK9&itct=CHUQh_YEGAEiEwj1t9ah49OJAxUHgGMGHaUMNkhaD0ZFd2hhdF90b193YXRjaJoBBQgkEI4e
+.youtube.com TRUE / FALSE 1731310799 ST-ss2mbx csn=TgXFmi3VemchnwK9&itct=CH4Q_FoiEwj1t9ah49OJAxUHgGMGHaUMNkgyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+.youtube.com TRUE / FALSE 1731310803 ST-sa15x3 csn=J7wxCucV3U5CuQlm&itct=CHIQ_FoYACITCI-wtKbj04kDFUt2nQkdLbUnKDIHcmVsYXRlZEju6db3sNmL5acBmgEFCAEQ-B0%3D
+.youtube.com TRUE / FALSE 1731310817 ST-wv7pqz
+#HttpOnly_.youtube.com TRUE / TRUE 1731312621 GPS 1
+#HttpOnly_.youtube.com TRUE / TRUE 1762847096 __Secure-1PSIDTS sidts-CjIBQT4rX63PeixF2QvoqjJzG-Zwh_ZD_KFu5sc68yAIZZG-Y7WbIRsXAs5KYTmz8gjoeBAA
+#HttpOnly_.youtube.com TRUE / TRUE 1762847096 __Secure-3PSIDTS sidts-CjIBQT4rX63PeixF2QvoqjJzG-Zwh_ZD_KFu5sc68yAIZZG-Y7WbIRsXAs5KYTmz8gjoeBAA
+#HttpOnly_.youtube.com TRUE / FALSE 1765871096 HSID AhT0woOwMn0qHVF1w
+#HttpOnly_.youtube.com TRUE / TRUE 1765871096 SSID A321JMdwBLZPcTQm5
+.youtube.com TRUE / FALSE 1765871096 APISID ySRPSCycFqPSjayh/AP1u2i5feSLZaGGz8
+.youtube.com TRUE / TRUE 1765871096 SAPISID 4CFXEGtGZOCSlLRK/ACyxISi7PlpH7HGn5
+.youtube.com TRUE / TRUE 1765871096 __Secure-1PAPISID 4CFXEGtGZOCSlLRK/ACyxISi7PlpH7HGn5
+.youtube.com TRUE / TRUE 1765871096 __Secure-3PAPISID 4CFXEGtGZOCSlLRK/ACyxISi7PlpH7HGn5
+.youtube.com TRUE / FALSE 1765871096 SID g.a000qAhBmZch4B3RxV6Rnuw9hxVEy5M430-6bho3sVnE6UPRBreqWzC1JXl6l9kbUSPAjdnKUwACgYKAaQSARcSFQHGX2MipyI7bVsmc_jhPFZv6AN7BxoVAUF8yKqZ1IUJhGXX4Ytan5Ast3z_0076
+#HttpOnly_.youtube.com TRUE / TRUE 1765871096 __Secure-1PSID g.a000qAhBmZch4B3RxV6Rnuw9hxVEy5M430-6bho3sVnE6UPRBreq1izOgEemvYOtbQJ0mB1x4AACgYKAfkSARcSFQHGX2MiUasfsnR-K3o39pLjtE_wSRoVAUF8yKrAT2vB_navTgOPqOkkl7Yk0076
+#HttpOnly_.youtube.com TRUE / TRUE 1765871096 __Secure-3PSID g.a000qAhBmZch4B3RxV6Rnuw9hxVEy5M430-6bho3sVnE6UPRBreqxH12nQbvrWjZdjnNIf9jRAACgYKAfISARcSFQHGX2MiO_QLXZmpiuOSrDRSMc1DARoVAUF8yKrNtwCpFIX62e_1FV2lR_u50076
+.youtube.com TRUE / FALSE 1762848103 SIDCC AKEyXzW1bZIvrn-e1ZVhoZB-CsjSwEKxkZzEcXscbUlw7M93NWLgNFppTlC8ENnFgmqFF1yX8g
+#HttpOnly_.youtube.com TRUE / TRUE 1762848103 __Secure-1PSIDCC AKEyXzVWs7IdS6Q7ZxUDKbpwLE0VxJT0Tum4KvXmIYK0SzZjEZ1RH4HcQIu20CH3kLeYNWUT5A
+#HttpOnly_.youtube.com TRUE / TRUE 1762848103 __Secure-3PSIDCC AKEyXzWnGNnMBuDp5SHAMGat1Z0KGN0LLB2gIPpNFtW1fHWEIOpTyHhwwTujKlwYknvKJWgd9w
+#HttpOnly_.youtube.com TRUE / TRUE 1765871097 LOGIN_INFO AFmmF2swRgIhAKlyRZZgTV4-cPuj2z4Zgg9DiBRqGXbUmxhrd8E-TROlAiEAk_bvigwZrgXTJKrsacdFh7y8QyQzrvjCg31hoPKejvo:QUQ3MjNmeEd2eWU2M0g2RUxVVFN5Y3VjS0hpenZRcEpselVuLV8xZS1WVF9yRHhWWjNON25vNHZFUkdEdlNFM2dXVlZyVEV5a3I5aTBobzVMMmN6ODY0STR0ZFJrWTduR0gzT1dnMnd2RXo1eG5TS1NtbTl1U0UtWmVkUVhEYjBTclZBbm9GazdEWS1rOTJRSVhKSVhlM3lVM3ZYNzR4SWF3
+.youtube.com TRUE / FALSE 1731311131 ST-uwzxim csn=7vrrWx82cPWeJEV6&itct=CJoBEPxaGAAiEwiki53C5NOJAxUT96ACHUupAlkyBnNlYXJjaFIEbW9vbpoBAxD0JA%3D%3D
+.youtube.com TRUE / FALSE 1731311169 ST-1mw8apn csn=aPwzi8OwXIL6Rc0s&itct=CH0Q_FoiEwjovYHU5NOJAxXgdJ0JHSHLCSsyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+.youtube.com TRUE / FALSE 1731312064 ST-1gueups csn=f1TElGSXmQ6bti6-&itct=CEQQh_YEGAEiEwjwq5D659OJAxUxTQ8CHfysO8xaD0ZFd2hhdF90b193YXRjaJoBBQgkEI4e
+.youtube.com TRUE / FALSE 1731312065 ST-msyzfr csn=f1TElGSXmQ6bti6-&itct=CH0Q_FoiEwjwq5D659OJAxUxTQ8CHfysO8wyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+#HttpOnly_.youtube.com TRUE / TRUE 0 YSC TebnYDrURSw
+.youtube.com TRUE / FALSE 1731312103 ST-1bjeiut csn=mLIHUX_WCT2FN14P&itct=CH0Q_FoiEwiW8biS6NOJAxUVS_UFHWALJewyCmctaGlnaC1yZWNaD0ZFd2hhdF90b193YXRjaJoBBhCOHhieAQ%3D%3D
+#HttpOnly_.google.com TRUE / TRUE 1747121991 NID 519=ABMCPx5bokwWCY2b55S9K2-xLobzCr6K22iyN-W2GrwNNh8-8sr36Iu6Yrzh1DSxIt5MbLGhiLT9Q0tg-XsfG37eYseyvrIgIyNIo1C2iN746JyPfcIMkjuouP5QF9lKeakmGDS3JqctnhYFwpcPN7pYaKmrgjhaBzJa4J5mKzH1KZN2eFCB5aCpCWA
+#HttpOnly_accounts.google.com FALSE / TRUE 1765870822 __Host-GAPS 1:oFCh77_mCyLaqchAxqZJSILlW4LJ7A:xLbP4Vb3YnTtbo5e
+#HttpOnly_.doubleclick.net TRUE / TRUE 1731312997 test_cookie CheckForPermission
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000000000000000000000000000000000000..951e346676e87d6978fc946c08b3b24624641d6a
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,20 @@
+version: "3.9"
+services:
+ worker:
+ build: .
+ environment:
+ REDIS_URI: $REDIS_URI
+ REDIS_PASSWORD: $REDIS_PASSWORD
+ SESSION: $SESSION
+ API_ID: $API_ID # defaults to None
+ API_HASH: $API_HASH # defaults to None
+ MONGO_URI: $MONGO_URI # defaults to None
+ BOT_TOKEN: $BOT_TOKEN # Not mandatory
+ LOG_CHANNEL: $LOG_CHANNEL # Not mandatory
+ DATABASE_URL: $DATABASE_URL # defaults to None
+ OKTETO_TOKEN: $OKTETO_TOKEN
+ logging:
+ driver: "json-file"
+ options:
+ max-size: "5m"
+ max-file: "3"
diff --git a/kk/.gitkeep b/kk/.gitkeep
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/nni.py b/nni.py
new file mode 100644
index 0000000000000000000000000000000000000000..b78970727368ddd2890f9605aae144d4e2127f11
--- /dev/null
+++ b/nni.py
@@ -0,0 +1,15 @@
+from huggingface_hub import HfApi
+import os
+
+space_id = "shivam413/spaces" # Your Space ID
+token = os.environ.get("HF_TOKEN")
+
+if not token:
+ raise ValueError("HF_TOKEN environment variable not set")
+
+api = HfApi()
+
+# Restart the Space
+api.restart_space(repo_id=space_id, token=token)
+print(f"Restart requested for {space_id}")
+
diff --git a/okteto-pipeline.yml b/okteto-pipeline.yml
new file mode 100644
index 0000000000000000000000000000000000000000..4b883dbc2b6decb81569662360a454c867316733
--- /dev/null
+++ b/okteto-pipeline.yml
@@ -0,0 +1,3 @@
+icon: https://raw.githubusercontent.com/TeamUltroid/Ultroid/main/resources/extras/logo_readme.jpg
+deploy:
+ - okteto deploy --build -f docker-compose.yml
diff --git a/plugins/__init__.py b/plugins/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..9b98484c1ec83af46d41129935848af72e91e4eb
--- /dev/null
+++ b/plugins/__init__.py
@@ -0,0 +1,100 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import asyncio
+import os
+import time
+from random import choice
+
+import requests
+from telethon import Button, events
+from telethon.tl import functions, types # pylint:ignore
+
+from pyUltroid import *
+from pyUltroid._misc._assistant import asst_cmd, callback, in_pattern
+from pyUltroid._misc._decorators import ultroid_cmd
+from pyUltroid._misc._wrappers import eod, eor
+from pyUltroid.dB import DEVLIST, ULTROID_IMAGES
+from pyUltroid.fns.helper import *
+from pyUltroid.fns.misc import *
+from pyUltroid.fns.tools import *
+from pyUltroid.startup._database import _BaseDatabase as Database
+from pyUltroid.version import __version__, ultroid_version
+from strings import get_help, get_string
+
+udB: Database
+
+Redis = udB.get_key
+con = TgConverter
+quotly = Quotly()
+OWNER_NAME = ultroid_bot.full_name
+OWNER_ID = ultroid_bot.uid
+
+ultroid_bot: UltroidClient
+asst: UltroidClient
+
+LOG_CHANNEL = udB.get_key("LOG_CHANNEL")
+
+
+def inline_pic():
+ INLINE_PIC = udB.get_key("INLINE_PIC")
+ if INLINE_PIC is None:
+ INLINE_PIC = choice(ULTROID_IMAGES)
+ elif INLINE_PIC == False:
+ INLINE_PIC = None
+ return INLINE_PIC
+
+
+Telegraph = telegraph_client()
+
+List = []
+Dict = {}
+InlinePlugin = {}
+N = 0
+cmd = ultroid_cmd
+STUFF = {}
+
+# Chats, which needs to be ignore for some cases
+# Considerably, there can be many
+# Feel Free to Add Any other...
+
+NOSPAM_CHAT = [
+ -1001361294038, # UltroidSupportChat
+ -1001387666944, # PyrogramChat
+ -1001109500936, # TelethonChat
+ -1001050982793, # Python
+ -1001256902287, # DurovsChat
+ -1001473548283, # SharingUserbot
+]
+
+KANGING_STR = [
+ "Using Witchery to kang this sticker...",
+ "Plagiarising hehe...",
+ "Inviting this sticker over to my pack...",
+ "Kanging this sticker...",
+ "Hey that's a nice sticker!\nMind if I kang?!..",
+ "Hehe me stel ur stiker...",
+ "Ay look over there (â・â)!â\nWhile I kang this...",
+ "Roses are red violets are blue, kanging this sticker so my pack looks cool",
+ "Imprisoning this sticker...",
+ "Mr.Steal-Your-Sticker is stealing this sticker... ",
+]
+
+ATRA_COL = [
+ "DarkCyan",
+ "DeepSkyBlue",
+ "DarkTurquoise",
+ "Cyan",
+ "LightSkyBlue",
+ "Turquoise",
+ "MediumVioletRed",
+ "Aquamarine",
+ "Lightcyan",
+ "Azure",
+ "Moccasin",
+ "PowderBlue",
+]
diff --git a/plugins/_chatactions.py b/plugins/_chatactions.py
new file mode 100644
index 0000000000000000000000000000000000000000..8f1a9d3baa6ba98e4e7df05ccfe926063c7ebc4a
--- /dev/null
+++ b/plugins/_chatactions.py
@@ -0,0 +1,253 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import asyncio
+
+from telethon import events
+from telethon.errors.rpcerrorlist import UserNotParticipantError
+from telethon.tl.functions.channels import GetParticipantRequest
+from telethon.utils import get_display_name
+
+from pyUltroid.dB import stickers
+from pyUltroid.dB.echo_db import check_echo
+from pyUltroid.dB.forcesub_db import get_forcesetting
+from pyUltroid.dB.gban_mute_db import is_gbanned
+from pyUltroid.dB.greetings_db import get_goodbye, get_welcome, must_thank
+from pyUltroid.dB.nsfw_db import is_profan
+from pyUltroid.fns.helper import inline_mention
+from pyUltroid.fns.tools import async_searcher, create_tl_btn, get_chatbot_reply
+
+try:
+ from ProfanityDetector import detector
+except ImportError:
+ detector = None
+from . import LOG_CHANNEL, LOGS, asst, get_string, types, udB, ultroid_bot
+from ._inline import something
+
+
+@ultroid_bot.on(events.ChatAction())
+async def Function(event):
+ try:
+ await DummyHandler(event)
+ except Exception as er:
+ LOGS.exception(er)
+
+
+async def DummyHandler(ult):
+ # clean chat actions
+ key = udB.get_key("CLEANCHAT") or []
+ if ult.chat_id in key:
+ try:
+ await ult.delete()
+ except BaseException:
+ pass
+
+ # thank members
+ if must_thank(ult.chat_id):
+ chat_count = (await ult.client.get_participants(ult.chat_id, limit=0)).total
+ if chat_count % 100 == 0:
+ stik_id = chat_count / 100 - 1
+ sticker = stickers[stik_id]
+ await ult.respond(file=sticker)
+ # force subscribe
+ if (
+ udB.get_key("FORCESUB")
+ and ((ult.user_joined or ult.user_added))
+ and get_forcesetting(ult.chat_id)
+ ):
+ user = await ult.get_user()
+ if not user.bot:
+ joinchat = get_forcesetting(ult.chat_id)
+ try:
+ await ultroid_bot(GetParticipantRequest(int(joinchat), user.id))
+ except UserNotParticipantError:
+ await ultroid_bot.edit_permissions(
+ ult.chat_id, user.id, send_messages=False
+ )
+ res = await ultroid_bot.inline_query(
+ asst.me.username, f"fsub {user.id}_{joinchat}"
+ )
+ await res[0].click(ult.chat_id, reply_to=ult.action_message.id)
+
+ if ult.user_joined or ult.added_by:
+ user = await ult.get_user()
+ chat = await ult.get_chat()
+ # gbans and @UltroidBans checks
+ if udB.get_key("ULTROID_BANS"):
+ try:
+ is_banned = await async_searcher(
+ "https://bans.ultroid.tech/api/status",
+ json={"userId": user.id},
+ post=True,
+ re_json=True,
+ )
+ if is_banned["is_banned"]:
+ await ult.client.edit_permissions(
+ chat.id,
+ user.id,
+ view_messages=False,
+ )
+ await ult.respond(
+ f'**@UltroidBans:** Banned user detected and banned!\n`{str(is_banned)}`.\nBan reason: {is_banned["reason"]}',
+ )
+
+ except BaseException:
+ pass
+ reason = is_gbanned(user.id)
+ if reason and chat.admin_rights:
+ try:
+ await ult.client.edit_permissions(
+ chat.id,
+ user.id,
+ view_messages=False,
+ )
+ gban_watch = get_string("can_1").format(inline_mention(user), reason)
+ await ult.reply(gban_watch)
+ except Exception as er:
+ LOGS.exception(er)
+
+ # greetings
+ elif get_welcome(ult.chat_id):
+ user = await ult.get_user()
+ chat = await ult.get_chat()
+ title = chat.title or "this chat"
+ count = (
+ chat.participants_count
+ or (await ult.client.get_participants(chat, limit=0)).total
+ )
+ mention = inline_mention(user)
+ name = user.first_name
+ fullname = get_display_name(user)
+ uu = user.username
+ username = f"@{uu}" if uu else mention
+ wel = get_welcome(ult.chat_id)
+ msgg = wel["welcome"]
+ med = wel["media"] or None
+ userid = user.id
+ msg = None
+ if msgg:
+ msg = msgg.format(
+ mention=mention,
+ group=title,
+ count=count,
+ name=name,
+ fullname=fullname,
+ username=username,
+ userid=userid,
+ )
+ if wel.get("button"):
+ btn = create_tl_btn(wel["button"])
+ await something(ult, msg, med, btn)
+ elif msg:
+ send = await ult.reply(
+ msg,
+ file=med,
+ )
+ await asyncio.sleep(150)
+ await send.delete()
+ else:
+ await ult.reply(file=med)
+ elif (ult.user_left or ult.user_kicked) and get_goodbye(ult.chat_id):
+ user = await ult.get_user()
+ chat = await ult.get_chat()
+ title = chat.title or "this chat"
+ count = (
+ chat.participants_count
+ or (await ult.client.get_participants(chat, limit=0)).total
+ )
+ mention = inline_mention(user)
+ name = user.first_name
+ fullname = get_display_name(user)
+ uu = user.username
+ username = f"@{uu}" if uu else mention
+ wel = get_goodbye(ult.chat_id)
+ msgg = wel["goodbye"]
+ med = wel["media"]
+ userid = user.id
+ msg = None
+ if msgg:
+ msg = msgg.format(
+ mention=mention,
+ group=title,
+ count=count,
+ name=name,
+ fullname=fullname,
+ username=username,
+ userid=userid,
+ )
+ if wel.get("button"):
+ btn = create_tl_btn(wel["button"])
+ await something(ult, msg, med, btn)
+ elif msg:
+ send = await ult.reply(
+ msg,
+ file=med,
+ )
+ await asyncio.sleep(150)
+ await send.delete()
+ else:
+ await ult.reply(file=med)
+
+
+@ultroid_bot.on(events.NewMessage(incoming=True))
+async def chatBot_replies(e):
+ sender = await e.get_sender()
+ if not isinstance(sender, types.User) or sender.bot:
+ return
+ if check_echo(e.chat_id, e.sender_id):
+ try:
+ await e.respond(e.message)
+ except Exception as er:
+ LOGS.exception(er)
+ key = udB.get_key("CHATBOT_USERS") or {}
+ if e.text and key.get(e.chat_id) and sender.id in key[e.chat_id]:
+ msg = await get_chatbot_reply(e.message.message)
+ if msg:
+ sleep = udB.get_key("CHATBOT_SLEEP") or 1.5
+ await asyncio.sleep(sleep)
+ await e.reply(msg)
+ chat = await e.get_chat()
+ if e.is_group and sender.username:
+ await uname_stuff(e.sender_id, sender.username, sender.first_name)
+ elif e.is_private and chat.username:
+ await uname_stuff(e.sender_id, chat.username, chat.first_name)
+ if detector and is_profan(e.chat_id) and e.text:
+ x, y = detector(e.text)
+ if y:
+ await e.delete()
+
+
+@ultroid_bot.on(events.Raw(types.UpdateUserName))
+async def uname_change(e):
+ await uname_stuff(e.user_id, e.usernames[0] if e.usernames else None, e.first_name)
+
+
+async def uname_stuff(id, uname, name):
+ if udB.get_key("USERNAME_LOG"):
+ old_ = udB.get_key("USERNAME_DB") or {}
+ old = old_.get(id)
+ # Ignore Name Logs
+ if old and old == uname:
+ return
+ if old and uname:
+ await asst.send_message(
+ LOG_CHANNEL,
+ get_string("can_2").format(old, uname),
+ )
+ elif old:
+ await asst.send_message(
+ LOG_CHANNEL,
+ get_string("can_3").format(f"[{name}](tg://user?id={id})", old),
+ )
+ elif uname:
+ await asst.send_message(
+ LOG_CHANNEL,
+ get_string("can_4").format(f"[{name}](tg://user?id={id})", uname),
+ )
+
+ old_[id] = uname
+ udB.set_key("USERNAME_DB", old_)
diff --git a/plugins/_help.py b/plugins/_help.py
new file mode 100644
index 0000000000000000000000000000000000000000..b36101e7f5d5769f2c309797905e265bdc7e8f1a
--- /dev/null
+++ b/plugins/_help.py
@@ -0,0 +1,136 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from telethon.errors.rpcerrorlist import (
+ BotInlineDisabledError,
+ BotMethodInvalidError,
+ BotResponseTimeoutError,
+)
+from telethon.tl.custom import Button
+
+from pyUltroid.dB._core import HELP, LIST
+from pyUltroid.fns.tools import cmd_regex_replace
+
+from . import HNDLR, LOGS, OWNER_NAME, asst, get_string, inline_pic, udB, ultroid_cmd
+
+_main_help_menu = [
+ [
+ Button.inline(get_string("help_4"), data="uh_Official_"),
+ Button.inline(get_string("help_5"), data="uh_Addons_"),
+ ],
+ [
+ Button.inline(get_string("help_6"), data="uh_VCBot_"),
+ Button.inline(get_string("help_7"), data="inlone"),
+ ],
+ [
+ Button.inline(get_string("help_8"), data="ownr"),
+ Button.url(
+ get_string("help_9"), url=f"https://t.me/{asst.me.username}?start=set"
+ ),
+ ],
+ [Button.inline(get_string("help_10"), data="close")],
+]
+
+
+@ultroid_cmd(pattern="help( (.*)|$)")
+async def _help(ult):
+ plug = ult.pattern_match.group(1).strip()
+ chat = await ult.get_chat()
+ if plug:
+ try:
+ if plug in HELP["Official"]:
+ output = f"**Plugin** - `{plug}`\n"
+ for i in HELP["Official"][plug]:
+ output += i
+ output += "\nŠ @TeamUltroid"
+ await ult.eor(output)
+ elif HELP.get("Addons") and plug in HELP["Addons"]:
+ output = f"**Plugin** - `{plug}`\n"
+ for i in HELP["Addons"][plug]:
+ output += i
+ output += "\nŠ @TeamUltroid"
+ await ult.eor(output)
+ elif HELP.get("VCBot") and plug in HELP["VCBot"]:
+ output = f"**Plugin** - `{plug}`\n"
+ for i in HELP["VCBot"][plug]:
+ output += i
+ output += "\nŠ @TeamUltroid"
+ await ult.eor(output)
+ else:
+ try:
+ x = get_string("help_11").format(plug)
+ for d in LIST[plug]:
+ x += HNDLR + d
+ x += "\n"
+ x += "\nŠ @TeamUltroid"
+ await ult.eor(x)
+ except BaseException:
+ file = None
+ compare_strings = []
+ for file_name in LIST:
+ compare_strings.append(file_name)
+ value = LIST[file_name]
+ for j in value:
+ j = cmd_regex_replace(j)
+ compare_strings.append(j)
+ if j.strip() == plug:
+ file = file_name
+ break
+ if not file:
+ # the enter command/plugin name is not found
+ text = f"`{plug}` is not a valid plugin!"
+ best_match = None
+ for _ in compare_strings:
+ if plug in _ and not _.startswith("_"):
+ best_match = _
+ break
+ if best_match:
+ text += f"\nDid you mean `{best_match}`?"
+ return await ult.eor(text)
+ output = f"**Command** `{plug}` **found in plugin** - `{file}`\n"
+ if file in HELP["Official"]:
+ for i in HELP["Official"][file]:
+ output += i
+ elif HELP.get("Addons") and file in HELP["Addons"]:
+ for i in HELP["Addons"][file]:
+ output += i
+ elif HELP.get("VCBot") and file in HELP["VCBot"]:
+ for i in HELP["VCBot"][file]:
+ output += i
+ output += "\nŠ @TeamUltroid"
+ await ult.eor(output)
+ except BaseException as er:
+ LOGS.exception(er)
+ await ult.eor("Error đ¤ occured.")
+ else:
+ try:
+ results = await ult.client.inline_query(asst.me.username, "ultd")
+ except BotMethodInvalidError:
+ z = []
+ for x in LIST.values():
+ z.extend(x)
+ cmd = len(z) + 10
+ if udB.get_key("MANAGER") and udB.get_key("DUAL_HNDLR") == "/":
+ _main_help_menu[2:3] = [[Button.inline("⢠Manager Help â˘", "mngbtn")]]
+ return await ult.reply(
+ get_string("inline_4").format(
+ OWNER_NAME,
+ len(HELP["Official"]),
+ len(HELP["Addons"] if "Addons" in HELP else []),
+ cmd,
+ ),
+ file=inline_pic(),
+ buttons=_main_help_menu,
+ )
+ except BotResponseTimeoutError:
+ return await ult.eor(
+ get_string("help_2").format(HNDLR),
+ )
+ except BotInlineDisabledError:
+ return await ult.eor(get_string("help_3"))
+ await results[0].click(chat.id, reply_to=ult.reply_to_msg_id, hide_via=True)
+ await ult.delete()
diff --git a/plugins/_inline.py b/plugins/_inline.py
new file mode 100644
index 0000000000000000000000000000000000000000..bcda7ee726539e975a10ad783b401be2f6677a49
--- /dev/null
+++ b/plugins/_inline.py
@@ -0,0 +1,451 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import re
+import time
+from datetime import datetime
+from os import remove
+
+from git import Repo
+from telethon import Button
+from telethon.tl.types import InputWebDocument, Message
+from telethon.utils import resolve_bot_file_id
+
+from pyUltroid._misc._assistant import callback, in_pattern
+from pyUltroid.dB._core import HELP, LIST
+from pyUltroid.fns.helper import gen_chlog, time_formatter, updater
+from pyUltroid.fns.misc import split_list
+
+from . import (
+ HNDLR,
+ LOGS,
+ OWNER_NAME,
+ InlinePlugin,
+ asst,
+ get_string,
+ inline_pic,
+ split_list,
+ start_time,
+ udB,
+)
+from ._help import _main_help_menu
+
+# ================================================#
+
+helps = get_string("inline_1")
+
+add_ons = udB.get_key("ADDONS")
+
+zhelps = get_string("inline_3") if add_ons is False else get_string("inline_2")
+PLUGINS = HELP.get("Official", [])
+ADDONS = HELP.get("Addons", [])
+upage = 0
+# ============================================#
+
+# --------------------BUTTONS--------------------#
+
+SUP_BUTTONS = [
+ [
+ Button.url("⢠Repo â˘", url="https://github.com/TeamUltroid/Ultroid"),
+ Button.url("⢠Support â˘", url="t.me/UltroidSupportChat"),
+ ],
+]
+
+# --------------------BUTTONS--------------------#
+
+
+@in_pattern(owner=True, func=lambda x: not x.text)
+async def inline_alive(o):
+ TLINK = inline_pic() or "https://graph.org/file/74d6259983e0642923fdb.jpg"
+ MSG = "⢠**Ultroid Userbot â˘**"
+ WEB0 = InputWebDocument(
+ "https://graph.org/file/acd4f5d61369f74c5e7a7.jpg", 0, "image/jpg", []
+ )
+ RES = [
+ await o.builder.article(
+ type="photo",
+ text=MSG,
+ include_media=True,
+ buttons=SUP_BUTTONS,
+ title="Ultroid Userbot",
+ description="Userbot | Telethon",
+ url=TLINK,
+ thumb=WEB0,
+ content=InputWebDocument(TLINK, 0, "image/jpg", []),
+ )
+ ]
+ await o.answer(
+ RES,
+ private=True,
+ cache_time=300,
+ switch_pm="đĽ ULTROID PORTAL",
+ switch_pm_param="start",
+ )
+
+
+@in_pattern("ultd", owner=True)
+async def inline_handler(event):
+ z = []
+ for x in LIST.values():
+ z.extend(x)
+ text = get_string("inline_4").format(
+ OWNER_NAME,
+ len(HELP.get("Official", [])),
+ len(HELP.get("Addons", [])),
+ len(z),
+ )
+ if inline_pic():
+ result = await event.builder.photo(
+ file=inline_pic(),
+ link_preview=False,
+ text=text,
+ buttons=_main_help_menu,
+ )
+ else:
+ result = await event.builder.article(
+ title="Ultroid Help Menu", text=text, buttons=_main_help_menu
+ )
+ await event.answer([result], private=True, cache_time=300, gallery=True)
+
+
+@in_pattern("pasta", owner=True)
+async def _(event):
+ ok = event.text.split("-")[1]
+ link = f"https://spaceb.in/{ok}"
+ raw = f"https://spaceb.in/api/{ok}/raw"
+ result = await event.builder.article(
+ title="Paste",
+ text="Pasted to Spacebin đ",
+ buttons=[
+ [
+ Button.url("SpaceBin", url=link),
+ Button.url("Raw", url=raw),
+ ],
+ ],
+ )
+ await event.answer([result])
+
+
+@callback("ownr", owner=True)
+async def setting(event):
+ z = []
+ for x in LIST.values():
+ z.extend(x)
+ await event.edit(
+ get_string("inline_4").format(
+ OWNER_NAME,
+ len(HELP.get("Official", [])),
+ len(HELP.get("Addons", [])),
+ len(z),
+ ),
+ file=inline_pic(),
+ link_preview=False,
+ buttons=[
+ [
+ Button.inline("â˘Pɪɴɢâ˘", data="pkng"),
+ Button.inline("â˘Uá´á´ÉŞá´á´â˘", data="upp"),
+ ],
+ [
+ Button.inline("â˘Statsâ˘", data="alive"),
+ Button.inline("â˘Uá´á´
á´á´á´â˘", data="doupdate"),
+ ],
+ [Button.inline("ÂŤ Bá´á´á´", data="open")],
+ ],
+ )
+
+
+_strings = {"Official": helps, "Addons": zhelps, "VCBot": get_string("inline_6")}
+
+
+@callback(re.compile("uh_(.*)"), owner=True)
+async def help_func(ult):
+ key, count = ult.data_match.group(1).decode("utf-8").split("_")
+ if key == "VCBot" and HELP.get("VCBot") is None:
+ return await ult.answer(get_string("help_12"), alert=True)
+ elif key == "Addons" and HELP.get("Addons") is None:
+ return await ult.answer(get_string("help_13").format(HNDLR), alert=True)
+ if "|" in count:
+ _, count = count.split("|")
+ count = int(count) if count else 0
+ text = _strings.get(key, "").format(OWNER_NAME, len(HELP.get(key)))
+ await ult.edit(text, buttons=page_num(count, key), link_preview=False)
+
+
+@callback(re.compile("uplugin_(.*)"), owner=True)
+async def uptd_plugin(event):
+ key, file = event.data_match.group(1).decode("utf-8").split("_")
+ index = None
+ if "|" in file:
+ file, index = file.split("|")
+ key_ = HELP.get(key, [])
+ hel_p = f"Plugin Name - `{file}`\n"
+ help_ = ""
+ try:
+ for i in key_[file]:
+ help_ += i
+ except BaseException:
+ if file in LIST:
+ help_ = get_string("help_11").format(file)
+ for d in LIST[file]:
+ help_ += HNDLR + d
+ help_ += "\n"
+ if not help_:
+ help_ = f"{file} has no Detailed Help!"
+ help_ += "\nŠ @TeamUltroid"
+ buttons = []
+ if inline_pic():
+ data = f"sndplug_{key}_{file}"
+ if index is not None:
+ data += f"|{index}"
+ buttons.append(
+ [
+ Button.inline(
+ "ÂŤ Sá´É´á´
PĘá´É˘ÉŞÉ´ Âť",
+ data=data,
+ )
+ ]
+ )
+ data = f"uh_{key}_"
+ if index is not None:
+ data += f"|{index}"
+ buttons.append(
+ [
+ Button.inline("ÂŤ Bá´á´á´", data=data),
+ ]
+ )
+ try:
+ await event.edit(help_, buttons=buttons)
+ except Exception as er:
+ LOGS.exception(er)
+ help = f"Do `{HNDLR}help {key}` to get list of commands."
+ await event.edit(help, buttons=buttons)
+
+
+@callback(data="doupdate", owner=True)
+async def _(event):
+ if not await updater():
+ return await event.answer(get_string("inline_9"), cache_time=0, alert=True)
+ if not inline_pic():
+ return await event.answer(f"Do '{HNDLR}update' to update..")
+ repo = Repo.init()
+ changelog, tl_chnglog = await gen_chlog(
+ repo, f"HEAD..upstream/{repo.active_branch}"
+ )
+ changelog_str = changelog + "\n\n" + get_string("inline_8")
+ if len(changelog_str) > 1024:
+ await event.edit(get_string("upd_4"))
+ with open("ultroid_updates.txt", "w+") as file:
+ file.write(tl_chnglog)
+ await event.edit(
+ get_string("upd_5"),
+ file="ultroid_updates.txt",
+ buttons=[
+ [Button.inline("⢠Uá´á´
á´á´á´ Ná´á´Ą â˘", data="updatenow")],
+ [Button.inline("ÂŤ Bá´á´á´", data="ownr")],
+ ],
+ )
+ remove("ultroid_updates.txt")
+ else:
+ await event.edit(
+ changelog_str,
+ buttons=[
+ [Button.inline("Update Now", data="updatenow")],
+ [Button.inline("ÂŤ Bá´á´á´", data="ownr")],
+ ],
+ parse_mode="html",
+ )
+
+
+@callback(data="pkng", owner=True)
+async def _(event):
+ start = datetime.now()
+ end = datetime.now()
+ ms = (end - start).microseconds
+ pin = f"đPɪɴɢ = {ms} microseconds"
+ await event.answer(pin, cache_time=0, alert=True)
+
+
+@callback(data="upp", owner=True)
+async def _(event):
+ uptime = time_formatter((time.time() - start_time) * 1000)
+ pin = f"đUá´á´ÉŞá´á´ = {uptime}"
+ await event.answer(pin, cache_time=0, alert=True)
+
+
+@callback(data="inlone", owner=True)
+async def _(e):
+ _InButtons = [
+ Button.switch_inline(_, query=InlinePlugin[_], same_peer=True)
+ for _ in list(InlinePlugin.keys())
+ ]
+ InButtons = split_list(_InButtons, 2)
+
+ button = InButtons.copy()
+ button.append(
+ [
+ Button.inline("ÂŤ Bá´á´á´", data="open"),
+ ],
+ )
+ await e.edit(buttons=button, link_preview=False)
+
+
+@callback(data="open", owner=True)
+async def opner(event):
+ z = []
+ for x in LIST.values():
+ z.extend(x)
+ await event.edit(
+ get_string("inline_4").format(
+ OWNER_NAME,
+ len(HELP.get("Official", [])),
+ len(HELP.get("Addons", [])),
+ len(z),
+ ),
+ buttons=_main_help_menu,
+ link_preview=False,
+ )
+
+
+@callback(data="close", owner=True)
+async def on_plug_in_callback_query_handler(event):
+ await event.edit(
+ get_string("inline_5"),
+ buttons=Button.inline("Oá´á´É´ Aɢá´ÉŞÉ´", data="open"),
+ )
+
+
+def page_num(index, key):
+ rows = udB.get_key("HELP_ROWS") or 5
+ cols = udB.get_key("HELP_COLUMNS") or 2
+ loaded = HELP.get(key, [])
+ emoji = udB.get_key("EMOJI_IN_HELP") or "â"
+ List = [
+ Button.inline(f"{emoji} {x} {emoji}", data=f"uplugin_{key}_{x}|{index}")
+ for x in sorted(loaded)
+ ]
+ all_ = split_list(List, cols)
+ fl_ = split_list(all_, rows)
+ try:
+ new_ = fl_[index]
+ except IndexError:
+ new_ = fl_[0] if fl_ else []
+ index = 0
+ if index == 0 and len(fl_) == 1:
+ new_.append([Button.inline("ÂŤ Bá´á´á´ Âť", data="open")])
+ else:
+ new_.append(
+ [
+ Button.inline(
+ "ÂŤ PĘá´á´ ÉŞá´á´s",
+ data=f"uh_{key}_{index-1}",
+ ),
+ Button.inline("ÂŤ Bá´á´á´ Âť", data="open"),
+ Button.inline(
+ "Ná´xá´ Âť",
+ data=f"uh_{key}_{index+1}",
+ ),
+ ]
+ )
+ return new_
+
+
+# --------------------------------------------------------------------------------- #
+
+
+STUFF = {}
+
+
+@in_pattern("stf(.*)", owner=True)
+async def ibuild(e):
+ n = e.pattern_match.group(1).strip()
+ builder = e.builder
+ if not (n and n.isdigit()):
+ return
+ ok = STUFF.get(int(n))
+ txt = ok.get("msg")
+ pic = ok.get("media")
+ btn = ok.get("button")
+ if not (pic or txt):
+ txt = "Hey!"
+ if pic:
+ try:
+ include_media = True
+ mime_type, _pic = None, None
+ cont, results = None, None
+ try:
+ ext = str(pic).split(".")[-1].lower()
+ except BaseException:
+ ext = None
+ if ext in ["img", "jpg", "png"]:
+ _type = "photo"
+ mime_type = "image/jpg"
+ elif ext in ["mp4", "mkv", "gif"]:
+ mime_type = "video/mp4"
+ _type = "gif"
+ else:
+ try:
+ if "telethon.tl.types" in str(type(pic)):
+ _pic = pic
+ else:
+ _pic = resolve_bot_file_id(pic)
+ except BaseException:
+ pass
+ if _pic:
+ results = [
+ await builder.document(
+ _pic,
+ title="Ultroid Op",
+ text=txt,
+ description="@TeamUltroid",
+ buttons=btn,
+ link_preview=False,
+ )
+ ]
+ else:
+ _type = "article"
+ include_media = False
+ if not results:
+ if include_media:
+ cont = InputWebDocument(pic, 0, mime_type, [])
+ results = [
+ await builder.article(
+ title="Ultroid Op",
+ type=_type,
+ text=txt,
+ description="@TeamUltroid",
+ include_media=include_media,
+ buttons=btn,
+ thumb=cont,
+ content=cont,
+ link_preview=False,
+ )
+ ]
+ return await e.answer(results)
+ except Exception as er:
+ LOGS.exception(er)
+ result = [
+ await builder.article("Ultroid Op", text=txt, link_preview=False, buttons=btn)
+ ]
+ await e.answer(result)
+
+
+async def something(e, msg, media, button, reply=True, chat=None):
+ if e.client._bot:
+ return await e.reply(msg, file=media, buttons=button)
+ num = len(STUFF) + 1
+ STUFF.update({num: {"msg": msg, "media": media, "button": button}})
+ try:
+ res = await e.client.inline_query(asst.me.username, f"stf{num}")
+ return await res[0].click(
+ chat or e.chat_id,
+ reply_to=bool(isinstance(e, Message) and reply),
+ hide_via=True,
+ silent=True,
+ )
+
+ except Exception as er:
+ LOGS.exception(er)
diff --git a/plugins/_ultroid.py b/plugins/_ultroid.py
new file mode 100644
index 0000000000000000000000000000000000000000..b2a3e2a6fb4bbf30e35f0fe5979307c2b3c145e2
--- /dev/null
+++ b/plugins/_ultroid.py
@@ -0,0 +1,66 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from telethon.errors import (
+ BotMethodInvalidError,
+ ChatSendInlineForbiddenError,
+ ChatSendMediaForbiddenError,
+)
+
+from . import LOG_CHANNEL, LOGS, Button, asst, eor, get_string, ultroid_cmd
+
+REPOMSG = """
+⢠**ULTROID USERBOT** â˘\n
+⢠Repo - [Click Here](https://github.com/TeamUltroid/Ultroid)
+⢠Addons - [Click Here](https://github.com/TeamUltroid/UltroidAddons)
+⢠Support - @UltroidSupportChat
+"""
+
+RP_BUTTONS = [
+ [
+ Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
+ Button.url("Addons", "https://github.com/TeamUltroid/UltroidAddons"),
+ ],
+ [Button.url("Support Group", "t.me/UltroidSupportChat")],
+]
+
+ULTSTRING = """đ **Thanks for Deploying Ultroid Userbot!**
+
+⢠Here, are the Some Basic stuff from, where you can Know, about its Usage."""
+
+
+@ultroid_cmd(
+ pattern="repo$",
+ manager=True,
+)
+async def repify(e):
+ try:
+ q = await e.client.inline_query(asst.me.username, "")
+ await q[0].click(e.chat_id)
+ return await e.delete()
+ except (
+ ChatSendInlineForbiddenError,
+ ChatSendMediaForbiddenError,
+ BotMethodInvalidError,
+ ):
+ pass
+ except Exception as er:
+ LOGS.info(f"Error while repo command : {str(er)}")
+ await e.eor(REPOMSG)
+
+
+@ultroid_cmd(pattern="ultroid$")
+async def useUltroid(rs):
+ button = Button.inline("Start >>", "initft_2")
+ msg = await asst.send_message(
+ LOG_CHANNEL,
+ ULTSTRING,
+ file="https://graph.org/file/54a917cc9dbb94733ea5f.jpg",
+ buttons=button,
+ )
+ if not (rs.chat_id == LOG_CHANNEL and rs.client._bot):
+ await eor(rs, f"**[Click Here]({msg.message_link})**")
diff --git a/plugins/_userlogs.py b/plugins/_userlogs.py
new file mode 100644
index 0000000000000000000000000000000000000000..0696ce5b2edfe0b7dad6b98b6ea7e9f8ae499abb
--- /dev/null
+++ b/plugins/_userlogs.py
@@ -0,0 +1,297 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import os
+import re
+
+from telethon.errors.rpcerrorlist import (
+ ChannelPrivateError,
+ ChatWriteForbiddenError,
+ MediaCaptionTooLongError,
+ MediaEmptyError,
+ MessageTooLongError,
+ PeerIdInvalidError,
+ UserNotParticipantError,
+)
+from telethon.tl.types import MessageEntityMention, MessageEntityMentionName, User
+from telethon.utils import get_display_name
+
+from pyUltroid.dB.botchat_db import tag_add, who_tag
+
+from . import (
+ LOG_CHANNEL,
+ LOGS,
+ Button,
+ asst,
+ callback,
+ events,
+ get_string,
+ inline_mention,
+ udB,
+ ultroid_bot,
+)
+
+CACHE_SPAM = {}
+TAG_EDITS = {}
+
+
+@ultroid_bot.on(
+ events.NewMessage(
+ incoming=True,
+ func=lambda e: (e.mentioned),
+ ),
+)
+async def all_messages_catcher(e):
+ x = await e.get_sender()
+ if isinstance(x, User) and (x.bot or x.verified):
+ return
+ if not udB.get_key("TAG_LOG"):
+ return
+ NEEDTOLOG = udB.get_key("TAG_LOG")
+ buttons = await parse_buttons(e)
+ try:
+ sent = await asst.send_message(NEEDTOLOG, e.message, buttons=buttons)
+ if TAG_EDITS.get(e.chat_id):
+ TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
+ else:
+ TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
+ tag_add(sent.id, e.chat_id, e.id)
+ except MediaEmptyError as er:
+ LOGS.debug(f"handling {er}.")
+ try:
+ msg = await asst.get_messages(e.chat_id, ids=e.id)
+ sent = await asst.send_message(NEEDTOLOG, msg, buttons=buttons)
+ if TAG_EDITS.get(e.chat_id):
+ TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
+ else:
+ TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
+ tag_add(sent.id, e.chat_id, e.id)
+ except Exception as me:
+ if not isinstance(me, (PeerIdInvalidError, ValueError)):
+ LOGS.exception(me)
+ if e.photo or e.sticker or e.gif:
+ try:
+ media = await e.download_media()
+ sent = await asst.send_message(
+ NEEDTOLOG, e.message.text, file=media, buttons=buttons
+ )
+ if TAG_EDITS.get(e.chat_id):
+ TAG_EDITS[e.chat_id].update({e.id: {"id": sent.id, "msg": e}})
+ else:
+ TAG_EDITS.update({e.chat_id: {e.id: {"id": sent.id, "msg": e}}})
+ return os.remove(media)
+ except Exception as er:
+ LOGS.exception(er)
+ await asst.send_message(NEEDTOLOG, get_string("com_4"), buttons=buttons)
+ except (PeerIdInvalidError, ValueError) as er:
+ LOGS.exception(er)
+ try:
+ CACHE_SPAM[NEEDTOLOG]
+ except KeyError:
+ await asst.send_message(
+ udB.get_key("LOG_CHANNEL"), get_string("userlogs_1")
+ )
+ CACHE_SPAM.update({NEEDTOLOG: True})
+ except ChatWriteForbiddenError:
+ try:
+ await asst.get_permissions(NEEDTOLOG, "me")
+ MSG = get_string("userlogs_4")
+ except UserNotParticipantError:
+ MSG = get_string("userlogs_2")
+ try:
+ CACHE_SPAM[NEEDTOLOG]
+ except KeyError:
+ await asst.send_message(LOG_CHANNEL, MSG)
+ CACHE_SPAM.update({NEEDTOLOG: True})
+ except Exception as er:
+ LOGS.exception(er)
+
+
+if udB.get_key("TAG_LOG"):
+
+ @ultroid_bot.on(events.MessageEdited(func=lambda x: not x.out))
+ async def upd_edits(event):
+ x = event.sender
+ if isinstance(x, User) and (x.bot or x.verified):
+ return
+ if event.chat_id not in TAG_EDITS:
+ if event.sender_id == udB.get_key("TAG_LOG"):
+ return
+ if event.is_private:
+ return
+ if entities := event.get_entities_text():
+ is_self = False
+ username = event.client.me.username
+ if username:
+ username = username.lower()
+ for ent, text in entities:
+ if isinstance(ent, MessageEntityMention):
+ is_self = text[1:].lower() == username
+ elif isinstance(ent, MessageEntityMentionName):
+ is_self = ent.user_id == event.client.me.id
+ if is_self:
+ text = f"**#Edited & #Mentioned**\n\n{event.text}"
+ try:
+ sent = await asst.send_message(
+ udB.get_key("TAG_LOG"),
+ text,
+ buttons=await parse_buttons(event),
+ )
+ except Exception as er:
+ return LOGS.exception(er)
+ if TAG_EDITS.get(event.chat_id):
+ TAG_EDITS[event.chat_id].update({event.id: {"id": sent.id}})
+ else:
+ TAG_EDITS.update({event.chat_id: {event.id: {"id": sent.id}}})
+ return
+ d_ = TAG_EDITS[event.chat_id]
+ if not d_.get(event.id):
+ return
+ d_ = d_[event.id]
+ if d_["msg"].text == event.text:
+ return
+ msg = None
+ if d_.get("count"):
+ d_["count"] += 1
+ else:
+ msg = True
+ d_.update({"count": 1})
+ if d_["count"] > 10:
+ return # some limit to take edits
+ try:
+ MSG = await asst.get_messages(udB.get_key("TAG_LOG"), ids=d_["id"])
+ except Exception as er:
+ return LOGS.exception(er)
+ TEXT = MSG.text
+ if msg:
+ TEXT += "\n\nđ **Later Edited to !**"
+ strf = event.edit_date.strftime("%H:%M:%S")
+ if "\n" not in event.text:
+ TEXT += f"\n⢠`{strf}` : {event.text}"
+ else:
+ TEXT += f"\n⢠`{strf}` :\n-> {event.text}"
+ if d_["count"] == 10:
+ TEXT += "\n\n⢠__Only the first 10 Edits are shown.__"
+ try:
+ msg = await MSG.edit(TEXT, buttons=await parse_buttons(event))
+ d_["msg"] = msg
+ except (MessageTooLongError, MediaCaptionTooLongError):
+ del TAG_EDITS[event.chat_id][event.id]
+ except Exception as er:
+ LOGS.exception(er)
+
+ @ultroid_bot.on(
+ events.NewMessage(
+ outgoing=True,
+ chats=[udB.get_key("TAG_LOG")],
+ func=lambda e: e.reply_to,
+ )
+ )
+ async def idk(e):
+ id = e.reply_to_msg_id
+ chat, msg = who_tag(id)
+ if chat and msg:
+ try:
+ await ultroid_bot.send_message(chat, e.message, reply_to=msg)
+ except BaseException as er:
+ LOGS.exception(er)
+
+
+# log for assistant/user joins/add
+
+
+async def when_added_or_joined(event):
+ user = await event.get_user()
+ chat = await event.get_chat()
+ if not (user and user.is_self):
+ return
+ if getattr(chat, "username", None):
+ chat = f"[{chat.title}](https://t.me/{chat.username}/{event.action_message.id})"
+ else:
+ chat = f"[{chat.title}](https://t.me/c/{chat.id}/{event.action_message.id})"
+ key = "bot" if event.client._bot else "user"
+ buttons = Button.inline(
+ get_string("userlogs_3"), data=f"leave_ch_{event.chat_id}|{key}"
+ )
+ if event.user_added:
+ tmp = event.added_by
+ text = f"#ADD_LOG\n\n{inline_mention(tmp)} just added {inline_mention(user)} to {chat}."
+ elif event.from_request:
+ text = f"#APPROVAL_LOG\n\n{inline_mention(user)} just got Chat Join Approval to {chat}."
+ else:
+ text = f"#JOIN_LOG\n\n{inline_mention(user)} just joined {chat}."
+ await asst.send_message(udB.get_key("LOG_CHANNEL"), text, buttons=buttons)
+
+
+asst.add_event_handler(
+ when_added_or_joined, events.ChatAction(func=lambda x: x.user_added)
+)
+ultroid_bot.add_event_handler(
+ when_added_or_joined,
+ events.ChatAction(func=lambda x: x.user_added or x.user_joined),
+)
+_client = {"bot": asst, "user": ultroid_bot}
+
+
+@callback(
+ re.compile(
+ "leave_ch_(.*)",
+ ),
+ from_users=[ultroid_bot.uid],
+)
+async def leave_ch_at(event):
+ cht = event.data_match.group(1).decode("UTF-8")
+ ch_id, client = cht.split("|")
+ try:
+ client = _client[client]
+ except KeyError:
+ return
+ try:
+ name = (await client.get_entity(int(ch_id))).title
+ await client.delete_dialog(int(ch_id))
+ except UserNotParticipantError:
+ pass
+ except ChannelPrivateError:
+ return await event.edit(
+ "`[CANT_ACCESS_CHAT]` `Maybe already left or got banned.`"
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ return await event.answer(str(er))
+ await event.edit(get_string("userlogs_5").format(name))
+
+
+@callback("do_nothing")
+async def _(event):
+ await event.answer()
+
+
+async def parse_buttons(event):
+ y, x = event.chat, event.sender
+ where_n, who_n = get_display_name(y), get_display_name(x)
+ where_l = event.message_link
+ buttons = [[Button.url(where_n, where_l)]]
+ if isinstance(x, User) and x.username:
+ try:
+ buttons.append(
+ [Button.mention(who_n, await asst.get_input_entity(x.username))]
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ buttons.append([Button.url(who_n, f"t.me/{x.username}")])
+ elif getattr(x, "username"):
+ buttons.append([Button.url(who_n, f"t.me/{x.username}")])
+ else:
+ buttons.append([Button.url(who_n, where_l)])
+ replied = await event.get_reply_message()
+ if replied and replied.out:
+ button = Button.url("Replied to", replied.message_link)
+ if len(who_n) > 7:
+ buttons.append([button])
+ else:
+ buttons[-1].append(button)
+ return buttons
diff --git a/plugins/_wspr.py b/plugins/_wspr.py
new file mode 100644
index 0000000000000000000000000000000000000000..f46def7dadebbc0e02e845fe53070f99224aac0a
--- /dev/null
+++ b/plugins/_wspr.py
@@ -0,0 +1,204 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+import re
+
+from telethon import Button
+from telethon.errors.rpcerrorlist import (
+ BotInlineDisabledError,
+ BotResponseTimeoutError,
+ MessageNotModifiedError,
+)
+from telethon.tl import types
+from telethon.tl.functions.users import GetFullUserRequest as gu
+
+from . import (
+ HNDLR,
+ LOGS,
+ asst,
+ callback,
+ get_string,
+ in_pattern,
+ inline_mention,
+ ultroid_bot,
+ ultroid_cmd,
+)
+
+buddhhu = {}
+
+
+@ultroid_cmd(
+ pattern="wspr( (.*)|$)",
+)
+async def _(e):
+ if e.reply_to_msg_id:
+ okk = await e.get_reply_message()
+ put = f"@{okk.sender.username}" if okk.sender.username else okk.sender_id
+ else:
+ put = e.pattern_match.group(1).strip()
+ if put:
+ try:
+ results = await e.client.inline_query(asst.me.username, f"msg {put}")
+ except BotResponseTimeoutError:
+ return await e.eor(
+ get_string("help_2").format(HNDLR),
+ )
+ except BotInlineDisabledError:
+ return await e.eor(get_string("help_3"))
+ await results[0].click(e.chat_id, reply_to=e.reply_to_msg_id, hide_via=True)
+ return await e.delete()
+ await e.eor(get_string("wspr_3"))
+
+
+@in_pattern("wspr", owner=True)
+async def _(e):
+ iuser = e.query.user_id
+ zzz = e.text.split(maxsplit=2)
+ try:
+ query = zzz[1]
+ if query.isdigit():
+ query = int(query)
+ logi = await ultroid_bot.get_entity(query)
+ if not isinstance(logi, types.User):
+ raise ValueError("Invalid Username.")
+ except IndexError:
+ sur = await e.builder.article(
+ title="Give Username",
+ description="You Didn't Type Username or id.",
+ text="You Didn't Type Username or id.",
+ )
+ return await e.answer([sur])
+ except ValueError as er:
+ LOGS.exception(er)
+ sur = await e.builder.article(
+ title="User Not Found",
+ description="Make sure username or id is correct.",
+ text="Make sure username or id is correct.",
+ )
+ return await e.answer([sur])
+ try:
+ desc = zzz[2]
+ except IndexError:
+ sur = await e.builder.article(
+ title="Type ur msg", text="You Didn't Type Your Msg"
+ )
+ return await e.answer([sur])
+ button = [
+ [
+ Button.inline("Secret Msg", data=f"dd_{e.id}"),
+ Button.inline("Delete Msg", data=f"del_{e.id}"),
+ ],
+ [
+ Button.switch_inline(
+ "New", query=f"wspr {logi.username or logi.id}", same_peer=True
+ )
+ ],
+ ]
+ us = logi.username or logi.first_name
+ sur = await e.builder.article(
+ title=logi.first_name,
+ description=desc,
+ text=get_string("wspr_1").format(us),
+ buttons=button,
+ )
+ buddhhu.update({e.id: [logi.id, iuser, desc]})
+ await e.answer([sur])
+
+
+@in_pattern("msg", owner=True)
+async def _(e):
+ zzz = e.text.split(maxsplit=1)
+ desc = "Touch me"
+ try:
+ query = zzz[1]
+ if query.isdigit():
+ query = int(query)
+ logi = await ultroid_bot(gu(id=query))
+ user = logi.users[0]
+ mention = inline_mention(user)
+ x = user.status
+ if isinstance(x, types.UserStatusOnline):
+ status = "Online"
+ elif isinstance(x, types.UserStatusOffline):
+ status = "Offline"
+ elif isinstance(x, types.UserStatusRecently):
+ status = "Last Seen Recently"
+ elif isinstance(x, types.UserStatusLastMonth):
+ status = "Last seen months ago"
+ elif isinstance(x, types.UserStatusLastWeek):
+ status = "Last seen weeks ago"
+ else:
+ status = "Can't Tell"
+ text = f"**Name:** `{user.first_name}`\n"
+ text += f"**Id:** `{user.id}`\n"
+ if user.username:
+ text += f"**Username:** `{user.username}`\n"
+ url = f"https://t.me/{user.username}"
+ else:
+ text += f"**Mention:** `{mention}`\n"
+ url = f"tg://user?id={user.id}"
+ text += f"**Status:** `{status}`\n"
+ text += f"**About:** `{logi.full_user.about}`"
+ button = [
+ Button.url("Private", url=url),
+ Button.switch_inline(
+ "Secret msg",
+ query=f"wspr {query} Hello đ",
+ same_peer=True,
+ ),
+ ]
+ sur = e.builder.article(
+ title=user.first_name,
+ description=desc,
+ text=text,
+ buttons=button,
+ )
+ except IndexError:
+ sur = e.builder.article(
+ title="Give Username",
+ description="You Didn't Type Username or id.",
+ text="You Didn't Type Username or id.",
+ )
+ except BaseException as er:
+ LOGS.exception(er)
+ name = get_string("wspr_4").format(query)
+ sur = e.builder.article(
+ title=name,
+ text=name,
+ )
+
+ await e.answer([sur])
+
+
+@callback(
+ re.compile(
+ "dd_(.*)",
+ ),
+)
+async def _(e):
+ ids = int(e.pattern_match.group(1).strip().decode("UTF-8"))
+ if buddhhu.get(ids):
+ if e.sender_id in buddhhu[ids]:
+ await e.answer(buddhhu[ids][-1], alert=True)
+ else:
+ await e.answer("Not For You", alert=True)
+ else:
+ await e.answer(get_string("wspr_2"), alert=True)
+
+
+@callback(re.compile("del_(.*)"))
+async def _(e):
+ ids = int(e.pattern_match.group(1).strip().decode("UTF-8"))
+ if buddhhu.get(ids):
+ if e.sender_id in buddhhu[ids]:
+ buddhhu.pop(ids)
+ try:
+ await e.edit(get_string("wspr_2"))
+ except MessageNotModifiedError:
+ pass
+ else:
+ await e.answer(get_string("wspr_5"), alert=True)
diff --git a/plugins/admintools.py b/plugins/admintools.py
new file mode 100644
index 0000000000000000000000000000000000000000..0d402ff2d6a220a1d884460ae595012a97d4e47a
--- /dev/null
+++ b/plugins/admintools.py
@@ -0,0 +1,472 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_admintools")
+
+import asyncio
+
+from telethon.errors import BadRequestError
+from telethon.errors.rpcerrorlist import ChatNotModifiedError, UserIdInvalidError
+from telethon.tl.functions.channels import EditAdminRequest, GetFullChannelRequest
+from telethon.tl.functions.messages import GetFullChatRequest, SetHistoryTTLRequest
+from telethon.tl.types import InputMessagesFilterPinned
+from telethon.utils import get_display_name
+
+from pyUltroid.dB import DEVLIST
+from pyUltroid.fns.admins import ban_time
+from pyUltroid.fns.info import get_uinfo
+
+from . import HNDLR, LOGS, eod, eor, get_string, inline_mention, types, ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="promote( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="add_admins",
+ fullsudo=True,
+)
+async def prmte(ult):
+ xx = await ult.eor(get_string("com_1"))
+ user, rank = await get_uinfo(ult)
+ rank = rank or "Admin"
+ FullRight = False
+ if not user:
+ return await xx.edit(get_string("pro_1"))
+ if rank.split()[0] == "-f":
+ try:
+ rank = rank.split(maxsplit=1)[1]
+ except IndexError:
+ rank = "Admin"
+ FullRight = True
+ try:
+ if FullRight:
+ await ult.client(
+ EditAdminRequest(ult.chat_id, user.id, ult.chat.admin_rights, rank)
+ )
+ else:
+ await ult.client.edit_admin(
+ ult.chat_id,
+ user.id,
+ invite_users=True,
+ ban_users=True,
+ delete_messages=True,
+ pin_messages=True,
+ manage_call=True,
+ title=rank,
+ )
+ await eod(
+ xx, get_string("pro_2").format(inline_mention(user), ult.chat.title, rank)
+ )
+ except Exception as ex:
+ return await xx.edit(f"`{ex}`")
+
+
+@ultroid_cmd(
+ pattern="demote( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="add_admins",
+ fullsudo=True,
+)
+async def dmote(ult):
+ xx = await ult.eor(get_string("com_1"))
+ user, rank = await get_uinfo(ult)
+ if not rank:
+ rank = "Not Admin"
+ if not user:
+ return await xx.edit(get_string("de_1"))
+ try:
+ await ult.client.edit_admin(
+ ult.chat_id,
+ user.id,
+ invite_users=None,
+ ban_users=None,
+ delete_messages=None,
+ pin_messages=None,
+ manage_call=None,
+ title=rank,
+ )
+ await eod(xx, get_string("de_2").format(inline_mention(user), ult.chat.title))
+ except Exception as ex:
+ return await xx.edit(f"`{ex}`")
+
+
+@ultroid_cmd(
+ pattern="ban( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="ban_users",
+ fullsudo=True,
+)
+async def bban(ult):
+ something = await get_uinfo(ult)
+ if not something:
+ return
+ user, reason = something
+ if not user:
+ return await eod(ult, get_string("ban_1"))
+ if user.id in DEVLIST:
+ return await eod(ult, get_string("ban_2"))
+ try:
+ await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=False)
+ except UserIdInvalidError:
+ return await eod(ult, get_string("adm_1"))
+ except BadRequestError:
+ return await eod(ult, get_string("ban_3"))
+ senderme = inline_mention(await ult.get_sender())
+ userme = inline_mention(user)
+ text = get_string("ban_4").format(userme, senderme, ult.chat.title)
+ if reason:
+ text += get_string("ban_5").format(reason)
+ await eod(ult, text)
+
+
+@ultroid_cmd(
+ pattern="unban( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="ban_users",
+ fullsudo=True,
+)
+async def uunban(ult):
+ xx = await ult.eor(get_string("com_1"))
+ if ult.text[1:].startswith("unbanall"):
+ return
+ something = await get_uinfo(ult)
+ if not something:
+ return
+ user, reason = something
+ if not user:
+ return await xx.edit(get_string("unban_1"))
+ try:
+ await ult.client.edit_permissions(ult.chat_id, user.id, view_messages=True)
+ except UserIdInvalidError:
+ return await eod(ult, get_string("adm_1"))
+ except BadRequestError:
+ return await xx.edit(get_string("adm_2"))
+ sender = inline_mention(await ult.get_sender())
+ text = get_string("unban_3").format(inline_mention(user), sender, ult.chat.title)
+ if reason:
+ text += get_string("ban_5").format(reason)
+ await xx.edit(text)
+
+
+@ultroid_cmd(
+ pattern="kick( (.*)|$)",
+ manager=True,
+ require="ban_users",
+ fullsudo=True,
+)
+async def kck(ult):
+ if "kickme" in ult.text:
+ return
+ if ult.is_private:
+ return await ult.eor("`Use this in Group/Channel.`", time=5)
+ ml = ult.text.split(" ", maxsplit=1)[0]
+ xx = await ult.eor(get_string("com_1"))
+ something = await get_uinfo(ult)
+ if not something:
+ return
+ user, reason = something
+ if not user:
+ return await xx.edit(get_string("adm_1"))
+ if user.id in DEVLIST:
+ return await xx.edit(get_string("kick_2"))
+ if getattr(user, "is_self", False):
+ return await xx.edit(get_string("kick_3"))
+ try:
+ await ult.client.kick_participant(ult.chat_id, user.id)
+ except BadRequestError as er:
+ LOGS.info(er)
+ return await xx.edit(get_string("kick_1"))
+ except Exception as e:
+ LOGS.exception(e)
+ return
+ text = get_string("kick_4").format(
+ inline_mention(user), inline_mention(await ult.get_sender()), ult.chat.title
+ )
+ if reason:
+ text += get_string("ban_5").format(reason)
+ await xx.edit(text)
+
+
+@ultroid_cmd(
+ pattern="tban( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="ban_users",
+ fullsudo=True,
+)
+async def tkicki(e):
+ huh = e.text.split()
+ inputt = None
+ try:
+ tme = huh[1]
+ except IndexError:
+ return await e.eor(get_string("adm_3"), time=15)
+ try:
+ inputt = huh[2]
+ except IndexError:
+ if e.reply_to_msg_id:
+ inputt = (await e.get_reply_message()).sender_id
+ if not inputt:
+ return await e.eor(get_string("tban_1"))
+ userid = await e.client.parse_id(inputt)
+ try:
+ user = await e.client.get_entity(userid)
+ except Exception as ex:
+ return await eor(e, f"`{ex}`")
+ try:
+ bun = ban_time(tme)
+ await e.client.edit_permissions(
+ e.chat_id, user.id, until_date=bun, view_messages=False
+ )
+ await eod(
+ e,
+ get_string("tban_2").format(inline_mention(user), e.chat.title, tme),
+ time=15,
+ )
+ except Exception as m:
+ return await e.eor(str(m))
+
+
+@ultroid_cmd(pattern="pin$", manager=True, require="pin_messages", fullsudo=True)
+async def pin(msg):
+ if not msg.is_reply:
+ return await eor(msg, get_string("pin_1"))
+ me = await msg.get_reply_message()
+ if me.is_private:
+ text = "`Pinned.`"
+ else:
+ text = f"Pinned [This Message]({me.message_link}) !"
+ try:
+ await msg.client.pin_message(msg.chat_id, me.id, notify=False)
+ except BadRequestError:
+ return await eor(msg, get_string("adm_2"))
+ except Exception as e:
+ return await eor(msg, f"**ERROR:**`{e}`")
+ await eor(msg, text)
+
+
+@ultroid_cmd(
+ pattern="unpin($| (.*))",
+ manager=True,
+ require="pin_messages",
+ fullsudo=True,
+)
+async def unp(ult):
+ xx = await ult.eor(get_string("com_1"))
+ ch = (ult.pattern_match.group(1).strip()).strip()
+ msg = None
+ if ult.is_reply:
+ msg = ult.reply_to_msg_id
+ elif ch != "all":
+ return await xx.edit(get_string("unpin_1").format(HNDLR))
+ try:
+ await ult.client.unpin_message(ult.chat_id, msg)
+ except BadRequestError:
+ return await xx.edit(get_string("adm_2"))
+ except Exception as e:
+ return await xx.edit(f"**ERROR:**`{e}`")
+ await xx.edit("`Unpinned!`")
+
+
+@ultroid_cmd(
+ pattern="tpin( (.*)|$)",
+ admins_only=True,
+ manager=True,
+ require="pin_messages",
+ fullsudo=True,
+)
+async def pin_message(ult):
+ match = ult.pattern_match.group(1).strip()
+ if not ult.is_reply:
+ return await ult.eor("`Reply to message..`", time=6)
+ if not match:
+ return await ult.eor("`Please provide time..`", time=8)
+ msg = await ult.eor(get_string("com_1"))
+ msg_id = ult.reply_to_msg_id
+ try:
+ time = ban_time(match)
+ await ult.client.pin_message(ult.chat_id, msg_id)
+ await msg.eor(f"`pinned for time` `{time}`", time=8)
+ except Exception as er:
+ return await msg.edit(str(er))
+ await asyncio.sleep(time)
+ try:
+ await ult.client.unpin_message(ult.chat_id, msg_id)
+ except Exception as er:
+ LOGS.exception(er)
+
+
+@ultroid_cmd(pattern="purge( (.*)|$)", manager=True, require="delete_messages")
+async def fastpurger(purg):
+ match = purg.pattern_match.group(1).strip()
+ try:
+ ABC = purg.text[6]
+ except IndexError:
+ ABC = None
+ if ABC and purg.text[6] in ["m", "a"]:
+ return
+ if not purg._client._bot and (
+ (match)
+ or (purg.is_reply and (purg.is_private or isinstance(purg.chat, types.Chat)))
+ ):
+ p = 0
+ async for msg in purg.client.iter_messages(
+ purg.chat_id,
+ limit=int(match) if match else None,
+ min_id=purg.reply_to_msg_id if purg.is_reply else None,
+ ):
+ await msg.delete()
+ p += 0
+ return await eor(purg, f"Purged {p} Messages! ", time=5)
+ if not purg.reply_to_msg_id:
+ return await eor(purg, get_string("purge_1"), time=10)
+ try:
+ await purg.client.delete_messages(
+ purg.chat_id, list(range(purg.reply_to_msg_id, purg.id))
+ )
+
+ except Exception as er:
+ LOGS.info(er)
+ await purg.eor("__Fast purge complete!__", time=5)
+
+
+@ultroid_cmd(
+ pattern="purgeme( (.*)|$)",
+)
+async def fastpurgerme(purg):
+ if num := purg.pattern_match.group(1).strip():
+ try:
+ nnt = int(num)
+ except BaseException:
+ await eor(purg, get_string("com_3"), time=5)
+ return
+ mp = 0
+ async for mm in purg.client.iter_messages(
+ purg.chat_id, limit=nnt, from_user="me"
+ ):
+ await mm.delete()
+ mp += 1
+ await eor(purg, f"Purged {mp} Messages!", time=5)
+ return
+ elif not purg.reply_to_msg_id:
+ return await eod(
+ purg,
+ "`Reply to a message to purge from or use it like ``purgeme `",
+ time=10,
+ )
+ chat = await purg.get_input_chat()
+ msgs = []
+ async for msg in purg.client.iter_messages(
+ chat,
+ from_user="me",
+ min_id=purg.reply_to_msg_id,
+ ):
+ msgs.append(msg)
+ if msgs:
+ await purg.client.delete_messages(chat, msgs)
+ await purg.eor(
+ "__Fast purge complete!__\n**Purged** `" + str(len(msgs)) + "` **messages.**",
+ time=5,
+ )
+
+
+@ultroid_cmd(
+ pattern="purgeall$",
+)
+async def _(e):
+ if not e.is_reply:
+ return await eod(
+ e,
+ get_string("purgeall_1"),
+ )
+
+ msg = await e.get_reply_message()
+ name = msg.sender
+ try:
+ await e.client.delete_messages(e.chat_id, from_user=msg.sender_id)
+ await e.eor(get_string("purgeall_2").format(name.first_name), time=5)
+ except Exception as er:
+ return await e.eor(str(er), time=5)
+
+
+@ultroid_cmd(pattern="pinned", manager=True, groups_only=True)
+async def djshsh(event):
+ chat = await event.get_chat()
+ if isinstance(chat, types.Chat):
+ FChat = await event.client(GetFullChatRequest(chat.id))
+ elif isinstance(chat, types.Channel):
+ FChat = await event.client(GetFullChannelRequest(chat.id))
+ else:
+ return
+ msg_id = FChat.full_chat.pinned_msg_id
+ if not msg_id:
+ return await event.eor(get_string("pinned_1"))
+ msg = await event.client.get_messages(chat.id, ids=msg_id)
+ if msg:
+ await event.eor(get_string("pinned_2").format(msg.message_link))
+
+
+@ultroid_cmd(
+ pattern="listpinned$",
+)
+async def get_all_pinned(event):
+ x = await event.eor(get_string("com_1"))
+ chat_id = (str(event.chat_id)).replace("-100", "")
+ chat_name = get_display_name(event.chat)
+ a = ""
+ c = 1
+ async for i in event.client.iter_messages(
+ event.chat_id, filter=InputMessagesFilterPinned
+ ):
+ if i.message:
+ t = " ".join(i.message.split()[:4])
+ txt = f"{t}...."
+ else:
+ txt = "Go to message."
+ a += f"{c}. {txt}\n"
+ c += 1
+
+ if c == 1:
+ m = f"The pinned message in {chat_name}:\n\n"
+ else:
+ m = f"List of pinned message(s) in {chat_name}:\n\n"
+
+ if not a:
+ return await eor(x, get_string("listpin_1"), time=5)
+
+ await x.edit(m + a, parse_mode="html")
+
+
+@ultroid_cmd(
+ pattern="autodelete( (.*)|$)",
+ admins_only=True,
+)
+async def autodelte(ult):
+ match = ult.pattern_match.group(1).strip()
+ if not match or match not in ["24h", "7d", "1m", "off"]:
+ return await ult.eor("`Please Use in Proper Format..`", time=5)
+ if match == "24h":
+ tt = 3600 * 24
+ elif match == "7d":
+ tt = 3600 * 24 * 7
+ elif match == "1m":
+ tt = 3600 * 24 * 31
+ else:
+ tt = 0
+ try:
+ await ult.client(SetHistoryTTLRequest(ult.chat_id, period=tt))
+ except ChatNotModifiedError:
+ return await ult.eor(
+ f"Auto Delete Setting is Already same to `{match}`", time=5
+ )
+ await ult.eor(f"Auto Delete Status Changed to `{match}` !")
diff --git a/plugins/afk.py b/plugins/afk.py
new file mode 100644
index 0000000000000000000000000000000000000000..830136a449f960298a7a45fe2f4e6c717df31615
--- /dev/null
+++ b/plugins/afk.py
@@ -0,0 +1,166 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_afk")
+
+
+import asyncio
+
+from telegraph import upload_file as uf
+from telethon import events
+
+from pyUltroid.dB.afk_db import add_afk, del_afk, is_afk
+from pyUltroid.dB.base import KeyManager
+
+from . import (
+ LOG_CHANNEL,
+ NOSPAM_CHAT,
+ Redis,
+ asst,
+ get_string,
+ mediainfo,
+ udB,
+ ultroid_bot,
+ ultroid_cmd,
+)
+
+old_afk_msg = []
+
+is_approved = KeyManager("PMPERMIT", cast=list).contains
+
+
+@ultroid_cmd(pattern="afk( (.*)|$)", owner_only=True)
+async def set_afk(event):
+ if event.client._bot or is_afk():
+ return
+ text, media, media_type = None, None, None
+ if event.pattern_match.group(1).strip():
+ text = event.text.split(maxsplit=1)[1]
+ reply = await event.get_reply_message()
+ if reply:
+ if reply.text and not text:
+ text = reply.text
+ if reply.media:
+ media_type = mediainfo(reply.media)
+ if media_type.startswith(("pic", "gif")):
+ file = await event.client.download_media(reply.media)
+ iurl = uf(file)
+ media = f"https://graph.org{iurl[0]}"
+ else:
+ media = reply.file.id
+ await event.eor("`Done`", time=2)
+ add_afk(text, media_type, media)
+ ultroid_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
+ ultroid_bot.add_handler(
+ on_afk,
+ events.NewMessage(
+ incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
+ ),
+ )
+ msg1, msg2 = None, None
+ if text and media:
+ if "sticker" in media_type:
+ msg1 = await ultroid_bot.send_file(event.chat_id, file=media)
+ msg2 = await ultroid_bot.send_message(
+ event.chat_id, get_string("afk_5").format(text)
+ )
+ else:
+ msg1 = await ultroid_bot.send_message(
+ event.chat_id, get_string("afk_5").format(text), file=media
+ )
+ elif media:
+ if "sticker" in media_type:
+ msg1 = await ultroid_bot.send_file(event.chat_id, file=media)
+ msg2 = await ultroid_bot.send_message(event.chat_id, get_string("afk_6"))
+ else:
+ msg1 = await ultroid_bot.send_message(
+ event.chat_id, get_string("afk_6"), file=media
+ )
+ elif text:
+ msg1 = await event.respond(get_string("afk_5").format(text))
+ else:
+ msg1 = await event.respond(get_string("afk_6"))
+ old_afk_msg.append(msg1)
+ if msg2:
+ old_afk_msg.append(msg2)
+ return await asst.send_message(LOG_CHANNEL, msg2.text)
+ await asst.send_message(LOG_CHANNEL, msg1.text)
+
+
+async def remove_afk(event):
+ if event.is_private and udB.get_key("PMSETTING") and not is_approved(event.chat_id):
+ return
+ elif "afk" in event.text.lower():
+ return
+ elif event.chat_id in NOSPAM_CHAT:
+ return
+ if is_afk():
+ _, _, _, afk_time = is_afk()
+ del_afk()
+ off = await event.reply(get_string("afk_1").format(afk_time))
+ await asst.send_message(LOG_CHANNEL, get_string("afk_2").format(afk_time))
+ for x in old_afk_msg:
+ try:
+ await x.delete()
+ except BaseException:
+ pass
+ await asyncio.sleep(10)
+ await off.delete()
+
+
+async def on_afk(event):
+ if event.is_private and Redis("PMSETTING") and not is_approved(event.chat_id):
+ return
+ elif "afk" in event.text.lower():
+ return
+ elif not is_afk():
+ return
+ if event.chat_id in NOSPAM_CHAT:
+ return
+ sender = await event.get_sender()
+ if sender.bot or sender.verified:
+ return
+ text, media_type, media, afk_time = is_afk()
+ msg1, msg2 = None, None
+ if text and media:
+ if "sticker" in media_type:
+ msg1 = await event.reply(file=media)
+ msg2 = await event.reply(get_string("afk_3").format(afk_time, text))
+ else:
+ msg1 = await event.reply(
+ get_string("afk_3").format(afk_time, text), file=media
+ )
+ elif media:
+ if "sticker" in media_type:
+ msg1 = await event.reply(file=media)
+ msg2 = await event.reply(get_string("afk_4").format(afk_time))
+ else:
+ msg1 = await event.reply(get_string("afk_4").format(afk_time), file=media)
+ elif text:
+ msg1 = await event.reply(get_string("afk_3").format(afk_time, text))
+ else:
+ msg1 = await event.reply(get_string("afk_4").format(afk_time))
+ for x in old_afk_msg:
+ try:
+ await x.delete()
+ except BaseException:
+ pass
+ old_afk_msg.append(msg1)
+ if msg2:
+ old_afk_msg.append(msg2)
+
+
+if udB.get_key("AFK_DB"):
+ ultroid_bot.add_handler(remove_afk, events.NewMessage(outgoing=True))
+ ultroid_bot.add_handler(
+ on_afk,
+ events.NewMessage(
+ incoming=True, func=lambda e: bool(e.mentioned or e.is_private)
+ ),
+ )
diff --git a/plugins/antiflood.py b/plugins/antiflood.py
new file mode 100644
index 0000000000000000000000000000000000000000..82225c16956e7096bb3e05457ef1892fa14541ef
--- /dev/null
+++ b/plugins/antiflood.py
@@ -0,0 +1,121 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_antiflood")
+
+
+import re
+
+from telethon.events import NewMessage as NewMsg
+
+from pyUltroid.dB import DEVLIST
+from pyUltroid.dB.antiflood_db import get_flood, get_flood_limit, rem_flood, set_flood
+from pyUltroid.fns.admins import admin_check
+
+from . import Button, Redis, asst, callback, eod, get_string, ultroid_bot, ultroid_cmd
+
+_check_flood = {}
+
+if Redis("ANTIFLOOD"):
+
+ @ultroid_bot.on(
+ NewMsg(
+ chats=list(get_flood().keys()),
+ ),
+ )
+ async def flood_checm(event):
+ count = 1
+ chat = (await event.get_chat()).title
+ if event.chat_id in _check_flood.keys():
+ if event.sender_id == list(_check_flood[event.chat_id].keys())[0]:
+ count = _check_flood[event.chat_id][event.sender_id]
+ _check_flood[event.chat_id] = {event.sender_id: count + 1}
+ else:
+ _check_flood[event.chat_id] = {event.sender_id: count}
+ else:
+ _check_flood[event.chat_id] = {event.sender_id: count}
+ if await admin_check(event, silent=True) or getattr(event.sender, "bot", None):
+ return
+ if event.sender_id in DEVLIST:
+ return
+ if _check_flood[event.chat_id][event.sender_id] >= int(
+ get_flood_limit(event.chat_id)
+ ):
+ try:
+ name = event.sender.first_name
+ await event.client.edit_permissions(
+ event.chat_id, event.sender_id, send_messages=False
+ )
+ del _check_flood[event.chat_id]
+ await event.reply(f"#AntiFlood\n\n{get_string('antiflood_3')}")
+ await asst.send_message(
+ int(Redis("LOG_CHANNEL")),
+ f"#Antiflood\n\n`Muted `[{name}](tg://user?id={event.sender_id})` in {chat}`",
+ buttons=Button.inline(
+ "Unmute", data=f"anti_{event.sender_id}_{event.chat_id}"
+ ),
+ )
+ except BaseException:
+ pass
+
+
+@callback(
+ re.compile(
+ "anti_(.*)",
+ ),
+)
+async def unmuting(e):
+ ino = (e.data_match.group(1)).decode("UTF-8").split("_")
+ user = int(ino[0])
+ chat = int(ino[1])
+ user_name = (await ultroid_bot.get_entity(user)).first_name
+ chat_title = (await ultroid_bot.get_entity(chat)).title
+ await ultroid_bot.edit_permissions(chat, user, send_messages=True)
+ await e.edit(
+ f"#Antiflood\n\n`Unmuted `[{user_name}](tg://user?id={user})` in {chat_title}`"
+ )
+
+
+@ultroid_cmd(
+ pattern="setflood ?(\\d+)",
+ admins_only=True,
+)
+async def setflood(e):
+ input_ = e.pattern_match.group(1).strip()
+ if not input_:
+ return await e.eor("`What?`", time=5)
+ if not input_.isdigit():
+ return await e.eor(get_string("com_3"), time=5)
+ if m := set_flood(e.chat_id, input_):
+ return await eod(e, get_string("antiflood_4").format(input_))
+
+
+@ultroid_cmd(
+ pattern="remflood$",
+ admins_only=True,
+)
+async def remove_flood(e):
+ hmm = rem_flood(e.chat_id)
+ try:
+ del _check_flood[e.chat_id]
+ except BaseException:
+ pass
+ if hmm:
+ return await e.eor(get_string("antiflood_1"), time=5)
+ await e.eor(get_string("antiflood_2"), time=5)
+
+
+@ultroid_cmd(
+ pattern="getflood$",
+ admins_only=True,
+)
+async def getflood(e):
+ if ok := get_flood_limit(e.chat_id):
+ return await e.eor(get_string("antiflood_5").format(ok), time=5)
+ await e.eor(get_string("antiflood_2"), time=5)
diff --git a/plugins/asstcmd.py b/plugins/asstcmd.py
new file mode 100644
index 0000000000000000000000000000000000000000..b88446ef7d5e50d4578c2f59e6742e90fd06f89e
--- /dev/null
+++ b/plugins/asstcmd.py
@@ -0,0 +1,107 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_asstcmd")
+
+import os
+
+from pyUltroid.dB.asstcmd_db import add_cmd, cmd_reply, list_cmds, rem_cmd
+from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
+
+try:
+ from telegraph import upload_file as uf
+except ImportError:
+ uf = None
+from telethon import events, utils
+
+from . import asst, get_string, mediainfo, udB, ultroid_cmd
+
+
+@ultroid_cmd(pattern="addcmd( (.*)|$)")
+async def ac(e):
+ wrd = (e.pattern_match.group(1).strip()).lower()
+ wt = await e.get_reply_message()
+ if not (wt and wrd):
+ return await e.eor(get_string("asstcmd_1"), time=5)
+ if "/" in wrd:
+ wrd = wrd.replace("/", "")
+ btn = format_btn(wt.buttons) if wt.buttons else None
+ if wt and wt.media:
+ wut = mediainfo(wt.media)
+ if wut.startswith(("pic", "gif")):
+ dl = await e.client.download_media(wt.media)
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "video":
+ if wt.media.document.size > 8 * 1000 * 1000:
+ return await e.eor(get_string("com_4"), time=5)
+ dl = await e.client.download_media(wt.media)
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ else:
+ m = utils.pack_bot_file_id(wt.media)
+ if wt.text:
+ txt = wt.text
+ if not btn:
+ txt, btn = get_msg_button(wt.text)
+ add_cmd(wrd, txt, m, btn)
+ else:
+ add_cmd(wrd, None, m, btn)
+ else:
+ txt = wt.text
+ if not btn:
+ txt, btn = get_msg_button(wt.text)
+ add_cmd(wrd, txt, None, btn)
+ asst.add_handler(
+ astcmds,
+ events.NewMessage(
+ func=lambda x: x.text.startswith("/") and x.text[1:] in list(list_cmds())
+ ),
+ )
+ await e.eor(get_string("asstcmd_4").format(wrd))
+
+
+@ultroid_cmd(pattern="remcmd( (.*)|$)")
+async def rc(e):
+ wrd = (e.pattern_match.group(1).strip()).lower()
+ if not wrd:
+ return await e.eor(get_string("asstcmd_2"), time=5)
+ wrd = wrd.replace("/", "")
+ rem_cmd(wrd)
+ await e.eor(get_string("asstcmd_3").format(wrd))
+
+
+@ultroid_cmd(pattern="listcmd$")
+async def lscmd(e):
+ if list_cmds():
+ ok = get_string("asstcmd_6")
+ for x in list_cmds():
+ ok += f"/{x}" + "\n"
+ return await e.eor(ok)
+ return await e.eor(get_string("asstcmd_5"))
+
+
+async def astcmds(e):
+ xx = (e.text.replace("/", "")).lower().split()[0]
+ if cmd_reply(xx):
+ msg, media, bt = cmd_reply(xx)
+ if bt:
+ bt = create_tl_btn(bt)
+ await e.reply(msg, file=media, buttons=bt)
+
+
+if udB.get_key("ASST_CMDS"):
+ asst.add_handler(
+ astcmds,
+ events.NewMessage(
+ func=lambda x: x.text.startswith("/") and x.text[1:] in list(list_cmds())
+ ),
+ )
diff --git a/plugins/audiotools.py b/plugins/audiotools.py
new file mode 100644
index 0000000000000000000000000000000000000000..f8c0b52558cc3642647a2145d8693182305a6c98
--- /dev/null
+++ b/plugins/audiotools.py
@@ -0,0 +1,160 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+import os
+import time
+from datetime import datetime as dt
+
+from pyUltroid.fns.tools import set_attributes
+
+from . import (
+ LOGS,
+ ULTConfig,
+ bash,
+ downloader,
+ eod,
+ eor,
+ genss,
+ get_help,
+ get_string,
+ humanbytes,
+ mediainfo,
+ stdr,
+ time_formatter,
+ ultroid_cmd,
+ uploader,
+)
+
+__doc__ = get_help("help_audiotools")
+
+
+@ultroid_cmd(pattern="makevoice$")
+async def vnc(e):
+ if not e.reply_to:
+ return await eod(e, get_string("audiotools_1"))
+ r = await e.get_reply_message()
+ if not mediainfo(r.media).startswith(("audio", "video")):
+ return await eod(e, get_string("spcltool_1"))
+ xxx = await e.eor(get_string("com_1"))
+ file, _ = await e.client.fast_downloader(
+ r.document,
+ )
+ await xxx.edit(get_string("audiotools_2"))
+ await bash(
+ f"ffmpeg -i '{file.name}' -map 0:a -codec:a libopus -b:a 100k -vbr on out.opus"
+ )
+ try:
+ await e.client.send_message(
+ e.chat_id, file="out.opus", force_document=False, reply_to=r
+ )
+ except Exception as er:
+ LOGS.exception(er)
+ return await xxx.edit("`Failed to convert in Voice...`")
+ await xxx.delete()
+ os.remove(file.name)
+ os.remove("out.opus")
+
+
+@ultroid_cmd(pattern="atrim( (.*)|$)")
+async def trim_aud(e):
+ sec = e.pattern_match.group(1).strip()
+ if not sec or "-" not in sec:
+ return await eod(e, get_string("audiotools_3"))
+ a, b = sec.split("-")
+ if int(a) >= int(b):
+ return await eod(e, get_string("audiotools_4"))
+ vido = await e.get_reply_message()
+ if vido and vido.media and mediainfo(vido.media).startswith(("video", "audio")):
+ if hasattr(vido.media, "document"):
+ vfile = vido.media.document
+ name = vido.file.name
+ else:
+ vfile = vido.media
+ name = ""
+ if not name:
+ name = dt.now().isoformat("_", "seconds") + ".mp4"
+ xxx = await e.eor(get_string("audiotools_5"))
+ c_time = time.time()
+ file = await downloader(
+ f"resources/downloads/{name}",
+ vfile,
+ xxx,
+ c_time,
+ f"Downloading {name}...",
+ )
+
+ o_size = os.path.getsize(file.name)
+ d_time = time.time()
+ diff = time_formatter((d_time - c_time) * 1000)
+ file_name = (file.name).split("/")[-1]
+ out = file_name.replace(file_name.split(".")[-1], "_trimmed.aac")
+ if int(b) > int(await genss(file.name)):
+ os.remove(file.name)
+ return await eod(xxx, get_string("audiotools_6"))
+ ss, dd = stdr(int(a)), stdr(int(b))
+ xxx = await xxx.edit(
+ f"Downloaded `{file.name}` of `{humanbytes(o_size)}` in `{diff}`.\n\nNow Trimming Audio from `{ss}` to `{dd}`..."
+ )
+ cmd = f'ffmpeg -i "{file.name}" -preset ultrafast -ss {ss} -to {dd} -vn -acodec copy "{out}" -y'
+ await bash(cmd)
+ os.remove(file.name)
+ f_time = time.time()
+ mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
+ attributes = await set_attributes(out)
+
+ caption = get_string("audiotools_7").format(ss, dd)
+ await e.client.send_file(
+ e.chat_id,
+ mmmm,
+ thumb=ULTConfig.thumb,
+ caption=caption,
+ attributes=attributes,
+ force_document=False,
+ reply_to=e.reply_to_msg_id,
+ )
+ await xxx.delete()
+ else:
+ await e.eor(get_string("audiotools_1"), time=5)
+
+
+@ultroid_cmd(pattern="extractaudio$")
+async def ex_aud(e):
+ reply = await e.get_reply_message()
+ if not (reply and reply.media and mediainfo(reply.media).startswith("video")):
+ return await e.eor(get_string("audiotools_8"))
+ name = reply.file.name or "video.mp4"
+ vfile = reply.media.document
+ msg = await e.eor(get_string("com_1"))
+ c_time = time.time()
+ file = await downloader(
+ f"resources/downloads/{name}",
+ vfile,
+ msg,
+ c_time,
+ f"Downloading {name}...",
+ )
+
+ out_file = f"{file.name}.aac"
+ cmd = f"ffmpeg -i {file.name} -vn -acodec copy {out_file}"
+ o, err = await bash(cmd)
+ os.remove(file.name)
+ attributes = await set_attributes(out_file)
+
+ f_time = time.time()
+ try:
+ fo = await uploader(out_file, out_file, f_time, msg, f"Uploading {out_file}...")
+
+ except FileNotFoundError:
+ return await eor(msg, get_string("audiotools_9"))
+ await e.reply(
+ get_string("audiotools_10"),
+ file=fo,
+ thumb=ULTConfig.thumb,
+ attributes=attributes,
+ )
+ await msg.delete()
diff --git a/plugins/autoban.py b/plugins/autoban.py
new file mode 100644
index 0000000000000000000000000000000000000000..597323213b309398b1f2a8f047f095aa904dc0df
--- /dev/null
+++ b/plugins/autoban.py
@@ -0,0 +1,59 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_autoban")
+
+from telethon import events
+
+from pyUltroid.dB.base import KeyManager
+
+from . import LOGS, asst, ultroid_bot, ultroid_cmd
+
+Keym = KeyManager("DND_CHATS", cast=list)
+
+
+def join_func(e):
+ return e.user_joined and Keym.contains(e.chat_id)
+
+
+async def dnd_func(event):
+ for user in event.users:
+ try:
+ await (await event.client.kick_participant(event.chat_id, user)).delete()
+ except Exception as ex:
+ LOGS.error("Error in DND:")
+ LOGS.exception(ex)
+ await event.delete()
+
+
+@ultroid_cmd(
+ pattern="autokick (on|off)$",
+ admins_only=True,
+ manager=True,
+ require="ban_users",
+ fullsudo=True,
+)
+async def _(event):
+ match = event.pattern_match.group(1)
+ if match == "on":
+ if Keym.contains(event.chat_id):
+ return await event.eor("`Chat already in do not disturb mode.`", time=3)
+ Keym.add(event.chat_id)
+ event.client.add_handler(dnd_func, events.ChatAction(func=join_func))
+ await event.eor("`Do not disturb mode activated for this chat.`", time=3)
+ elif match == "off":
+ if not Keym.contains(event.chat_id):
+ return await event.eor("`Chat is not in do not disturb mode.`", time=3)
+ Keym.remove(event.chat_id)
+ await event.eor("`Do not disturb mode deactivated for this chat.`", time=3)
+
+
+if Keym.get():
+ ultroid_bot.add_handler(dnd_func, events.ChatAction(func=join_func))
+ asst.add_handler(dnd_func, events.ChatAction(func=join_func))
diff --git a/plugins/autopic.py b/plugins/autopic.py
new file mode 100644
index 0000000000000000000000000000000000000000..f6e5127662bc1aaf78bf85ba4bcda347ffc841a3
--- /dev/null
+++ b/plugins/autopic.py
@@ -0,0 +1,84 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+import asyncio
+import os
+import random
+from random import shuffle
+
+from telethon.tl.functions.photos import UploadProfilePhotoRequest
+
+from pyUltroid.fns.helper import download_file
+from pyUltroid.fns.tools import get_google_images
+
+from . import LOGS, get_help, get_string, udB, ultroid_bot, ultroid_cmd
+
+__doc__ = get_help("help_autopic")
+
+
+@ultroid_cmd(pattern="autopic( (.*)|$)")
+async def autopic(e):
+ search = e.pattern_match.group(1).strip()
+ if udB.get_key("AUTOPIC") and not search:
+ udB.del_key("AUTOPIC")
+ return await e.eor(get_string("autopic_5"))
+ if not search:
+ return await e.eor(get_string("autopic_1"), time=5)
+ e = await e.eor(get_string("com_1"))
+ gi = googleimagesdownload()
+ args = {
+ "keywords": search,
+ "limit": 50,
+ "format": "jpg",
+ "output_directory": "./resources/downloads/",
+ }
+ try:
+ pth = await gi.download(args)
+ ok = pth[0][search]
+ except Exception as er:
+ LOGS.exception(er)
+ return await e.eor(str(er))
+ if not ok:
+ return await e.eor(get_string("autopic_2").format(search), time=5)
+ await e.eor(get_string("autopic_3").format(search))
+ udB.set_key("AUTOPIC", search)
+ SLEEP_TIME = udB.get_key("SLEEP_TIME") or 1221
+ while True:
+ for lie in ok:
+ if udB.get_key("AUTOPIC") != search:
+ return
+ file = await e.client.upload_file(lie)
+ await e.client(UploadProfilePhotoRequest(file))
+ await asyncio.sleep(SLEEP_TIME)
+ shuffle(ok)
+
+
+if search := udB.get_key("AUTOPIC"):
+ images = {}
+ sleep = udB.get_key("SLEEP_TIME") or 1221
+
+ async def autopic_func():
+ search = udB.get_key("AUTOPIC")
+ if images.get(search) is None:
+ images[search] = await get_google_images(search)
+ if not images.get(search):
+ return
+ img = random.choice(images[search])
+ filee = await download_file(img["original"], "resources/downloads/autopic.jpg")
+ file = await ultroid_bot.upload_file(filee)
+ await ultroid_bot(UploadProfilePhotoRequest(file))
+ os.remove(filee)
+
+ try:
+ from apscheduler.schedulers.asyncio import AsyncIOScheduler
+
+ schedule = AsyncIOScheduler()
+ schedule.add_job(autopic_func, "interval", seconds=sleep)
+ schedule.start()
+ except ModuleNotFoundError as er:
+ LOGS.error(f"autopic: '{er.name}' not installed.")
diff --git a/plugins/beautify.py b/plugins/beautify.py
new file mode 100644
index 0000000000000000000000000000000000000000..ea83cd2436fbacd520aaedbcd68c798cf0f2cb0a
--- /dev/null
+++ b/plugins/beautify.py
@@ -0,0 +1,213 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_beautify")
+
+
+import os
+import random
+
+from telethon.utils import get_display_name
+from urllib.parse import urlencode
+from . import Carbon, ultroid_cmd, get_string, inline_mention, LOGS
+from secrets import token_hex
+
+_colorspath = "resources/colorlist.txt"
+
+if os.path.exists(_colorspath):
+ with open(_colorspath, "r") as f:
+ all_col = f.read().split()
+else:
+ all_col = []
+
+
+@ultroid_cmd(
+ pattern="(rc|c)arbon",
+)
+async def cr_bn(event):
+ xxxx = await event.eor(get_string("com_1"))
+ te = event.pattern_match.group(1)
+ col = random.choice(all_col) if te[0] == "r" else "White"
+ if event.reply_to_msg_id:
+ temp = await event.get_reply_message()
+ if temp.media:
+ b = await event.client.download_media(temp)
+ with open(b) as a:
+ code = a.read()
+ os.remove(b)
+ else:
+ code = temp.message
+ else:
+ try:
+ code = event.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ return await xxxx.eor(get_string("carbon_2"))
+ xx = await Carbon(code=code, file_name="ultroid_carbon", backgroundColor=col)
+ if isinstance(xx, dict):
+ await xxxx.edit(f"`{xx}`")
+ return
+ await xxxx.delete()
+ await event.reply(
+ f"Carbonised by {inline_mention(event.sender)}",
+ file=xx,
+ )
+
+
+@ultroid_cmd(
+ pattern="ccarbon( (.*)|$)",
+)
+async def crbn(event):
+ match = event.pattern_match.group(1).strip()
+ if not match:
+ return await event.eor(get_string("carbon_3"))
+ msg = await event.eor(get_string("com_1"))
+ if event.reply_to_msg_id:
+ temp = await event.get_reply_message()
+ if temp.media:
+ b = await event.client.download_media(temp)
+ with open(b) as a:
+ code = a.read()
+ os.remove(b)
+ else:
+ code = temp.message
+ else:
+ try:
+ match = match.split(" ", maxsplit=1)
+ code = match[1]
+ match = match[0]
+ except IndexError:
+ return await msg.eor(get_string("carbon_2"))
+ xx = await Carbon(code=code, backgroundColor=match)
+ await msg.delete()
+ await event.reply(
+ f"Carbonised by {inline_mention(event.sender)}",
+ file=xx,
+ )
+
+
+RaySoTheme = [
+ "meadow",
+ "breeze",
+ "raindrop",
+ "candy",
+ "crimson",
+ "falcon",
+ "sunset",
+ "noir",
+ "midnight",
+ "bitmap",
+ "ice",
+ "sand",
+ "forest",
+ "mono"
+]
+
+
+@ultroid_cmd(pattern="rayso")
+async def pass_on(ult):
+ try:
+ from playwright.async_api import async_playwright
+ except ImportError:
+ await ult.eor(
+ "`playwright` is not installed!\nPlease install it to use this command.."
+ )
+ return
+
+ proc = await ult.eor(get_string("com_1"))
+ spli = ult.text.split()
+ theme, dark, title, text = None, True, get_display_name(ult.chat), None
+
+ if len(spli) > 2:
+ if spli[1] in RaySoTheme:
+ theme = spli[1]
+ dark = spli[2].lower().strip() in ["true", "t"]
+ elif len(spli) > 1:
+ if spli[1] in RaySoTheme:
+ theme = spli[1]
+ elif spli[1] == "list":
+ text = "**List of Rayso Themes:**\n" + "\n".join(
+ [f"- `{th_}`" for th_ in RaySoTheme]
+ )
+ await proc.eor(text)
+ return
+ else:
+ try:
+ text = ult.text.split(maxsplit=1)[1]
+ except IndexError:
+ pass
+
+ if not theme or theme not in RaySoTheme:
+ theme = random.choice(RaySoTheme)
+
+ if ult.is_reply:
+ try:
+ msg = await ult.get_reply_message()
+ text = msg.message
+ title = get_display_name(msg.sender)
+ except Exception as sam:
+ ErrInfo(sam)
+
+ if not text:
+ await proc.eor("No text to beautify!")
+ return
+
+ cleaned_text = "\n".join([line.strip() for line in text.splitlines()])
+
+ name = token_hex(8) + ".png"
+ data = {"darkMode": dark, "theme": theme, "title": title}
+ url = f"https://ray.so/#{urlencode(data)}"
+
+ async with async_playwright() as play:
+ try:
+ browser = await play.chromium.launch()
+ page = await browser.new_page()
+ await page.goto(url)
+ await page.wait_for_load_state("networkidle")
+
+ try:
+ await page.wait_for_selector("div[class*='Editor_editor__']", timeout=60000)
+ editor = await page.query_selector("div[class*='Editor_editor__']")
+ await editor.focus()
+ await editor.click()
+
+ for line in cleaned_text.split("\n"):
+ await page.keyboard.type(line)
+ await page.keyboard.press("Enter")
+
+ await page.evaluate("""() => {
+ const button = document.querySelector('button[aria-label="Export as PNG"]');
+ button.click();
+ }""")
+
+ async with page.expect_download() as download_info:
+ download = await download_info.value
+ await download.save_as(name)
+
+ except playwright._impl._errors.TimeoutError:
+ LOGS.info("Timeout error: Selector not found within 60 seconds.")
+ await proc.eor("Failed to find the editor within 60 seconds.")
+ return
+
+ except Exception as e:
+ LOGS.info(f"Error occurred during playwright operation: {e}")
+ await proc.eor("An error occurred during the operation.")
+ return
+
+ finally:
+ if os.path.exists(name):
+ try:
+ await ult.reply(file=name)
+ await proc.try_delete()
+ os.remove(name)
+ except Exception as e:
+ LOGS.info(f"Error occurred while replying with the file: {e}")
+ await proc.eor("Failed to send the file.")
+ else:
+ LOGS.info(f"Error: File {name} not found or inaccessible.")
+ await proc.eor("Failed to save the file.")
\ No newline at end of file
diff --git a/plugins/blacklist.py b/plugins/blacklist.py
new file mode 100644
index 0000000000000000000000000000000000000000..78f2d42afe65f3cf377a7b28654333fa806446ba
--- /dev/null
+++ b/plugins/blacklist.py
@@ -0,0 +1,69 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_blacklist")
+
+
+from pyUltroid.dB.blacklist_db import (
+ add_blacklist,
+ get_blacklist,
+ list_blacklist,
+ rem_blacklist,
+)
+
+from . import events, get_string, udB, ultroid_bot, ultroid_cmd
+
+
+@ultroid_cmd(pattern="blacklist( (.*)|$)", admins_only=True)
+async def af(e):
+ wrd = e.pattern_match.group(1).strip()
+ chat = e.chat_id
+ if not (wrd):
+ return await e.eor(get_string("blk_1"), time=5)
+ wrd = e.text[11:]
+ heh = wrd.split(" ")
+ for z in heh:
+ add_blacklist(int(chat), z.lower())
+ ultroid_bot.add_handler(blacklist, events.NewMessage(incoming=True))
+ await e.eor(get_string("blk_2").format(wrd))
+
+
+@ultroid_cmd(pattern="remblacklist( (.*)|$)", admins_only=True)
+async def rf(e):
+ wrd = e.pattern_match.group(1).strip()
+ chat = e.chat_id
+ if not wrd:
+ return await e.eor(get_string("blk_3"), time=5)
+ wrd = e.text[14:]
+ heh = wrd.split(" ")
+ for z in heh:
+ rem_blacklist(int(chat), z.lower())
+ await e.eor(get_string("blk_4").format(wrd))
+
+
+@ultroid_cmd(pattern="listblacklist$", admins_only=True)
+async def lsnote(e):
+ if x := list_blacklist(e.chat_id):
+ sd = get_string("blk_5")
+ return await e.eor(sd + x)
+ await e.eor(get_string("blk_6"))
+
+
+async def blacklist(e):
+ if x := get_blacklist(e.chat_id):
+ text = e.text.lower().split()
+ if any((z in text) for z in x):
+ try:
+ await e.delete()
+ except BaseException:
+ pass
+
+
+if udB.get_key("BLACKLIST_DB"):
+ ultroid_bot.add_handler(blacklist, events.NewMessage(incoming=True))
diff --git a/plugins/bot.py b/plugins/bot.py
new file mode 100644
index 0000000000000000000000000000000000000000..1e185c20d4851fd60438564ee10de67d71908eb4
--- /dev/null
+++ b/plugins/bot.py
@@ -0,0 +1,356 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_bot")
+
+import os
+import sys
+import time
+from platform import python_version as pyver
+from random import choice
+
+from telethon import __version__
+from telethon.errors.rpcerrorlist import (
+ BotMethodInvalidError,
+ ChatSendMediaForbiddenError,
+)
+
+from pyUltroid.version import __version__ as UltVer
+
+from . import HOSTED_ON, LOGS
+
+try:
+ from git import Repo
+except ImportError:
+ LOGS.error("bot: 'gitpython' module not found!")
+ Repo = None
+
+from telethon.utils import resolve_bot_file_id
+
+from . import (
+ ATRA_COL,
+ LOGS,
+ OWNER_NAME,
+ ULTROID_IMAGES,
+ Button,
+ Carbon,
+ Telegraph,
+ Var,
+ allcmds,
+ asst,
+ bash,
+ call_back,
+ callback,
+ def_logs,
+ eor,
+ get_string,
+ heroku_logs,
+ in_pattern,
+ inline_pic,
+ restart,
+ shutdown,
+ start_time,
+ time_formatter,
+ udB,
+ ultroid_cmd,
+ ultroid_version,
+ updater,
+)
+
+
+def ULTPIC():
+ return inline_pic() or choice(ULTROID_IMAGES)
+
+
+buttons = [
+ [
+ Button.url(get_string("bot_3"), "https://github.com/TeamUltroid/Ultroid"),
+ Button.url(get_string("bot_4"), "t.me/UltroidSupportChat"),
+ ]
+]
+
+# Will move to strings
+alive_txt = """
+The Ultroid Userbot
+
+ â Version - {}
+ â Py-Ultroid - {}
+ â Telethon - {}
+"""
+
+in_alive = "{}\n\nđ Ultroid Version -> {}\nđ PyUltroid -> {}\nđ Python -> {}\nđ Uptime -> {}\nđ Branch ->[ {} ]\n\n⢠Join @TeamUltroid"
+
+
+@callback("alive")
+async def alive(event):
+ text = alive_txt.format(ultroid_version, UltVer, __version__)
+ await event.answer(text, alert=True)
+
+
+@ultroid_cmd(
+ pattern="alive( (.*)|$)",
+)
+async def lol(ult):
+ match = ult.pattern_match.group(1).strip()
+ inline = None
+ if match in ["inline", "i"]:
+ try:
+ res = await ult.client.inline_query(asst.me.username, "alive")
+ return await res[0].click(ult.chat_id)
+ except BotMethodInvalidError:
+ pass
+ except BaseException as er:
+ LOGS.exception(er)
+ inline = True
+ pic = udB.get_key("ALIVE_PIC")
+ if isinstance(pic, list):
+ pic = choice(pic)
+ uptime = time_formatter((time.time() - start_time) * 1000)
+ header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
+ y = Repo().active_branch
+ xx = Repo().remotes[0].config_reader.get("url")
+ rep = xx.replace(".git", f"/tree/{y}")
+ kk = f" `[{y}]({rep})` "
+ if inline:
+ kk = f"{y}"
+ parse = "html"
+ als = in_alive.format(
+ header,
+ f"{ultroid_version} [{HOSTED_ON}]",
+ UltVer,
+ pyver(),
+ uptime,
+ kk,
+ )
+
+ if _e := udB.get_key("ALIVE_EMOJI"):
+ als = als.replace("đ", _e)
+ else:
+ parse = "md"
+ als = (get_string("alive_1")).format(
+ header,
+ OWNER_NAME,
+ f"{ultroid_version} [{HOSTED_ON}]",
+ UltVer,
+ uptime,
+ pyver(),
+ __version__,
+ kk,
+ )
+
+ if a := udB.get_key("ALIVE_EMOJI"):
+ als = als.replace("âľ", a)
+ if pic:
+ try:
+ await ult.reply(
+ als,
+ file=pic,
+ parse_mode=parse,
+ link_preview=False,
+ buttons=buttons if inline else None,
+ )
+ return await ult.try_delete()
+ except ChatSendMediaForbiddenError:
+ pass
+ except BaseException as er:
+ LOGS.exception(er)
+ try:
+ await ult.reply(file=pic)
+ await ult.reply(
+ als,
+ parse_mode=parse,
+ buttons=buttons if inline else None,
+ link_preview=False,
+ )
+ return await ult.try_delete()
+ except BaseException as er:
+ LOGS.exception(er)
+ await eor(
+ ult,
+ als,
+ parse_mode=parse,
+ link_preview=False,
+ buttons=buttons if inline else None,
+ )
+
+
+@ultroid_cmd(pattern="ping$", chats=[], type=["official", "assistant"])
+async def _(event):
+ start = time.time()
+ x = await event.eor("Pong !")
+ end = round((time.time() - start) * 1000)
+ uptime = time_formatter((time.time() - start_time) * 1000)
+ await x.edit(get_string("ping").format(end, uptime))
+
+
+@ultroid_cmd(
+ pattern="cmds$",
+)
+async def cmds(event):
+ await allcmds(event, Telegraph)
+
+
+heroku_api = Var.HEROKU_API
+
+
+@ultroid_cmd(
+ pattern="restart$",
+ fullsudo=True,
+)
+async def restartbt(ult):
+ ok = await ult.eor(get_string("bot_5"))
+ call_back()
+ who = "bot" if ult.client._bot else "user"
+ udB.set_key("_RESTART", f"{who}_{ult.chat_id}_{ok.id}")
+ if heroku_api:
+ return await restart(ok)
+ await bash("git pull && pip3 install -r requirements.txt")
+ if len(sys.argv) > 1:
+ os.execl(sys.executable, sys.executable, "main.py")
+ else:
+ os.execl(sys.executable, sys.executable, "-m", "pyUltroid")
+
+
+@ultroid_cmd(
+ pattern="shutdown$",
+ fullsudo=True,
+)
+async def shutdownbot(ult):
+ await shutdown(ult)
+
+
+@ultroid_cmd(
+ pattern="logs( (.*)|$)",
+ chats=[],
+)
+async def _(event):
+ opt = event.pattern_match.group(1).strip()
+ file = f"ultroid{sys.argv[-1]}.txt" if len(sys.argv) > 1 else "ultroid.txt"
+ if opt == "heroku":
+ await heroku_logs(event)
+ elif opt == "carbon" and Carbon:
+ event = await event.eor(get_string("com_1"))
+ with open(file, "r") as f:
+ code = f.read()[-2500:]
+ file = await Carbon(
+ file_name="ultroid-logs",
+ code=code,
+ backgroundColor=choice(ATRA_COL),
+ )
+ if isinstance(file, dict):
+ await event.eor(f"`{file}`")
+ return
+ await event.reply("**Ultroid Logs.**", file=file)
+ elif opt == "open":
+ with open("ultroid.txt", "r") as f:
+ file = f.read()[-4000:]
+ return await event.eor(f"`{file}`")
+ else:
+ await def_logs(event, file)
+ await event.try_delete()
+
+
+@in_pattern("alive", owner=True)
+async def inline_alive(ult):
+ pic = udB.get_key("ALIVE_PIC")
+ if isinstance(pic, list):
+ pic = choice(pic)
+ uptime = time_formatter((time.time() - start_time) * 1000)
+ header = udB.get_key("ALIVE_TEXT") or get_string("bot_1")
+ y = Repo().active_branch
+ xx = Repo().remotes[0].config_reader.get("url")
+ rep = xx.replace(".git", f"/tree/{y}")
+ kk = f"{y}"
+ als = in_alive.format(
+ header, f"{ultroid_version} [{HOSTED_ON}]", UltVer, pyver(), uptime, kk
+ )
+
+ if _e := udB.get_key("ALIVE_EMOJI"):
+ als = als.replace("đ", _e)
+ builder = ult.builder
+ if pic:
+ try:
+ if ".jpg" in pic:
+ results = [
+ await builder.photo(
+ pic, text=als, parse_mode="html", buttons=buttons
+ )
+ ]
+ else:
+ if _pic := resolve_bot_file_id(pic):
+ pic = _pic
+ buttons.insert(
+ 0, [Button.inline(get_string("bot_2"), data="alive")]
+ )
+ results = [
+ await builder.document(
+ pic,
+ title="Inline Alive",
+ description="@TeamUltroid",
+ parse_mode="html",
+ buttons=buttons,
+ )
+ ]
+ return await ult.answer(results)
+ except BaseException as er:
+ LOGS.exception(er)
+ result = [
+ await builder.article(
+ "Alive", text=als, parse_mode="html", link_preview=False, buttons=buttons
+ )
+ ]
+ await ult.answer(result)
+
+
+@ultroid_cmd(pattern="update( (.*)|$)")
+async def _(e):
+ xx = await e.eor(get_string("upd_1"))
+ if e.pattern_match.group(1).strip() and (
+ "fast" in e.pattern_match.group(1).strip()
+ or "soft" in e.pattern_match.group(1).strip()
+ ):
+ await bash("git pull -f && pip3 install -r requirements.txt")
+ call_back()
+ await xx.edit(get_string("upd_7"))
+ os.execl(sys.executable, "python3", "-m", "pyUltroid")
+ # return
+ m = await updater()
+ branch = (Repo.init()).active_branch
+ if m:
+ x = await asst.send_file(
+ udB.get_key("LOG_CHANNEL"),
+ ULTPIC(),
+ caption="⢠**Update Available** â˘",
+ force_document=False,
+ buttons=Button.inline("Changelogs", data="changes"),
+ )
+ Link = x.message_link
+ await xx.edit(
+ f'[ChangeLogs]',
+ parse_mode="html",
+ link_preview=False,
+ )
+ else:
+ await xx.edit(
+ f'Your BOT is up-to-date with [{branch}]',
+ parse_mode="html",
+ link_preview=False,
+ )
+
+
+@callback("updtavail", owner=True)
+async def updava(event):
+ await event.delete()
+ await asst.send_file(
+ udB.get_key("LOG_CHANNEL"),
+ ULTPIC(),
+ caption="⢠**Update Available** â˘",
+ force_document=False,
+ buttons=Button.inline("Changelogs", data="changes"),
+ )
diff --git a/plugins/broadcast.py b/plugins/broadcast.py
new file mode 100644
index 0000000000000000000000000000000000000000..f8aedf2f086d04c9a54d45d90b9d031af2ad66ae
--- /dev/null
+++ b/plugins/broadcast.py
@@ -0,0 +1,216 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+from . import get_help
+
+__doc__ = get_help("help_broadcast")
+
+import asyncio
+import io
+
+from telethon.utils import get_display_name
+
+from pyUltroid.dB.base import KeyManager
+
+from . import HNDLR, LOGS, eor, get_string, udB, ultroid_bot, ultroid_cmd
+
+KeyM = KeyManager("BROADCAST", cast=list)
+
+
+@ultroid_cmd(
+ pattern="addch( (.*)|$)",
+ allow_sudo=False,
+)
+async def broadcast_adder(event):
+ msgg = event.pattern_match.group(1).strip()
+ x = await event.eor(get_string("bd_1"))
+ if msgg == "all":
+ await x.edit(get_string("bd_2"))
+ chats = [
+ e.entity
+ for e in await event.client.get_dialogs()
+ if (e.is_group or e.is_channel)
+ ]
+ new = 0
+ for i in chats:
+ try:
+ if (
+ i.broadcast
+ and (i.creator or i.admin_rights)
+ and not KeyM.contains(i.id)
+ ):
+ new += 1
+ cid = f"-100{i.id}"
+ KeyM.add(int(cid))
+ except Exception as Ex:
+ LOGS.exception(Ex)
+ await x.edit(get_string("bd_3").format(KeyM.count(), new))
+ return
+ if event.reply_to_msg_id:
+ previous_message = await event.get_reply_message()
+ raw_text = previous_message.text
+ lines = raw_text.split("\n")
+ length = len(lines)
+ for line_number in range(1, length - 2):
+ channel_id = lines[line_number][4:-1]
+ if not KeyM.contains(channel_id):
+ KeyM.add(channel_id)
+ await x.edit(get_string("bd_4"))
+ await asyncio.sleep(3)
+ await event.delete()
+ return
+ chat_id = event.chat_id
+ if chat_id == udB.get_key("LOG_CHANNEL"):
+ return
+ if KeyM.contains(chat_id):
+ await x.edit(get_string("bd_6"))
+ elif xx := KeyM.add(chat_id):
+ await x.edit(get_string("bd_5"))
+ else:
+ await x.edit(get_string("sf_8"))
+ await asyncio.sleep(3)
+ await x.delete()
+
+
+@ultroid_cmd(
+ pattern="remch( (.*)|$)",
+ allow_sudo=False,
+)
+async def broadcast_remover(event):
+ chat_id = event.pattern_match.group(1).strip() or event.chat_id
+ x = await event.eor(get_string("com_1"))
+ if chat_id == "all":
+ await x.edit(get_string("bd_8"))
+ udB.del_key("BROADCAST")
+ await x.edit("Database cleared.")
+ return
+ if KeyM.contains(chat_id):
+ KeyM.remove(chat_id)
+ await x.edit(get_string("bd_7"))
+ else:
+ await x.edit(get_string("bd_9"))
+ await asyncio.sleep(3)
+ await x.delete()
+
+
+@ultroid_cmd(
+ pattern="listchannels$",
+)
+async def list_all(event):
+ x = await event.eor(get_string("com_1"))
+ channels = KeyM.get()
+ num = KeyM.count()
+ if not channels:
+ return await eor(x, "No chats were added.", time=5)
+ msg = "Channels in database:\n"
+ for channel in channels:
+ name = ""
+ try:
+ name = get_display_name(await event.client.get_entity(channel))
+ except ValueError:
+ name = ""
+ msg += f"=> **{name}** [`{channel}`]\n"
+ msg += f"\nTotal {num} channels."
+ if len(msg) > 4096:
+ MSG = msg.replace("*", "").replace("`", "")
+ with io.BytesIO(str.encode(MSG)) as out_file:
+ out_file.name = "channels.txt"
+ await event.reply(
+ "Channels in Database",
+ file=out_file,
+ force_document=True,
+ allow_cache=False,
+ )
+ await x.delete()
+ else:
+ await x.edit(msg)
+
+
+@ultroid_cmd(
+ pattern="forward$",
+ allow_sudo=False,
+)
+async def forw(event):
+ if not event.is_reply:
+ return await event.eor(get_string("ex_1"))
+ ultroid_bot = event.client
+ channels = KeyM.get()
+ x = await event.eor("Sending...")
+ if not channels:
+ return await x.edit(f"Please add channels by using `{HNDLR}add` in them.")
+ error_count = 0
+ sent_count = 0
+ previous_message = await event.get_reply_message()
+ error_count = 0
+ for channel in channels:
+ try:
+ await ultroid_bot.forward_messages(channel, previous_message)
+ sent_count += 1
+ await x.edit(
+ f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
+ )
+ except Exception:
+ try:
+ await ultroid_bot.send_message(
+ udB.get_key("LOG_CHANNEL"),
+ f"Error in sending at {channel}.",
+ )
+ except Exception as Em:
+ LOGS.info(Em)
+ error_count += 1
+ await x.edit(
+ f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
+ )
+ await x.edit(f"{sent_count} messages sent with {error_count} errors.")
+ if error_count > 0:
+ await ultroid_bot.send_message(
+ udB.get_key("LOG_CHANNEL"), f"{error_count} Errors"
+ )
+
+
+@ultroid_cmd(
+ pattern="broadcast( (.*)|$)",
+ allow_sudo=False,
+)
+async def sending(event):
+ x = await event.eor(get_string("com_1"))
+ if not event.is_reply:
+ return await x.edit(get_string("ex_1"))
+ channels = KeyM.get()
+ if not channels:
+ return await x.edit(f"Please add channels by using `{HNDLR}add` in them.")
+ await x.edit("Sending....")
+ if event.reply_to_msg_id:
+ previous_message = await event.get_reply_message()
+ if previous_message.poll:
+ return await x.edit(f"Reply `{HNDLR}forward` for polls.")
+ if previous_message:
+ error_count = 0
+ sent_count = 0
+ for channel in channels:
+ try:
+ await ultroid_bot.send_message(channel, previous_message)
+ sent_count += 1
+ await x.edit(
+ f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
+ )
+ except Exception as error:
+ await ultroid_bot.send_message(
+ udB.get_key("LOG_CHANNEL"),
+ f"Error in sending at {channel}.\n\n{error}",
+ )
+ error_count += 1
+ await x.edit(
+ f"Sent : {sent_count}\nError : {error_count}\nTotal : {len(channels)}",
+ )
+ await x.edit(f"{sent_count} messages sent with {error_count} errors.")
+ if error_count > 0:
+ await ultroid_bot.send_message(
+ udB.get_key("LOG_CHANNEL"),
+ f"{error_count} Errors",
+ )
diff --git a/plugins/button.py b/plugins/button.py
new file mode 100644
index 0000000000000000000000000000000000000000..b3d616d709be1a04ede2c6996d393bf12ac27f56
--- /dev/null
+++ b/plugins/button.py
@@ -0,0 +1,56 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_button")
+
+import os
+
+from telegraph import upload_file as uf
+from telethon.utils import pack_bot_file_id
+
+from pyUltroid.fns.tools import create_tl_btn, get_msg_button
+
+from . import HNDLR, get_string, mediainfo, ultroid_cmd
+from ._inline import something
+
+
+@ultroid_cmd(pattern="button")
+async def butt(event):
+ media, wut, text = None, None, None
+ if event.reply_to:
+ wt = await event.get_reply_message()
+ if wt.text:
+ text = wt.text
+ if wt.media:
+ wut = mediainfo(wt.media)
+ if wut and wut.startswith(("pic", "gif")):
+ dl = await wt.download_media()
+ variable = uf(dl)
+ media = f"https://graph.org{variable[0]}"
+ elif wut == "video":
+ if wt.media.document.size > 8 * 1000 * 1000:
+ return await event.eor(get_string("com_4"), time=5)
+ dl = await wt.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ media = f"https://graph.org{variable[0]}"
+ else:
+ media = pack_bot_file_id(wt.media)
+ try:
+ text = event.text.split(maxsplit=1)[1]
+ except IndexError:
+ if not text:
+ return await event.eor(
+ f"**Please give some text in correct format.**\n\n`{HNDLR}help button`",
+ )
+ text, buttons = get_msg_button(text)
+ if buttons:
+ buttons = create_tl_btn(buttons)
+ await something(event, text, media, buttons)
+ await event.delete()
diff --git a/plugins/calculator.py b/plugins/calculator.py
new file mode 100644
index 0000000000000000000000000000000000000000..28f2bae144d25287460e4a08daa452c6acba2f9f
--- /dev/null
+++ b/plugins/calculator.py
@@ -0,0 +1,153 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+from . import get_help
+
+__doc__ = get_help("help_calculator")
+
+import re
+
+from . import Button, asst, callback, get_string, in_pattern, udB, ultroid_cmd
+
+CALC = {}
+
+m = [
+ "AC",
+ "C",
+ "âŤ",
+ "%",
+ "7",
+ "8",
+ "9",
+ "+",
+ "4",
+ "5",
+ "6",
+ "-",
+ "1",
+ "2",
+ "3",
+ "x",
+ "00",
+ "0",
+ ".",
+ "á",
+]
+tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
+lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
+lst.append([Button.inline("=", data="calc=")])
+
+
+@ultroid_cmd(pattern="calc")
+async def icalc(e):
+ udB.del_key("calc")
+ if e.client._bot:
+ return await e.reply(get_string("calc_1"), buttons=lst)
+ results = await e.client.inline_query(asst.me.username, "calc")
+ await results[0].click(e.chat_id, silent=True, hide_via=True)
+ await e.delete()
+
+
+@in_pattern("calc", owner=True)
+async def _(e):
+ calc = e.builder.article("Calc", text=get_string("calc_1"), buttons=lst)
+ await e.answer([calc])
+
+
+@callback(re.compile("calc(.*)"), owner=True)
+async def _(e):
+ x = (e.data_match.group(1)).decode()
+ user = e.query.user_id
+ get = None
+ if x == "AC":
+ if CALC.get(user):
+ CALC.pop(user)
+ await e.edit(
+ get_string("calc_1"),
+ buttons=[Button.inline(get_string("calc_2"), data="recalc")],
+ )
+ elif x == "C":
+ if CALC.get(user):
+ CALC.pop(user)
+ await e.answer("cleared")
+ elif x == "âŤ":
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ CALC.update({user: get[:-1]})
+ await e.answer(str(get[:-1]))
+ elif x == "%":
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ CALC.update({user: f"{get}/100"})
+ await e.answer(str(f"{get}/100"))
+ elif x == "á":
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ CALC.update({user: f"{get}/"})
+ await e.answer(str(f"{get}/"))
+ elif x == "x":
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ CALC.update({user: f"{get}*"})
+ await e.answer(str(f"{get}*"))
+ elif x == "=":
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ if get.endswith(("*", ".", "/", "-", "+")):
+ get = get[:-1]
+ out = eval(get)
+ try:
+ num = float(out)
+ await e.answer(f"Answer : {num}", cache_time=0, alert=True)
+ except BaseException:
+ CALC.pop(user)
+ await e.answer(get_string("sf_8"), cache_time=0, alert=True)
+ await e.answer("None")
+ else:
+ if CALC.get(user):
+ get = CALC[user]
+ if get:
+ CALC.update({user: get + x})
+ return await e.answer(str(get + x))
+ CALC.update({user: x})
+ await e.answer(str(x))
+
+
+@callback("recalc", owner=True)
+async def _(e):
+ m = [
+ "AC",
+ "C",
+ "âŤ",
+ "%",
+ "7",
+ "8",
+ "9",
+ "+",
+ "4",
+ "5",
+ "6",
+ "-",
+ "1",
+ "2",
+ "3",
+ "x",
+ "00",
+ "0",
+ ".",
+ "á",
+ ]
+ tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
+ lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
+ lst.append([Button.inline("=", data="calc=")])
+ await e.edit(get_string("calc_1"), buttons=lst)
diff --git a/plugins/channelhacks.py b/plugins/channelhacks.py
new file mode 100644
index 0000000000000000000000000000000000000000..d333249a0fc0a82ec5cd8f37ec3014b25c21bcb6
--- /dev/null
+++ b/plugins/channelhacks.py
@@ -0,0 +1,224 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+from . import get_help
+
+__doc__ = get_help("help_channelhacks")
+
+
+import asyncio
+import io
+
+from telethon.errors.rpcerrorlist import FloodWaitError
+from telethon.utils import get_display_name, get_peer_id
+
+from pyUltroid.dB.base import KeyManager
+
+from . import LOGS, asst, eor, events, get_string, udB, ultroid_bot, ultroid_cmd
+
+ERROR = {}
+SourceM = KeyManager("CH_SOURCE", cast=list)
+DestiM = KeyManager("CH_DESTINATIONS", cast=list)
+
+
+async def autopost_func(e):
+ if not udB.get_key("AUTOPOST"):
+ return
+ x = SourceM.get()
+ th = await e.get_chat()
+ if get_peer_id(th) not in x:
+ return
+ y = DestiM.get()
+ for ys in y:
+ try:
+ await e.client.send_message(int(ys), e.message)
+ except Exception as ex:
+ try:
+ ERROR[str(ex)]
+ except KeyError:
+ ERROR.update({str(ex): ex})
+ Error = f"**Error on AUTOPOST**\n\n`{ex}`"
+ await asst.send_message(udB.get_key("LOG_CHANNEL"), Error)
+
+
+@ultroid_cmd(pattern="shift (.*)")
+async def _(e):
+ x = e.pattern_match.group(1).strip()
+ z = await e.eor(get_string("com_1"))
+ a, b = x.split("|")
+ try:
+ c = await e.client.parse_id(a)
+ except Exception:
+ await z.edit(get_string("cha_1"))
+ return
+ try:
+ d = await e.client.parse_id(b)
+ except Exception as er:
+ LOGS.exception(er)
+ await z.edit(get_string("cha_1"))
+ return
+ async for msg in e.client.iter_messages(int(c), reverse=True):
+ try:
+ await asyncio.sleep(2)
+ await e.client.send_message(int(d), msg)
+ except FloodWaitError as er:
+ await asyncio.sleep(er.seconds + 5)
+ await e.client.send_message(int(d), msg)
+ except BaseException as er:
+ LOGS.exception(er)
+ await z.edit("Done")
+
+
+@ultroid_cmd(pattern="asource (.*)")
+async def source(e):
+ if x := e.pattern_match.group(1).strip():
+ try:
+ y = await e.client.parse_id(x)
+ except Exception as er:
+ LOGS.exception(er)
+ return
+ else:
+ y = e.chat_id
+ if not SourceM.contains(y):
+ SourceM.add(y)
+ await e.eor(get_string("cha_2"))
+ ultroid_bot.add_handler(autopost_func, events.NewMessage())
+ else:
+ await e.eor(get_string("cha_3"))
+
+
+@ultroid_cmd(pattern="dsource( (.*)|$)")
+async def dd(event):
+ chat_id = event.pattern_match.group(1).strip()
+ x = await event.eor(get_string("com_1"))
+ if chat_id == "all":
+ await x.edit(get_string("bd_8"))
+ udB.del_key("CH_SOURCE")
+ await x.edit(get_string("cha_4"))
+ return
+ if chat_id:
+ try:
+ y = await event.client.parse_id(chat_id)
+ except Exception as er:
+ LOGS.exception(er)
+ return
+ else:
+ y = event.chat_id
+ if SourceM.contains(y):
+ SourceM.remove(y)
+ await eor(x, get_string("cha_5"), time=5)
+ else:
+ await eor(x, "Source channel is already removed from database. ", time=3)
+
+
+@ultroid_cmd(pattern="listsource")
+async def list_all(event):
+ x = await event.eor(get_string("com_1"))
+ num = SourceM.count()
+ if not num:
+ return await eor(x, "No chats were added.", time=5)
+ msg = get_string("cha_8")
+ channels = SourceM.get()
+ for channel in channels:
+ name = ""
+ try:
+ name = get_display_name(await event.client.get_entity(int(channel)))
+ except BaseException:
+ name = ""
+ msg += f"\n=> **{name}** [`{channel}`]"
+ msg += f"\nTotal {num} channels."
+ if len(msg) > 4096:
+ MSG = msg.replace("*", "").replace("`", "")
+ with io.BytesIO(str.encode(MSG)) as out_file:
+ out_file.name = "channels.txt"
+ await event.reply(
+ "Channels in database",
+ file=out_file,
+ force_document=True,
+ allow_cache=False,
+ )
+ await x.delete()
+ else:
+ await x.edit(msg)
+
+
+@ultroid_cmd(pattern="adest (.*)")
+async def destination(e):
+ if x := e.pattern_match.group(1).strip():
+ try:
+ y = await e.client.parse_id(x)
+ except Exception as er:
+ LOGS.exception(er)
+ return
+ else:
+ y = e.chat_id
+ if not DestiM.contains(y):
+ DestiM.add(y)
+ await e.eor("Destination added succesfully")
+ else:
+ await e.eor("Destination channel already added")
+
+
+@ultroid_cmd(pattern="ddest( (.*)|$)")
+async def dd(event):
+ chat_id = event.pattern_match.group(1).strip()
+ x = await event.eor(get_string("com_1"))
+ if chat_id == "all":
+ await x.edit(get_string("bd_8"))
+ udB.del_key("CH_DESTINATION")
+ await x.edit("Destinations database cleared.")
+ return
+ if chat_id:
+ try:
+ y = await event.client.parse_id(chat_id)
+ except Exception as er:
+ LOGS.exception(er)
+ return
+ else:
+ y = event.chat_id
+ if DestiM.contains(y):
+ DestiM.remove(y)
+ await eor(x, "Destination removed from database")
+ else:
+ await eor(x, "Destination channel is already removed from database. ", time=5)
+
+
+@ultroid_cmd(pattern="listdest")
+async def list_all(event):
+ ultroid_bot = event.client
+ x = await event.eor(get_string("com_1"))
+ channels = DestiM.get()
+ num = len(channels)
+ if not num:
+ return await eor(x, "No chats were added.", time=5)
+ msg = get_string("cha_7")
+ for channel in channels:
+ name = ""
+ try:
+ name = get_display_name(await ultroid_bot.get_entity(int(channel)))
+ except BaseException:
+ name = ""
+ msg += f"\n=> **{name}** [`{channel}`]"
+ msg += f"\nTotal {num} channels."
+ if len(msg) > 4096:
+ MSG = msg.replace("*", "").replace("`", "")
+ with io.BytesIO(str.encode(MSG)) as out_file:
+ out_file.name = "channels.txt"
+ await ultroid_bot.send_file(
+ event.chat_id,
+ out_file,
+ force_document=True,
+ allow_cache=False,
+ caption="Destination channels in database",
+ reply_to=event,
+ )
+ await x.delete()
+ else:
+ await x.edit(msg)
+
+
+if udB.get_key("AUTOPOST"):
+ ultroid_bot.add_handler(autopost_func, events.NewMessage())
diff --git a/plugins/chatbot.py b/plugins/chatbot.py
new file mode 100644
index 0000000000000000000000000000000000000000..f050be1955b3554d4cffb494fd03755f6eda9d90
--- /dev/null
+++ b/plugins/chatbot.py
@@ -0,0 +1,89 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_chatbot")
+
+
+from pyUltroid.fns.tools import get_chatbot_reply
+
+from . import LOGS, eod, get_string, inline_mention, udB, ultroid_cmd
+
+
+@ultroid_cmd(pattern="repai")
+async def im_lonely_chat_with_me(event):
+ if event.reply_to:
+ message = (await event.get_reply_message()).message
+ else:
+ try:
+ message = event.text.split(" ", 1)[1]
+ except IndexError:
+ return await eod(event, get_string("tban_1"), time=10)
+ reply_ = await get_chatbot_reply(message=message)
+ await event.eor(reply_)
+
+
+@ultroid_cmd(pattern="addai")
+async def add_chatBot(event):
+ await chat_bot_fn(event, type_="add")
+
+
+@ultroid_cmd(pattern="remai")
+async def rem_chatBot(event):
+ await chat_bot_fn(event, type_="remov")
+
+
+@ultroid_cmd(pattern="listai")
+async def lister(event):
+ key = udB.get_key("CHATBOT_USERS") or {}
+ users = key.get(event.chat_id, [])
+ if not users:
+ return await event.eor(get_string("chab_2"), time=5)
+ msg = "**Total List Of AI Enabled Users In This Chat :**\n\n"
+ for i in users:
+ try:
+ user = await event.client.get_entity(int(i))
+ user = inline_mention(user)
+ except BaseException:
+ user = f"`{i}`"
+ msg += f"⢠{user}\n"
+ await event.eor(msg, link_preview=False)
+
+
+async def chat_bot_fn(event, type_):
+ if event.reply_to:
+ user_ = (await event.get_reply_message()).sender
+ else:
+ temp = event.text.split(maxsplit=1)
+ try:
+ user_ = await event.client.get_entity(await event.client.parse_id(temp[1]))
+ except BaseException as er:
+ LOGS.exception(er)
+ user_ = event.chat if event.is_private else None
+ if not user_:
+ return await eod(
+ event,
+ get_string("chab_1"),
+ )
+ key = udB.get_key("CHATBOT_USERS") or {}
+ chat = event.chat_id
+ user = user_.id
+ if type_ == "add":
+ if key.get(chat):
+ if user not in key[chat]:
+ key[chat].append(user)
+ else:
+ key.update({chat: [user]})
+ elif type_ == "remov":
+ if key.get(chat):
+ if user in key[chat]:
+ key[chat].remove(user)
+ if chat in key and not key[chat]:
+ del key[chat]
+ udB.set_key("CHATBOT_USERS", key)
+ await event.eor(f"**ChatBot:**\n{type_}ed {inline_mention(user_)}")
diff --git a/plugins/chats.py b/plugins/chats.py
new file mode 100644
index 0000000000000000000000000000000000000000..2ef171b1de3fd9f5ac67936cd116d1c9885189fe
--- /dev/null
+++ b/plugins/chats.py
@@ -0,0 +1,368 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+from . import get_help
+
+__doc__ = get_help("help_chats")
+
+
+from telethon.errors import ChatAdminRequiredError as no_admin
+from telethon.tl.functions.channels import (
+ CreateChannelRequest,
+ DeleteChannelRequest,
+ EditPhotoRequest,
+ GetFullChannelRequest,
+ UpdateUsernameRequest,
+)
+from telethon.tl.functions.messages import (
+ CreateChatRequest,
+ ExportChatInviteRequest,
+ GetFullChatRequest,
+)
+from telethon.tl.types import (
+ ChannelParticipantsKicked,
+ User,
+ UserStatusEmpty,
+ UserStatusLastMonth,
+ UserStatusLastWeek,
+ UserStatusOffline,
+ UserStatusOnline,
+ UserStatusRecently,
+)
+
+from . import HNDLR, LOGS, asst, con, get_string, mediainfo, os, types, udB, ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="delchat",
+ groups_only=True,
+)
+async def _(e):
+ xx = await e.eor(get_string("com_1"))
+ try:
+ match = e.text.split(" ", maxsplit=1)[1]
+ chat = await e.client.parse_id(match)
+ except IndexError:
+ chat = e.chat_id
+ try:
+ await e.client(DeleteChannelRequest(chat))
+ except TypeError:
+ return await xx.eor(get_string("chats_1"), time=10)
+ except no_admin:
+ return await xx.eor(get_string("chats_2"), time=10)
+ await e.client.send_message(
+ int(udB.get_key("LOG_CHANNEL")), get_string("chats_6").format(e.chat_id)
+ )
+
+
+@ultroid_cmd(
+ pattern="getlink( (.*)|$)",
+ groups_only=True,
+ manager=True,
+)
+async def _(e):
+ reply = await e.get_reply_message()
+ match = e.pattern_match.group(1).strip()
+ if reply and not isinstance(reply.sender, User):
+ chat = await reply.get_sender()
+ else:
+ chat = await e.get_chat()
+ if hasattr(chat, "username") and chat.username:
+ return await e.eor(f"Username: @{chat.username}")
+ request, usage, title, link = None, None, None, None
+ if match:
+ split = match.split(maxsplit=1)
+ request = split[0] in ["r", "request"]
+ title = "Created by Ultroid"
+ if len(split) > 1:
+ match = split[1]
+ spli = match.split(maxsplit=1)
+ if spli[0].isdigit():
+ usage = int(spli[0])
+ if len(spli) > 1:
+ title = spli[1]
+ elif not request:
+ if match.isdigit():
+ usage = int(match)
+ else:
+ title = match
+ if request and usage:
+ usage = 0
+ if request or title:
+ try:
+ r = await e.client(
+ ExportChatInviteRequest(
+ e.chat_id,
+ request_needed=request,
+ usage_limit=usage,
+ title=title,
+ ),
+ )
+ except no_admin:
+ return await e.eor(get_string("chats_2"), time=10)
+ link = r.link
+ else:
+ if isinstance(chat, types.Chat):
+ FC = await e.client(GetFullChatRequest(chat.id))
+ elif isinstance(chat, types.Channel):
+ FC = await e.client(GetFullChannelRequest(chat.id))
+ else:
+ return
+ Inv = FC.full_chat.exported_invite
+ if Inv and not Inv.revoked:
+ link = Inv.link
+ if link:
+ return await e.eor(f"Link:- {link}")
+ await e.eor("`Failed to getlink!\nSeems like link is inaccessible to you...`")
+
+
+@ultroid_cmd(
+ pattern="create (b|g|c)(?: |$)(.*)",
+)
+async def _(e):
+ type_of_group = e.pattern_match.group(1).strip()
+ group_name = e.pattern_match.group(2)
+ username = None
+ if " ; " in group_name:
+ group_ = group_name.split(" ; ", maxsplit=1)
+ group_name = group_[0]
+ username = group_[1]
+ xx = await e.eor(get_string("com_1"))
+ if type_of_group == "b":
+ try:
+ r = await e.client(
+ CreateChatRequest(
+ users=[asst.me.username],
+ title=group_name,
+ ),
+ )
+ created_chat_id = r.chats[0].id
+ result = await e.client(
+ ExportChatInviteRequest(
+ peer=created_chat_id,
+ ),
+ )
+ await xx.edit(
+ get_string("chats_4").format(group_name, result.link),
+ link_preview=False,
+ )
+ except Exception as ex:
+ await xx.edit(str(ex))
+ elif type_of_group in ["g", "c"]:
+ try:
+ r = await e.client(
+ CreateChannelRequest(
+ title=group_name,
+ about=get_string("chats_5"),
+ megagroup=type_of_group != "c",
+ )
+ )
+
+ created_chat_id = r.chats[0].id
+ if username:
+ await e.client(UpdateUsernameRequest(created_chat_id, username))
+ result = f"https://t.me/{username}"
+ else:
+ result = (
+ await e.client(
+ ExportChatInviteRequest(
+ peer=created_chat_id,
+ ),
+ )
+ ).link
+ await xx.edit(
+ get_string("chats_6").format(f"[{group_name}]({result})"),
+ link_preview=False,
+ )
+ except Exception as ex:
+ await xx.edit(str(ex))
+
+
+# ---------------------------------------------------------------- #
+
+
+@ultroid_cmd(
+ pattern="setgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
+)
+async def _(ult):
+ if not ult.is_reply:
+ return await ult.eor("`Reply to a Media..`", time=5)
+ match = ult.pattern_match.group(1).strip()
+ if not ult.client._bot and match:
+ try:
+ chat = await ult.client.parse_id(match)
+ except Exception as ok:
+ return await ult.eor(str(ok))
+ else:
+ chat = ult.chat_id
+ reply = await ult.get_reply_message()
+ if reply.photo or reply.sticker or reply.video:
+ replfile = await reply.download_media()
+ elif reply.document and reply.document.thumbs:
+ replfile = await reply.download_media(thumb=-1)
+ else:
+ return await ult.eor("Reply to a Photo or Video..")
+ mediain = mediainfo(reply.media)
+ if "animated" in mediain:
+ replfile = await con.convert(replfile, convert_to="mp4")
+ else:
+ replfile = await con.convert(
+ replfile, outname="chatphoto", allowed_formats=["jpg", "png", "mp4"]
+ )
+ file = await ult.client.upload_file(replfile)
+ try:
+ if "pic" not in mediain:
+ file = types.InputChatUploadedPhoto(video=file)
+ await ult.client(EditPhotoRequest(chat, file))
+ await ult.eor("`Group Photo has Successfully Changed !`", time=5)
+ except Exception as ex:
+ await ult.eor(f"Error occured.\n`{str(ex)}`", time=5)
+ os.remove(replfile)
+
+
+@ultroid_cmd(
+ pattern="delgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
+)
+async def _(ult):
+ match = ult.pattern_match.group(1).strip()
+ chat = ult.chat_id
+ if not ult.client._bot and match:
+ chat = match
+ try:
+ await ult.client(EditPhotoRequest(chat, types.InputChatPhotoEmpty()))
+ text = "`Removed Chat Photo..`"
+ except Exception as E:
+ text = str(E)
+ return await ult.eor(text, time=5)
+
+
+@ultroid_cmd(pattern="unbanall$", manager=True, admins_only=True, require="ban_users")
+async def _(event):
+ xx = await event.eor("Searching Participant Lists.")
+ p = 0
+ title = (await event.get_chat()).title
+ async for i in event.client.iter_participants(
+ event.chat_id,
+ filter=ChannelParticipantsKicked,
+ aggressive=True,
+ ):
+ try:
+ await event.client.edit_permissions(event.chat_id, i, view_messages=True)
+ p += 1
+ except no_admin:
+ pass
+ except BaseException as er:
+ LOGS.exception(er)
+ await xx.eor(f"{title}: {p} unbanned", time=5)
+
+
+@ultroid_cmd(
+ pattern="rmusers( (.*)|$)",
+ groups_only=True,
+ admins_only=True,
+ fullsudo=True,
+)
+async def _(event):
+ xx = await event.eor(get_string("com_1"))
+ input_str = event.pattern_match.group(1).strip()
+ p, a, b, c, d, m, n, y, w, o, q, r = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ async for i in event.client.iter_participants(event.chat_id):
+ p += 1 # Total Count
+ if isinstance(i.status, UserStatusEmpty):
+ if "empty" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ y += 1
+ if isinstance(i.status, UserStatusLastMonth):
+ if "month" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ m += 1
+ if isinstance(i.status, UserStatusLastWeek):
+ if "week" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ w += 1
+ if isinstance(i.status, UserStatusOffline):
+ if "offline" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ o += 1
+ if isinstance(i.status, UserStatusOnline):
+ if "online" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ q += 1
+ if isinstance(i.status, UserStatusRecently):
+ if "recently" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ r += 1
+ if i.bot:
+ if "bot" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ b += 1
+ elif i.deleted:
+ if "deleted" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ d += 1
+ elif i.status is None:
+ if "none" in input_str:
+ try:
+ await event.client.kick_participant(event.chat_id, i)
+ c += 1
+ except BaseException:
+ pass
+ else:
+ n += 1
+ if input_str:
+ required_string = f"**>> Kicked** `{c} / {p}` **users**\n\n"
+ else:
+ required_string = f"**>> Total** `{p}` **users**\n\n"
+ required_string += f" `{HNDLR}rmusers deleted` **â˘â˘** `{d}`\n"
+ required_string += f" `{HNDLR}rmusers empty` **â˘â˘** `{y}`\n"
+ required_string += f" `{HNDLR}rmusers month` **â˘â˘** `{m}`\n"
+ required_string += f" `{HNDLR}rmusers week` **â˘â˘** `{w}`\n"
+ required_string += f" `{HNDLR}rmusers offline` **â˘â˘** `{o}`\n"
+ required_string += f" `{HNDLR}rmusers online` **â˘â˘** `{q}`\n"
+ required_string += f" `{HNDLR}rmusers recently` **â˘â˘** `{r}`\n"
+ required_string += f" `{HNDLR}rmusers bot` **â˘â˘** `{b}`\n"
+ required_string += f" `{HNDLR}rmusers none` **â˘â˘** `{n}`"
+ await xx.eor(required_string)
diff --git a/plugins/cleanaction.py b/plugins/cleanaction.py
new file mode 100644
index 0000000000000000000000000000000000000000..ebc65752f3267e175da561ea383edc31cb5bfa20
--- /dev/null
+++ b/plugins/cleanaction.py
@@ -0,0 +1,48 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_cleanaction")
+
+
+from telethon.utils import get_display_name
+
+from . import get_string, udB, ultroid_cmd
+
+
+@ultroid_cmd(pattern="addclean$", admins_only=True)
+async def _(e):
+ key = udB.get_key("CLEANCHAT") or []
+ if e.chat_id in key:
+ return await eod(e, get_string("clan_5"))
+ key.append(e.chat_id)
+ udB.set_key("CLEANCHAT", key)
+ await e.eor(get_string("clan_1"), time=5)
+
+
+@ultroid_cmd(pattern="remclean$")
+async def _(e):
+ key = udB.get_key("CLEANCHAT") or []
+ if e.chat_id in key:
+ key.remove(e.chat_id)
+ udB.set_key("CLEANCHAT", key)
+ await e.eor(get_string("clan_2"), time=5)
+
+
+@ultroid_cmd(pattern="listclean$")
+async def _(e):
+ if k := udB.get_key("CLEANCHAT"):
+ o = ""
+ for x in k:
+ try:
+ title = get_display_name(await e.client.get_entity(x))
+ except BaseException:
+ title = get_string("clan_3")
+ o += f"{x} {title}\n"
+ return await e.eor(o)
+ await e.eor(get_string("clan_4"), time=5)
diff --git a/plugins/compressor.py b/plugins/compressor.py
new file mode 100644
index 0000000000000000000000000000000000000000..4161a9f4fa6d397ccd225ceda0ef031f80458a1b
--- /dev/null
+++ b/plugins/compressor.py
@@ -0,0 +1,175 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_compressor")
+
+
+import asyncio
+import os
+import re
+import time
+from datetime import datetime as dt
+
+from telethon.errors.rpcerrorlist import MessageNotModifiedError
+from telethon.tl.types import DocumentAttributeVideo
+
+from pyUltroid.fns.tools import metadata
+
+from . import (
+ ULTConfig,
+ bash,
+ downloader,
+ get_string,
+ humanbytes,
+ math,
+ mediainfo,
+ time_formatter,
+ ultroid_cmd,
+ uploader,
+)
+
+
+@ultroid_cmd(pattern="compress( (.*)|$)")
+async def _(e):
+ cr = e.pattern_match.group(1).strip()
+ crf = 27
+ to_stream = False
+ if cr:
+ k = e.text.split()
+ if len(k) == 2:
+ crf = int(k[1]) if k[1].isdigit() else 27
+ elif len(k) > 2:
+ crf = int(k[1]) if k[1].isdigit() else 27
+ to_stream = "stream" in k[2]
+ vido = await e.get_reply_message()
+ if vido and vido.media and "video" in mediainfo(vido.media):
+ if hasattr(vido.media, "document"):
+ vfile = vido.media.document
+ name = vido.file.name
+ else:
+ vfile = vido.media
+ name = ""
+ if not name:
+ name = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
+ xxx = await e.eor(get_string("audiotools_5"))
+ c_time = time.time()
+ file = await downloader(
+ f"resources/downloads/{name}",
+ vfile,
+ xxx,
+ c_time,
+ f"Downloading {name}...",
+ )
+
+ o_size = os.path.getsize(file.name)
+ d_time = time.time()
+ diff = time_formatter((d_time - c_time) * 1000)
+ file_name = (file.name).split("/")[-1]
+ out = file_name.replace(file_name.split(".")[-1], "compressed.mkv")
+ await xxx.edit(
+ f"`Downloaded {file.name} of {humanbytes(o_size)} in {diff}.\nNow Compressing...`"
+ )
+ x, y = await bash(
+ f'mediainfo --fullscan """{file.name}""" | grep "Frame count"'
+ )
+ if y and y.endswith("NOT_FOUND"):
+ return await xxx.edit(f"ERROR: `{y}`")
+ total_frames = x.split(":")[1].split("\n")[0]
+ progress = f"progress-{c_time}.txt"
+ with open(progress, "w"):
+ pass
+ proce = await asyncio.create_subprocess_shell(
+ f'ffmpeg -hide_banner -loglevel quiet -progress {progress} -i """{file.name}""" -preset ultrafast -vcodec libx265 -crf {crf} -c:a copy """{out}""" -y',
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ )
+ while proce.returncode != 0:
+ await asyncio.sleep(3)
+ with open(progress, "r+") as fil:
+ text = fil.read()
+ frames = re.findall("frame=(\\d+)", text)
+ size = re.findall("total_size=(\\d+)", text)
+ speed = 0
+ if len(frames):
+ elapse = int(frames[-1])
+ if len(size):
+ size = int(size[-1])
+ per = elapse * 100 / int(total_frames)
+ time_diff = time.time() - int(d_time)
+ speed = round(elapse / time_diff, 2)
+ if int(speed) != 0:
+ some_eta = ((int(total_frames) - elapse) / speed) * 1000
+ text = f"`Compressing {file_name} at {crf} CRF.\n`"
+ progress_str = "`[{0}{1}] {2}%\n\n`".format(
+ "".join("â" for _ in range(math.floor(per / 5))),
+ "".join("" for _ in range(20 - math.floor(per / 5))),
+ round(per, 2),
+ )
+
+ e_size = f"{humanbytes(size)} of ~{humanbytes((size / per) * 100)}"
+ eta = f"~{time_formatter(some_eta)}"
+ try:
+ await xxx.edit(
+ text
+ + progress_str
+ + "`"
+ + e_size
+ + "`"
+ + "\n\n`"
+ + eta
+ + "`"
+ )
+ except MessageNotModifiedError:
+ pass
+ os.remove(file.name)
+ c_size = os.path.getsize(out)
+ f_time = time.time()
+ difff = time_formatter((f_time - d_time) * 1000)
+ await xxx.edit(
+ f"`Compressed {humanbytes(o_size)} to {humanbytes(c_size)} in {difff}\nTrying to Upload...`"
+ )
+ differ = 100 - ((c_size / o_size) * 100)
+ caption = f"**Original Size: **`{humanbytes(o_size)}`\n"
+ caption += f"**Compressed Size: **`{humanbytes(c_size)}`\n"
+ caption += f"**Compression Ratio: **`{differ:.2f}%`\n"
+ caption += f"\n**Time Taken To Compress: **`{difff}`"
+ mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
+ if to_stream:
+ data = await metadata(out)
+ width = data["width"]
+ height = data["height"]
+ duration = data["duration"]
+ attributes = [
+ DocumentAttributeVideo(
+ duration=duration, w=width, h=height, supports_streaming=True
+ )
+ ]
+ await e.client.send_file(
+ e.chat_id,
+ mmmm,
+ thumb=ULTConfig.thumb,
+ caption=caption,
+ attributes=attributes,
+ force_document=False,
+ reply_to=e.reply_to_msg_id,
+ )
+ else:
+ await e.client.send_file(
+ e.chat_id,
+ mmmm,
+ thumb=ULTConfig.thumb,
+ caption=caption,
+ force_document=True,
+ reply_to=e.reply_to_msg_id,
+ )
+ await xxx.delete()
+ os.remove(out)
+ os.remove(progress)
+ else:
+ await e.eor(get_string("audiotools_8"), time=5)
diff --git a/plugins/converter.py b/plugins/converter.py
new file mode 100644
index 0000000000000000000000000000000000000000..0ed3e36037be740b8b23b96ef8f9073644f8dd47
--- /dev/null
+++ b/plugins/converter.py
@@ -0,0 +1,191 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_converter")
+
+import os
+import time
+
+from . import LOGS
+
+try:
+ import cv2
+except ImportError:
+ cv2 = None
+
+try:
+ from PIL import Image
+except ImportError:
+ LOGS.info(f"{__file__}: PIL not Installed.")
+ Image = None
+
+from telegraph import upload_file as uf
+
+from . import (
+ ULTConfig,
+ bash,
+ con,
+ downloader,
+ get_paste,
+ get_string,
+ udB,
+ ultroid_cmd,
+ uploader,
+)
+
+opn = []
+
+
+@ultroid_cmd(
+ pattern="thumbnail$",
+)
+async def _(e):
+ r = await e.get_reply_message()
+ if r.photo:
+ dl = await r.download_media()
+ elif r.document and r.document.thumbs:
+ dl = await r.download_media(thumb=-1)
+ else:
+ return await e.eor("`Reply to Photo or media with thumb...`")
+ variable = uf(dl)
+ os.remove(dl)
+ nn = f"https://graph.org{variable[0]}"
+ udB.set_key("CUSTOM_THUMBNAIL", str(nn))
+ await bash(f"wget {nn} -O resources/extras/ultroid.jpg")
+ await e.eor(get_string("cvt_6").format(nn), link_preview=False)
+
+
+@ultroid_cmd(
+ pattern="rename( (.*)|$)",
+)
+async def imak(event):
+ reply = await event.get_reply_message()
+ t = time.time()
+ if not reply:
+ return await event.eor(get_string("cvt_1"))
+ inp = event.pattern_match.group(1).strip()
+ if not inp:
+ return await event.eor(get_string("cvt_2"))
+ xx = await event.eor(get_string("com_1"))
+ if reply.media:
+ if hasattr(reply.media, "document"):
+ file = reply.media.document
+ image = await downloader(
+ reply.file.name or str(time.time()),
+ reply.media.document,
+ xx,
+ t,
+ get_string("com_5"),
+ )
+
+ file = image.name
+ else:
+ file = await event.client.download_media(reply.media)
+ if os.path.exists(inp):
+ os.remove(inp)
+ await bash(f'mv """{file}""" """{inp}"""')
+ if not os.path.exists(inp) or os.path.exists(inp) and not os.path.getsize(inp):
+ os.rename(file, inp)
+ k = time.time()
+ xxx = await uploader(inp, inp, k, xx, get_string("com_6"))
+ await event.reply(
+ f"`{xxx.name}`",
+ file=xxx,
+ force_document=True,
+ thumb=ULTConfig.thumb,
+ )
+ os.remove(inp)
+ await xx.delete()
+
+
+conv_keys = {
+ "img": "png",
+ "sticker": "webp",
+ "webp": "webp",
+ "image": "png",
+ "webm": "webm",
+ "gif": "gif",
+ "json": "json",
+ "tgs": "tgs",
+}
+
+
+@ultroid_cmd(
+ pattern="convert( (.*)|$)",
+)
+async def uconverter(event):
+ xx = await event.eor(get_string("com_1"))
+ a = await event.get_reply_message()
+ if a is None:
+ return await event.eor("`Reply to Photo or media with thumb...`")
+ input_ = event.pattern_match.group(1).strip()
+ b = await a.download_media("resources/downloads/")
+ if not b and (a.document and a.document.thumbs):
+ b = await a.download_media(thumb=-1)
+ if not b:
+ return await xx.edit(get_string("cvt_3"))
+ try:
+ convert = conv_keys[input_]
+ except KeyError:
+ return await xx.edit(get_string("sts_3").format("gif/img/sticker/webm"))
+ file = await con.convert(b, outname="ultroid", convert_to=convert)
+ if file:
+ await event.client.send_file(
+ event.chat_id, file, reply_to=event.reply_to_msg_id or event.id
+ )
+ os.remove(file)
+ await xx.delete()
+
+
+@ultroid_cmd(
+ pattern="doc( (.*)|$)",
+)
+async def _(event):
+ input_str = event.pattern_match.group(1).strip()
+ if not (input_str and event.is_reply):
+ return await event.eor(get_string("cvt_1"), time=5)
+ xx = await event.eor(get_string("com_1"))
+ a = await event.get_reply_message()
+ if not a.message:
+ return await xx.edit(get_string("ex_1"))
+ with open(input_str, "w") as b:
+ b.write(str(a.message))
+ await xx.edit(f"**Packing into** `{input_str}`")
+ await event.reply(file=input_str, thumb=ULTConfig.thumb)
+ await xx.delete()
+ os.remove(input_str)
+
+
+@ultroid_cmd(
+ pattern="open( (.*)|$)",
+)
+async def _(event):
+ a = await event.get_reply_message()
+ b = event.pattern_match.group(1).strip()
+ if not ((a and a.media) or (b and os.path.exists(b))):
+ return await event.eor(get_string("cvt_7"), time=5)
+ xx = await event.eor(get_string("com_1"))
+ rem = None
+ if not b:
+ b = await a.download_media()
+ rem = True
+ try:
+ with open(b) as c:
+ d = c.read()
+ except UnicodeDecodeError:
+ return await xx.eor(get_string("cvt_8"), time=5)
+ try:
+ await xx.edit(f"```{d}```")
+ except BaseException:
+ what, key = await get_paste(d)
+ await xx.edit(
+ f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN](https://spaceb.in/{key})"
+ )
+ if rem:
+ os.remove(b)
diff --git a/plugins/core.py b/plugins/core.py
new file mode 100644
index 0000000000000000000000000000000000000000..6664fa5800275464bee832f87e88a1b2238cc5e5
--- /dev/null
+++ b/plugins/core.py
@@ -0,0 +1,124 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+from . import get_help
+
+__doc__ = get_help("help_core")
+
+
+import os
+
+from pyUltroid.startup.loader import load_addons
+
+from . import LOGS, async_searcher, eod, get_string, safeinstall, ultroid_cmd, un_plug
+
+
+@ultroid_cmd(pattern="install", fullsudo=True)
+async def install(event):
+ await safeinstall(event)
+
+
+@ultroid_cmd(
+ pattern=r"unload( (.*)|$)",
+)
+async def unload(event):
+ shortname = event.pattern_match.group(1).strip()
+ if not shortname:
+ await event.eor(get_string("core_9"))
+ return
+ lsd = os.listdir("addons")
+ zym = f"{shortname}.py"
+ if zym in lsd:
+ try:
+ un_plug(shortname)
+ await event.eor(f"**UÉ´Ęá´á´á´
á´á´
** `{shortname}` **Sá´á´á´á´ssŇá´ĘĘĘ.**", time=3)
+ except Exception as ex:
+ LOGS.exception(ex)
+ return await event.eor(str(ex))
+ elif zym in os.listdir("plugins"):
+ return await event.eor(get_string("core_11"), time=3)
+ else:
+ await event.eor(f"**Ná´ PĘá´É˘ÉŞÉ´ Ná´á´á´á´
** `{shortname}`", time=3)
+
+
+@ultroid_cmd(
+ pattern=r"uninstall( (.*)|$)",
+)
+async def uninstall(event):
+ shortname = event.pattern_match.group(1).strip()
+ if not shortname:
+ await event.eor(get_string("core_13"))
+ return
+ lsd = os.listdir("addons")
+ zym = f"{shortname}.py"
+ if zym in lsd:
+ try:
+ un_plug(shortname)
+ await event.eor(f"**UÉ´ÉŞÉ´sá´á´ĘĘá´á´
** `{shortname}` **Sá´á´á´á´ssŇá´ĘĘĘ.**", time=3)
+ os.remove(f"addons/{shortname}.py")
+ except Exception as ex:
+ return await event.eor(str(ex))
+ elif zym in os.listdir("plugins"):
+ return await event.eor(get_string("core_15"), time=3)
+ else:
+ return await event.eor(f"**Ná´ PĘá´É˘ÉŞÉ´ Ná´á´á´á´
** `{shortname}`", time=3)
+
+
+@ultroid_cmd(
+ pattern=r"load( (.*)|$)",
+ fullsudo=True,
+)
+async def load(event):
+ shortname = event.pattern_match.group(1).strip()
+ if not shortname:
+ await event.eor(get_string("core_16"))
+ return
+ try:
+ try:
+ un_plug(shortname)
+ except BaseException:
+ pass
+ load_addons(f"addons/{shortname}.py")
+ await event.eor(get_string("core_17").format(shortname), time=3)
+ except Exception as e:
+ LOGS.exception(e)
+ await eod(
+ event,
+ get_string("core_18").format(shortname, e),
+ time=3,
+ )
+
+
+@ultroid_cmd(pattern="getaddons( (.*)|$)", fullsudo=True)
+async def get_the_addons_lol(event):
+ thelink = event.pattern_match.group(1).strip()
+ xx = await event.eor(get_string("com_1"))
+ fool = get_string("gas_1")
+ if thelink is None:
+ return await xx.eor(fool, time=10)
+ split_thelink = thelink.split("/")
+ if not ("raw" in thelink and thelink.endswith(".py")):
+ return await xx.eor(fool, time=10)
+ name_of_it = split_thelink[-1]
+ plug = await async_searcher(thelink)
+ fil = f"addons/{name_of_it}"
+ await xx.edit("Packing the codes...")
+ with open(fil, "w", encoding="utf-8") as uult:
+ uult.write(plug)
+ await xx.edit("Packed. Now loading the plugin..")
+ shortname = name_of_it.split(".")[0]
+ try:
+ load_addons(fil)
+ await xx.eor(get_string("core_17").format(shortname), time=15)
+ except Exception as e:
+ LOGS.exception(e)
+ await eod(
+ xx,
+ get_string("core_18").format(shortname, e),
+ time=3,
+ )
diff --git a/plugins/database.py b/plugins/database.py
new file mode 100644
index 0000000000000000000000000000000000000000..8c50ea2a3a80b452217dfdfdeca18fa4ae380279
--- /dev/null
+++ b/plugins/database.py
@@ -0,0 +1,77 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+
+from . import get_help
+
+__doc__ = get_help("help_database")
+
+
+import re
+
+from . import Redis, eor, get_string, udB, ultroid_cmd
+
+
+@ultroid_cmd(pattern="setdb( (.*)|$)", fullsudo=True)
+async def _(ult):
+ match = ult.pattern_match.group(1).strip()
+ if not match:
+ return await ult.eor("Provide key and value to set!")
+ try:
+ delim = " " if re.search("[|]", match) is None else " | "
+ data = match.split(delim, maxsplit=1)
+ if data[0] in ["--extend", "-e"]:
+ data = data[1].split(maxsplit=1)
+ data[1] = f"{str(udB.get_key(data[0]))} {data[1]}"
+ udB.set_key(data[0], data[1])
+ await ult.eor(
+ f"**DB Key Value Pair Updated\nKey :** `{data[0]}`\n**Value :** `{data[1]}`"
+ )
+
+ except BaseException:
+ await ult.eor(get_string("com_7"))
+
+
+@ultroid_cmd(pattern="deldb( (.*)|$)", fullsudo=True)
+async def _(ult):
+ key = ult.pattern_match.group(1).strip()
+ if not key:
+ return await ult.eor("Give me a key name to delete!", time=5)
+ _ = key.split(maxsplit=1)
+ try:
+ if _[0] == "-m":
+ for key in _[1].split():
+ k = udB.del_key(key)
+ key = _[1]
+ else:
+ k = udB.del_key(key)
+ if k == 0:
+ return await ult.eor("`No Such Key.`")
+ await ult.eor(f"`Successfully deleted key {key}`")
+ except BaseException:
+ await ult.eor(get_string("com_7"))
+
+
+@ultroid_cmd(pattern="rendb( (.*)|$)", fullsudo=True)
+async def _(ult):
+ match = ult.pattern_match.group(1).strip()
+ if not match:
+ return await ult.eor("`Provide Keys name to rename..`")
+ delim = " " if re.search("[|]", match) is None else " | "
+ data = match.split(delim)
+ if Redis(data[0]):
+ try:
+ udB.rename(data[0], data[1])
+ await eor(
+ ult,
+ f"**DB Key Rename Successful\nOld Key :** `{data[0]}`\n**New Key :** `{data[1]}`",
+ )
+
+ except BaseException:
+ await ult.eor(get_string("com_7"))
+ else:
+ await ult.eor("Key not found")
diff --git a/plugins/devtools.py b/plugins/devtools.py
new file mode 100644
index 0000000000000000000000000000000000000000..4ce74d70f8f20ea224be2927fe2456cf5747cf93
--- /dev/null
+++ b/plugins/devtools.py
@@ -0,0 +1,392 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_devtools")
+
+import inspect
+import sys
+import traceback
+from io import BytesIO, StringIO
+from os import remove
+from pprint import pprint
+
+from telethon.utils import get_display_name
+
+from pyUltroid import _ignore_eval
+
+from . import *
+
+# Used for Formatting Eval Code, if installed
+try:
+ import black
+except ImportError:
+ black = None
+from random import choice
+
+try:
+ from yaml import safe_load
+except ImportError:
+ from pyUltroid.fns.tools import safe_load
+try:
+ from telegraph import upload_file as uf
+except ImportError:
+ uf = None
+from telethon.tl import functions
+
+fn = functions
+
+
+@ultroid_cmd(
+ pattern="(sysinfo|neofetch)$",
+)
+async def _(e):
+ xx = await e.eor(get_string("com_1"))
+ x, y = await bash("neofetch|sed 's/\x1B\\[[0-9;\\?]*[a-zA-Z]//g' >> neo.txt")
+ if y and y.endswith("NOT_FOUND"):
+ return await xx.edit(f"Error: `{y}`")
+ with open("neo.txt", "r", encoding="utf-8") as neo:
+ p = (neo.read()).replace("\n\n", "")
+ haa = await Carbon(code=p, file_name="neofetch", backgroundColor=choice(ATRA_COL))
+ if isinstance(haa, dict):
+ await xx.edit(f"`{haa}`")
+ else:
+ await e.reply(file=haa)
+ await xx.delete()
+ remove("neo.txt")
+
+
+@ultroid_cmd(pattern="bash", fullsudo=True, only_devs=True)
+async def _(event):
+ carb, rayso, yamlf = None, None, False
+ try:
+ cmd = event.text.split(" ", maxsplit=1)[1]
+ if cmd.split()[0] in ["-c", "--carbon"]:
+ cmd = cmd.split(maxsplit=1)[1]
+ carb = True
+ if cmd.split()[0] in ["-r", "--rayso"]:
+ cmd = cmd.split(maxsplit=1)[1]
+ rayso = True
+ except IndexError:
+ return await event.eor(get_string("devs_1"), time=10)
+ xx = await event.eor(get_string("com_1"))
+ reply_to_id = event.reply_to_msg_id or event.id
+ d_time = time.perf_counter()
+ d_time = (time.perf_counter() - d_time) * 1000
+ stdout, stderr = await bash(cmd, run_code=1)
+ timeform = time_formatter(d_time)
+ if timeform == "0s":
+ await asyncio.sleep(0.6)
+ timeform = f"{d_time:.3f}ms"
+ OUT = f"**â BASH** (__{timeform}__)\n{cmd}\n\n"
+ err, out = "", ""
+ if stderr:
+ err = f"**⢠ERROR:** \n`{stderr}`\n\n"
+ if stdout:
+ if (carb or udB.get_key("CARBON_ON_BASH")) and (
+ event.is_private
+ or event.chat.admin_rights
+ or event.chat.creator
+ or event.chat.default_banned_rights.embed_links
+ ):
+ li = await Carbon(
+ code=stdout,
+ file_name="bash",
+ download=True,
+ backgroundColor=choice(ATRA_COL),
+ )
+ if isinstance(li, dict):
+ await xx.edit(
+ f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
+ )
+ return
+ url = f"https://graph.org{uf(li)[-1]}"
+ OUT = f"[\xad]({url}){OUT}"
+ out = "**⢠OUTPUT:**"
+ remove(li)
+ elif (rayso or udB.get_key("RAYSO_ON_BASH")) and (
+ event.is_private
+ or event.chat.admin_rights
+ or event.chat.creator
+ or event.chat.default_banned_rights.embed_links
+ ):
+ li = await Carbon(
+ code=stdout,
+ file_name="bash",
+ download=True,
+ backgroundColor=choice(ATRA_COL),
+ rayso=True,
+ )
+ if isinstance(li, dict):
+ await xx.edit(
+ f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
+ )
+ return
+ url = f"https://graph.org{uf(li)[-1]}"
+ OUT = f"[\xad]({url}){OUT}"
+ out = "**⢠OUTPUT:**"
+ remove(li)
+ else:
+ if "pip" in cmd and all(":" in line for line in stdout.split("\n")):
+ try:
+ load = safe_load(stdout)
+ stdout = ""
+ for data in list(load.keys()):
+ res = load[data] or ""
+ if res and "http" not in str(res):
+ res = f"`{res}`"
+ stdout += f"**{data}** : {res}\n"
+ yamlf = True
+ except Exception as er:
+ stdout = f"`{stdout}`"
+ LOGS.exception(er)
+ else:
+ stdout = f"`{stdout}`"
+ out = f"**⢠OUTPUT:**\n{stdout}"
+ if not stderr and not stdout:
+ out = "**⢠OUTPUT:**\n`Success`"
+ OUT += err + out
+ if len(OUT) > 4096:
+ ultd = err + out
+ with BytesIO(str.encode(ultd)) as out_file:
+ out_file.name = "bash.txt"
+ await event.client.send_file(
+ event.chat_id,
+ out_file,
+ force_document=True,
+ thumb=ULTConfig.thumb,
+ allow_cache=False,
+ caption=f"`{cmd}`" if len(cmd) < 998 else None,
+ reply_to=reply_to_id,
+ )
+
+ await xx.delete()
+ else:
+ await xx.edit(OUT, link_preview=not yamlf)
+
+
+pp = pprint # ignore: pylint
+bot = ultroid = ultroid_bot
+
+
+class u:
+ _ = ""
+
+
+def _parse_eval(value=None):
+ if not value:
+ return value
+ if hasattr(value, "stringify"):
+ try:
+ return value.stringify()
+ except TypeError:
+ pass
+ elif isinstance(value, dict):
+ try:
+ return json_parser(value, indent=1)
+ except BaseException:
+ pass
+ elif isinstance(value, list):
+ newlist = "["
+ for index, child in enumerate(value):
+ newlist += "\n " + str(_parse_eval(child))
+ if index < len(value) - 1:
+ newlist += ","
+ newlist += "\n]"
+ return newlist
+ return str(value)
+
+
+@ultroid_cmd(pattern="eval", fullsudo=True, only_devs=True)
+async def _(event):
+ try:
+ cmd = event.text.split(maxsplit=1)[1]
+ except IndexError:
+ return await event.eor(get_string("devs_2"), time=5)
+ xx = None
+ mode = ""
+ spli = cmd.split()
+
+ async def get_():
+ try:
+ cm = cmd.split(maxsplit=1)[1]
+ except IndexError:
+ await event.eor("->> Wrong Format <<-")
+ cm = None
+ return cm
+
+ if spli[0] in ["-s", "--silent"]:
+ await event.delete()
+ mode = "silent"
+ elif spli[0] in ["-n", "-noedit"]:
+ mode = "no-edit"
+ xx = await event.reply(get_string("com_1"))
+ elif spli[0] in ["-gs", "--source"]:
+ mode = "gsource"
+ elif spli[0] in ["-ga", "--args"]:
+ mode = "g-args"
+ if mode:
+ cmd = await get_()
+ if not cmd:
+ return
+ if not mode == "silent" and not xx:
+ xx = await event.eor(get_string("com_1"))
+ if black:
+ try:
+ cmd = black.format_str(cmd, mode=black.Mode())
+ except BaseException:
+ # Consider it as Code Error, and move on to be shown ahead.
+ pass
+ reply_to_id = event.reply_to_msg_id or event
+ if any(item in cmd for item in KEEP_SAFE().All) and (
+ not (event.out or event.sender_id == ultroid_bot.uid)
+ ):
+ warning = await event.forward_to(udB.get_key("LOG_CHANNEL"))
+ await warning.reply(
+ f"Malicious Activities suspected by {inline_mention(await event.get_sender())}"
+ )
+ _ignore_eval.append(event.sender_id)
+ return await xx.edit(
+ "`Malicious Activities suspectedâ ď¸!\nReported to owner. Aborted this request!`"
+ )
+ old_stderr = sys.stderr
+ old_stdout = sys.stdout
+ redirected_output = sys.stdout = StringIO()
+ redirected_error = sys.stderr = StringIO()
+ stdout, stderr, exc, timeg = None, None, None, None
+ tima = time.time()
+ try:
+ value = await aexec(cmd, event)
+ except Exception:
+ value = None
+ exc = traceback.format_exc()
+ tima = time.time() - tima
+ stdout = redirected_output.getvalue()
+ stderr = redirected_error.getvalue()
+ sys.stdout = old_stdout
+ sys.stderr = old_stderr
+ if value:
+ try:
+ if mode == "gsource":
+ exc = inspect.getsource(value)
+ elif mode == "g-args":
+ args = inspect.signature(value).parameters.values()
+ name = ""
+ if hasattr(value, "__name__"):
+ name = value.__name__
+ exc = f"**{name}**\n\n" + "\n ".join([str(arg) for arg in args])
+ except Exception:
+ exc = traceback.format_exc()
+ evaluation = exc or stderr or stdout or _parse_eval(value) or get_string("instu_4")
+ if mode == "silent":
+ if exc:
+ msg = f"⢠EVAL ERROR\n\n⢠CHAT: {get_display_name(event.chat)} [{event.chat_id}]"
+ msg += f"\n\nâ CODE:\n{cmd}\n\nâ ERROR:\n{exc}"
+ log_chat = udB.get_key("LOG_CHANNEL")
+ if len(msg) > 4000:
+ with BytesIO(msg.encode()) as out_file:
+ out_file.name = "Eval-Error.txt"
+ return await event.client.send_message(
+ log_chat, f"`{cmd}`", file=out_file
+ )
+ await event.client.send_message(log_chat, msg, parse_mode="html")
+ return
+ tmt = tima * 1000
+ timef = time_formatter(tmt)
+ timeform = timef if not timef == "0s" else f"{tmt:.3f}ms"
+ final_output = "__âş__ **EVAL** (__in {}__)\n```{}``` \n\n __âş__ **OUTPUT**: \n```{}``` \n".format(
+ timeform,
+ cmd,
+ evaluation,
+ )
+ if len(final_output) > 4096:
+ final_output = evaluation
+ with BytesIO(str.encode(final_output)) as out_file:
+ out_file.name = "eval.txt"
+ await event.client.send_file(
+ event.chat_id,
+ out_file,
+ force_document=True,
+ thumb=ULTConfig.thumb,
+ allow_cache=False,
+ caption=f"```{cmd}```" if len(cmd) < 998 else None,
+ reply_to=reply_to_id,
+ )
+ return await xx.delete()
+ await xx.edit(final_output)
+
+
+def _stringify(text=None, *args, **kwargs):
+ if text:
+ u._ = text
+ text = _parse_eval(text)
+ return print(text, *args, **kwargs)
+
+
+async def aexec(code, event):
+ exec(
+ (
+ "async def __aexec(e, client): "
+ + "\n print = p = _stringify"
+ + "\n message = event = e"
+ + "\n u.r = reply = await event.get_reply_message()"
+ + "\n chat = event.chat_id"
+ + "\n u.lr = locals()"
+ )
+ + "".join(f"\n {l}" for l in code.split("\n"))
+ )
+
+ return await locals()["__aexec"](event, event.client)
+
+
+DUMMY_CPP = """#include
+using namespace std;
+
+int main(){
+!code
+}
+"""
+
+
+@ultroid_cmd(pattern="cpp", only_devs=True)
+async def doie(e):
+ match = e.text.split(" ", maxsplit=1)
+ try:
+ match = match[1]
+ except IndexError:
+ return await e.eor(get_string("devs_3"))
+ msg = await e.eor(get_string("com_1"))
+ if "main(" not in match:
+ new_m = "".join(" " * 4 + i + "\n" for i in match.split("\n"))
+ match = DUMMY_CPP.replace("!code", new_m)
+ open("cpp-ultroid.cpp", "w").write(match)
+ m = await bash("g++ -o CppUltroid cpp-ultroid.cpp")
+ o_cpp = f"⢠**Eval-Cpp**\n`{match}`"
+ if m[1]:
+ o_cpp += f"\n\n**⢠Error :**\n`{m[1]}`"
+ if len(o_cpp) > 3000:
+ os.remove("cpp-ultroid.cpp")
+ if os.path.exists("CppUltroid"):
+ os.remove("CppUltroid")
+ with BytesIO(str.encode(o_cpp)) as out_file:
+ out_file.name = "error.txt"
+ return await msg.reply(f"`{match}`", file=out_file)
+ return await eor(msg, o_cpp)
+ m = await bash("./CppUltroid")
+ if m[0] != "":
+ o_cpp += f"\n\n**⢠Output :**\n`{m[0]}`"
+ if m[1]:
+ o_cpp += f"\n\n**⢠Error :**\n`{m[1]}`"
+ if len(o_cpp) > 3000:
+ with BytesIO(str.encode(o_cpp)) as out_file:
+ out_file.name = "eval.txt"
+ await msg.reply(f"`{match}`", file=out_file)
+ else:
+ await eor(msg, o_cpp)
+ os.remove("CppUltroid")
+ os.remove("cpp-ultroid.cpp")
diff --git a/plugins/downloadupload.py b/plugins/downloadupload.py
new file mode 100644
index 0000000000000000000000000000000000000000..003da9fad7ae8c7bd92c83f4c71a44b1b18a83d0
--- /dev/null
+++ b/plugins/downloadupload.py
@@ -0,0 +1,222 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_downloadupload")
+
+import asyncio
+import glob
+import os
+import time
+from datetime import datetime as dt
+
+from aiohttp.client_exceptions import InvalidURL
+from telethon.errors.rpcerrorlist import MessageNotModifiedError
+
+from pyUltroid.fns.helper import time_formatter
+from pyUltroid.fns.tools import get_chat_and_msgid, set_attributes
+
+from . import (
+ LOGS,
+ ULTConfig,
+ downloader,
+ eor,
+ fast_download,
+ get_all_files,
+ get_string,
+ progress,
+ time_formatter,
+ ultroid_cmd,
+)
+
+
+@ultroid_cmd(
+ pattern="download( (.*)|$)",
+)
+async def down(event):
+ matched = event.pattern_match.group(1).strip()
+ msg = await event.eor(get_string("udl_4"))
+ if not matched:
+ return await eor(msg, get_string("udl_5"), time=5)
+ try:
+ splited = matched.split(" | ")
+ link = splited[0]
+ filename = splited[1]
+ except IndexError:
+ filename = None
+ s_time = time.time()
+ try:
+ filename, d = await fast_download(
+ link,
+ filename,
+ progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
+ progress(
+ d,
+ t,
+ msg,
+ s_time,
+ f"Downloading from {link}",
+ )
+ ),
+ )
+ except InvalidURL:
+ return await msg.eor("`Invalid URL provided :(`", time=5)
+ await msg.eor(f"`{filename}` `downloaded in {time_formatter(d*1000)}.`")
+
+
+@ultroid_cmd(
+ pattern="dl( (.*)|$)",
+)
+async def download(event):
+ match = event.pattern_match.group(1).strip()
+ if match and "t.me/" in match:
+ chat, msg = get_chat_and_msgid(match)
+ if not (chat and msg):
+ return await event.eor(get_string("gms_1"))
+ match = ""
+ ok = await event.client.get_messages(chat, ids=msg)
+ elif event.reply_to_msg_id:
+ ok = await event.get_reply_message()
+ else:
+ return await event.eor(get_string("cvt_3"), time=8)
+ xx = await event.eor(get_string("com_1"))
+ if not (ok and ok.media):
+ return await xx.eor(get_string("udl_1"), time=5)
+ s = dt.now()
+ k = time.time()
+ if hasattr(ok.media, "document"):
+ file = ok.media.document
+ mime_type = file.mime_type
+ filename = match or ok.file.name
+ if not filename:
+ if "audio" in mime_type:
+ filename = "audio_" + dt.now().isoformat("_", "seconds") + ".ogg"
+ elif "video" in mime_type:
+ filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
+ try:
+ result = await downloader(
+ f"resources/downloads/{filename}",
+ file,
+ xx,
+ k,
+ f"Downloading {filename}...",
+ )
+
+ except MessageNotModifiedError as err:
+ return await xx.edit(str(err))
+ file_name = result.name
+ else:
+ d = "resources/downloads/"
+ file_name = await event.client.download_media(
+ ok,
+ d,
+ progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
+ progress(
+ d,
+ t,
+ xx,
+ k,
+ get_string("com_5"),
+ ),
+ ),
+ )
+ e = dt.now()
+ t = time_formatter(((e - s).seconds) * 1000)
+ await xx.eor(get_string("udl_2").format(file_name, t))
+
+
+@ultroid_cmd(
+ pattern="ul( (.*)|$)",
+)
+async def _(event):
+ msg = await event.eor(get_string("com_1"))
+ match = event.pattern_match.group(1)
+ if match:
+ match = match.strip()
+ if not event.out and match == ".env":
+ return await event.reply("`You can't do this...`")
+ stream, force_doc, delete, thumb = (
+ False,
+ True,
+ False,
+ ULTConfig.thumb,
+ )
+ if "--stream" in match:
+ stream = True
+ force_doc = False
+ if "--delete" in match:
+ delete = True
+ if "--no-thumb" in match:
+ thumb = None
+ arguments = ["--stream", "--delete", "--no-thumb"]
+ if any(item in match for item in arguments):
+ match = (
+ match.replace("--stream", "")
+ .replace("--delete", "")
+ .replace("--no-thumb", "")
+ .strip()
+ )
+ if match.endswith("/"):
+ match += "*"
+ results = glob.glob(match)
+ if not results and os.path.exists(match):
+ results = [match]
+ if not results:
+ try:
+ await event.reply(file=match)
+ return await event.try_delete()
+ except Exception as er:
+ LOGS.exception(er)
+ return await msg.eor(get_string("ls1"))
+ for result in results:
+ if os.path.isdir(result):
+ c, s = 0, 0
+ for files in get_all_files(result):
+ attributes = None
+ if stream:
+ try:
+ attributes = await set_attributes(files)
+ except KeyError as er:
+ LOGS.exception(er)
+ try:
+ file, _ = await event.client.fast_uploader(
+ files, show_progress=True, event=msg, to_delete=delete
+ )
+ await event.client.send_file(
+ event.chat_id,
+ file,
+ supports_streaming=stream,
+ force_document=force_doc,
+ thumb=thumb,
+ attributes=attributes,
+ caption=f"`Uploaded` `{files}` `in {time_formatter(_*1000)}`",
+ reply_to=event.reply_to_msg_id or event,
+ )
+ s += 1
+ except (ValueError, IsADirectoryError):
+ c += 1
+ break
+ attributes = None
+ if stream:
+ try:
+ attributes = await set_attributes(result)
+ except KeyError as er:
+ LOGS.exception(er)
+ file, _ = await event.client.fast_uploader(
+ result, show_progress=True, event=msg, to_delete=delete
+ )
+ await event.client.send_file(
+ event.chat_id,
+ file,
+ supports_streaming=stream,
+ force_document=force_doc,
+ thumb=thumb,
+ attributes=attributes,
+ caption=f"`Uploaded` `{result}` `in {time_formatter(_*1000)}`",
+ )
+ await msg.try_delete()
diff --git a/plugins/echo.py b/plugins/echo.py
new file mode 100644
index 0000000000000000000000000000000000000000..03c4d0e860a4988ec57111db09abb2216c0102b8
--- /dev/null
+++ b/plugins/echo.py
@@ -0,0 +1,76 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_echo")
+
+
+from telethon.utils import get_display_name
+
+from pyUltroid.dB.echo_db import add_echo, check_echo, list_echo, rem_echo
+
+from . import inline_mention, ultroid_cmd
+
+
+@ultroid_cmd(pattern="addecho( (.*)|$)")
+async def echo(e):
+ r = await e.get_reply_message()
+ if r:
+ user = r.sender_id
+ else:
+ try:
+ user = e.text.split()[1]
+ if user.startswith("@"):
+ ok = await e.client.get_entity(user)
+ user = ok.id
+ else:
+ user = int(user)
+ except BaseException:
+ return await e.eor("Reply To A user.", time=5)
+ if check_echo(e.chat_id, user):
+ return await e.eor("Echo already activated for this user.", time=5)
+ add_echo(e.chat_id, user)
+ ok = await e.client.get_entity(user)
+ user = inline_mention(ok)
+ await e.eor(f"Activated Echo For {user}.")
+
+
+@ultroid_cmd(pattern="remecho( (.*)|$)")
+async def rm(e):
+ r = await e.get_reply_message()
+ if r:
+ user = r.sender_id
+ else:
+ try:
+ user = e.text.split()[1]
+ if user.startswith("@"):
+ ok = await e.client.get_entity(user)
+ user = ok.id
+ else:
+ user = int(user)
+ except BaseException:
+ return await e.eor("Reply To A User.", time=5)
+ if check_echo(e.chat_id, user):
+ rem_echo(e.chat_id, user)
+ ok = await e.client.get_entity(user)
+ user = f"[{get_display_name(ok)}](tg://user?id={ok.id})"
+ return await e.eor(f"Deactivated Echo For {user}.")
+ await e.eor("Echo not activated for this user")
+
+
+@ultroid_cmd(pattern="listecho$")
+async def lstecho(e):
+ if k := list_echo(e.chat_id):
+ user = "**Activated Echo For Users:**\n\n"
+ for x in k:
+ ok = await e.client.get_entity(int(x))
+ kk = f"[{get_display_name(ok)}](tg://user?id={ok.id})"
+ user += f"â˘{kk}" + "\n"
+ await e.eor(user)
+ else:
+ await e.eor("`List is Empty, For echo`", time=5)
diff --git a/plugins/extra.py b/plugins/extra.py
new file mode 100644
index 0000000000000000000000000000000000000000..f9abda572addb4a676be73d4faf38abe6cb60bbc
--- /dev/null
+++ b/plugins/extra.py
@@ -0,0 +1,85 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("extra")
+
+import asyncio
+
+from . import get_string, ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="del$",
+ manager=True,
+)
+async def delete_it(delme):
+ msg_src = await delme.get_reply_message()
+ if not msg_src:
+ return
+ await msg_src.try_delete()
+ await delme.try_delete()
+
+
+@ultroid_cmd(
+ pattern="copy$",
+)
+async def copy(e):
+ reply = await e.get_reply_message()
+ if reply:
+ await reply.reply(reply)
+ return await e.try_delete()
+ await e.eor(get_string("ex_1"), time=5)
+
+
+@ultroid_cmd(
+ pattern="edit",
+)
+async def editer(edit):
+ message = edit.text
+ chat = await edit.get_input_chat()
+ string = str(message[6:])
+ reply = await edit.get_reply_message()
+ if reply and reply.text:
+ try:
+ await reply.edit(string)
+ await edit.delete()
+ except BaseException:
+ pass
+ else:
+ i = 1
+ async for message in edit.client.iter_messages(chat, from_user="me", limit=2):
+ if i == 2:
+ await message.edit(string)
+ await edit.delete()
+ break
+ i += 1
+
+
+@ultroid_cmd(
+ pattern="reply$",
+)
+async def _(e):
+ if e.reply_to_msg_id:
+ chat = e.chat_id
+ try:
+ msg = (await e.client.get_messages(e.chat_id, limit=1, max_id=e.id))[0]
+ except IndexError:
+ return await e.eor(
+ "`You have previously sent no message to reply again...`", time=5
+ )
+ except BaseException as er:
+ return await e.eor(f"**ERROR:** `{er}`")
+ await asyncio.wait(
+ [
+ e.client.delete_messages(chat, [e.id, msg.id]),
+ e.client.send_message(chat, msg, reply_to=e.reply_to_msg_id),
+ ]
+ )
+ else:
+ await e.try_delete()
diff --git a/plugins/fakeaction.py b/plugins/fakeaction.py
new file mode 100644
index 0000000000000000000000000000000000000000..0f4b25492e2c4b9afbae3f6972dd400f2acf504a
--- /dev/null
+++ b/plugins/fakeaction.py
@@ -0,0 +1,36 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_fakeaction")
+
+import math
+import time
+
+from pyUltroid.fns.admins import ban_time
+
+from . import asyncio, get_string, ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="f(typing|audio|contact|document|game|location|sticker|photo|round|video)( (.*)|$)"
+)
+async def _(e):
+ act = e.pattern_match.group(1).strip()
+ t = e.pattern_match.group(2)
+ if act in ["audio", "round", "video"]:
+ act = f"record-{act}"
+ if t.isdigit():
+ t = int(t)
+ elif t.endswith(("s", "h", "d", "m")):
+ t = math.ceil((ban_time(t)) - time.time())
+ else:
+ t = 60
+ await e.eor(get_string("fka_1").format(str(t)), time=5)
+ async with e.client.action(e.chat_id, act):
+ await asyncio.sleep(t)
diff --git a/plugins/fileshare.py b/plugins/fileshare.py
new file mode 100644
index 0000000000000000000000000000000000000000..430e8cd5beddec9e679000014085639e3926bf29
--- /dev/null
+++ b/plugins/fileshare.py
@@ -0,0 +1,95 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_fileshare")
+
+import os
+
+from pyUltroid.dB.filestore_db import del_stored, get_stored_msg, list_all_stored_msgs
+from pyUltroid.fns.tools import get_file_link
+
+from . import HNDLR, asst, get_string, in_pattern, udB, ultroid_bot, ultroid_cmd
+
+
+@ultroid_cmd(pattern="store$")
+async def filestoreplg(event):
+ msg = await event.get_reply_message()
+ if not msg:
+ return await event.eor(get_string("fsh_3"), time=10)
+ # allow storing both messages and media.
+ filehash = await get_file_link(msg)
+ link_to_file = f"https://t.me/{asst.me.username}?start={filehash}"
+ await event.eor(
+ get_string("fsh_2").format(link_to_file),
+ link_preview=False,
+ )
+
+
+@ultroid_cmd("delstored ?(.*)")
+async def _(event):
+ match = event.pattern_match.group(1)
+ if not match:
+ return await event.eor("`Give stored film's link to delete.`", time=5)
+ match = match.split("?start=")
+ botusername = match[0].split("/")[-1]
+ if botusername != asst.me.username:
+ return await event.eor(
+ "`Message/Media of provided link was not stored by this bot.`", time=5
+ )
+ msg_id = get_stored_msg(match[1])
+ if not msg_id:
+ return await event.eor(
+ "`Message/Media of provided link was already deleted.`", time=5
+ )
+ del_stored(match[1])
+ await ultroid_bot.delete_messages(udB.get_key("LOG_CHANNEL"), int(msg_id))
+ await event.eor("__Deleted__")
+
+
+@ultroid_cmd("liststored$")
+async def liststored(event):
+ files = list_all_stored_msgs()
+ if not files:
+ return await event.eor(get_string("fsh_4"), time=5)
+ msg = "**Stored files:**\n"
+ for c, i in enumerate(files, start=1):
+ msg += f"`{c}`. https://t.me/{asst.me.username}?start={i}\n"
+ if len(msg) > 4095:
+ with open("liststored.txt", "w") as f:
+ f.write(msg.replace("**", "").replace("`", ""))
+ await event.reply(get_string("fsh_1"), file="liststored.txt")
+ os.remove("liststored.txt")
+ return
+ await event.eor(msg, link_preview=False)
+
+
+@in_pattern("filestore", owner=True)
+async def file_short(event):
+ all_ = list_all_stored_msgs()
+ res = []
+ if all_:
+ LOG_CHA = udB.get_key("LOG_CHANNEL")
+ for msg in all_[:50]:
+ m_id = get_stored_msg(msg)
+ if not m_id:
+ continue
+ message = await asst.get_messages(LOG_CHA, ids=m_id)
+ if not message:
+ continue
+ if message.media:
+ res.append(await event.builder.document(title=msg, file=message.media))
+ elif message.text:
+ res.append(
+ await event.builder.article(title=message.text, text=message.text)
+ )
+ if not res:
+ title = "You have no stored file :("
+ text = f"{title}\n\nRead `{HNDLR}help fileshare` to know how to store."
+ return await event.answer([await event.builder.article(title=title, text=text)])
+ await event.answer(res, switch_pm="⢠File Store â˘", switch_pm_param="start")
diff --git a/plugins/filter.py b/plugins/filter.py
new file mode 100644
index 0000000000000000000000000000000000000000..84ab5931efb3e1d9c9ee359f52483ae45f6a5731
--- /dev/null
+++ b/plugins/filter.py
@@ -0,0 +1,102 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_filter")
+
+import os
+import re
+
+from telegraph import upload_file as uf
+from telethon.tl.types import User
+from telethon.utils import pack_bot_file_id
+
+from pyUltroid.dB.filter_db import add_filter, get_filter, list_filter, rem_filter
+from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
+
+from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd
+from ._inline import something
+
+
+@ultroid_cmd(pattern="addfilter( (.*)|$)")
+async def af(e):
+ wrd = (e.pattern_match.group(1).strip()).lower()
+ wt = await e.get_reply_message()
+ chat = e.chat_id
+ if not (wt and wrd):
+ return await e.eor(get_string("flr_1"))
+ btn = format_btn(wt.buttons) if wt.buttons else None
+ if wt and wt.media:
+ wut = mediainfo(wt.media)
+ if wut.startswith(("pic", "gif")):
+ dl = await wt.download_media()
+ variable = uf(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "video":
+ if wt.media.document.size > 8 * 1000 * 1000:
+ return await e.eor(get_string("com_4"), time=5)
+ dl = await wt.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ else:
+ m = pack_bot_file_id(wt.media)
+ if wt.text:
+ txt = wt.text
+ if not btn:
+ txt, btn = get_msg_button(wt.text)
+ add_filter(chat, wrd, txt, m, btn)
+ else:
+ add_filter(chat, wrd, None, m, btn)
+ else:
+ txt = wt.text
+ if not btn:
+ txt, btn = get_msg_button(wt.text)
+ add_filter(chat, wrd, txt, None, btn)
+ await e.eor(get_string("flr_4").format(wrd))
+ ultroid_bot.add_handler(filter_func, events.NewMessage())
+
+
+@ultroid_cmd(pattern="remfilter( (.*)|$)")
+async def rf(e):
+ wrd = (e.pattern_match.group(1).strip()).lower()
+ chat = e.chat_id
+ if not wrd:
+ return await e.eor(get_string("flr_3"))
+ rem_filter(int(chat), wrd)
+ await e.eor(get_string("flr_5").format(wrd))
+
+
+@ultroid_cmd(pattern="listfilter$")
+async def lsnote(e):
+ if x := list_filter(e.chat_id):
+ sd = "Filters Found In This Chats Are\n\n"
+ return await e.eor(sd + x)
+ await e.eor(get_string("flr_6"))
+
+
+async def filter_func(e):
+ if isinstance(e.sender, User) and e.sender.bot:
+ return
+ xx = (e.text).lower()
+ chat = e.chat_id
+ if x := get_filter(chat):
+ for c in x:
+ pat = r"( |^|[^\w])" + re.escape(c) + r"( |$|[^\w])"
+ if re.search(pat, xx):
+ if k := x.get(c):
+ msg = k["msg"]
+ media = k["media"]
+ if k.get("button"):
+ btn = create_tl_btn(k["button"])
+ return await something(e, msg, media, btn)
+ await e.reply(msg, file=media)
+
+
+if udB.get_key("FILTERS"):
+ ultroid_bot.add_handler(filter_func, events.NewMessage())
diff --git a/plugins/fontgen.py b/plugins/fontgen.py
new file mode 100644
index 0000000000000000000000000000000000000000..1cce172bef98b71597fbf085ce14ae1df696ac28
--- /dev/null
+++ b/plugins/fontgen.py
@@ -0,0 +1,60 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+
+from . import get_help
+
+__doc__ = get_help("help_fontgen")
+
+import string
+
+from . import eod, ultroid_cmd
+
+_default = string.ascii_letters
+Fonts = {
+ "small caps": "á´Ęá´á´
á´ŇɢĘÉŞá´á´Ęá´É´á´á´ĎĘsá´á´á´ á´ĄxĘá´˘ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+ "monospace": "đđđđđđđđđđđđđđđđđđđđđđđ đĄđ˘đŁđ°đąđ˛đłđ´đľđśđˇđ¸đšđşđťđźđ˝đžđżđđđđđđ
đđđđ",
+ "double stroke": "đđđđđđđđđđđđđđđ đĄđ˘đŁđ¤đĽđŚđ§đ¨đŠđŞđŤđ¸đšâđťđźđ˝đžâđđđđđâđâââđđđđđđđâ¤",
+ "script royal": "đśđˇđ¸đšđđťđđ˝đžđżđđđđđđ
đđđđđđđđđđđâŹđđâ°âąđ˘ââđĽđŚââłđŠđŞđŤđŹâđŽđŻđ°đąđ˛đłđ´đľ",
+}
+
+
+@ultroid_cmd(
+ pattern="font( (.*)|$)",
+)
+async def _(e):
+ input = e.pattern_match.group(1).strip()
+ reply = await e.get_reply_message()
+ if not input:
+ m = "**Available Fonts**\n\n"
+ for x in Fonts.keys():
+ m += f"⢠`{x}`\n"
+ return await e.eor(m, time=5)
+ if not reply:
+ try:
+ _ = input.split(":", maxsplit=1)
+ font = _[0][:-1]
+ text = _[1]
+ except IndexError:
+ return await eod(e, help)
+ elif not input:
+ return await eod(e, "`Give font dude :/`")
+ else:
+ font = input
+ text = reply.message
+ if font not in Fonts.keys():
+ return await e.eor(f"`{font} not in font list`.", time=5)
+ msg = gen_font(text, Fonts[font])
+ await e.eor(msg)
+
+
+def gen_font(text, new_font):
+ new_font = " ".join(new_font).split()
+ for q in text:
+ if q in _default:
+ new = new_font[_default.index(q)]
+ text = text.replace(q, new)
+ return text
diff --git a/plugins/forcesubscribe.py b/plugins/forcesubscribe.py
new file mode 100644
index 0000000000000000000000000000000000000000..9804b28687bd4f6082783323a8aab989300e9ff4
--- /dev/null
+++ b/plugins/forcesubscribe.py
@@ -0,0 +1,179 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}fsub `
+ Enable ForceSub in Used Chat !
+
+⢠`{i}checkfsub`
+ Check/Get Active ForceSub Setting of Used Chat.
+
+⢠`{i}remfsub`
+ Remove ForceSub from Used Chat !
+
+ Note - You Need to be Admin in Both Channel/Chats
+ in order to Use ForceSubscribe.
+"""
+
+import re
+
+from telethon.errors.rpcerrorlist import ChatAdminRequiredError, UserNotParticipantError
+from telethon.tl.custom import Button
+from telethon.tl.functions.channels import GetParticipantRequest
+from telethon.tl.functions.messages import ExportChatInviteRequest
+from telethon.tl.types import (
+ Channel,
+ ChannelParticipantBanned,
+ ChannelParticipantLeft,
+ User,
+)
+
+from pyUltroid.dB.forcesub_db import add_forcesub, get_forcesetting, rem_forcesub
+
+from . import (
+ LOGS,
+ asst,
+ callback,
+ events,
+ get_string,
+ in_pattern,
+ inline_mention,
+ udB,
+ ultroid_bot,
+ ultroid_cmd,
+)
+
+CACHE = {}
+
+
+@ultroid_cmd(pattern="fsub( (.*)|$)", admins_only=True, groups_only=True)
+async def addfor(e):
+ match = e.pattern_match.group(1).strip()
+ if not match:
+ return await e.eor(get_string("fsub_1"), time=5)
+ try:
+ match = await e.client.parse_id(match)
+ except BaseException:
+ return await e.eor(get_string("fsub_2"), time=5)
+ add_forcesub(e.chat_id, match)
+ await e.eor("Added ForceSub in This Chat !")
+ ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))
+
+
+@ultroid_cmd(pattern="remfsub$")
+async def remor(e):
+ res = rem_forcesub(e.chat_id)
+ if not res:
+ return await e.eor(get_string("fsub_3"), time=5)
+ await e.eor("Removed ForceSub...")
+
+
+@ultroid_cmd(pattern="checkfsub$")
+async def getfsr(e):
+ res = get_forcesetting(e.chat_id)
+ if not res:
+ return await e.eor("ForceSub is Not Active In This Chat !", time=5)
+ cha = await e.client.get_entity(int(res))
+ await e.eor(f"**ForceSub Status** : `Active`\n- **{cha.title}** `({res})`")
+
+
+@in_pattern("fsub( (.*)|$)", owner=True)
+async def fcall(e):
+ match = e.pattern_match.group(1).strip()
+ spli = match.split("_")
+ user = await ultroid_bot.get_entity(int(spli[0]))
+ cl = await ultroid_bot.get_entity(int(spli[1]))
+ text = f"Hi {inline_mention(user)}, You Need to Join"
+ text += f" {cl.title} in order to Chat in this Group."
+ el = (
+ f"https://t.me/{cl.username}"
+ if cl.username
+ else (await ultroid_bot(ExportChatInviteRequest(cl))).link
+ )
+
+ res = [
+ await e.builder.article(
+ title="forcesub",
+ text=text,
+ buttons=[
+ [Button.url(text=get_string("fsub_4"), url=el)],
+ [Button.inline(get_string("fsub_5"), data=f"unm_{match}")],
+ ],
+ )
+ ]
+ await e.answer(res)
+
+
+@callback(re.compile("unm_(.*)"))
+async def diesoon(e):
+ match = (e.data_match.group(1)).decode("UTF-8")
+ spli = match.split("_")
+ if e.sender_id != int(spli[0]):
+ return await e.answer(get_string("fsub_7"), alert=True)
+ try:
+ values = await ultroid_bot(GetParticipantRequest(int(spli[1]), int(spli[0])))
+ if isinstance(values.participant, ChannelParticipantLeft) or (
+ isinstance(values.participant, ChannelParticipantBanned) and values.left
+ ):
+ raise UserNotParticipantError("")
+ except UserNotParticipantError:
+ return await e.answer(
+ "Please Join That Channel !\nThen Click This Button !", alert=True
+ )
+ await ultroid_bot.edit_permissions(
+ e.chat_id, int(spli[0]), send_messages=True, until_date=None
+ )
+ await e.edit(get_string("fsub_8"))
+
+
+async def force_sub(ult):
+ if not udB.get_key("FORCESUB"):
+ return
+ user = await ult.get_sender()
+ joinchat = get_forcesetting(ult.chat_id)
+ if (not joinchat) or (isinstance(user, User) and user.bot):
+ return
+ if CACHE.get(ult.chat_id):
+ if CACHE[ult.chat_id].get(user.id):
+ CACHE[ult.chat_id].update({user.id: CACHE[ult.chat_id][user.id] + 1})
+ else:
+ CACHE[ult.chat_id].update({user.id: 1})
+ else:
+ CACHE.update({ult.chat_id: {user.id: 1}})
+ count = CACHE[ult.chat_id][user.id]
+ if count == 11:
+ CACHE[ult.chat_id][user.id] = 1
+ return
+ if count in range(2, 11):
+ return
+ try:
+ await ultroid_bot.get_permissions(int(joinchat), user.id)
+ return
+ except UserNotParticipantError:
+ pass
+ if isinstance(user, Channel):
+ try:
+ await ultroid_bot.edit_permissions(
+ ult.chat_id, user.id, view_messages=False
+ )
+ return
+ except BaseException as er:
+ LOGS.exception(er)
+ try:
+ await ultroid_bot.edit_permissions(ult.chat_id, user.id, send_messages=False)
+ except ChatAdminRequiredError:
+ return
+ except Exception as e:
+ await ult.delete()
+ LOGS.info(e)
+ res = await ultroid_bot.inline_query(asst.me.username, f"fsub {user.id}_{joinchat}")
+ await res[0].click(ult.chat_id, reply_to=ult.id)
+
+
+if udB.get_key("FORCESUB"):
+ ultroid_bot.add_handler(force_sub, events.NewMessage(incoming=True))
diff --git a/plugins/gdrive.py b/plugins/gdrive.py
new file mode 100644
index 0000000000000000000000000000000000000000..fbadce676830ef2d2b582eed78f7646c572dd606
--- /dev/null
+++ b/plugins/gdrive.py
@@ -0,0 +1,232 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available
+
+⢠`{i}gdul `
+ Reply to file to upload on Google Drive.
+ Add file name to upload on Google Drive.
+
+⢠`{i}gdown | `
+ Download from Gdrive link or file id.
+
+⢠`{i}gdsearch `
+ Search file name on Google Drive and get link.
+
+⢠`{i}gdlist`
+ List all GDrive files.
+
+⢠`{i}gdfolder`
+ Link to your Google Drive Folder.
+ If added then all files will be uploaded in this folder.
+"""
+
+import os
+import time
+
+from telethon.tl.types import Message
+
+from pyUltroid.fns.gDrive import GDriveManager
+from pyUltroid.fns.helper import time_formatter
+
+from . import ULTConfig, asst, eod, eor, get_string, ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="gdown( (.*)|$)",
+ fullsudo=True,
+)
+async def gdown(event):
+ GDrive = GDriveManager()
+ match = event.pattern_match.group(1).strip()
+ if not match:
+ return await eod(event, "`Give file id or Gdrive link to download from!`")
+ filename = match.split(" | ")[1].strip() if " | " in match else None
+ eve = await event.eor(get_string("com_1"))
+ _start = time.time()
+ status, response = await GDrive._download_file(eve, match, filename)
+ if not status:
+ return await eve.edit(response)
+ await eve.edit(
+ f"`Downloaded ``{response}`` in {time_formatter((time.time() - _start)*1000)}`"
+ )
+
+
+@ultroid_cmd(
+ pattern="gdlist$",
+ fullsudo=True,
+)
+async def files(event):
+ GDrive = GDriveManager()
+ if not os.path.exists(GDrive.token_file):
+ return await event.eor(get_string("gdrive_6").format(asst.me.username))
+ eve = await event.eor(get_string("com_1"))
+ msg = ""
+ if files := GDrive._list_files:
+ msg += f"{len(files.keys())} files found in gdrive.\n\n"
+ for _ in files:
+ msg += f"> [{files[_]}]({_})\n"
+ else:
+ msg += "Nothing in Gdrive"
+ if len(msg) < 4096:
+ await eve.edit(msg, link_preview=False)
+ else:
+ with open("drive-files.txt", "w") as f:
+ f.write(
+ msg.replace("[", "File Name: ")
+ .replace("](", "\nÂť Link: ")
+ .replace(")\n", "\n\n")
+ )
+ try:
+ await eve.delete()
+ except BaseException:
+ pass
+ await event.client.send_file(
+ event.chat_id,
+ "drive-files.txt",
+ thumb=ULTConfig.thumb,
+ reply_to=event,
+ )
+ os.remove("drive-files.txt")
+
+
+@ultroid_cmd(
+ pattern="gdul( (.*)|$)",
+ fullsudo=True,
+)
+async def _(event):
+ GDrive = GDriveManager()
+ if not os.path.exists(GDrive.token_file):
+ return await eod(event, get_string("gdrive_6").format(asst.me.username))
+ input_file = event.pattern_match.group(1).strip() or await event.get_reply_message()
+ if not input_file:
+ return await eod(event, "`Reply to file or give its location.`")
+ mone = await event.eor(get_string("com_1"))
+ if isinstance(input_file, Message):
+ location = "resources/downloads"
+ if input_file.photo:
+ filename = await input_file.download_media(location)
+ else:
+ filename = input_file.file.name
+ if not filename:
+ filename = str(round(time.time()))
+ filename = f"{location}/{filename}"
+ try:
+ filename, downloaded_in = await event.client.fast_downloader(
+ file=input_file.media.document,
+ filename=filename,
+ show_progress=True,
+ event=mone,
+ message=get_string("com_5"),
+ )
+ filename = filename.name
+ except Exception as e:
+ return await eor(mone, str(e), time=10)
+ await mone.edit(
+ f"`Downloaded to ``{filename}`.`",
+ )
+ else:
+ filename = input_file.strip()
+ if not os.path.exists(filename):
+ return await eod(
+ mone,
+ "File Not found in local server. Give me a file path :((",
+ time=5,
+ )
+ folder_id = None
+ if os.path.isdir(filename):
+ files = os.listdir(filename)
+ if not files:
+ return await eod(
+ mone, "`Requested directory is empty. Can't create empty directory.`"
+ )
+ folder_id = GDrive.create_directory(filename)
+ c = 0
+ for files in sorted(files):
+ file = f"{filename}/{files}"
+ if not os.path.isdir(file):
+ try:
+ await GDrive._upload_file(mone, path=file, folder_id=folder_id)
+ c += 1
+ except Exception as e:
+ return await mone.edit(
+ f"Exception occurred while uploading to gDrive {e}"
+ )
+ return await mone.edit(
+ f"`Uploaded `[{filename}](https://drive.google.com/folderview?id={folder_id})` with {c} files.`"
+ )
+ try:
+ g_drive_link = await GDrive._upload_file(
+ mone,
+ filename,
+ )
+ await mone.edit(
+ get_string("gdrive_7").format(filename.split("/")[-1], g_drive_link)
+ )
+ except Exception as e:
+ await mone.edit(f"Exception occurred while uploading to gDrive {e}")
+
+
+@ultroid_cmd(
+ pattern="gdsearch( (.*)|$)",
+ fullsudo=True,
+)
+async def _(event):
+ GDrive = GDriveManager()
+ if not os.path.exists(GDrive.token_file):
+ return await event.eor(get_string("gdrive_6").format(asst.me.username))
+ input_str = event.pattern_match.group(1).strip()
+ if not input_str:
+ return await event.eor("`Give filename to search on GDrive...`")
+ eve = await event.eor(f"`Searching for {input_str} in G-Drive...`")
+ files = GDrive.search(input_str)
+ msg = ""
+ if files:
+ msg += (
+ f"{len(files.keys())} files with {input_str} in title found in GDrive.\n\n"
+ )
+ for _ in files:
+ msg += f"> [{files[_]}]({_})\n"
+ else:
+ msg += f"`No files with title {input_str}`"
+ if len(msg) < 4096:
+ await eve.eor(msg, link_preview=False)
+ else:
+ with open("drive-files.txt", "w") as f:
+ f.write(
+ msg.replace("[", "File Name: ")
+ .replace("](", "\nÂť Link: ")
+ .replace(")\n", "\n\n")
+ )
+ try:
+ await eve.delete()
+ except BaseException:
+ pass
+ await event.client.send_file(
+ event.chat_id,
+ f"{input_str}.txt",
+ thumb=ULTConfig.thumb,
+ reply_to=event,
+ )
+ os.remove(f"{input_str}.txt")
+
+
+@ultroid_cmd(
+ pattern="gdfolder$",
+ fullsudo=True,
+)
+async def _(event):
+ GDrive = GDriveManager()
+ if not os.path.exists(GDrive.token_file):
+ return await event.eor(get_string("gdrive_6").format(asst.me.username))
+ if GDrive.folder_id:
+ await event.eor(
+ "`Your G-Drive Folder link : `\n"
+ + GDrive._create_folder_link(GDrive.folder_id)
+ )
+ else:
+ await eod(event, "Set FOLDERID from your Assistant bot's Settings ")
diff --git a/plugins/giftools.py b/plugins/giftools.py
new file mode 100644
index 0000000000000000000000000000000000000000..38fdb1f79e4869ac71b7e170d692abf13697f3d1
--- /dev/null
+++ b/plugins/giftools.py
@@ -0,0 +1,128 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available
+
+â˘`{i}invertgif`
+ Make Gif Inverted(negative).
+
+â˘`{i}bwgif`
+ Make Gif black and white
+
+â˘`{i}rvgif`
+ Reverse a gif
+
+â˘`{i}vtog`
+ Reply To Video , It will Create Gif
+ Video to Gif
+
+â˘`{i}gif `
+ Send video regarding to query.
+"""
+import os
+import random
+import time
+from datetime import datetime as dt
+
+from . import HNDLR, LOGS, bash, downloader, get_string, mediainfo, ultroid_cmd
+
+
+@ultroid_cmd(pattern="(bw|invert)gif$")
+async def igif(e):
+ match = e.pattern_match.group(1).strip()
+ a = await e.get_reply_message()
+ if not (a and a.media):
+ return await e.eor("`Reply To gif only`", time=5)
+ wut = mediainfo(a.media)
+ if "gif" not in wut:
+ return await e.eor("`Reply To Gif Only`", time=5)
+ xx = await e.eor(get_string("com_1"))
+ z = await a.download_media()
+ if match == "bw":
+ cmd = f'ffmpeg -i "{z}" -vf format=gray ult.gif -y'
+ else:
+ cmd = f'ffmpeg -i "{z}" -vf lutyuv="y=negval:u=negval:v=negval" ult.gif -y'
+ try:
+ await bash(cmd)
+ await e.client.send_file(e.chat_id, "ult.gif", supports_streaming=True)
+ os.remove(z)
+ os.remove("ult.gif")
+ await xx.delete()
+ except Exception as er:
+ LOGS.info(er)
+
+
+@ultroid_cmd(pattern="rvgif$")
+async def reverse_gif(event):
+ a = await event.get_reply_message()
+ if not (a and a.media) and "video" not in mediainfo(a.media):
+ return await event.eor("`Reply To Video only`", time=5)
+ msg = await event.eor(get_string("com_1"))
+ file = await a.download_media()
+ await bash(f'ffmpeg -i "{file}" -vf reverse -af areverse reversed.mp4 -y')
+ await event.respond("- **Reversed Video/GIF**", file="reversed.mp4")
+ await msg.delete()
+ os.remove(file)
+ os.remove("reversed.mp4")
+
+
+@ultroid_cmd(pattern="gif( (.*)|$)")
+async def gifs(ult):
+ get = ult.pattern_match.group(1).strip()
+ xx = random.randint(0, 5)
+ n = 0
+ if ";" in get:
+ try:
+ n = int(get.split(";")[-1])
+ except IndexError:
+ pass
+ if not get:
+ return await ult.eor(f"`{HNDLR}gif `")
+ m = await ult.eor(get_string("com_2"))
+ gifs = await ult.client.inline_query("gif", get)
+ if not n:
+ await gifs[xx].click(
+ ult.chat_id, reply_to=ult.reply_to_msg_id, silent=True, hide_via=True
+ )
+ else:
+ for x in range(n):
+ await gifs[x].click(
+ ult.chat_id, reply_to=ult.reply_to_msg_id, silent=True, hide_via=True
+ )
+ await m.delete()
+
+
+@ultroid_cmd(pattern="vtog$")
+async def vtogif(e):
+ a = await e.get_reply_message()
+ if not (a and a.media):
+ return await e.eor("`Reply To video only`", time=5)
+ wut = mediainfo(a.media)
+ if "video" not in wut:
+ return await e.eor("`Reply To Video Only`", time=5)
+ xx = await e.eor(get_string("com_1"))
+ dur = a.media.document.attributes[0].duration
+ tt = time.time()
+ if int(dur) < 120:
+ z = await a.download_media()
+ await bash(
+ f'ffmpeg -i {z} -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 ult.gif -y'
+ )
+ else:
+ filename = a.file.name
+ if not filename:
+ filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
+ vid = await downloader(filename, a.media.document, xx, tt, get_string("com_5"))
+ z = vid.name
+ await bash(
+ f'ffmpeg -ss 3 -t 100 -i {z} -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 ult.gif'
+ )
+
+ await e.client.send_file(e.chat_id, "ult.gif", support_stream=True)
+ os.remove(z)
+ os.remove("ult.gif")
+ await xx.delete()
diff --git a/plugins/glitch.py b/plugins/glitch.py
new file mode 100644
index 0000000000000000000000000000000000000000..a612e959e57fe8a9c75c9af5965d03b3d8368612
--- /dev/null
+++ b/plugins/glitch.py
@@ -0,0 +1,42 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+â˘`{i}glitch `
+ gives a glitchy gif.
+"""
+import os
+
+from . import bash, get_string, mediainfo, ultroid_cmd
+
+
+@ultroid_cmd(pattern="glitch$")
+async def _(e):
+ try:
+ import glitch_me # ignore :pylint
+ except ModuleNotFoundError:
+ await bash(
+ "pip install -e git+https://github.com/1Danish-00/glitch_me.git#egg=glitch_me"
+ )
+ reply = await e.get_reply_message()
+ if not reply or not reply.media:
+ return await e.eor(get_string("cvt_3"))
+ xx = await e.eor(get_string("glitch_1"))
+ wut = mediainfo(reply.media)
+ if wut.startswith(("pic", "sticker")):
+ ok = await reply.download_media()
+ elif reply.document and reply.document.thumbs:
+ ok = await reply.download_media(thumb=-1)
+ else:
+ return await xx.eor(get_string("com_4"))
+ cmd = f"glitch_me gif --line_count 200 -f 10 -d 50 '{ok}' ult.gif"
+ await bash(cmd)
+ await e.reply(file="ult.gif", force_document=False)
+ await xx.delete()
+ os.remove(ok)
+ os.remove("ult.gif")
diff --git a/plugins/globaltools.py b/plugins/globaltools.py
new file mode 100644
index 0000000000000000000000000000000000000000..087db364c488745a470477c022f0b978c7cbc6a7
--- /dev/null
+++ b/plugins/globaltools.py
@@ -0,0 +1,753 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}gban `
+⢠`{i}ungban`
+ Ban/Unban Globally.
+
+⢠`{i}gstat `
+ Check if user is GBanned.
+
+⢠`{i}listgban` : List all GBanned users.
+
+⢠`{i}gmute` | `{i}ungmute`
+ Mute/UnMute Globally.
+
+⢠`{i}gkick ` `Globally Kick User`
+⢠`{i}gcast ` `Globally Send msg in all grps`
+
+⢠`{i}gadmincast ` `Globally broadcast in your admin chats`
+⢠`{i}gucast ` `Globally send msg in all pm users`
+
+⢠`{i}gblacklist `
+ globally promote user where you are admin
+ - Set whether To promote only in groups/channels/all.
+ Eg- `gpromote group boss` ~ promotes user in all grps.
+ `gpromote @username all sar` ~ promote the user in all group & channel
+⢠`{i}gdemote` - `demote user globally`
+"""
+import asyncio
+import os
+
+from telethon.errors.rpcerrorlist import ChatAdminRequiredError, FloodWaitError
+from telethon.tl.functions.channels import EditAdminRequest
+from telethon.tl.functions.contacts import BlockRequest, UnblockRequest
+from telethon.tl.types import ChatAdminRights, User
+
+from pyUltroid.dB import DEVLIST
+from pyUltroid.dB.base import KeyManager
+from pyUltroid.dB.gban_mute_db import (
+ gban,
+ gmute,
+ is_gbanned,
+ is_gmuted,
+ list_gbanned,
+ ungban,
+ ungmute,
+)
+from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
+
+from . import (
+ HNDLR,
+ LOGS,
+ NOSPAM_CHAT,
+ OWNER_NAME,
+ eod,
+ eor,
+ get_string,
+ inline_mention,
+ ultroid_bot,
+ ultroid_cmd,
+)
+from ._inline import something
+
+_gpromote_rights = ChatAdminRights(
+ add_admins=False,
+ invite_users=True,
+ change_info=False,
+ ban_users=True,
+ delete_messages=True,
+ pin_messages=True,
+)
+
+_gdemote_rights = ChatAdminRights(
+ add_admins=False,
+ invite_users=False,
+ change_info=False,
+ ban_users=False,
+ delete_messages=False,
+ pin_messages=False,
+)
+
+keym = KeyManager("GBLACKLISTS", cast=list)
+
+
+@ultroid_cmd(pattern="gpromote( (.*)|$)", fullsudo=True)
+async def _(e):
+ x = e.pattern_match.group(1).strip()
+ ultroid_bot = e.client
+ if not x:
+ return await e.eor(get_string("schdl_2"), time=5)
+ user = await e.get_reply_message()
+ if user:
+ ev = await e.eor("`Promoting Replied User Globally`")
+ ok = e.text.split()
+ key = "all"
+ if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):
+ key = ok[1]
+ rank = ok[2] if len(ok) > 2 else "AdMin"
+ c = 0
+ user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id
+ async for x in e.client.iter_dialogs():
+ if (
+ "group" in key.lower()
+ and x.is_group
+ or "group" not in key.lower()
+ and "channel" in key.lower()
+ and x.is_channel
+ ):
+ try:
+ await e.client(
+ EditAdminRequest(
+ x.id,
+ user.id,
+ _gpromote_rights,
+ rank,
+ ),
+ )
+ c += 1
+ except BaseException:
+ pass
+ elif (
+ ("group" not in key.lower() or x.is_group)
+ and (
+ "group" in key.lower()
+ or "channel" not in key.lower()
+ or x.is_channel
+ )
+ and (
+ "group" in key.lower()
+ or "channel" in key.lower()
+ or x.is_group
+ or x.is_channel
+ )
+ ):
+ try:
+ await e.client(
+ EditAdminRequest(
+ x.id,
+ user.id,
+ _gpromote_rights,
+ rank,
+ ),
+ )
+ c += 1
+ except Exception as er:
+ LOGS.info(er)
+ await eor(ev, f"Promoted The Replied Users in Total : {c} {key} chats")
+ else:
+ k = e.text.split()
+ if not k[1]:
+ return await eor(
+ e, "`Give someone's username/id or replied to user.", time=5
+ )
+ user = k[1]
+ if user.isdigit():
+ user = int(user)
+ try:
+ name = await e.client.get_entity(user)
+ except BaseException:
+ return await e.eor(f"`No User Found Regarding {user}`", time=5)
+ ev = await e.eor(f"`Promoting {name.first_name} globally.`")
+ key = "all"
+ if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):
+ key = k[2]
+ rank = k[3] if len(k) > 3 else "AdMin"
+ c = 0
+ async for x in e.client.iter_dialogs():
+ if (
+ "group" in key.lower()
+ and x.is_group
+ or "group" not in key.lower()
+ and "channel" in key.lower()
+ and x.is_channel
+ or "group" not in key.lower()
+ and "channel" not in key.lower()
+ and (x.is_group or x.is_channel)
+ ):
+ try:
+ await ultroid_bot(
+ EditAdminRequest(
+ x.id,
+ user,
+ _gpromote_rights,
+ rank,
+ ),
+ )
+ c += 1
+ except BaseException:
+ pass
+ await eor(ev, f"Promoted {name.first_name} in Total : {c} {key} chats.")
+
+
+@ultroid_cmd(pattern="gdemote( (.*)|$)", fullsudo=True)
+async def _(e):
+ x = e.pattern_match.group(1).strip()
+ ultroid_bot = e.client
+ if not x:
+ return await e.eor(get_string("schdl_2"), time=5)
+ user = await e.get_reply_message()
+ if user:
+ user.id = user.peer_id.user_id if e.is_private else user.from_id.user_id
+ ev = await e.eor("`Demoting Replied User Globally`")
+ ok = e.text.split()
+ key = "all"
+ if len(ok) > 1 and (("group" in ok[1]) or ("channel" in ok[1])):
+ key = ok[1]
+ rank = "Not AdMin"
+ c = 0
+ async for x in e.client.iter_dialogs():
+ if (
+ "group" in key.lower()
+ and x.is_group
+ or "group" not in key.lower()
+ and "channel" in key.lower()
+ and x.is_channel
+ or "group" not in key.lower()
+ and "channel" not in key.lower()
+ and (x.is_group or x.is_channel)
+ ):
+ try:
+ await ultroid_bot(
+ EditAdminRequest(
+ x.id,
+ user.id,
+ _gdemote_rights,
+ rank,
+ ),
+ )
+ c += 1
+ except BaseException:
+ pass
+ await eor(ev, f"Demoted The Replied Users in Total : {c} {key} chats")
+ else:
+ k = e.text.split()
+ if not k[1]:
+ return await eor(
+ e, "`Give someone's username/id or replied to user.", time=5
+ )
+ user = k[1]
+ if user.isdigit():
+ user = int(user)
+ try:
+ name = await ultroid_bot.get_entity(user)
+ except BaseException:
+ return await e.eor(f"`No User Found Regarding {user}`", time=5)
+ ev = await e.eor(f"`Demoting {name.first_name} globally.`")
+ key = "all"
+ if len(k) > 2 and (("group" in k[2]) or ("channel" in k[2])):
+ key = k[2]
+ rank = "Not AdMin"
+ c = 0
+ async for x in ultroid_bot.iter_dialogs():
+ if (
+ "group" in key.lower()
+ and x.is_group
+ or "group" not in key.lower()
+ and "channel" in key.lower()
+ and x.is_channel
+ or "group" not in key.lower()
+ and "channel" not in key.lower()
+ and (x.is_group or x.is_channel)
+ ):
+ try:
+ await ultroid_bot(
+ EditAdminRequest(
+ x.id,
+ user,
+ _gdemote_rights,
+ rank,
+ ),
+ )
+ c += 1
+ except BaseException:
+ pass
+ await eor(ev, f"Demoted {name.first_name} in Total : {c} {key} chats.")
+
+
+@ultroid_cmd(pattern="ungban( (.*)|$)", fullsudo=True)
+async def _(e):
+ xx = await e.eor("`UnGbanning...`")
+ match = e.pattern_match.group(1).strip()
+ peer = None
+ if e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ elif match:
+ try:
+ userid = int(match)
+ except ValueError:
+ userid = match
+ try:
+ userid = (await e.client.get_entity(userid)).id
+ except Exception as er:
+ return await xx.edit(f"Failed to get User...\nError: {er}")
+ elif e.is_private:
+ userid = e.chat_id
+ else:
+ return await xx.eor("`Reply to some msg or add their id.`", time=5)
+ if not is_gbanned(userid):
+ return await xx.edit("`User/Channel is not Gbanned...`")
+ try:
+ if not peer:
+ peer = await e.client.get_entity(userid)
+ name = inline_mention(peer)
+ except BaseException:
+ userid = int(userid)
+ name = str(userid)
+ chats = 0
+ if e.client._dialogs:
+ dialog = e.client._dialogs
+ else:
+ dialog = await e.client.get_dialogs()
+ e.client._dialogs.extend(dialog)
+ for ggban in dialog:
+ if ggban.is_group or ggban.is_channel:
+ try:
+ await e.client.edit_permissions(ggban.id, userid, view_messages=True)
+ chats += 1
+ except FloodWaitError as fw:
+ LOGS.info(
+ f"[FLOOD_WAIT_ERROR] : on Ungban\nSleeping for {fw.seconds+10}"
+ )
+ await asyncio.sleep(fw.seconds + 10)
+ try:
+ await e.client.edit_permissions(
+ ggban.id, userid, view_messages=True
+ )
+ chats += 1
+ except BaseException as er:
+ LOGS.exception(er)
+ except (ChatAdminRequiredError, ValueError):
+ pass
+ except BaseException as er:
+ LOGS.exception(er)
+ ungban(userid)
+ if isinstance(peer, User):
+ await e.client(UnblockRequest(userid))
+ await xx.edit(
+ f"`Ungbaned` {name} in {chats} `chats.\nRemoved from gbanwatch.`",
+ )
+
+
+@ultroid_cmd(pattern="gban( (.*)|$)", fullsudo=True)
+async def _(e):
+ xx = await e.eor("`Gbanning...`")
+ reason = ""
+ if e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ try:
+ reason = e.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ pass
+ elif e.pattern_match.group(1).strip():
+ usr = e.text.split(maxsplit=2)[1]
+ try:
+ userid = await e.client.parse_id(usr)
+ except ValueError:
+ userid = usr
+ try:
+ reason = e.text.split(maxsplit=2)[2]
+ except IndexError:
+ pass
+ elif e.is_private:
+ userid = e.chat_id
+ try:
+ reason = e.text.split(" ", maxsplit=1)[1]
+ except IndexError:
+ pass
+ else:
+ return await xx.eor("`Reply to some msg or add their id.`", time=5)
+ user = None
+ try:
+ user = await e.client.get_entity(userid)
+ name = inline_mention(user)
+ except BaseException:
+ userid = int(userid)
+ name = str(userid)
+ chats = 0
+ if userid == ultroid_bot.uid:
+ return await xx.eor("`I can't gban myself.`", time=3)
+ elif userid in DEVLIST:
+ return await xx.eor("`I can't gban my Developers.`", time=3)
+ elif is_gbanned(userid):
+ return await eod(
+ xx,
+ "`User is already gbanned and added to gbanwatch.`",
+ time=4,
+ )
+ if e.client._dialogs:
+ dialog = e.client._dialogs
+ else:
+ dialog = await e.client.get_dialogs()
+ e.client._dialogs.extend(dialog)
+ for ggban in dialog:
+ if ggban.is_group or ggban.is_channel:
+ try:
+ await e.client.edit_permissions(ggban.id, userid, view_messages=False)
+ chats += 1
+ except FloodWaitError as fw:
+ LOGS.info(
+ f"[FLOOD_WAIT_ERROR] : on GBAN Command\nSleeping for {fw.seconds+10}"
+ )
+ await asyncio.sleep(fw.seconds + 10)
+ try:
+ await e.client.edit_permissions(
+ ggban.id, userid, view_messages=False
+ )
+ chats += 1
+ except BaseException as er:
+ LOGS.exception(er)
+ except (ChatAdminRequiredError, ValueError):
+ pass
+ except BaseException as er:
+ LOGS.exception(er)
+ gban(userid, reason)
+ if isinstance(user, User):
+ await e.client(BlockRequest(userid))
+ gb_msg = f"**#Gbanned** {name} `in {chats} chats and added to gbanwatch!`"
+ if reason:
+ gb_msg += f"\n**Reason** : {reason}"
+ await xx.edit(gb_msg)
+
+
+@ultroid_cmd(pattern="g(admin|)cast( (.*)|$)", fullsudo=True)
+async def gcast(event):
+ text, btn, reply = "", None, None
+ if xx := event.pattern_match.group(2):
+ msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])
+ elif event.is_reply:
+ reply = await event.get_reply_message()
+ msg = reply.text
+ if reply.buttons:
+ btn = format_btn(reply.buttons)
+ else:
+ msg, btn = get_msg_button(msg)
+ else:
+ return await eor(
+ event, "`Give some text to Globally Broadcast or reply a message..`"
+ )
+
+ kk = await event.eor("`Globally Broadcasting Msg...`")
+ er = 0
+ done = 0
+ err = ""
+ if event.client._dialogs:
+ dialog = event.client._dialogs
+ else:
+ dialog = await event.client.get_dialogs()
+ event.client._dialogs.extend(dialog)
+ for x in dialog:
+ if x.is_group:
+ chat = x.entity.id
+ if (
+ not keym.contains(chat)
+ and int(f"-100{str(chat)}") not in NOSPAM_CHAT
+ and (
+ (
+ event.text[2:7] != "admin"
+ or (x.entity.admin_rights or x.entity.creator)
+ )
+ )
+ ):
+ try:
+ if btn:
+ bt = create_tl_btn(btn)
+ await something(
+ event,
+ msg,
+ reply.media if reply else None,
+ bt,
+ chat=chat,
+ reply=False,
+ )
+ else:
+ await event.client.send_message(
+ chat, msg, file=reply.media if reply else None
+ )
+ done += 1
+ except FloodWaitError as fw:
+ await asyncio.sleep(fw.seconds + 10)
+ try:
+ if btn:
+ bt = create_tl_btn(btn)
+ await something(
+ event,
+ msg,
+ reply.media if reply else None,
+ bt,
+ chat=chat,
+ reply=False,
+ )
+ else:
+ await event.client.send_message(
+ chat, msg, file=reply.media if reply else None
+ )
+ done += 1
+ except Exception as rr:
+ err += f"⢠{rr}\n"
+ er += 1
+ except BaseException as h:
+ err += f"⢠{str(h)}" + "\n"
+ er += 1
+ text += f"Done in {done} chats, error in {er} chat(s)"
+ if err != "":
+ open("gcast-error.log", "w+").write(err)
+ text += f"\nYou can do `{HNDLR}ul gcast-error.log` to know error report."
+ await kk.edit(text)
+
+
+@ultroid_cmd(pattern="gucast( (.*)|$)", fullsudo=True)
+async def gucast(event):
+ msg, btn, reply = "", None, None
+ if xx := event.pattern_match.group(1).strip():
+ msg, btn = get_msg_button(event.text.split(maxsplit=1)[1])
+ elif event.is_reply:
+ reply = await event.get_reply_message()
+ msg = reply.text
+ if reply.buttons:
+ btn = format_btn(reply.buttons)
+ else:
+ msg, btn = get_msg_button(msg)
+ else:
+ return await eor(
+ event, "`Give some text to Globally Broadcast or reply a message..`"
+ )
+ kk = await event.eor("`Globally Broadcasting Msg...`")
+ er = 0
+ done = 0
+ if event.client._dialogs:
+ dialog = event.client._dialogs
+ else:
+ dialog = await event.client.get_dialogs()
+ event.client._dialogs.extend(dialog)
+ for x in dialog:
+ if x.is_user and not x.entity.bot:
+ chat = x.id
+ if not keym.contains(chat):
+ try:
+ if btn:
+ bt = create_tl_btn(btn)
+ await something(
+ event,
+ msg,
+ reply.media if reply else None,
+ bt,
+ chat=chat,
+ reply=False,
+ )
+ else:
+ await event.client.send_message(
+ chat, msg, file=reply.media if reply else None
+ )
+ done += 1
+ except BaseException:
+ er += 1
+ await kk.edit(f"Done in {done} chats, error in {er} chat(s)")
+
+
+@ultroid_cmd(pattern="gkick( (.*)|$)", fullsudo=True)
+async def gkick(e):
+ xx = await e.eor("`Gkicking...`")
+ if e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ elif e.pattern_match.group(1).strip():
+ userid = await e.client.parse_id(e.pattern_match.group(1).strip())
+ elif e.is_private:
+ userid = e.chat_id
+ else:
+ return await xx.edit("`Reply to some msg or add their id.`", time=5)
+ name = (await e.client.get_entity(userid)).first_name
+ chats = 0
+ if userid == ultroid_bot.uid:
+ return await xx.eor("`I can't gkick myself.`", time=3)
+ if userid in DEVLIST:
+ return await xx.eor("`I can't gkick my Developers.`", time=3)
+ if e.client._dialogs:
+ dialog = e.client._dialogs
+ else:
+ dialog = await e.client.get_dialogs()
+ e.client._dialogs.extend(dialog)
+ for gkick in dialog:
+ if gkick.is_group or gkick.is_channel:
+ try:
+ await e.client.kick_participant(gkick.id, userid)
+ chats += 1
+ except BaseException:
+ pass
+ await xx.edit(f"`Gkicked` [{name}](tg://user?id={userid}) `in {chats} chats.`")
+
+
+@ultroid_cmd(pattern="gmute( (.*)|$)", fullsudo=True)
+async def _(e):
+ xx = await e.eor("`Gmuting...`")
+ if e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ elif e.pattern_match.group(1).strip():
+ userid = await e.client.parse_id(e.pattern_match.group(1).strip())
+ elif e.is_private:
+ userid = e.chat_id
+ else:
+ return await xx.eor("`Reply to some msg or add their id.`", tome=5, time=5)
+ name = await e.client.get_entity(userid)
+ chats = 0
+ if userid == ultroid_bot.uid:
+ return await xx.eor("`I can't gmute myself.`", time=3)
+ if userid in DEVLIST:
+ return await xx.eor("`I can't gmute my Developers.`", time=3)
+ if is_gmuted(userid):
+ return await xx.eor("`User is already gmuted.`", time=4)
+ if e.client._dialogs:
+ dialog = e.client._dialogs
+ else:
+ dialog = await e.client.get_dialogs()
+ e.client._dialogs.extend(dialog)
+ for onmute in dialog:
+ if onmute.is_group:
+ try:
+ await e.client.edit_permissions(onmute.id, userid, send_messages=False)
+ chats += 1
+ except BaseException:
+ pass
+ gmute(userid)
+ await xx.edit(f"`Gmuted` {inline_mention(name)} `in {chats} chats.`")
+
+
+@ultroid_cmd(pattern="ungmute( (.*)|$)", fullsudo=True)
+async def _(e):
+ xx = await e.eor("`UnGmuting...`")
+ if e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ elif e.pattern_match.group(1).strip():
+ userid = await e.client.parse_id(e.pattern_match.group(1).strip())
+ elif e.is_private:
+ userid = e.chat_id
+ else:
+ return await xx.eor("`Reply to some msg or add their id.`", time=5)
+ name = (await e.client.get_entity(userid)).first_name
+ chats = 0
+ if not is_gmuted(userid):
+ return await xx.eor("`User is not gmuted.`", time=3)
+ if e.client._dialogs:
+ dialog = e.client._dialogs
+ else:
+ dialog = await e.client.get_dialogs()
+ e.client._dialogs.extend(dialog)
+ for hurr in dialog:
+ if hurr.is_group:
+ try:
+ await e.client.edit_permissions(hurr.id, userid, send_messages=True)
+ chats += 1
+ except BaseException:
+ pass
+ ungmute(userid)
+ await xx.edit(f"`Ungmuted` {inline_mention(name)} `in {chats} chats.`")
+
+
+@ultroid_cmd(
+ pattern="listgban$",
+)
+async def list_gengbanned(event):
+ users = list_gbanned()
+ x = await event.eor(get_string("com_1"))
+ msg = ""
+ if not users:
+ return await x.edit("`You haven't GBanned anyone!`")
+ for i in users:
+ try:
+ name = await event.client.get_entity(int(i))
+ except BaseException:
+ name = i
+ msg += f"User: {inline_mention(name, html=True)}\n"
+ reason = users[i]
+ msg += f"Reason: {reason}\n\n" if reason is not None else "\n"
+ gbanned_users = f"List of users GBanned by {OWNER_NAME}:\n\n{msg}"
+ if len(gbanned_users) > 4096:
+ with open("gbanned.txt", "w") as f:
+ f.write(
+ gbanned_users.replace("", "")
+ .replace("", "")
+ .replace("", "")
+ )
+ await x.reply(
+ file="gbanned.txt",
+ message=f"List of users GBanned by {inline_mention(ultroid_bot.me)}",
+ )
+ os.remove("gbanned.txt")
+ await x.delete()
+ else:
+ await x.edit(gbanned_users, parse_mode="html")
+
+
+@ultroid_cmd(
+ pattern="gstat( (.*)|$)",
+)
+async def gstat_(e):
+ xx = await e.eor(get_string("com_1"))
+ if e.is_private:
+ userid = (await e.get_chat()).id
+ elif e.reply_to_msg_id:
+ userid = (await e.get_reply_message()).sender_id
+ elif e.pattern_match.group(1).strip():
+ try:
+ userid = await e.client.parse_id(e.pattern_match.group(1).strip())
+ except Exception as err:
+ return await xx.eor(f"{err}", time=10)
+ else:
+ return await xx.eor("`Reply to some msg or add their id.`", time=5)
+ name = (await e.client.get_entity(userid)).first_name
+ msg = f"**{name} is "
+ is_banned = is_gbanned(userid)
+ reason = list_gbanned().get(userid)
+ if is_banned:
+ msg += "Globally Banned"
+ msg += f" with reason** `{reason}`" if reason else ".**"
+ else:
+ msg += "not Globally Banned.**"
+ await xx.edit(msg)
+
+
+@ultroid_cmd(pattern="gblacklist$")
+async def blacklist_(event):
+ await gblacker(event, "add")
+
+
+@ultroid_cmd(pattern="ungblacklist$")
+async def ungblacker(event):
+ await gblacker(event, "remove")
+
+
+async def gblacker(event, type_):
+ try:
+ chat_id = int(event.text.split(maxsplit=1)[1])
+ try:
+ chat_id = (await event.client.get_entity(chat_id)).id
+ except Exception as e:
+ return await event.eor(f"**ERROR**\n`{str(e)}`")
+ except IndexError:
+ chat_id = event.chat_id
+ if type_ == "add":
+ keym.add(chat_id)
+ elif type_ == "remove":
+ keym.remove(chat_id)
+ await event.eor(f"Global Broadcasts: \n{type_}ed {chat_id}")
diff --git a/plugins/greetings.py b/plugins/greetings.py
new file mode 100644
index 0000000000000000000000000000000000000000..6254a6be539c94ee6529ae141d12cb9ab7807bf1
--- /dev/null
+++ b/plugins/greetings.py
@@ -0,0 +1,205 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+---- Welcomes ----
+⢠`{i}setwelcome `
+ Set welcome message in the current chat.
+
+⢠`{i}clearwelcome`
+ Delete the welcome in the current chat.
+
+⢠`{i}getwelcome`
+ Get the welcome message in the current chat.
+
+---- GoodByes ----
+⢠`{i}setgoodbye `
+ Set goodbye message in the current chat.
+
+⢠`{i}cleargoodbye`
+ Delete the goodbye in the current chat.
+
+⢠`{i}getgoodbye`
+ Get the goodbye message in the current chat.
+
+⢠`{i}thankmembers on/off`
+ Send a thank you sticker on hitting a members count of 100*x in your groups.
+"""
+import os
+
+from telegraph import upload_file as uf
+from telethon.utils import pack_bot_file_id
+
+from pyUltroid.dB.greetings_db import (
+ add_goodbye,
+ add_thanks,
+ add_welcome,
+ delete_goodbye,
+ delete_welcome,
+ get_goodbye,
+ get_welcome,
+ must_thank,
+ remove_thanks,
+)
+from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
+
+from . import HNDLR, eor, get_string, mediainfo, ultroid_cmd
+from ._inline import something
+
+Note = "\n\nNote: `{mention}`, `{group}`, `{count}`, `{name}`, `{fullname}`, `{username}`, `{userid}` can be used as formatting parameters.\n\n"
+
+
+@ultroid_cmd(pattern="setwelcome", groups_only=True)
+async def setwel(event):
+ x = await event.eor(get_string("com_1"))
+ r = await event.get_reply_message()
+ btn = format_btn(r.buttons) if (r and r.buttons) else None
+ try:
+ text = event.text.split(maxsplit=1)[1]
+ except IndexError:
+ text = r.text if r else None
+ if r and r.media:
+ wut = mediainfo(r.media)
+ if wut.startswith(("pic", "gif")):
+ dl = await r.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "video":
+ if r.media.document.size > 8 * 1000 * 1000:
+ return await eor(x, get_string("com_4"), time=5)
+ dl = await r.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "web":
+ m = None
+ else:
+ m = pack_bot_file_id(r.media)
+ if r.text:
+ txt = r.text
+ if not btn:
+ txt, btn = get_msg_button(r.text)
+ add_welcome(event.chat_id, txt, m, btn)
+ else:
+ add_welcome(event.chat_id, None, m, btn)
+ await eor(x, get_string("grt_1"))
+ elif text:
+ if not btn:
+ txt, btn = get_msg_button(text)
+ add_welcome(event.chat_id, txt, None, btn)
+ await eor(x, get_string("grt_1"))
+ else:
+ await eor(x, get_string("grt_3"), time=5)
+
+
+@ultroid_cmd(pattern="clearwelcome$", groups_only=True)
+async def clearwel(event):
+ if not get_welcome(event.chat_id):
+ return await event.eor(get_string("grt_4"), time=5)
+ delete_welcome(event.chat_id)
+ await event.eor(get_string("grt_5"), time=5)
+
+
+@ultroid_cmd(pattern="getwelcome$", groups_only=True)
+async def listwel(event):
+ wel = get_welcome(event.chat_id)
+ if not wel:
+ return await event.eor(get_string("grt_4"), time=5)
+ msgg, med = wel["welcome"], wel["media"]
+ if wel.get("button"):
+ btn = create_tl_btn(wel["button"])
+ return await something(event, msgg, med, btn)
+ await event.reply(f"**Welcome Note in this chat**\n\n`{msgg}`", file=med)
+ await event.delete()
+
+
+@ultroid_cmd(pattern="setgoodbye", groups_only=True)
+async def setgb(event):
+ x = await event.eor(get_string("com_1"))
+ r = await event.get_reply_message()
+ btn = format_btn(r.buttons) if (r and r.buttons) else None
+ try:
+ text = event.text.split(maxsplit=1)[1]
+ except IndexError:
+ text = r.text if r else None
+ if r and r.media:
+ wut = mediainfo(r.media)
+ if wut.startswith(("pic", "gif")):
+ dl = await r.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "video":
+ if r.media.document.size > 8 * 1000 * 1000:
+ return await eor(x, get_string("com_4"), time=5)
+ dl = await r.download_media()
+ variable = uf(dl)
+ os.remove(dl)
+ m = f"https://graph.org{variable[0]}"
+ elif wut == "web":
+ m = None
+ else:
+ m = pack_bot_file_id(r.media)
+ if r.text:
+ txt = r.text
+ if not btn:
+ txt, btn = get_msg_button(r.text)
+ add_goodbye(event.chat_id, txt, m, btn)
+ else:
+ add_goodbye(event.chat_id, None, m, btn)
+ await eor(x, "`Goodbye note saved`")
+ elif text:
+ if not btn:
+ txt, btn = get_msg_button(text)
+ add_goodbye(event.chat_id, txt, None, btn)
+ await eor(x, "`Goodbye note saved`")
+ else:
+ await eor(x, get_string("grt_7"), time=5)
+
+
+@ultroid_cmd(pattern="cleargoodbye$", groups_only=True)
+async def clearwgb(event):
+ if not get_goodbye(event.chat_id):
+ return await event.eor(get_string("grt_6"), time=5)
+ delete_goodbye(event.chat_id)
+ await event.eor("`Goodbye Note Deleted`", time=5)
+
+
+@ultroid_cmd(pattern="getgoodbye$", groups_only=True)
+async def listgd(event):
+ wel = get_goodbye(event.chat_id)
+ if not wel:
+ return await event.eor(get_string("grt_6"), time=5)
+ msgg = wel["goodbye"]
+ med = wel["media"]
+ if wel.get("button"):
+ btn = create_tl_btn(wel["button"])
+ return await something(event, msgg, med, btn)
+ await event.reply(f"**Goodbye Note in this chat**\n\n`{msgg}`", file=med)
+ await event.delete()
+
+
+@ultroid_cmd(pattern="thankmembers (on|off)", groups_only=True)
+async def thank_set(event):
+ type_ = event.pattern_match.group(1).strip()
+ if not type_ or type_ == "":
+ await eor(
+ event,
+ f"**Current Chat Settings:**\n**Thanking Members:** `{must_thank(event.chat_id)}`\n\nUse `{HNDLR}thankmembers on` or `{HNDLR}thankmembers off` to toggle current settings!",
+ )
+ return
+ chat = event.chat_id
+ if type_.lower() == "on":
+ add_thanks(chat)
+ elif type_.lower() == "off":
+ remove_thanks(chat)
+ await eor(
+ event,
+ f"**Done! Thank you members has been turned** `{type_.lower()}` **for this chat**!",
+ )
diff --git a/plugins/imagetools.py b/plugins/imagetools.py
new file mode 100644
index 0000000000000000000000000000000000000000..ef633427e4df89fb6d964a4fbce7f83001561f69
--- /dev/null
+++ b/plugins/imagetools.py
@@ -0,0 +1,292 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}border `
+ To create border around that media..
+ Ex - `{i}border 12,22,23`
+ - `{i}border 12,22,23 ; width (in number)`
+
+⢠`{i}grey `
+ To make it black nd white.
+
+⢠`{i}color `
+ To make it Colorfull.
+
+⢠`{i}toon `
+ To make it toon.
+
+⢠`{i}danger `
+ To make it look Danger.
+
+⢠`{i}negative `
+ To make negative image.
+
+⢠`{i}blur `
+ To make it blurry.
+
+⢠`{i}quad `
+ create a Vortex.
+
+⢠`{i}mirror `
+ To create mirror pic.
+
+⢠`{i}flip `
+ To make it flip.
+
+⢠`{i}sketch `
+ To draw its sketch.
+
+⢠`{i}blue `
+ just cool.
+
+⢠`{i}csample `
+ example : `{i}csample red`
+ `{i}csample #ffffff`
+
+⢠`{i}pixelator `
+ Create a Pixelated Image..
+"""
+import os
+
+from . import LOGS, con
+
+try:
+ import cv2
+except ImportError:
+ LOGS.error(f"{__file__}: OpenCv not Installed.")
+
+import numpy as np
+
+try:
+ from PIL import Image
+except ImportError:
+ Image = None
+ LOGS.info(f"{__file__}: PIL not Installed.")
+from telegraph import upload_file as upf
+from telethon.errors.rpcerrorlist import (
+ ChatSendMediaForbiddenError,
+ MessageDeleteForbiddenError,
+)
+
+from . import (
+ Redis,
+ async_searcher,
+ download_file,
+ get_string,
+ requests,
+ udB,
+ ultroid_cmd,
+)
+
+
+@ultroid_cmd(pattern="color$")
+async def _(event):
+ reply = await event.get_reply_message()
+ if not (reply and reply.media):
+ return await event.eor("`Reply To a Black and White Image`")
+ xx = await event.eor("`Coloring image đ¨đď¸...`")
+ image = await reply.download_media()
+ img = cv2.VideoCapture(image)
+ ret, frame = img.read()
+ cv2.imwrite("ult.jpg", frame)
+ if udB.get_key("DEEP_API"):
+ key = Redis("DEEP_API")
+ else:
+ key = "quickstart-QUdJIGlzIGNvbWluZy4uLi4K"
+ r = requests.post(
+ "https://api.deepai.org/api/colorizer",
+ files={"image": open("ult.jpg", "rb")},
+ headers={"api-key": key},
+ )
+ os.remove("ult.jpg")
+ os.remove(image)
+ if "status" in r.json():
+ return await event.edit(
+ r.json()["status"] + "\nGet api nd set `{i}setdb DEEP_API key`"
+ )
+ r_json = r.json()["output_url"]
+ await event.client.send_file(event.chat_id, r_json, reply_to=reply)
+ await xx.delete()
+
+
+@ultroid_cmd(pattern="(grey|blur|negative|danger|mirror|quad|sketch|flip|toon)$")
+async def ult_tools(event):
+ match = event.pattern_match.group(1)
+ ureply = await event.get_reply_message()
+ if not (ureply and (ureply.media)):
+ await event.eor(get_string("cvt_3"))
+ return
+ ultt = await ureply.download_media()
+ xx = await event.eor(get_string("com_1"))
+ if ultt.endswith(".tgs"):
+ xx = await xx.edit(get_string("sts_9"))
+ file = await con.convert(ultt, convert_to="png", outname="ult")
+ ult = cv2.imread(file)
+ if match == "grey":
+ ultroid = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)
+ elif match == "blur":
+ ultroid = cv2.GaussianBlur(ult, (35, 35), 0)
+ elif match == "negative":
+ ultroid = cv2.bitwise_not(ult)
+ elif match == "danger":
+ dan = cv2.cvtColor(ult, cv2.COLOR_BGR2RGB)
+ ultroid = cv2.cvtColor(dan, cv2.COLOR_HSV2BGR)
+ elif match == "mirror":
+ ish = cv2.flip(ult, 1)
+ ultroid = cv2.hconcat([ult, ish])
+ elif match == "flip":
+ trn = cv2.flip(ult, 1)
+ ish = cv2.rotate(trn, cv2.ROTATE_180)
+ ultroid = cv2.vconcat([ult, ish])
+ elif match == "quad":
+ ult = cv2.imread(file)
+ roid = cv2.flip(ult, 1)
+ mici = cv2.hconcat([ult, roid])
+ fr = cv2.flip(mici, 1)
+ trn = cv2.rotate(fr, cv2.ROTATE_180)
+ ultroid = cv2.vconcat([mici, trn])
+ elif match == "sketch":
+ gray_image = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)
+ inverted_gray_image = 255 - gray_image
+ blurred_img = cv2.GaussianBlur(inverted_gray_image, (21, 21), 0)
+ inverted_blurred_img = 255 - blurred_img
+ ultroid = cv2.divide(gray_image, inverted_blurred_img, scale=256.0)
+ elif match == "toon":
+ height, width, _ = ult.shape
+ samples = np.zeros([height * width, 3], dtype=np.float32)
+ count = 0
+ for x in range(height):
+ for y in range(width):
+ samples[count] = ult[x][y]
+ count += 1
+ _, labels, centers = cv2.kmeans(
+ samples,
+ 12,
+ None,
+ (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10000, 0.0001),
+ 5,
+ cv2.KMEANS_PP_CENTERS,
+ )
+ centers = np.uint8(centers)
+ ish = centers[labels.flatten()]
+ ultroid = ish.reshape(ult.shape)
+ cv2.imwrite("ult.jpg", ultroid)
+ await ureply.reply(
+ file="ult.jpg",
+ force_document=False,
+ )
+ await xx.delete()
+ os.remove("ult.jpg")
+ os.remove(file)
+
+
+@ultroid_cmd(pattern="csample (.*)")
+async def sampl(ult):
+ if color := ult.pattern_match.group(1).strip():
+ img = Image.new("RGB", (200, 100), f"{color}")
+ img.save("csample.png")
+ try:
+ try:
+ await ult.delete()
+ await ult.respond(f"Colour Sample for `{color}` !", file="csample.png")
+ except MessageDeleteForbiddenError:
+ await ult.reply(f"Colour Sample for `{color}` !", file="csample.png")
+ except ChatSendMediaForbiddenError:
+ await ult.eor("Umm! Sending Media is disabled here!")
+
+ else:
+ await ult.eor("Wrong Color Name/Hex Code specified!")
+
+
+@ultroid_cmd(
+ pattern="blue$",
+)
+async def ultd(event):
+ ureply = await event.get_reply_message()
+ xx = await event.eor("`...`")
+ if not (ureply and (ureply.media)):
+ await xx.edit(get_string("cvt_3"))
+ return
+ ultt = await ureply.download_media()
+ if ultt.endswith(".tgs"):
+ await xx.edit(get_string("sts_9"))
+ file = await con.convert(ultt, convert_to="png", outname="ult")
+ got = upf(file)
+ lnk = f"https://graph.org{got[0]}"
+ r = await async_searcher(
+ f"https://nekobot.xyz/api/imagegen?type=blurpify&image={lnk}", re_json=True
+ )
+ ms = r.get("message")
+ if not r["success"]:
+ return await xx.edit(ms)
+ await download_file(ms, "ult.png")
+ img = Image.open("ult.png").convert("RGB")
+ img.save("ult.webp", "webp")
+ await event.client.send_file(
+ event.chat_id,
+ "ult.webp",
+ force_document=False,
+ reply_to=event.reply_to_msg_id,
+ )
+ await xx.delete()
+ os.remove("ult.png")
+ os.remove("ult.webp")
+ os.remove(ultt)
+
+
+@ultroid_cmd(pattern="border( (.*)|$)")
+async def ok(event):
+ hm = await event.get_reply_message()
+ if not (hm and (hm.photo or hm.sticker)):
+ return await event.eor("`Reply to Sticker or Photo..`")
+ col = event.pattern_match.group(1).strip()
+ wh = 20
+ if not col:
+ col = [255, 255, 255]
+ else:
+ try:
+ if ";" in col:
+ col_ = col.split(";", maxsplit=1)
+ wh = int(col_[1])
+ col = col_[0]
+ col = [int(col) for col in col.split(",")[:2]]
+ except ValueError:
+ return await event.eor("`Not a Valid Input...`")
+ okla = await hm.download_media()
+ img1 = cv2.imread(okla)
+ constant = cv2.copyMakeBorder(img1, wh, wh, wh, wh, cv2.BORDER_CONSTANT, value=col)
+ cv2.imwrite("output.png", constant)
+ await event.client.send_file(event.chat.id, "output.png")
+ os.remove("output.png")
+ os.remove(okla)
+ await event.delete()
+
+
+@ultroid_cmd(pattern="pixelator( (.*)|$)")
+async def pixelator(event):
+ reply_message = await event.get_reply_message()
+ if not (reply_message and (reply_message.photo or reply_message.sticker)):
+ return await event.eor("`Reply to a photo`")
+ hw = 50
+ try:
+ hw = int(event.pattern_match.group(1).strip())
+ except (ValueError, TypeError):
+ pass
+ msg = await event.eor(get_string("com_1"))
+ image = await reply_message.download_media()
+ input_ = cv2.imread(image)
+ height, width = input_.shape[:2]
+ w, h = (hw, hw)
+ temp = cv2.resize(input_, (w, h), interpolation=cv2.INTER_LINEAR)
+ output = cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)
+ cv2.imwrite("output.jpg", output)
+ await msg.respond("⢠Pixelated by Ultroid", file="output.jpg")
+ await msg.delete()
+ os.remove("output.jpg")
+ os.remove(image)
diff --git a/plugins/locks.py b/plugins/locks.py
new file mode 100644
index 0000000000000000000000000000000000000000..849c242164be9a5b588b513a6d868742eeb51311
--- /dev/null
+++ b/plugins/locks.py
@@ -0,0 +1,39 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}lock `
+ Lock the Used Setting in Used Group.
+
+⢠`{i}unlock `
+ UNLOCK the Used Setting in Used Group.
+"""
+from telethon.tl.functions.messages import EditChatDefaultBannedRightsRequest
+
+from pyUltroid.fns.admins import lock_unlock
+
+from . import ultroid_cmd
+
+
+@ultroid_cmd(
+ pattern="(un|)lock( (.*)|$)", admins_only=True, manager=True, require="change_info"
+)
+async def un_lock(e):
+ mat = e.pattern_match.group(2).strip()
+ if not mat:
+ return await e.eor("`Give some Proper Input..`", time=5)
+ lock = e.pattern_match.group(1) == ""
+ ml = lock_unlock(mat, lock)
+ if not ml:
+ return await e.eor("`Incorrect Input`", time=5)
+ msg = "Locked" if lock else "Unlocked"
+ try:
+ await e.client(EditChatDefaultBannedRightsRequest(e.chat_id, ml))
+ except Exception as er:
+ return await e.eor(str(er))
+ await e.eor(f"**{msg}** - `{mat}` ! ")
diff --git a/plugins/logo.py b/plugins/logo.py
new file mode 100644
index 0000000000000000000000000000000000000000..92531bb1bf342597c0f3a9e1e4a12a1ce7cba95d
--- /dev/null
+++ b/plugins/logo.py
@@ -0,0 +1,101 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}logo `
+ Generate a logo of the given Text
+ Or Reply To image , to write ur text on it.
+ Or Reply To Font File, To write with that font.
+
+"""
+import glob
+import os
+import random
+
+from telethon.tl.types import InputMessagesFilterPhotos
+
+try:
+ from PIL import Image
+except ImportError:
+ Image = None
+from pyUltroid.fns.misc import unsplashsearch
+from pyUltroid.fns.tools import LogoHelper
+
+from . import OWNER_ID, OWNER_NAME, download_file, get_string, mediainfo, ultroid_cmd
+
+
+@ultroid_cmd(pattern="logo( (.*)|$)")
+async def logo_gen(event):
+ xx = await event.eor(get_string("com_1"))
+ name = event.pattern_match.group(1).strip()
+ if not name:
+ return await xx.eor("`Give a name too!`", time=5)
+ bg_, font_ = None, None
+ if event.reply_to_msg_id:
+ temp = await event.get_reply_message()
+ if temp.media:
+ if hasattr(temp.media, "document") and (
+ ("font" in temp.file.mime_type)
+ or (".ttf" in temp.file.name)
+ or (".otf" in temp.file.name)
+ ):
+ font_ = await temp.download_media("resources/fonts/")
+ elif "pic" in mediainfo(temp.media):
+ bg_ = await temp.download_media()
+ if not bg_:
+ SRCH = [
+ "background",
+ "neon",
+ "anime",
+ "art",
+ "bridges",
+ "streets",
+ "computer",
+ "cyberpunk",
+ "nature",
+ "abstract",
+ "exoplanet",
+ "magic",
+ "3d render",
+ ]
+ res = await unsplashsearch(random.choice(SRCH), limit=1)
+ bg_, _ = await download_file(res[0], "resources/downloads/logo.png")
+ newimg = "resources/downloads/unsplash-temp.jpg"
+ img_ = Image.open(bg_)
+ img_.save(newimg)
+ os.remove(bg_)
+ bg_ = newimg
+
+ if not font_:
+ fpath_ = glob.glob("resources/fonts/*")
+ font_ = random.choice(fpath_)
+ if len(name) <= 8:
+ strke = 10
+ elif len(name) >= 9:
+ strke = 5
+ else:
+ strke = 20
+ name = LogoHelper.make_logo(
+ bg_,
+ name,
+ font_,
+ fill="white",
+ stroke_width=strke,
+ stroke_fill="black",
+ )
+ await xx.edit("`Done!`")
+ await event.client.send_file(
+ event.chat_id,
+ file=name,
+ caption=f"Logo by [{OWNER_NAME}](tg://user?id={OWNER_ID})",
+ force_document=True,
+ )
+ os.remove(name)
+ await xx.delete()
+ if os.path.exists(bg_):
+ os.remove(bg_)
diff --git a/plugins/mediatools.py b/plugins/mediatools.py
new file mode 100644
index 0000000000000000000000000000000000000000..91773026da9ccf5e1d586cabd29d9c360d09b199
--- /dev/null
+++ b/plugins/mediatools.py
@@ -0,0 +1,146 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}mediainfo //`
+ To get info about it.
+
+⢠`{i}rotate `
+ Rotate any video/photo/media..
+ Note : for video it should be angle of 90's
+"""
+import os
+import time
+from datetime import datetime as dt
+
+from pyUltroid.fns.misc import rotate_image
+from pyUltroid.fns.tools import make_html_telegraph
+
+from . import (
+ LOGS,
+ Telegraph,
+ bash,
+ downloader,
+ get_string,
+ is_url_ok,
+ mediainfo,
+ ultroid_cmd,
+)
+
+try:
+ import cv2
+except ImportError:
+ LOGS.info("WARNING: 'cv2' not found!")
+ cv2 = None
+
+
+@ultroid_cmd(pattern="mediainfo( (.*)|$)")
+async def mi(e):
+ r = await e.get_reply_message()
+ match = e.pattern_match.group(1).strip()
+ taime = time.time()
+ extra = ""
+ if r and r.media:
+ xx = mediainfo(r.media)
+ murl = r.media.stringify()
+ url = await make_html_telegraph("Mediainfo", f"{murl}")
+ extra = f"**[{xx}]({url})**\n\n"
+ e = await e.eor(f"{extra}`Loading More...`", link_preview=False)
+
+ if hasattr(r.media, "document"):
+ file = r.media.document
+ mime_type = file.mime_type
+ filename = r.file.name
+ if not filename:
+ if "audio" in mime_type:
+ filename = "audio_" + dt.now().isoformat("_", "seconds") + ".ogg"
+ elif "video" in mime_type:
+ filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"
+ dl = await downloader(
+ f"resources/downloads/{filename}",
+ file,
+ e,
+ taime,
+ f"{extra}`Loading More...`",
+ )
+
+ naam = dl.name
+ else:
+ naam = await r.download_media()
+ elif match and (
+ os.path.isfile(match)
+ or (match.startswith("https://") and (await is_url_ok(match)))
+ ):
+ naam, xx = match, "file"
+ else:
+ return await e.eor(get_string("cvt_3"), time=5)
+ out, er = await bash(f"mediainfo '{naam}'")
+ if er:
+ LOGS.info(er)
+ out = extra or str(er)
+ return await e.edit(out, link_preview=False)
+ makehtml = ""
+ if naam.endswith((".jpg", ".png")):
+ if os.path.exists(naam):
+ med = "https://graph.org" + Telegraph.upload_file(naam)[0]["src"]
+ else:
+ med = match
+ makehtml += f"
"
+ for line in out.split("\n"):
+ line = line.strip()
+ if not line:
+ makehtml += "
"
+ elif ":" not in line:
+ makehtml += f"{line}
"
+ else:
+ makehtml += f"{line}
"
+ try:
+ urll = await make_html_telegraph("Mediainfo", makehtml)
+ except Exception as er:
+ LOGS.exception(er)
+ return
+ await e.eor(f"{extra}[{get_string('mdi_1')}]({urll})", link_preview=False)
+ if not match:
+ os.remove(naam)
+
+
+@ultroid_cmd(pattern="rotate( (.*)|$)")
+async def rotate_(ult):
+ match = ult.pattern_match.group(1).strip()
+ if not ult.is_reply:
+ return await ult.eor("`Reply to a media...`")
+ if match:
+ try:
+ match = int(match)
+ except ValueError:
+ match = None
+ if not match:
+ return await ult.eor("`Please provide a valid angle to rotate media..`")
+ reply = await ult.get_reply_message()
+ msg = await ult.eor(get_string("com_1"))
+ photo = reply.game.photo if reply.game else None
+ if reply.video:
+ media = await reply.download_media()
+ file = f"{media}.mp4"
+ await bash(
+ f'ffmpeg -i "{media}" -c copy -metadata:s:v:0 rotate={match} "{file}" -y'
+ )
+ elif photo or reply.photo or reply.sticker:
+ media = await ult.client.download_media(photo or reply)
+ img = cv2.imread(media)
+ new_ = rotate_image(img, match)
+ file = "ult.png"
+ cv2.imwrite(file, new_)
+ else:
+ return await msg.edit("`Unsupported Media..\nReply to Photo/Video`")
+ if os.path.exists(file):
+ await ult.client.send_file(
+ ult.chat_id, file=file, video_note=bool(reply.video_note), reply_to=reply.id
+ )
+ os.remove(media)
+ await msg.try_delete()
diff --git a/plugins/misc.py b/plugins/misc.py
new file mode 100644
index 0000000000000000000000000000000000000000..e82b6702e97262c19c7e95bfc2055c0dcc1e5d19
--- /dev/null
+++ b/plugins/misc.py
@@ -0,0 +1,140 @@
+# Ultroid - UserBot
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}eod`
+ `Get Event of the Today`
+
+⢠`{i}pntrst `
+ Download and send pinterest pins
+
+⢠`{i}gadget `
+ Gadget Search from Telegram.
+
+⢠`{i}randomuser`
+ Generate details about a random user.
+
+⢠`{i}ascii `
+ Convert replied image into html.
+"""
+
+import os
+from datetime import datetime as dt
+
+from bs4 import BeautifulSoup as bs
+
+try:
+ from htmlwebshot import WebShot
+except ImportError:
+ WebShot = None
+try:
+ from img2html.converter import Img2HTMLConverter
+except ImportError:
+ Img2HTMLConverter = None
+
+from . import async_searcher, get_random_user_data, get_string, re, ultroid_cmd
+
+
+@ultroid_cmd(pattern="eod$")
+async def diela(e):
+ m = await e.eor(get_string("com_1"))
+ li = "https://daysoftheyear.com"
+ te = "đ **Events of the Day**\n\n"
+ da = dt.now()
+ month = da.strftime("%b")
+ li += f"/days/{month}/" + da.strftime("%F").split("-")[2]
+ ct = await async_searcher(li, re_content=True)
+ bt = bs(ct, "html.parser", from_encoding="utf-8")
+ ml = bt.find_all("a", "js-link-target", href=re.compile("daysoftheyear.com/days"))
+ for eve in ml[:5]:
+ te += f'⢠[{eve.text}]({eve["href"]})\n'
+ await m.edit(te, link_preview=False)
+
+
+@ultroid_cmd(
+ pattern="pntrst( (.*)|$)",
+)
+async def pinterest(e):
+ m = e.pattern_match.group(1).strip()
+ if not m:
+ return await e.eor("`Give pinterest link.`", time=3)
+ soup = await async_searcher(
+ "https://www.expertstool.com/download-pinterest-video/",
+ data={"url": m},
+ post=True,
+ )
+ try:
+ _soup = bs(soup, "html.parser").find("table").tbody.find_all("tr")
+ except BaseException:
+ return await e.eor("`Wrong link or private pin.`", time=5)
+ file = _soup[1] if len(_soup) > 1 else _soup[0]
+ file = file.td.a["href"]
+ await e.client.send_file(e.chat_id, file, caption=f"Pin:- {m}")
+
+
+@ultroid_cmd(pattern="gadget( (.*)|$)")
+async def mobs(e):
+ mat = e.pattern_match.group(1).strip()
+ if not mat:
+ await e.eor("Please Give a Mobile Name to look for.")
+ query = mat.replace(" ", "%20")
+ jwala = f"https://gadgets.ndtv.com/search?searchtext={query}"
+ c = await async_searcher(jwala)
+ b = bs(c, "html.parser", from_encoding="utf-8")
+ co = b.find_all("div", "rvw-imgbox")
+ if not co:
+ return await e.eor("No Results Found!")
+ bt = await e.eor(get_string("com_1"))
+ out = "**đą Mobile / Gadgets Search**\n\n"
+ li = co[0].find("a")
+ imu, title = None, li.find("img")["title"]
+ cont = await async_searcher(li["href"])
+ nu = bs(cont, "html.parser", from_encoding="utf-8")
+ req = nu.find_all("div", "_pdsd")
+ imu = nu.find_all(
+ "img", src=re.compile("https://i.gadgets360cdn.com/products/large/")
+ )
+ if imu:
+ imu = imu[0]["src"].split("?")[0] + "?downsize=*:420&output-quality=80"
+ out += f"âď¸ **[{title}]({li['href']})**\n\n"
+ for fp in req:
+ ty = fp.findNext()
+ out += f"- **{ty.text}** - `{ty.findNext().text}`\n"
+ out += "_"
+ if imu == []:
+ imu = None
+ await e.reply(out, file=imu, link_preview=False)
+ await bt.delete()
+
+
+@ultroid_cmd(pattern="randomuser")
+async def _gen_data(event):
+ x = await event.eor(get_string("com_1"))
+ msg, pic = await get_random_user_data()
+ await event.reply(file=pic, message=msg)
+ await x.delete()
+
+
+@ultroid_cmd(
+ pattern="ascii( (.*)|$)",
+)
+async def _(e):
+ if not Img2HTMLConverter:
+ return await e.eor("'img2html-converter' not installed!")
+ if not e.reply_to_msg_id:
+ return await e.eor(get_string("ascii_1"))
+ m = await e.eor(get_string("ascii_2"))
+ img = await (await e.get_reply_message()).download_media()
+ char = e.pattern_match.group(1).strip() or "â "
+ converter = Img2HTMLConverter(char=char)
+ html = converter.convert(img)
+ shot = WebShot(quality=85)
+ pic = await shot.create_pic_async(html=html)
+ await m.delete()
+ await e.reply(file=pic)
+ os.remove(pic)
+ os.remove(img)
diff --git a/plugins/mute.py b/plugins/mute.py
new file mode 100644
index 0000000000000000000000000000000000000000..2939908fa0fb5959ef01ae54d345c1054a38ee4c
--- /dev/null
+++ b/plugins/mute.py
@@ -0,0 +1,210 @@
+# Ultroid - UserBot
+# Copyright (C) 2021-2023 TeamUltroid
+#
+# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
+# PLease read the GNU Affero General Public License in
+# .
+"""
+â Commands Available -
+
+⢠`{i}mute `
+ Mute user in current chat.
+
+⢠`{i}unmute `
+ Unmute user in current chat.
+
+⢠`{i}dmute `
+ Mute user in current chat by deleting msgs.
+
+⢠`{i}undmute `
+ Unmute dmuted user in current chat.
+
+⢠`{i}tmute