├── runtime.txt ├── Procfile ├── cache ├── nexaub_data.json └── NEXAUB.png ├── .vscode └── settings.json ├── heroku.yml ├── nexa_userbot ├── core │ ├── nexaub_database │ │ ├── __init__.py │ │ ├── nexaub_db_anti_functions.py │ │ ├── nexaub_db_afk.py │ │ ├── nexaub_db_globals.py │ │ ├── nexaub_db_pm.py │ │ ├── nexaub_db_sudos.py │ │ └── nexaub_db_conf.py │ ├── errors.py │ ├── startup_checks.py │ └── main_cmd.py ├── __init__.py ├── modules │ ├── __init__.py │ ├── Extras │ │ └── __init__.py │ ├── unicode.py │ ├── installer.py │ ├── dl_downloader.py │ ├── extractor.py │ ├── github.py │ ├── webss.py │ ├── telegraph.py │ ├── owner.py │ ├── clouds.py │ ├── short_url.py │ ├── translator.py │ ├── help.py │ ├── search.py │ ├── whois.py │ ├── pictools.py │ ├── spam.py │ ├── megadl.py │ ├── wallpaper.py │ ├── afk.py │ ├── paste.py │ ├── hack.py │ ├── eval.py │ ├── sudos.py │ ├── alive.py │ ├── arq.py │ ├── groups.py │ ├── updater.py │ ├── antifuncs.py │ ├── stickers.py │ ├── pmguard.py │ └── globals.py ├── helpers │ ├── pictool_help.py │ ├── regexes.py │ ├── meganz_helpers.py │ ├── up_to_tg.py │ ├── downloader.py │ └── pyrogram_help.py └── __main__.py ├── Dockerfile ├── startup.sh ├── requirements.txt ├── config.py ├── pyro_str_gen.py ├── app.json └── README.md /runtime.txt: -------------------------------------------------------------------------------- 1 | python-3.9.7 -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | nexaub: bash startup.sh -------------------------------------------------------------------------------- /cache/nexaub_data.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v0.0.6a" 3 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.analysis.extraPaths": ["./nexa_userbot"] 3 | } -------------------------------------------------------------------------------- /cache/NEXAUB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Itz-fork/Nexa-Userbot/HEAD/cache/NEXAUB.png -------------------------------------------------------------------------------- /heroku.yml: -------------------------------------------------------------------------------- 1 | build: 2 | docker: 3 | worker: Dockerfile 4 | run: 5 | worker: bash startup.sh -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from motor.motor_asyncio import AsyncIOMotorClient 5 | from config import Config 6 | 7 | mongodb = AsyncIOMotorClient(Config.MONGODB_URL) 8 | nexa_mongodb = mongodb["NEXAUB"] -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:latest 2 | 3 | RUN apt update && apt upgrade -y 4 | RUN apt install git python3-pip ffmpeg -y 5 | RUN apt -qq install -y --no-install-recommends megatools 6 | RUN pip3 install -U pip 7 | RUN mkdir /app/ 8 | WORKDIR /app/ 9 | RUN git clone https://github.com/Itz-fork/Nexa-Userbot.git /app 10 | RUN pip3 install -U -r requirements.txt 11 | CMD bash startup.sh -------------------------------------------------------------------------------- /nexa_userbot/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | from time import time 4 | from pyrogram import Client 5 | from config import Config 6 | 7 | # Configs 8 | CMD_HELP = {} 9 | StartTime = time() 10 | 11 | NEXAUB = Client( 12 | api_hash=Config.API_HASH, 13 | api_id=Config.APP_ID, 14 | session_name=Config.PYRO_STR_SESSION, 15 | sleep_threshold=10 16 | ) -------------------------------------------------------------------------------- /nexa_userbot/modules/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot 4 | 5 | import glob 6 | from os.path import dirname, basename, isfile, join 7 | 8 | modules = glob.glob(join(dirname(__file__), "*.py")) 9 | __all__ = [ 10 | basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py") 11 | ] 12 | 13 | # Telegram IDs of ub dev(s) 14 | nexaub_devs = [1340254734, 1961906719] -------------------------------------------------------------------------------- /nexa_userbot/modules/Extras/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot 4 | 5 | import glob 6 | from os.path import dirname, basename, isfile, join 7 | 8 | async def get_xtra_modules_names(): 9 | modules = glob.glob(join(dirname(__file__), "*.py")) 10 | __xall__ = [ 11 | basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py") 12 | ] 13 | return __xall__ -------------------------------------------------------------------------------- /startup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | echo " 4 | ============ Nexa Userbot ============ 5 | 6 | 7 | Copyright (c) 2021 Itz-fork | @NexaBotsUpdates 8 | " 9 | 10 | start_nexaub () { 11 | if [[ -z "$PYRO_STR_SESSION" ]] 12 | then 13 | echo "WARNING: Please add Pyrogram String Session" 14 | else 15 | python3 -m nexa_userbot 16 | fi 17 | } 18 | 19 | _install_nexaub () { 20 | echo ">>>> Starting Nexa-Userbot" 21 | start_nexaub 22 | } 23 | 24 | _install_nexaub -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram 2 | TgCrypto 3 | requests 4 | aiohttp 5 | aiofiles 6 | pillow 7 | numpy 8 | beautifulsoup4 9 | gitpython 10 | heroku3 11 | filesplit 12 | filetype 13 | motor 14 | dnspython 15 | python-arq 16 | telegraph 17 | httpx 18 | emoji 19 | git+https://github.com/Itz-fork/Gofile2.git 20 | git+https://github.com/Itz-fork/py-extract.git 21 | git+https://github.com/Itz-fork/pyro-mega.py.git 22 | git+https://github.com/Itz-fork/py-trans.git 23 | git+https://github.com/Itz-fork/fake-useragent.git -------------------------------------------------------------------------------- /nexa_userbot/helpers/pictool_help.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: TheHamkerCat 4 | 5 | from io import BytesIO 6 | from aiohttp import ClientSession 7 | 8 | 9 | # Aiohttlp Session 10 | aiosession = ClientSession() 11 | 12 | async def gib_carbon_sar(code): 13 | url = "https://carbonara.vercel.app/api/cook" 14 | async with aiosession.post(url, json={"code": code}) as resp: 15 | image = BytesIO(await resp.read()) 16 | image.name = "carbon.png" 17 | return image -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | class Config(object): 7 | APP_ID = os.environ.get("APP_ID", "") 8 | API_HASH = os.environ.get("API_HASH", "") 9 | # Pyrogram Session 10 | PYRO_STR_SESSION = os.environ.get("PYRO_STR_SESSION", "") 11 | CMD_PREFIX = os.environ.get("CMD_PREFIX", ".") 12 | MONGODB_URL = os.environ.get("MONGODB_URL") 13 | HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME") 14 | HEROKU_API_KEY = os.environ.get("HEROKU_API_KEY") -------------------------------------------------------------------------------- /nexa_userbot/core/errors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | class Errors: 5 | """ 6 | ## Errors 7 | 8 | ### Arguments: 9 | 10 | None 11 | """ 12 | class SpamFailed(Exception): 13 | """ 14 | Raises when the spam task was failed 15 | """ 16 | pass 17 | 18 | class DownloadFailed(Exception): 19 | """ 20 | Raises when the download task was failed 21 | """ 22 | pass 23 | class DelAllFailed(Exception): 24 | """ 25 | Raises when the del all function was failed 26 | """ 27 | pass -------------------------------------------------------------------------------- /nexa_userbot/helpers/regexes.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from re import compile 5 | 6 | 7 | class REGEXES: 8 | """ 9 | Regexes Class 10 | 11 | Included Regexes: 12 | 13 | arab: Arabic Language 14 | chinese: Chinese Language 15 | japanese: Japanese Language (Includes Hiragana, Kanji and Katakana) 16 | sinhala: Sinhala Language 17 | tamil: Tamil Language 18 | cyrillic: Cyrillic Language 19 | """ 20 | 21 | arab = compile('[\u0627-\u064a]') 22 | chinese = compile('[\u4e00-\u9fff]') 23 | japanese = compile('[(\u30A0-\u30FF|\u3040-\u309Fー|\u4E00-\u9FFF)]') 24 | sinhala = compile('[\u0D80-\u0DFF]') 25 | tamil = compile('[\u0B02-\u0DFF]') 26 | cyrillic = compile('[\u0400-\u04FF]') -------------------------------------------------------------------------------- /nexa_userbot/helpers/meganz_helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from mega import Mega 5 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import get_custom_var 6 | 7 | async def getMegaEmailandPass(): 8 | m_email = await get_custom_var("MEGA_EMAIL") 9 | m_pass = await get_custom_var("MEGA_PASS") 10 | if not m_email or not m_pass: 11 | return None 12 | else: 13 | return [m_email, m_pass] 14 | 15 | async def loginToMega(e_and_m): 16 | client = Mega().login(e_and_m[0], e_and_m[1]) 17 | return client 18 | 19 | def UploadToMega(msg, file, mega): 20 | try: 21 | uploadfile = mega.upload(f"{file}", upstatusmsg=msg) 22 | public_link = mega.get_upload_link(uploadfile) 23 | # Editing the message with uploaded link 24 | msg.edit(f"**Successfully Uploaded!** \n\n**Link:** {public_link}", disable_web_page_preview=True) 25 | except Exception as e: 26 | return msg.edit(f"**Error:** \n`{e}`") -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_anti_functions.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_antif = nexa_mongodb["anti_functionsdb"] 7 | 8 | 9 | # To on / off / get anti functions 10 | async def set_anti_func(chat_id, status, mode): 11 | anti_f = await nexaub_antif.find_one({"_id": chat_id}) 12 | if anti_f: 13 | await nexaub_antif.update_one({"_id": chat_id}, {"$set": {"status": status, "mode": mode}}) 14 | else: 15 | await nexaub_antif.insert_one({"_id": chat_id, "status": status, "mode": mode}) 16 | 17 | async def get_anti_func(chat_id): 18 | anti_f = await nexaub_antif.find_one({"_id": chat_id}) 19 | if not anti_f: 20 | return None 21 | else: 22 | snm = [anti_f["status"], anti_f["mode"]] 23 | return snm 24 | 25 | async def del_anti_func(chat_id): 26 | anti_f = await nexaub_antif.find_one({"_id": chat_id}) 27 | if anti_f: 28 | await nexaub_antif.delete_one({"_id": chat_id}) 29 | return True 30 | else: 31 | return False -------------------------------------------------------------------------------- /pyro_str_gen.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import asyncio 5 | import tgcrypto 6 | from pyrogram import Client 7 | 8 | print(""" 9 | || Nexa Userbot || 10 | 11 | 12 | Copyright (c) 2021 Itz-fork 13 | """) 14 | 15 | async def pyro_str(): 16 | print("\nPlease Enter All Required Values to Generate Pyrogram String Session for your Account! \n") 17 | api_id = int(input("Enter Your APP ID: ")) 18 | api_hash = input("Enter Your API HASH: ") 19 | async with Client(":memory:", api_id, api_hash) as NEXAUB: 20 | pyro_session = await NEXAUB.export_session_string() 21 | session_msg = await NEXAUB.send_message("me", f"`{pyro_session}`") 22 | await session_msg.reply_text("Successfully Generated String Session! **Thanks for trying [Nexa Userbot](https://github.com/Itz-fork/Nexa-Userbot) 😊** \n\n**Join @NexaBotsUpdates**", disable_web_page_preview=True) 23 | print("\n🎉 String Session has been sent to your saved messages. Please check it. Thank You!\n") 24 | 25 | if __name__ == "__main__": 26 | loop = asyncio.get_event_loop() 27 | loop.run_until_complete(pyro_str()) -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_afk.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_afk = nexa_mongodb["afk_db"] 7 | 8 | # Database for afk module 9 | async def me_afk(afk_time, afk_reason="Busy 😴", delete_afk_msgs=False): 10 | p_afk = await nexaub_afk.find_one({"_id": "ME_AFK"}) 11 | if p_afk: 12 | await nexaub_afk.update_one({"_id": "ME_AFK"}, {"$set": {"g_afk_time": afk_time, "g_afk_reason": afk_reason, "del_afk_msgs": delete_afk_msgs}}) 13 | else: 14 | await nexaub_afk.insert_one({"_id": "ME_AFK", "g_afk_time": afk_time, "g_afk_reason": afk_reason, "del_afk_msgs": delete_afk_msgs}) 15 | 16 | async def get_afk(): 17 | alr_afk = await nexaub_afk.find_one({"_id": "ME_AFK"}) 18 | if alr_afk: 19 | afk_time = alr_afk["g_afk_time"] 20 | afk_reason = alr_afk["g_afk_reason"] 21 | del_afk_msgs = alr_afk["del_afk_msgs"] 22 | return afk_time, afk_reason, del_afk_msgs 23 | else: 24 | return None 25 | 26 | async def me_online(): 27 | r_afk = await nexaub_afk.find_one({"_id": "ME_AFK"}) 28 | if r_afk: 29 | await nexaub_afk.delete_one({"_id": "ME_AFK"}) 30 | else: 31 | return False -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_globals.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_gban = nexa_mongodb["gban_db"] 7 | 8 | ## Gban 9 | # Database for storing gban details 10 | async def gban_usr(gban_id, gban_reason="Abusing People!"): 11 | gban_user_id = int(gban_id) 12 | p_gbanned = await nexaub_gban.find_one({"gbanned_usr": gban_user_id}) 13 | if p_gbanned: 14 | return True 15 | else: 16 | await nexaub_gban.insert_one({"gbanned_usr": gban_user_id, "reason_for_gban": gban_reason}) 17 | 18 | # Get gbanned user list 19 | # Credits: Friday Userbot 20 | async def get_gbanned(): 21 | return [gban_usrs async for gban_usrs in nexaub_gban.find({})] 22 | 23 | # Get gbaned reason 24 | async def get_gban_reason(gban_id): 25 | gban_user_id = int(gban_id) 26 | pr_gbanned = await nexaub_gban.find_one({"gbanned_usr": gban_user_id}) 27 | if pr_gbanned: 28 | return pr_gbanned["reason_for_gban"] 29 | else: 30 | return None 31 | 32 | # Ungban a user 33 | async def ungban_usr(gban_id): 34 | gban_user_id = int(gban_id) 35 | alr_gbanned = await nexaub_gban.find_one({"gbanned_usr": gban_user_id}) 36 | if alr_gbanned: 37 | await nexaub_gban.delete_one({"gbanned_usr": gban_user_id}) 38 | else: 39 | return False -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_pm.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_pm_guard = nexa_mongodb["pm_gurad_db"] 7 | 8 | 9 | # Add a user to approved users database 10 | async def add_approved_user(user_id): 11 | good_usr = int(user_id) 12 | does_they_exists = await nexaub_pm_guard.find_one({"_id": "APPROVED_USERS"}) 13 | if does_they_exists: 14 | await nexaub_pm_guard.update_one({"_id": "APPROVED_USERS"}, {"$push": {"good_id": good_usr}}) 15 | else: 16 | await nexaub_pm_guard.insert_one({"_id": "APPROVED_USERS", "good_id": [good_usr]}) 17 | 18 | 19 | # Remove a user from approved users database 20 | async def rm_approved_user(user_id): 21 | bad_usr = int(user_id) 22 | does_good_ones_exists = await nexaub_pm_guard.find_one({"_id": "APPROVED_USERS"}) 23 | if does_good_ones_exists: 24 | await nexaub_pm_guard.update_one({"_id": "APPROVED_USERS"}, {"$pull": {"good_id": bad_usr}}) 25 | else: 26 | return None 27 | 28 | # Check if a user in approved users database 29 | async def check_user_approved(user_id): 30 | random_usr = int(user_id) 31 | does_good_users_exists = await nexaub_pm_guard.find_one({"_id": "APPROVED_USERS"}) 32 | if does_good_users_exists: 33 | good_users_list = [cool_user for cool_user in does_good_users_exists.get("good_id")] 34 | if random_usr in good_users_list: 35 | return True 36 | else: 37 | return False 38 | else: 39 | return False -------------------------------------------------------------------------------- /nexa_userbot/modules/unicode.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright (c) 2021 Itz-fork 3 | # Part of: Nexa-Userbot 4 | 5 | import os 6 | 7 | from pyrogram.types import Message 8 | from emoji import UNICODE_EMOJI 9 | from nexa_userbot import CMD_HELP 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from config import Config 12 | 13 | 14 | # Help 15 | mod_name = os.path.basename(__file__)[:-3] 16 | 17 | CMD_HELP.update( 18 | { 19 | f"{mod_name}": f""" 20 | **Unicode Detector,** 21 | 22 | ✘ `unicode` - To Check whether the replied message is unicode or not 23 | 24 | **Example:** 25 | 26 | ✘ `unicode`, 27 | ⤷ Reply to a message = `{Config.CMD_PREFIX}unicode` 28 | """, 29 | f"{mod_name}_category": "tools" 30 | } 31 | ) 32 | 33 | 34 | @nexaub.on_cmd(command=["unicode", "uni"]) 35 | async def checks_unicode(_, message: Message): 36 | uni_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 37 | r_msg = message.reply_to_message 38 | if not r_msg: 39 | return await uni_msg.edit("`Reply to a text message!`") 40 | msg_text = r_msg.text 41 | if not msg_text: 42 | return await uni_msg.edit("`Reply to a text message!`") 43 | # Checking if the message have unicode characters 44 | uni_count = 0 45 | for char in list(msg_text): 46 | try: 47 | char.encode("ascii") 48 | except: 49 | if char in UNICODE_EMOJI["en"]: 50 | return 51 | uni_count += 1 52 | if uni_count == 0: 53 | await uni_msg.edit("`Non-Unicode Characters are included in this message!`") 54 | else: 55 | await uni_msg.edit(f"`{uni_count} Unicode Characters are included in this message!`") -------------------------------------------------------------------------------- /nexa_userbot/__main__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import asyncio 4 | import logging 5 | 6 | from pyrogram import idle 7 | from nexa_userbot import NEXAUB 8 | from nexa_userbot.modules import * 9 | from nexa_userbot.core.startup_checks import check_or_set_log_channel, check_arq_api, download_plugins_in_channel, install_custom_plugins 10 | 11 | # Logging stuff 12 | logging.getLogger().setLevel(logging.INFO) 13 | logging.getLogger("pyrogram").setLevel(logging.WARNING) 14 | logging.getLogger("pyrogram.session.session").setLevel(logging.ERROR) 15 | logging.getLogger("pyrogram.parser.html").setLevel(logging.ERROR) 16 | 17 | 18 | async def main_startup(): 19 | print(""" 20 | || Nexa Userbot || 21 | 22 | Copyright (c) 2021 Itz-fork 23 | """ 24 | ) 25 | await NEXAUB.start() 26 | # Downloading and installing Custom Plugins 27 | logging.info(" >> Downloading Custom Plugins...") 28 | await download_plugins_in_channel() 29 | logging.info(" >> Installing Custom Plugins...") 30 | await install_custom_plugins() 31 | # Check or set log channel id 32 | logging.info(" >> Checking Log Channel...") 33 | log_channel_id = await check_or_set_log_channel() 34 | # Check if arq api is available else it'll obtain a one 35 | logging.info(" >> Checking ARQ API Key...") 36 | await check_arq_api() 37 | try: 38 | await NEXAUB.send_message(chat_id=log_channel_id[1], text="`Nexa Userbot is alive!`") 39 | except: 40 | logging.warn("There was an error while creating the LOG CHANNEL please add a one manually!") 41 | logging.info("\n\n ✨ Nexa-Userbot is Alive \n\n") 42 | await idle() 43 | 44 | loop = asyncio.get_event_loop() 45 | loop.run_until_complete(main_startup()) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Nexa Userbot", 3 | "description": "Simple and Light Weight Pyrogram Userbot", 4 | "logo": "https://telegra.ph/file/a2471aa31028b2c429390.jpg", 5 | "keywords": [ 6 | "userbot", 7 | "Telegram Bot", 8 | "nexa userbot" 9 | ], 10 | "website": "https://t.me/NexaBotsUpdates", 11 | "repository": "https://github.com/Itz-fork/Nexa-Userbot", 12 | "success_url": "https://t.me/NexaBotsUpdates", 13 | "env": { 14 | "APP_ID": { 15 | "description": "Your APP_ID from my.telegram.org", 16 | "required": true 17 | }, 18 | "API_HASH": { 19 | "description": "Your API_HASH from my.telegram.org", 20 | "required": true 21 | }, 22 | "CMD_PREFIX": { 23 | "description": "Command prefix", 24 | "required": false, 25 | "value": "." 26 | }, 27 | "HEROKU_APP_NAME": { 28 | "description": "Your Heroku App Name", 29 | "required": true 30 | }, 31 | "HEROKU_API_KEY": { 32 | "description": "Your Heroku API KEY", 33 | "required": true 34 | }, 35 | "MONGODB_URL": { 36 | "description": "Your MongoDB Url. Get it from www.mongodb.com", 37 | "required": true 38 | }, 39 | "PYRO_STR_SESSION": { 40 | "description": "Pyrogram String Session", 41 | "required": true 42 | } 43 | }, 44 | "addons": [], 45 | "buildpacks": [ 46 | { 47 | "url": "heroku/python" 48 | }, 49 | { 50 | "url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git" 51 | } 52 | ], 53 | "formation": { 54 | "worker": { 55 | "quantity": 1, 56 | "size": "free" 57 | } 58 | }, 59 | "stack": "container" 60 | } 61 | -------------------------------------------------------------------------------- /nexa_userbot/modules/installer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from pyrogram.types import Message 7 | from nexa_userbot import CMD_HELP 8 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 9 | from config import Config 10 | 11 | 12 | # Help 13 | mod_name = os.path.basename(__file__)[:-3] 14 | 15 | CMD_HELP.update( 16 | { 17 | f"{mod_name}": f""" 18 | **Plugin Installler,** 19 | 20 | ✘ `install` - To Install a Plugin 21 | 22 | **Example:** 23 | 24 | ✘ `install` 25 | ⤷ Reply to pyrogram module made by Nexa UB Author with `{Config.CMD_PREFIX}install` 26 | 27 | 28 | **Note:** `All Official Plugins are available at` **@NexaUBPlugins**! `Please don't install unofficial Plugins!` 29 | """, 30 | f"{mod_name}_category": "userbot" 31 | } 32 | ) 33 | 34 | 35 | @nexaub.on_cmd(command=["install"]) 36 | async def install_plugin(_, message: Message): 37 | msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 38 | replied_msg = message.reply_to_message 39 | if not replied_msg: 40 | return await msg.edit("`Please reply to a valid python module to install!`") 41 | if not replied_msg.document: 42 | return await msg.edit("`Please reply to a valid python module to install!`") 43 | plugin_name = replied_msg.document.file_name 44 | plugin_path = f"nexa_userbot/modules/Extras/{plugin_name}" 45 | plugin_extension = plugin_name.split(".")[1].lower() 46 | plugin_name_no_exe = plugin_name.split(".")[0] 47 | if plugin_extension != "py": 48 | return await msg.edit("`This file isn't a python file`") 49 | if os.path.isfile(plugin_path): 50 | return await msg.edit("`Plugin already installed!`") 51 | await replied_msg.download(file_name=plugin_path) 52 | try: 53 | await msg.edit("`Loading Plugin, Please wait...`") 54 | nexaub().import_plugin(plugin_path) 55 | await msg.edit(f"**Successfully Loaded Plugin** \n\n** ✗ Plugin Name:** `{plugin_name_no_exe}`") 56 | except Exception as e: 57 | await msg.edit(f"**Error:** {e}") -------------------------------------------------------------------------------- /nexa_userbot/modules/dl_downloader.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa Userbot 3 | 4 | import os 5 | import asyncio 6 | 7 | from pyrogram.types import Message 8 | from nexa_userbot import CMD_HELP 9 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 10 | from nexa_userbot.core.errors import Errors 11 | from nexa_userbot.helpers.downloader import NexaDL 12 | from nexa_userbot.helpers.up_to_tg import guess_and_send 13 | from nexa_userbot.helpers.pyrogram_help import get_arg, extract_url_from_txt 14 | from config import Config 15 | 16 | 17 | # Help 18 | mod_name = os.path.basename(__file__)[:-3] 19 | 20 | CMD_HELP.update( 21 | { 22 | f"{mod_name}": f""" 23 | **Downloader,** 24 | 25 | ✘ `dl` - To Download Files From Direct Links 26 | 27 | **Example:** 28 | 29 | ✘ `dl` 30 | ⤷ Send with command = `{Config.CMD_PREFIX}dl http://www.ovh.net/files/100Mb.dat` 31 | 32 | 33 | **Note:** `File size must be under 2GB (Telegram limits)` 34 | """, 35 | f"{mod_name}_category": "tools" 36 | } 37 | ) 38 | 39 | 40 | @nexaub.on_cmd(command=["dl"]) 41 | async def download_direct_links(_, message: Message): 42 | dl_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 43 | r_msg = message.reply_to_message 44 | args = get_arg(message) 45 | if r_msg: 46 | # Checks if the replied message has urls 47 | if not r_msg.text: 48 | return await dl_msg.edit("`Give a url or reply to a message that contains direct links to download it!`") 49 | urls = await extract_url_from_txt(r_msg.text) 50 | if not urls: 51 | return await dl_msg.edit("`Give a url or reply to a message that contains direct links to download it!`") 52 | elif args: 53 | urls = await extract_url_from_txt(args) 54 | if not urls: 55 | return await dl_msg.edit("`Give a url or reply to a message that contains direct links to download it!`") 56 | else: 57 | return await dl_msg.edit("`Give a url or reply to a message that contains direct links to download it!`") 58 | # Downloads the files from url 59 | dl_engine = NexaDL() 60 | file = await dl_engine.download(urls[0], message) 61 | await guess_and_send(file, message.chat.id, thumb_path="cache") -------------------------------------------------------------------------------- /nexa_userbot/modules/extractor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | import shutil 5 | 6 | from pyrogram.types import Message 7 | from py_extract import Video_tools 8 | 9 | from nexa_userbot import NEXAUB, CMD_HELP 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from config import Config 12 | 13 | # Help 14 | mod_name = os.path.basename(__file__)[:-3] 15 | 16 | CMD_HELP.update( 17 | { 18 | f"{mod_name}": f""" 19 | **Extractor** 20 | 21 | ✘ `ext_aud` - To Extract all audios from a video 22 | 23 | **Example:** 24 | 25 | ✘ `ext_aud` 26 | ⤷ Reply to a video file with audio = `{Config.CMD_PREFIX}ext_aud` (Reply to a video file) 27 | """, 28 | f"{mod_name}_category": "tools" 29 | } 30 | ) 31 | 32 | 33 | @nexaub.on_cmd(command=["ext_aud"]) 34 | async def extract_all_aud(_, message: Message): 35 | replied_msg = message.reply_to_message 36 | ext_text = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 37 | ext_out_path = os.getcwd() + "/" + "NexaUB/py_extract/audios" 38 | if not replied_msg: 39 | await ext_text.edit("`Please reply to a valid video file!`") 40 | return 41 | if not replied_msg.video: 42 | await ext_text.edit("`Please reply to a valid video file!`") 43 | return 44 | if os.path.exists(ext_out_path): 45 | await ext_text.edit("`Already one process is going on. Please wait till it finish!`") 46 | return 47 | replied_video = replied_msg.video 48 | try: 49 | await ext_text.edit("`Downloading...`") 50 | ext_video = await NEXAUB.download_media(message=replied_video) 51 | await ext_text.edit("`Extracting Audio(s)...`") 52 | exted_aud = Video_tools.extract_all_audio(input_file=ext_video, output_path=ext_out_path) 53 | await ext_text.edit("`Uploading...`") 54 | for nexa_aud in exted_aud: 55 | await message.reply_audio(audio=nexa_aud, caption=f"`Extracted by` {(await NEXAUB.get_me()).mention}") 56 | await ext_text.edit("`Extracting Finished!`") 57 | shutil.rmtree(ext_out_path) 58 | except Exception as e: 59 | await ext_text.edit(f"**Error:** `{e}`") -------------------------------------------------------------------------------- /nexa_userbot/helpers/up_to_tg.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa Userbot 3 | import os 4 | import re 5 | import filetype 6 | from .pyrogram_help import run_shell_cmds 7 | 8 | from nexa_userbot import NEXAUB 9 | 10 | async def get_vid_duration(input_video): 11 | result = await run_shell_cmds(f"ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 {input_video}") 12 | return int(result) 13 | 14 | async def guess_and_send(input_file, chat_id, thumb_path): 15 | thumbnail_bpath = thumb_path 16 | in_file = f"{input_file}" 17 | guessedfilemime = filetype.guess(in_file) 18 | if not guessedfilemime or not guessedfilemime.mime: 19 | return await NEXAUB.send_document(chat_id=chat_id, document=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 20 | try: 21 | filemimespotted = guessedfilemime.mime 22 | # For gifs 23 | if re.search(r'\bimage/gif\b', filemimespotted): 24 | await NEXAUB.send_animation(chat_id=chat_id, animation=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 25 | # For images 26 | elif re.search(r'\bimage\b', filemimespotted): 27 | await NEXAUB.send_photo(chat_id=chat_id, photo=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 28 | # For videos 29 | elif re.search(r'\bvideo\b', filemimespotted): 30 | viddura = await get_vid_duration(input_video=in_file) 31 | thumbnail_path = f"{thumbnail_bpath}/thumbnail_{os.path.basename(in_file)}.jpg" 32 | if os.path.exists(thumbnail_path): 33 | os.remove(thumbnail_path) 34 | await run_shell_cmds(f"ffmpeg -i {in_file} -ss 00:00:01.000 -vframes 1 {thumbnail_path}") 35 | await NEXAUB.send_video(chat_id=chat_id, video=in_file, duration=viddura, thumb=thumbnail_path, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 36 | # For audio 37 | elif re.search(r'\baudio\b', filemimespotted): 38 | await NEXAUB.send_audio(chat_id=chat_id, audio=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 39 | else: 40 | await NEXAUB.send_document(chat_id=chat_id, document=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") 41 | except Exception as e: 42 | print(e) 43 | await NEXAUB.send_document(chat_id=chat_id, document=in_file, caption=f"`Uploaded by` {(await NEXAUB.get_me()).mention}") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
6 |
7 | Userbot for CLI lovers ❤️
8 |
51 | 52 | Copyright (c) 2021 - Itz-fork | Nexa Userbot 53 |
54 | -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_sudos.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_sudos = nexa_mongodb["sudos_db"] 7 | 8 | # ========== Databse for sudo users ========== 9 | 10 | # Add sudo user to database 11 | async def add_sudo(sudo_id): 12 | isudo_id = int(sudo_id) 13 | sudo_db = await nexaub_sudos.find_one({"_id": "SUDO_USERS"}) 14 | if sudo_db: 15 | await nexaub_sudos.update_one({"_id": "SUDO_USERS"}, {"$push": {"sudo_id": isudo_id}}) 16 | else: 17 | isudo_id = [isudo_id] 18 | await nexaub_sudos.insert_one({"_id": "SUDO_USERS", "sudo_id": isudo_id}) 19 | 20 | # Get sudo users from database 21 | async def get_sudos(): 22 | s_u_i = await nexaub_sudos.find_one({"_id": "SUDO_USERS"}) 23 | if s_u_i: 24 | return [int(sudo_id) for sudo_id in s_u_i.get("sudo_id")] 25 | else: 26 | return [] 27 | 28 | # Remove sudo user from databse 29 | async def remove_sudo(sudo_id): 30 | r_sudo_id = await nexaub_sudos.find_one({"_id": "SUDO_USERS"}) 31 | irudo_id = int(sudo_id) 32 | if r_sudo_id: 33 | await nexaub_sudos.update_one({"_id": "SUDO_USERS"}, {"$pull": {"sudo_id": irudo_id}}) 34 | else: 35 | return False 36 | 37 | # Check if user already in sudo databse 38 | async def check_if_sudo(sudo_id): 39 | already_sudo = await nexaub_sudos.find_one({"_id": "SUDO_USERS"}) 40 | if already_sudo: 41 | sudo_list = [int(sudo_id) for sudo_id in already_sudo.get("sudo_id")] 42 | if int(sudo_id) in sudo_list: 43 | return True 44 | else: 45 | return False 46 | else: 47 | return False 48 | 49 | 50 | # Custom Plugin channel database 51 | 52 | async def add_custom_plugin_channel(channel): 53 | cpcdb = await nexaub_sudos.find_one({"_id": "CUSTOM_PLUGINS_CHANNELS"}) 54 | if cpcdb: 55 | await nexaub_sudos.update_one({"_id": "CUSTOM_PLUGINS_CHANNELS"}, {"$push": {"channel": channel}}) 56 | else: 57 | cp_channel = [channel] 58 | await nexaub_sudos.insert_one({"_id": "CUSTOM_PLUGINS_CHANNELS", "channel": cp_channel}) 59 | 60 | # Get sudo users from database 61 | async def get_custom_plugin_channels(): 62 | s_cp_i = await nexaub_sudos.find_one({"_id": "CUSTOM_PLUGINS_CHANNELS"}) 63 | if s_cp_i: 64 | return [cp_channel for cp_channel in s_cp_i.get("channel")] 65 | else: 66 | return [] 67 | 68 | # Remove sudo user from databse 69 | async def remove_custom_plugin_channel(channel): 70 | r_cpcdb = await nexaub_sudos.find_one({"_id": "CUSTOM_PLUGINS_CHANNELS"}) 71 | if r_cpcdb: 72 | await nexaub_sudos.update_one({"_id": "CUSTOM_PLUGINS_CHANNELS"}, {"$pull": {"channel": channel}}) 73 | else: 74 | return False -------------------------------------------------------------------------------- /nexa_userbot/core/nexaub_database/nexaub_db_conf.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | from . import nexa_mongodb 5 | 6 | nexaub_conf = nexa_mongodb["config_db"] 7 | 8 | # Database for log channel 9 | async def set_log_channel(tgcc_id): 10 | log_chanel_id = tgcc_id 11 | p_log_c_id = await nexaub_conf.find_one({"_id": "LOG_CHANNEL_ID"}) 12 | if p_log_c_id: 13 | return True 14 | else: 15 | await nexaub_conf.insert_one({"_id": "LOG_CHANNEL_ID", "nexaub_conf": log_chanel_id}) 16 | 17 | async def get_log_channel(): 18 | log_channel = await nexaub_conf.find_one({"_id": "LOG_CHANNEL_ID"}) 19 | if log_channel: 20 | return int(log_channel["nexaub_conf"]) 21 | else: 22 | return None 23 | 24 | # Database for custom alive message 25 | 26 | async def set_custom_alive_msg(a_text=None): 27 | if a_text is None: 28 | alive_msg = "Heya, I'm Using Nexa Userbot" 29 | else: 30 | alive_msg = a_text 31 | p_alive_msg = await nexaub_conf.find_one({"_id": "CUSTOM_ALIVE_MSG"}) 32 | if p_alive_msg: 33 | await nexaub_conf.update_one({"_id": "CUSTOM_ALIVE_MSG"}, {"$set": {"nexaub_conf": alive_msg}}) 34 | else: 35 | await nexaub_conf.insert_one({"_id": "CUSTOM_ALIVE_MSG", "nexaub_conf": alive_msg}) 36 | 37 | async def get_custom_alive_msg(): 38 | alive_msg = await nexaub_conf.find_one({"_id": "CUSTOM_ALIVE_MSG"}) 39 | if alive_msg: 40 | return alive_msg["nexaub_conf"] 41 | else: 42 | return None 43 | 44 | # Database for arq client 45 | async def set_arq_key(arq_key): 46 | p_arq_key = await nexaub_conf.find_one({"_id": "ARQ_API_KEY"}) 47 | if p_arq_key: 48 | await nexaub_conf.update_one({"_id": "ARQ_API_KEY"}, {"$set": {"nexaub_conf": arq_key}}) 49 | else: 50 | await nexaub_conf.insert_one({"_id": "ARQ_API_KEY", "nexaub_conf": arq_key}) 51 | 52 | async def get_arq_key(): 53 | p_arq = await nexaub_conf.find_one({"_id": "ARQ_API_KEY"}) 54 | if p_arq: 55 | return p_arq["nexaub_conf"] 56 | else: 57 | None 58 | 59 | # Database for set cutom variable 60 | async def set_custom_var(var, value): 61 | p_variable = await nexaub_conf.find_one({"_id": var}) 62 | if p_variable: 63 | await nexaub_conf.update_one({"_id": var}, {"$set": {"nexaub_conf": value}}) 64 | else: 65 | await nexaub_conf.insert_one({"_id": var, "nexaub_conf": value}) 66 | 67 | async def get_custom_var(var): 68 | custom_var = await nexaub_conf.find_one({"_id": var}) 69 | if not custom_var: 70 | return None 71 | else: 72 | g_custom_var = custom_var["nexaub_conf"] 73 | return g_custom_var 74 | 75 | async def del_custom_var(var): 76 | custom_var = await nexaub_conf.find_one({"_id": var}) 77 | if custom_var: 78 | await nexaub_conf.delete_one({"_id": var}) 79 | return True 80 | else: 81 | return False -------------------------------------------------------------------------------- /nexa_userbot/helpers/downloader.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa Userbot 3 | import os 4 | 5 | from aiohttp import ClientSession 6 | from aiofiles import open as openfile 7 | from asyncio import sleep 8 | from .pyrogram_help import humanbytes 9 | 10 | 11 | class NexaDL: 12 | """ 13 | ## NexaDL 14 | 15 | Downloads files from direct links using aiohttp 16 | 17 | ### Methods 18 | 19 | ``download`` - Function to download the file 20 | 21 | ### Arguments 22 | 23 | ``chunk_size`` - Custom chunk size (Default to 1024 * 6) 24 | """ 25 | 26 | def __init__(self) -> None: 27 | self.path = "cache/NexaDL" 28 | self.chunk_size = 1024 * 1024 29 | self.stat_txt = """ 30 | **File Name:** `{name}` 31 | 32 | **File Size:** `{size}` 33 | 34 | **Progress:** `{downloaded}` of `{total}` 35 | 36 | `{prgs_bar}` 37 | 38 | **Status:** `Downloading...` 39 | """ 40 | 41 | async def download(self, url, message, path=None): 42 | """ 43 | ## Arguments 44 | 45 | ``url`` - Url to download 46 | 47 | ``message`` - Pyrogram message object 48 | 49 | ``path`` (optional) - Path 50 | """ 51 | name = await self._get_file_name(url) 52 | await self._make_dir(path) 53 | if not path: 54 | fpath = f"{self.path}/{name}" 55 | else: 56 | fpath = f"{path}/{name}" 57 | downloaded = 0 58 | async with ClientSession() as session: 59 | async with session.get(url, timeout=None) as resp: 60 | fs = int(resp.headers.get("Content-Length")) 61 | async with openfile(fpath, mode="wb") as file: 62 | async for chunk in resp.content.iter_chunked(self.chunk_size): 63 | await file.write(chunk) 64 | downloaded += len(chunk) 65 | done = int(15 * downloaded / fs) 66 | try: 67 | await message.edit(self.stat_txt.format( 68 | name=name, 69 | size=humanbytes(fs), 70 | downloaded=humanbytes(downloaded), 71 | total=humanbytes(fs), 72 | prgs_bar="[%s%s]" % ( 73 | "▰" * done, "▱" * (15-done)) 74 | ) 75 | ) 76 | await sleep(0.1) 77 | except: 78 | pass 79 | return fpath 80 | 81 | async def _get_file_name(self, url): 82 | return os.path.basename(url) 83 | 84 | async def _make_dir(self, path): 85 | if not path: 86 | if not os.path.isdir(self.path): 87 | os.makedirs(self.path) 88 | else: 89 | if not os.path.isdir(path): 90 | os.makedirs(path) 91 | -------------------------------------------------------------------------------- /nexa_userbot/modules/github.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from pyrogram.types import Message 7 | from httpx import AsyncClient 8 | from nexa_userbot import CMD_HELP 9 | from nexa_userbot.helpers.pyrogram_help import get_arg 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from config import Config 12 | 13 | 14 | # Help 15 | mod_name = os.path.basename(__file__)[:-3] 16 | 17 | CMD_HELP.update( 18 | { 19 | f"{mod_name}": f""" 20 | **Github,** 21 | 22 | ✘ `github` - To Search for a github user 23 | 24 | **Example:** 25 | 26 | ✘ `github`, 27 | ⤷ Send command with username = `{Config.CMD_PREFIX}github Itz-fork` 28 | """, 29 | f"{mod_name}_category": "tools" 30 | } 31 | ) 32 | 33 | 34 | # Function to get data from github API 35 | async def get_data(username): 36 | base_msg = "" 37 | async with AsyncClient() as gpx: 38 | req = (await gpx.get(f"https://api.github.com/users/{username}")).json() 39 | # Parsing data 40 | try: 41 | avatar = req["avatar_url"] 42 | twitter = req['twitter_username'] 43 | base_msg += "**❆ Gitub Information ❆** \n\n" 44 | base_msg += f"**Profile Url:** {req['html_url']} \n" 45 | base_msg += f"**Name:** `{req['name']}` \n" 46 | base_msg += f"**Username:** `{req['login']}` \n" 47 | base_msg += f"**User ID:** `{req['id']}` \n" 48 | base_msg += f"**Location:** `{req['location']}` \n" 49 | base_msg += f"**Company:** `{req['company']}` \n" 50 | base_msg += f"**Blog:** `{req['name']}` \n" 51 | base_msg += f"**Twitter:** `{f'https://twitter.com/{twitter}' if twitter else 'None'}` \n" 52 | base_msg += f"**Bio:** `{req['bio']}` \n" 53 | base_msg += f"**Public Repos:** `{req['public_repos']}` \n" 54 | base_msg += f"**Public Gists:** `{req['public_gists']}` \n" 55 | base_msg += f"**Followers:** `{req['followers']}` \n" 56 | base_msg += f"**Following:** `{req['following']}` \n" 57 | base_msg += f"**Created At:** `{req['created_at']}` \n" 58 | base_msg += f"**Update At:** `{req['updated_at']}` \n" 59 | return [base_msg, avatar] 60 | except Exception as e: 61 | base_msg += f"**An error occured while parsing the data!** \n\n**Traceback:** \n `{e}` \n\n`Make sure that you've sent the command with the correct username!`" 62 | return [base_msg, "https://telegra.ph//file/32f69c18190666ea96553.jpg"] 63 | 64 | 65 | @nexaub.on_cmd(command=["github", "git"]) 66 | async def github_search(_, message: Message): 67 | git_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 68 | username = get_arg(message) 69 | if not username: 70 | return await git_msg.edit("`Give a github username to get information!`") 71 | details = await get_data(username) 72 | await git_msg.reply_photo(details[1], caption=details[0]) 73 | await git_msg.delete() -------------------------------------------------------------------------------- /nexa_userbot/modules/webss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | import re 6 | 7 | from pyrogram.types import Message 8 | from io import BytesIO 9 | from aiohttp import ClientSession 10 | 11 | from nexa_userbot import CMD_HELP 12 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 13 | from nexa_userbot.helpers.pyrogram_help import get_arg, extract_url_from_txt 14 | from config import Config 15 | 16 | 17 | # Help 18 | mod_name = os.path.basename(__file__)[:-3] 19 | 20 | CMD_HELP.update( 21 | { 22 | f"{mod_name}": f""" 23 | **Web Screenshot,** 24 | 25 | ✘ `webss` - To get a screenshot of given url 26 | 27 | **Example:** 28 | 29 | ✘ `webss`, 30 | ⤷ Send command with url = `{Config.CMD_PREFIX}webss https://google.com` 31 | ⤷ Reply to a message = `{Config.CMD_PREFIX}webss` 32 | 33 | **Tips 💡,** 34 | ⤷ You can generate screenshots for multiple urls at the same time 35 | ⤷ You can capture the full page too. To do so use one of these commands instead of the default one. 36 | ⤷ `{Config.CMD_PREFIX}webssf` 37 | ⤷ `{Config.CMD_PREFIX}wssf` 38 | """, 39 | f"{mod_name}_category": "tools" 40 | } 41 | ) 42 | 43 | 44 | # Function to get screenshot of the page 45 | async def gen_ss(url, full_page=False): 46 | if full_page: 47 | req_url = f"https://mini.s-shot.ru/1360x0/png/1024/Z100/?{url}" 48 | else: 49 | req_url = f"https://render-tron.appspot.com/screenshot/{url}" 50 | async with ClientSession() as webss_c: 51 | req = await webss_c.post(req_url) 52 | read_bytes = await req.read() 53 | screens = BytesIO(read_bytes) 54 | screens.name = f"Nexa-Userbot-webss_{url}.png" 55 | return screens 56 | 57 | # Function to check type of the ss 58 | async def is_full_page(cmd): 59 | if re.search(r'\bfwebss|wssf|fwss|webssf\b', cmd): 60 | full_page = True 61 | else: 62 | full_page = False 63 | return full_page 64 | 65 | @nexaub.on_cmd(command=["webss", "wss", "fwss", "fwebss", "wssf", "webssf"]) 66 | async def gimme_a_damn_ss(_, message: Message): 67 | webss_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 68 | r_msg = message.reply_to_message 69 | w_args = get_arg(message) 70 | if r_msg: 71 | urls = await extract_url_from_txt(r_msg.text) 72 | elif w_args: 73 | urls = await extract_url_from_txt(w_args) 74 | else: 75 | return await webss_msg.edit("`Give me some urls or reply to a message that contains urls!`") 76 | if not urls: 77 | return await webss_msg.edit("`Give me some urls or reply to a message that contains urls!`") 78 | # Generating the screenshots 79 | ss_type = await is_full_page(message.text) 80 | for url in urls: 81 | if ss_type: 82 | webss = await gen_ss(url, True) 83 | else: 84 | webss = await gen_ss(url) 85 | await webss_msg.reply_document(webss, caption=f"**Scrrenshot Generated!** \n\n**Url:** {url}") 86 | webss.close() 87 | await webss_msg.delete() -------------------------------------------------------------------------------- /nexa_userbot/modules/telegraph.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | 5 | from telegraph import Telegraph 6 | from pyrogram.types import Message 7 | 8 | from nexa_userbot import NEXAUB, CMD_HELP 9 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 10 | from nexa_userbot.helpers.pyrogram_help import get_arg, convert_to_image 11 | from config import Config 12 | 13 | 14 | # Help 15 | mod_name = os.path.basename(__file__)[:-3] 16 | 17 | CMD_HELP.update( 18 | { 19 | f"{mod_name}": f""" 20 | **Telegraph,** 21 | 22 | ✘ `telegraph` - To Paste Images/Text to Telegra.ph 23 | 24 | **Example:** 25 | 26 | ✘ `telegraph`, 27 | ⤷ Reply to a message that contains text/image/mp4 file = `{Config.CMD_PREFIX}telegraph` 28 | Tip: While pasting text to telegra.ph you can send title with command 29 | """, 30 | f"{mod_name}_category": "tools" 31 | } 32 | ) 33 | 34 | 35 | # Telegraph client 36 | telegraph = Telegraph() 37 | telegraph.create_account(short_name="Nexa-Userbot") 38 | 39 | # Paste text to telegraph 40 | async def paste_text_to_tgraph(title, text): 41 | try: 42 | nexaub_usr = await NEXAUB.get_me() 43 | f_name = nexaub_usr.first_name 44 | u_name = nexaub_usr.username 45 | if not title: 46 | title = f_name if f_name is not None else "By Nexa Userbot" 47 | t_response = telegraph.create_page(title=title, html_content=text, author_name=f_name if f_name is not None else "Nexa-Userbot", author_url=f"https://t.me/{u_name}" if u_name is not None else "https://github.com/Itz-fork/Nexa-Userbot") 48 | return f"{t_response['url']}" 49 | except Exception as e: 50 | return f"**Error:** {e}" 51 | 52 | # Upload media to telegraph 53 | async def upload_to_tgraph(file): 54 | try: 55 | t_response = telegraph.upload_file(file)[0]["src"] 56 | return f"https://telegra.ph/{t_response}" 57 | except Exception as e: 58 | return f"**Error:** {e}" 59 | 60 | 61 | @nexaub.on_cmd(command=["telegraph", "tgraph"]) 62 | async def telegraph_up(_, message: Message): 63 | tgraph_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 64 | r_msg = message.reply_to_message 65 | arg_txt = get_arg(message) 66 | if r_msg: 67 | # Photo / Video or Video note 68 | if r_msg.photo or r_msg.video or r_msg.video_note: 69 | r_content = await r_msg.download() 70 | # Stickers 71 | elif r_msg.sticker: 72 | r_content = await convert_to_image(message=r_msg, client=NEXAUB) 73 | # Text messages 74 | elif r_msg.text: 75 | r_content = r_msg.text 76 | # Set title if provided by user 77 | if arg_txt: 78 | t_title = arg_txt 79 | else: 80 | t_title = None 81 | # Paste text to telegraph 82 | t_pasted = await paste_text_to_tgraph(title=t_title, text=r_content) 83 | else: 84 | tgraph_msg.edit("`No Supported Media or Text to paste!`") 85 | # Paste media to telegraph 86 | t_pasted = await upload_to_tgraph(r_content) 87 | # Edit message with the telegraph link 88 | await tgraph_msg.edit(f"**Telegraph Link:** {t_pasted}") 89 | else: 90 | return await tgraph_msg.edit("Reply to a message that contains `text`/`image` or `mp4 file`!") -------------------------------------------------------------------------------- /nexa_userbot/modules/owner.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import time 5 | import os 6 | 7 | from pyrogram.types import Message 8 | from pyrogram.errors import FloodWait 9 | 10 | from nexa_userbot import NEXAUB, CMD_HELP 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Owner Stuff,** 22 | 23 | ✘ `block` - To Block a User 24 | ✘ `unblock` - To Unblock a Blocked User 25 | ✘ `kickme` - To Leave From a Chat 26 | ✘ `chats` - To Count your Chats (Unstable due to Floodwait Limits) 27 | 28 | **Example:** 29 | 30 | ✘ `block`, 31 | ⤷ Reply to a message from user = `{Config.CMD_PREFIX}block` 32 | ⤷ Just send `{Config.CMD_PREFIX}block` in PMs 33 | 34 | ✘ `unblock` 35 | ⤷ Send this command with user id to unblock = `{Config.CMD_PREFIX}unblock 1234567` 36 | """, 37 | f"{mod_name}_category": "utils" 38 | } 39 | ) 40 | 41 | 42 | # To Block a user 43 | @nexaub.on_cmd(command=["block"], no_sudos=True) 44 | async def block_dumb(_, message: Message): 45 | shit_id = message.chat.id 46 | r_msg = message.reply_to_message 47 | gonna_block_u = await e_or_r(nexaub_message=message, msg_text="`Blocking User...`") 48 | try: 49 | if r_msg: 50 | await NEXAUB.block_user(r_msg.from_user.id) 51 | await gonna_block_u.edit("`Successfully Blocked This User`") 52 | else: 53 | await NEXAUB.block_user(shit_id) 54 | await gonna_block_u.edit("`Successfully Blocked This User`") 55 | except Exception as lol: 56 | await gonna_block_u.edit(f"**Error:** `{lol}`") 57 | 58 | # To Unblock User That Already Blocked 59 | @nexaub.on_cmd(command=["unblock"], no_sudos=True) 60 | async def unblock_boi(_, message: Message): 61 | good_bro = int(message.command[1]) 62 | gonna_unblock_u = await e_or_r(nexaub_message=message, msg_text="`Unblocking User...`") 63 | try: 64 | await NEXAUB.unblock_user(good_bro) 65 | await gonna_unblock_u.edit(f"`Successfully Unblocked The User` \n**User ID:** `{good_bro}`") 66 | except Exception as lol: 67 | await gonna_unblock_u.edit(f"**Error:** `{lol}`") 68 | 69 | # Leave From a Chat 70 | @nexaub.on_cmd(command=["kickme"], no_sudos=True, only_groups=True) 71 | async def ubkickme(_, message: Message): 72 | i_go_away = await e_or_r(nexaub_message=message, msg_text="`Leaving This Chat...`") 73 | try: 74 | await NEXAUB.leave_chat(message.chat.id) 75 | await i_go_away.edit("`Successfully Leaved This Chat!`") 76 | except Exception as lol: 77 | await i_go_away.edit(f"**Error:** `{lol}`") 78 | 79 | # To Get How Many Chats that you are in (PM's also counted) 80 | async def count_chats(): 81 | total=0 82 | async for dialog in NEXAUB.iter_dialogs(): 83 | try: 84 | await NEXAUB.get_dialogs_count() 85 | total += 1 86 | except FloodWait as e: 87 | await time.sleep(e.x) 88 | return total 89 | 90 | @nexaub.on_cmd(command=["chats"], no_sudos=True) 91 | async def ubgetchats(_, message: Message): 92 | getting_chats = await e_or_r(nexaub_message=message, msg_text="`Checking Your Chats, Hang On...`") 93 | d_count = await count_chats() 94 | await getting_chats.edit(f"**Total Chats Counted:** `{d_count}`") -------------------------------------------------------------------------------- /nexa_userbot/modules/clouds.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | 5 | from time import time 6 | from pyrogram.types import Message 7 | from gofile2 import Async_Gofile 8 | from functools import partial 9 | from asyncio import get_running_loop 10 | 11 | from nexa_userbot import CMD_HELP 12 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 13 | from nexa_userbot.helpers.meganz_helpers import UploadToMega, getMegaEmailandPass, loginToMega 14 | from nexa_userbot.helpers.pyrogram_help import get_arg, progress_for_pyrogram 15 | from config import Config 16 | 17 | 18 | # Help 19 | mod_name = os.path.basename(__file__)[:-3] 20 | 21 | CMD_HELP.update( 22 | { 23 | f"{mod_name}": f""" 24 | **Cloud Storages,** 25 | 26 | ✘ `gofile` - To upload telegram media to gofile.io 27 | ✘ `meganz` - To upload telegram media to mega.nz 28 | 29 | **Example:** 30 | 31 | ✘ `gofile`, 32 | ⤷ Reply to telegram media = `{Config.CMD_PREFIX}gofile` (Reply to a valid telegram media file) 33 | Tip: You can also send a description alongside with command! 34 | 35 | ✘ `meganzup`, 36 | ⤷ Reply to telegram media = `{Config.CMD_PREFIX}meganz` (Reply to a valid telegram media file) 37 | """, 38 | f"{mod_name}_category": "tools" 39 | } 40 | ) 41 | 42 | 43 | @nexaub.on_cmd(command=["meganzup"]) 44 | async def meganz_upload(_, message: Message): 45 | meganz_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 46 | # Mega.nz Email and Pass 47 | creds = await getMegaEmailandPass() 48 | if not creds: 49 | return await meganz_msg.edit(f""" 50 | **No Mega.nz Email or Password Found!** 51 | For functionality of this function you must set the `MEGA_EMAIL` and `MEGA_PASS` variables using `{Config.CMD_PREFIX}setvar` command. 52 | 53 | **To do so,** 54 | 55 | - `{Config.CMD_PREFIX}setvar` MEGA_EMAIL your_mega_email@your.domain 56 | - `{Config.CMD_PREFIX}setvar` MEGA_PASS your_mega_password 57 | 58 | **Note ⚠️:** 59 | These emails and passwords are just dummy ones. So replace them with your own email and password before running the command.""" 60 | ) 61 | else: 62 | r_msg = message.reply_to_message 63 | if not r_msg: 64 | return await meganz_msg.edit("`Reply to a telegram media first!`") 65 | # Downloading the file 66 | m_file = await r_msg.download() 67 | # Login to mega.nz account 68 | m_client = await loginToMega(creds) 69 | loop = get_running_loop() 70 | await loop.run_in_executor(None, partial(UploadToMega, message, m_file, m_client)) 71 | 72 | 73 | 74 | @nexaub.on_cmd(command=["gofile"]) 75 | async def gofiles_up(_, message: Message): 76 | gofile_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 77 | r_go_f = message.reply_to_message 78 | go_f_arg = get_arg(message) 79 | if not r_go_f: 80 | return await gofile_msg.edit("`Reply to a telegram media to upload it to Gofile.io!`") 81 | await gofile_msg.edit("`Download has started! This may take a while!`") 82 | start_time = time() 83 | dl_go_f = await r_go_f.download(progress=progress_for_pyrogram, progress_args=("**💫 Downloading... 💫** \n", gofile_msg, start_time)) 84 | desc = go_f_arg if go_f_arg else None 85 | # Gofile2 client 86 | go_client = Async_Gofile() 87 | await gofile_msg.edit("`Upload has started! This may take a while!`") 88 | upl_go_f = await go_client.upload(file=dl_go_f, description=desc) 89 | await gofile_msg.edit(f"**Successfully Uploaded!** \n\n**File Name:** `{upl_go_f['fileName']}` \n**Link:** {upl_go_f['downloadPage']}", disable_web_page_preview=True) -------------------------------------------------------------------------------- /nexa_userbot/modules/short_url.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from httpx import AsyncClient 7 | from bs4 import BeautifulSoup 8 | from pyrogram.types import Message 9 | from nexa_userbot import CMD_HELP 10 | from nexa_userbot.helpers.pyrogram_help import get_arg, extract_url_from_txt 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Short Url,** 22 | 23 | ✘ `short` - To short long url using is.gd or da.gd 24 | 25 | **Example:** 26 | 27 | ✘ Usage Format, 28 | ⤷ Send command with urls - `{Config.CMD_PREFIX}short [shortner_name] [links]` 29 | ⤷ Reply to a message - `{Config.CMD_PREFIX}short [shortner_name]` 30 | 31 | ✘ dagd Example, 32 | ⤷ Send command with url = `{Config.CMD_PREFIX}short dagd https://google.com` 33 | ⤷ Reply to a message = `{Config.CMD_PREFIX}short dagd` 34 | 35 | **Tip 💡,** 36 | ⤷ You can short multiple urls at the same time 37 | """, 38 | f"{mod_name}_category": "tools" 39 | } 40 | ) 41 | 42 | 43 | # Supported url shortners list 44 | SUPPORTED_URL_SHORTNERS = ["isgd", "dagd"] 45 | default_shtnr = "isgd" 46 | # Headers for da.gd 47 | dagd_header = { 48 | "User-Agent": "Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Mobile Safari/537.36", 49 | "Accept": "text/html" 50 | } 51 | 52 | async def short_urls(url, shortner): 53 | async with AsyncClient() as shortner_session: 54 | if shortner == "isgd": 55 | isgd_short = await shortner_session.get(f"https://is.gd/create.php?format=json&url={url}") 56 | return [isgd_short.json()["shorturl"]] 57 | elif shortner == "dagd": 58 | dagd_short = await shortner_session.get(f"https://da.gd/?url={url}", headers=dagd_header) 59 | req_text = dagd_short.text 60 | soup = BeautifulSoup(req_text, "html.parser") 61 | url_div = soup.find_all("div", attrs={"class": "constraint"}) 62 | links = url_div[1].find("a", href=True) 63 | return await extract_url_from_txt(links) 64 | else: 65 | isgd_short = await shortner_session.get(f"https://is.gd/create.php?format=json&url={url}") 66 | return [isgd_short.json()["shorturl"]] 67 | 68 | 69 | @nexaub.on_cmd(command=["short"]) 70 | async def short_urls_func(_, message: Message): 71 | short_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 72 | replied_msg = message.reply_to_message 73 | args = get_arg(message) 74 | if replied_msg: 75 | base_txt = replied_msg.text 76 | elif args: 77 | base_txt = args 78 | else: 79 | return await short_msg.edit("`Give some urls or reply to a message that contains urls to short!`") 80 | # Extracting urls from text 81 | urls = await extract_url_from_txt(base_txt) 82 | if not urls: 83 | return await short_msg.edit("`Give some urls or reply to a message that contains urls to short!`") 84 | splitted_txt = base_txt.split(" ") 85 | if splitted_txt[0] in SUPPORTED_URL_SHORTNERS: 86 | shortner = splitted_txt[0] 87 | else: 88 | shortner = default_shtnr 89 | # Short urls 90 | short_urls_txt = "**Successfully Shortened the Url(s)** \n\n" 91 | for url in urls: 92 | shorted_url = await short_urls(url, shortner) 93 | short_urls_txt += f"► **Shortened Url:** {shorted_url[0]} \n **Original Url:** {url} \n" 94 | await short_msg.edit(short_urls_txt, disable_web_page_preview=True) -------------------------------------------------------------------------------- /nexa_userbot/modules/translator.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from pyrogram.types import Message 7 | from py_trans import Async_PyTranslator 8 | 9 | from nexa_userbot import CMD_HELP 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from nexa_userbot.helpers.pyrogram_help import get_arg 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Translator (py-trans),** 22 | 23 | ✘ `ptr` - Translate text using 24 | 25 | **Example:** 26 | 27 | **Options:** 28 | 29 | ⤷ dest_lang = destination language (Required) 30 | ⤷ tr_engine = translation_engine (Optional) - [list here](https://github.com/Itz-fork/py-trans#supported-engines) 31 | ⤷ to_tr_text = Translate text (Required) 32 | 33 | ✘ `ptr`, 34 | 35 | ⤷ Reply to a text message with options, 36 | **Structure:** 37 | `{Config.CMD_PREFIX}ptr [dest_lang] [tr_engine]` 38 | **Ex:** 39 | `{Config.CMD_PREFIX}ptr si google` 40 | 41 | ⤷ Send with text with options, 42 | **Structure:** 43 | `{Config.CMD_PREFIX}ptr [dest_lang] [tr_engine] [to_tr_text]` 44 | **Ex:** 45 | `{Config.CMD_PREFIX}ptr si google Heya, I'm using telegram` 46 | """, 47 | f"{mod_name}_category": "tools" 48 | } 49 | ) 50 | 51 | 52 | @nexaub.on_cmd(command=["ptr"]) 53 | async def pytrans_tr(_, message: Message): 54 | tr_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 55 | r_msg = message.reply_to_message 56 | args = get_arg(message) 57 | if r_msg: 58 | if r_msg.text: 59 | to_tr = r_msg.text 60 | else: 61 | return await tr_msg.edit("`Reply to a message that contains text!`") 62 | # Checks if dest lang is defined by the user 63 | if not args: 64 | return await tr_msg.edit(f"`Please define a destination language!` \n\n**Ex:** `{Config.CMD_PREFIX}ptr si Hey, I'm using telegram!`") 65 | # Setting translation if provided 66 | else: 67 | sp_args = args.split(" ") 68 | if len(sp_args) == 2: 69 | dest_lang = sp_args[0] 70 | tr_engine = sp_args[1] 71 | else: 72 | dest_lang = sp_args[0] 73 | tr_engine = "google" 74 | elif args: 75 | # Splitting provided arguments in to a list 76 | a_conts = args.split(None, 2) 77 | # Checks if translation engine is defined by the user 78 | if len(a_conts) == 3: 79 | dest_lang = a_conts[0] 80 | tr_engine = a_conts[1] 81 | to_tr = a_conts[2] 82 | else: 83 | dest_lang = a_conts[0] 84 | to_tr = a_conts[1] 85 | tr_engine = "google" 86 | # Translate the text 87 | py_trans = Async_PyTranslator(provider=tr_engine) 88 | translation = await py_trans.translate(to_tr, dest_lang) 89 | # Parse the translation message 90 | if translation["status"] == "success": 91 | tred_txt = f""" 92 | **Translation Engine**: `{translation["engine"]}` 93 | **Translated to:** `{translation["dest_lang"]}` 94 | **Translation:** 95 | `{translation["translation"]}` 96 | """ 97 | if len(tred_txt) > 4096: 98 | await tr_msg.edit("`Wah!! Translated Text So Long Tho!, Give me a minute, I'm sending it as a file!`") 99 | tr_txt_file = open("translated_NEXAUB.txt", "w+") 100 | tr_txt_file.write(tred_txt) 101 | tr_txt_file.close() 102 | await tr_msg.reply_document("ptranslated_NEXAUB.txt") 103 | os.remove("ptranslated_NEXAUB.txt") 104 | await tr_msg.delete() 105 | else: 106 | await tr_msg.edit(tred_txt) -------------------------------------------------------------------------------- /nexa_userbot/modules/help.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot 4 | import os 5 | import re 6 | 7 | from pyrogram.types import Message 8 | 9 | from . import __all__ as ALL_MODULES 10 | from .Extras import get_xtra_modules_names 11 | from nexa_userbot import CMD_HELP 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 14 | from config import Config 15 | 16 | 17 | mod_file = os.path.basename(__file__) 18 | 19 | 20 | # Removing last comma from variables 21 | async def rm_last_comma(text): 22 | index = text.rfind(",") 23 | if not index < 0: 24 | return text[:index] + "" + text[index+1:] 25 | else: 26 | return text 27 | 28 | # Configs 29 | DEFAULT_HELP_TXT = """ 30 | **Available Modules** 31 | 32 | {userbot_help} 33 | 34 | {dev_help} 35 | 36 | {tools_help} 37 | 38 | {utils_help} 39 | 40 | {unknown_help} 41 | 42 | 43 | `{cmd_prfx}help [module name]` 44 | """ 45 | 46 | CUSTOM_HELP_TXT = """ 47 | **Available Custom Modules** 48 | 49 | {userbot_help} 50 | 51 | {dev_help} 52 | 53 | {tools_help} 54 | 55 | {utils_help} 56 | 57 | {unknown_help} 58 | 59 | 60 | `{cmd_prfx}xhelp [module name]` 61 | """ 62 | 63 | async def get_help_type(htx): 64 | if re.search(r'\bxhelp|chelp\b', htx): 65 | help_list = [sorted(await get_xtra_modules_names()), CUSTOM_HELP_TXT] 66 | else: 67 | help_list = [sorted(ALL_MODULES), DEFAULT_HELP_TXT] 68 | return help_list 69 | 70 | @nexaub.on_cmd(command=["help", "xhelp", "chelp"]) 71 | async def help(_, message: Message): 72 | args = get_arg(message) 73 | help_user_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 74 | MODULE_LIST = await get_help_type(message.text.split(" ")[0]) 75 | if not args: 76 | # Base texts 77 | base_userbot_txt = "**🧭 Userbot:** " 78 | base_dev_txt = "**👨💻 Dev:** " 79 | base_tools_txt = "**⚙️ Tools:** " 80 | base_utils_txt = "**🗂 Utils:** " 81 | base_unknown_txt = "**🥷 Unknown:** " 82 | # Generating help menu text 83 | for module in MODULE_LIST[0]: 84 | # Checks the category of the module 85 | cat = CMD_HELP.get(f"{module}_category", False) 86 | if cat == "userbot": 87 | base_userbot_txt += f"`{module}`, " 88 | elif cat == "dev": 89 | base_dev_txt += f"`{module}`, " 90 | elif cat == "tools": 91 | base_tools_txt += f"`{module}`, " 92 | elif cat == "utils": 93 | base_utils_txt += f"`{module}`, " 94 | else: 95 | base_unknown_txt += f"`{module}`, " 96 | # Removing last comma from the text 97 | userbot_txt = await rm_last_comma(base_userbot_txt) 98 | dev_txt = await rm_last_comma(base_dev_txt) 99 | tools_txt = await rm_last_comma(base_tools_txt) 100 | utils_txt = await rm_last_comma(base_utils_txt) 101 | unknown_txt = await rm_last_comma(base_unknown_txt) 102 | await help_user_msg.edit(MODULE_LIST[1].format( 103 | userbot_help=userbot_txt, 104 | dev_help=dev_txt, 105 | tools_help=tools_txt, 106 | utils_help=utils_txt, 107 | unknown_help=unknown_txt, 108 | cmd_prfx=Config.CMD_PREFIX 109 | )) 110 | else: 111 | module_help = CMD_HELP.get(args, False) 112 | if not module_help: 113 | return await help_user_msg.edit("`Invalid Module Name!`") 114 | else: 115 | await help_user_msg.edit(module_help) -------------------------------------------------------------------------------- /nexa_userbot/modules/search.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Friday Userbot | DevsExpo 4 | 5 | import os 6 | import re 7 | import urllib 8 | import urllib.parse 9 | import requests 10 | 11 | from bs4 import BeautifulSoup 12 | from fake_useragent import UserAgent 13 | from nexa_userbot import CMD_HELP 14 | from nexa_userbot.helpers.pyrogram_help import get_arg 15 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 16 | from config import Config 17 | 18 | 19 | # Help 20 | mod_name = os.path.basename(__file__)[:-3] 21 | 22 | CMD_HELP.update( 23 | { 24 | f"{mod_name}": f""" 25 | **Search** 26 | 27 | ✘ `duck_s` - To Get Search Link In DuckDuckGo 28 | ✘ `google` - To Search In Google 29 | 30 | **Example:** 31 | 32 | ✘ `duck_s`, 33 | ⤷ Send command with query = `{Config.CMD_PREFIX}duck_s Nexa Userbot` 34 | 35 | ✘ `google`, 36 | ⤷ Send command with query = `{Config.CMD_PREFIX}google Nexa Userbot` 37 | ⤷ Reply to a text message = `{Config.CMD_PREFIX}google` (Reply to a text message) 38 | """, 39 | f"{mod_name}_category": "tools" 40 | } 41 | ) 42 | 43 | 44 | @nexaub.on_cmd(command=["duck_s"]) 45 | async def duckduckg_s(client, message): 46 | pablo = await e_or_r(nexaub_message=message, msg_text="`Searcing in DuckDuckGo...`") 47 | query = get_arg(message) 48 | if not query: 49 | await pablo.edit("`Give Something to Search!`") 50 | return 51 | sample_url = "https://duckduckgo.com/?q={}".format(query.replace(" ", "+")) 52 | link = sample_url.rstrip() 53 | await pablo.edit(f"**Query:** \n`{query}` \n\n**Result(s):** \n{link}") 54 | 55 | 56 | @nexaub.on_cmd(command=["google"]) 57 | async def google_s(client, message): 58 | gsearch_msg = await e_or_r(nexaub_message=message, msg_text="`Searching in Google...`") 59 | query = get_arg(message) 60 | replied_msg = message.reply_to_message 61 | if not query: 62 | try: 63 | if replied_msg: 64 | query = replied_msg.text 65 | except: 66 | return await gsearch_msg.edit("`Give Something to Search!`") 67 | query = urllib.parse.quote_plus(query) 68 | number_result = 8 69 | ua = UserAgent() 70 | google_url = ( 71 | "https://www.google.com/search?q=" + query + "&num=" + str(number_result) 72 | ) 73 | response = requests.get(google_url, {"User-Agent": ua.random}) 74 | soup = BeautifulSoup(response.text, "html.parser") 75 | result_div = soup.find_all("div", attrs={"class": "ZINbbc"}) 76 | links = [] 77 | titles = [] 78 | descriptions = [] 79 | for r in result_div: 80 | try: 81 | link = r.find("a", href=True) 82 | title = r.find("div", attrs={"class": "vvjwJb"}).get_text() 83 | description = r.find("div", attrs={"class": "s3v9rd"}).get_text() 84 | if link != "" and title != "" and description != "": 85 | links.append(link["href"]) 86 | titles.append(title) 87 | descriptions.append(description) 88 | 89 | except: 90 | continue 91 | to_remove = [] 92 | clean_links = [] 93 | for i, l in enumerate(links): 94 | clean = re.search("\/url\?q\=(.*)\&sa", l) 95 | if clean is None: 96 | to_remove.append(i) 97 | continue 98 | clean_links.append(clean.group(1)) 99 | for x in to_remove: 100 | del titles[x] 101 | del descriptions[x] 102 | msg = "" 103 | 104 | for tt, liek, d in zip(titles, clean_links, descriptions): 105 | msg += f"[{tt}]({liek})\n`{d}`\n\n" 106 | await gsearch_msg.edit(f"**Query:** \n`{query}` \n\n**Result(s):** \n{msg}") -------------------------------------------------------------------------------- /nexa_userbot/modules/whois.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from pyrogram.types import Message 7 | from nexa_userbot import NEXAUB, CMD_HELP 8 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 9 | from nexa_userbot.core.nexaub_database.nexaub_db_globals import get_gban_reason 10 | from nexa_userbot.core.nexaub_database.nexaub_db_sudos import check_if_sudo 11 | from nexa_userbot.helpers.pyrogram_help import get_arg 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Who is (Info),** 22 | 23 | ✘ `whois` - To get information about a user 24 | 25 | **Example:** 26 | 27 | ✘ `whois`, 28 | ⤷ Send command with username = `{Config.CMD_PREFIX}whois @Some_Telegram_User` 29 | ⤷ Reply to a message from a user = `{Config.CMD_PREFIX}whois` (Reply to a message) 30 | """, 31 | f"{mod_name}_category": "tools" 32 | } 33 | ) 34 | 35 | 36 | async def get_user_info(user): 37 | base_user_info = await NEXAUB.get_users(user) 38 | # Assigning user info to vars (idk why i'm doing this) 39 | user_id = base_user_info.id 40 | first_name = base_user_info.first_name 41 | last_name = base_user_info.last_name 42 | username = base_user_info.username 43 | user_info = { 44 | "id": user_id, 45 | "dc": base_user_info.dc_id, 46 | "photo_id": base_user_info.photo.big_file_id if base_user_info.photo else None, 47 | "first_name": first_name if first_name else "None", 48 | "last_name": last_name if last_name else "None", 49 | "user_name": username if username else "None", 50 | "user_mension": base_user_info.mention, 51 | "is_gbanned": "Yes" if await get_gban_reason(user_id) else "No", 52 | "is_sudo": "Yes" if await check_if_sudo(user_id) else "No", 53 | "is_contact": "Yes" if base_user_info.is_contact else "No", 54 | "is_bot": "Yes" if base_user_info.is_bot else "No", 55 | "is_scam": "Yes" if base_user_info.is_scam else "No" 56 | } 57 | return user_info 58 | 59 | 60 | @nexaub.on_cmd(command=["whois", "info"]) 61 | async def who_tf_is(_, message: Message): 62 | who_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 63 | r_msg = message.reply_to_message 64 | w_args = get_arg(message) 65 | if r_msg: 66 | if r_msg.from_user: 67 | iuser = r_msg.from_user.id 68 | else: 69 | return await who_msg.edit("`Reply to a message from user to extract info!`") 70 | elif w_args: 71 | if w_args.isnumeric(): 72 | iuser = int(w_args) 73 | else: 74 | iuser = w_args.replace("@", "") 75 | else: 76 | return await who_msg.edit("`Give a user id / username or reply to a message from user to extract info!`") 77 | # Fetching user info 78 | usr_info = await get_user_info(iuser) 79 | has_photo = usr_info["photo_id"] 80 | user_info_text = f""" 81 | **︾ First Name:** `{usr_info["first_name"]}` 82 | **︾ Last Name:** `{usr_info["last_name"]}` 83 | **︾ User Name:** @{usr_info["user_name"]} 84 | **︾ Mention:** {usr_info["user_mension"]} 85 | **︾ User ID:** `{usr_info["id"]}` 86 | **︾ DC ID:** `{usr_info["dc"]}` 87 | **︾ Is Bot?:** `{usr_info["is_bot"]}` 88 | **︾ Is Contact?:** `{usr_info["is_contact"]}` 89 | **︾ Is Scam?:** `{usr_info["is_scam"]}` 90 | **︾ Is GBanned?:** `{usr_info["is_gbanned"]}` 91 | **︾ Is Sudo?:** `{usr_info["is_sudo"]}` 92 | """ 93 | if has_photo: 94 | usr_dp = await NEXAUB.download_media(has_photo) 95 | await who_msg.delete() 96 | await message.reply_photo(usr_dp, caption=user_info_text) 97 | os.remove(usr_dp) 98 | else: 99 | await who_msg.edit(user_info_text) -------------------------------------------------------------------------------- /nexa_userbot/modules/pictools.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | import requests 5 | 6 | from pyrogram.types import Message 7 | from nexa_userbot import NEXAUB, CMD_HELP 8 | from nexa_userbot.helpers.pictool_help import gib_carbon_sar 9 | from nexa_userbot.helpers.pyrogram_help import get_arg 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import get_custom_var 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Picure Tools** 22 | 23 | ✘ `carbon` - To Carbonize a text 24 | ✘ `rmbg` - To Remove Background from Image using remove.bg API 25 | 26 | **Example:** 27 | 28 | ✘ `carbon`, 29 | ⤷ Send command with text to make a carbon = `{Config.CMD_PREFIX}carbon Carbon Text` 30 | ⤷ Reply to a text message to carbon it = `{Config.CMD_PREFIX}carbon` (Reply to a text message) 31 | 32 | ✘ `rmbg`, 33 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}rmbg` 34 | """, 35 | f"{mod_name}_category": "tools" 36 | } 37 | ) 38 | 39 | 40 | # Carbon a text 41 | # Credits: Friday Userbot | DevsExpo 42 | @nexaub.on_cmd(command=["carbon"]) 43 | async def gibcarbon(_, message: Message): 44 | r_msg = message.reply_to_message 45 | carbon_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 46 | carbonpic_msg = get_arg(message) 47 | if not carbonpic_msg: 48 | if not r_msg: 49 | await carbon_msg.edit("`Reply to a Text Message Lol!`") 50 | return 51 | if not r_msg.text: 52 | await carbon_msg.edit("`Reply to a Text Message Lol!`") 53 | return 54 | else: 55 | carbonpic_msg = r_msg.text 56 | carboned_pic = await gib_carbon_sar(carbonpic_msg) 57 | await carbon_msg.edit("`Uploading...`") 58 | await NEXAUB.send_photo(message.chat.id, carboned_pic) 59 | await carbon_msg.delete() 60 | carboned_pic.close() 61 | 62 | 63 | # Function to get remove.bg api key 64 | async def get_rmbg_api(): 65 | try: 66 | rmbg_bg_api = await get_custom_var("RMBG_API_KEY") 67 | return rmbg_bg_api 68 | except: 69 | return None 70 | 71 | # Background Remover 72 | @nexaub.on_cmd(command=["rmbg"]) 73 | async def removebg(_, message: Message): 74 | rmbg_api = await get_rmbg_api() 75 | rmbg_r_msg = message.reply_to_message 76 | rmbg_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 77 | if rmbg_api is None: 78 | return await rmbg_msg.edit(f"**Remove BG API is not in Database ❗️** \nSet it using `{Config.CMD_PREFIX}setvar RMBG_API_KEY your_api_key` \n\n__**Don't Know How to get your API Key? [Read This](https://nexa-userbot.netlify.app/docs/get-started/configs/#get-rmbg_api_key)**__", disable_web_page_preview=True) 79 | if not rmbg_r_msg: 80 | return await rmbg_msg.edit("`Give a Photo to Remove Background from It!`") 81 | if not rmbg_r_msg.photo: 82 | return await rmbg_msg.edit("`Give a Photo to Remove Background from It!`") 83 | else: 84 | rmbg_chat_id = message.chat.id 85 | rmbg_image = await rmbg_r_msg.download() 86 | rmbg_header = requests.post( 87 | 'https://api.remove.bg/v1.0/removebg', 88 | files={'image_file': open(rmbg_image, 'rb')}, 89 | data={'size': 'auto'}, 90 | headers={'X-Api-Key': rmbg_api}, 91 | ) 92 | if rmbg_header.status_code == requests.codes.ok: 93 | with open(f"NEXAUB-rmbg_{rmbg_chat_id}.png", "wb") as rmbg_out_image: 94 | rmbg_out_image.write(rmbg_header.content) 95 | await NEXAUB.send_document(chat_id=message.chat.id, document=f"NEXAUB-rmbg_{rmbg_chat_id}.png") 96 | os.remove(f"NEXAUB-rmbg_{rmbg_chat_id}.png") 97 | else: 98 | return await rmbg_msg.edit(f"**Error:** \nError Code `{rmbg_header.status_code}` and Error is `{rmbg_header.text}`") -------------------------------------------------------------------------------- /nexa_userbot/modules/spam.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from asyncio import sleep 7 | from pyrogram.types import Message 8 | from pyrogram.errors import FloodWait 9 | 10 | from nexa_userbot import NEXAUB, CMD_HELP 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r, LOG_CHANNEL_ID 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from nexa_userbot.core.errors import Errors 14 | from config import Config 15 | 16 | 17 | # Help 18 | mod_name = os.path.basename(__file__)[:-3] 19 | 20 | CMD_HELP.update( 21 | { 22 | f"{mod_name}": f""" 23 | **Spam,** 24 | 25 | ✘ `spam` - To spam a specific text 26 | ✘ `fspam` - To spam a specific photo / video 27 | 28 | **Example:** 29 | 30 | ✘ `spam`, 31 | ⤷ Send with command = `{Config.CMD_PREFIX}spam Text to Spam` 32 | ⤷ Reply to a text message = `{Config.CMD_PREFIX}spam` 33 | 34 | **Tip 💡,** 35 | ⤷ You can limit the spam too. Just type limit after the command - `{Config.CMD_PREFIX}spam 5` 36 | 37 | ✘ `fspam`, 38 | ⤷ Same arguments and logic as spam command 39 | """, 40 | f"{mod_name}_category": "unknown" 41 | } 42 | ) 43 | 44 | 45 | # Function to spam the message while avoiding the floodwait 46 | async def do_spam(limit, chat_id, spam_text=None, spam_message=None): 47 | # Sleep time (in seconds) 48 | sleep_time = 0.1 if limit <= 50 else 0.5 if limit <= 100 else 1 49 | spm_limit = int(limit) 50 | try: 51 | # Saves message in the log channel 52 | if spam_message: 53 | msg = await spam_message.copy(LOG_CHANNEL_ID) 54 | for i in range(0, spm_limit): 55 | if spam_text: 56 | await NEXAUB.send_message(chat_id, spam_text) 57 | elif msg: 58 | await msg.copy(chat_id) 59 | else: 60 | return 61 | await sleep(sleep_time) 62 | try: 63 | await msg.delete() 64 | except: 65 | pass 66 | except FloodWait as e: 67 | await sleep(e.x) 68 | return await do_spam(limit, chat_id, spam_text=None, spam_message=None) 69 | except BaseException as e: 70 | raise Errors.SpamFailed(e) 71 | 72 | 73 | # Text spam 74 | @nexaub.on_cmd(command=["spam"]) 75 | async def spam_text(_, message: Message): 76 | spm_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 77 | r_msg = message.reply_to_message 78 | args = get_arg(message) 79 | spam_limit = 10 80 | if r_msg: 81 | # Checks if the replied message has any text 82 | if not r_msg.text: 83 | return await spm_msg.edit(f"`Reply to a text message to spam it!` \n\nDid you meant `{Config.CMD_PREFIX}fspam` ?") 84 | to_spam = r_msg.text 85 | # Checks if spam limit is provided by the user 86 | if args and args.isnumeric(): 87 | spam_limit = int(args) 88 | elif args: 89 | splt_args = args.split(None, 1) 90 | if len(splt_args) < 2: 91 | return await spm_msg.edit("`Give some text or reply to a text message to spam it!`") 92 | to_spam = splt_args[1] 93 | if splt_args[0].isnumeric(): 94 | spam_limit = int(splt_args[0]) 95 | else: 96 | return await spm_msg.edit("`Give some text or reply to a text message to spam it!`") 97 | await do_spam(spam_limit, message.chat.id, spam_text=to_spam) 98 | await spm_msg.edit(f"`Successfully spammed {spam_limit} messages!`") 99 | 100 | 101 | # Doc / Audio / Video spam / Animation / Sticker (Basically copy of replied message) 102 | @nexaub.on_cmd(command=["fspam"]) 103 | async def copy_spam(_, message: Message): 104 | spm_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 105 | r_msg = message.reply_to_message 106 | args = get_arg(message) 107 | spam_limit = 10 108 | if r_msg: 109 | # Checks if spam limit is provided by the user 110 | if args and args.isnumeric(): 111 | spam_limit = int(args) 112 | else: 113 | return await spm_msg.edit("`Reply to a message to spam a copy of it!`") 114 | await do_spam(spam_limit, message.chat.id, spam_message=r_msg) 115 | await spm_msg.edit(f"`Successfully spammed {spam_limit} messages!`") -------------------------------------------------------------------------------- /nexa_userbot/modules/megadl.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa Userbot 3 | # Experimantal Mega.nz Downloader Plugin (Uses megatools) 4 | 5 | import os 6 | import subprocess 7 | import shutil 8 | 9 | from pyrogram.types import Message 10 | from functools import partial 11 | from asyncio import get_running_loop 12 | from fsplit.filesplit import Filesplit 13 | 14 | from nexa_userbot import CMD_HELP 15 | from nexa_userbot.helpers.up_to_tg import guess_and_send 16 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 17 | from config import Config 18 | 19 | 20 | # Help 21 | mod_name = os.path.basename(__file__)[:-3] 22 | 23 | CMD_HELP.update( 24 | { 25 | f"{mod_name}": f""" 26 | **Mega Downloader,** 27 | 28 | ✘ `megadl` - To Download Files / Folder from Mega.nz 29 | 30 | **Example:** 31 | 32 | ✘ `megadl` 33 | ⤷ Send with command = `{Config.CMD_PREFIX}megadl https://mega.nz/file/#43445234` (Link is fake tho) 34 | 35 | **Both files and folders are supported** 36 | """, 37 | f"{mod_name}_category": "tools" 38 | } 39 | ) 40 | 41 | 42 | # Run bash cmd in python 43 | def nexa_mega_runner(command): 44 | run = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) 45 | shell_ouput = run.stdout.read()[:-1].decode("utf-8") 46 | return shell_ouput 47 | 48 | # Splitting large files 49 | def split_files(input_file, out_base_path): 50 | nexa_fs = Filesplit() 51 | split_file = input_file 52 | split_fsize = 2040108421 53 | out_path = out_base_path 54 | nexa_fs.split(file=split_file, split_size=split_fsize, output_dir=out_path) 55 | 56 | @nexaub.on_cmd(command=["megadl"]) 57 | async def megatoolsdl(_, message: Message): 58 | megatools_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 59 | url = message.text 60 | cli_user_id = str(message.from_user.id) 61 | cli_download_path = f"{os.getcwd()}/NexaUb/Megatools/{str(message.from_user.id)}" 62 | if len(message.command) < 2: 63 | return await megatools_msg.edit("`Please send a valid mega.nz link to download!`") 64 | # Mega url to download 65 | cli_url = url.split(None, 1)[1] 66 | # Checking if sent message has a vaild mega.nz url 67 | if "https://mega.nz/" not in url: 68 | return await megatools_msg.edit("`Please send a valid mega.nz link to download!`") 69 | # Checking if there is a ongoing task for the user 70 | if os.path.isdir(cli_download_path): 71 | return await megatools_msg.edit("`Already One Process is Going On. Please wait until it's finished!`") 72 | else: 73 | os.makedirs(cli_download_path) 74 | await megatools_msg.edit(f"`Starting to download file / folder from mega.nz!` \n\nThis may take sometime. Depends on your file / folder size.") 75 | megacmd = f"megadl --limit-speed 0 --path {cli_download_path} {cli_url}" 76 | loop = get_running_loop() 77 | await loop.run_in_executor(None, partial(nexa_mega_runner, megacmd)) 78 | nexaub_path_f = f"{os.getcwd()}/NexaUb/Megatools/{str(message.from_user.id)}" 79 | folder_f = [val for sublist in [[os.path.join(i[0], j) for j in i[2]] for i in os.walk(nexaub_path_f)] for val in sublist] 80 | await megatools_msg.edit("`Downloading Finished! Trying to upload now`") 81 | try: 82 | for nexa_m in folder_f: 83 | file_size = os.stat(nexa_m).st_size 84 | if file_size > 2040108421: 85 | split_out_dir = nexaub_path_f + "splitted_files" 86 | await megatools_msg.edit("`Large File Detected, Trying to split it!`") 87 | loop = get_running_loop() 88 | await loop.run_in_executor(None, partial(split_files(input_file=nexa_m, out_base_path=split_out_dir))) 89 | await megatools_msg.edit("`Splitting Finished! Uploading Now...`") 90 | for splitted_f in split_out_dir: 91 | await guess_and_send(input_file=splitted_f, chat_id=message.chat.id, thumb_path="cache") 92 | else: 93 | await guess_and_send(input_file=nexa_m, chat_id=message.chat.id, thumb_path="cache") 94 | await megatools_msg.edit("`Uploading Finished!`") 95 | except Exception as e: 96 | await megatools_msg.edit(f"**Error:** `{e}`") 97 | try: 98 | shutil.rmtree(nexaub_path_f) 99 | except Exception as e: 100 | await megatools_msg.edit(f"**Error:** `{e}`") -------------------------------------------------------------------------------- /nexa_userbot/modules/wallpaper.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | import shutil 6 | 7 | from aiohttp import ClientSession 8 | from pyrogram.types import Message, InputMediaDocument 9 | 10 | from nexa_userbot import CMD_HELP 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from nexa_userbot.helpers.pyrogram_help import get_arg, download_images 13 | from config import Config 14 | 15 | 16 | # Help 17 | mod_name = os.path.basename(__file__)[:-3] 18 | 19 | CMD_HELP.update( 20 | { 21 | f"{mod_name}": f""" 22 | **Wallpaper,** 23 | 24 | ✘ `wall` - To get list of wallpapers according to the give query 25 | 26 | **Example:** 27 | 28 | ✘ `wall`, 29 | ⤷ Send command with url = `{Config.CMD_PREFIX}wall cyberpunk` 30 | ⤷ Reply to a message = `{Config.CMD_PREFIX}wall` 31 | 32 | **Tip 💡,** 33 | ⤷ You can limit the results too. See below examples, 34 | ⤷ Send command with url = `{Config.CMD_PREFIX}wall 5 cyberpunk` 35 | ⤷ Reply to a message = `{Config.CMD_PREFIX}wall 5` 36 | """, 37 | f"{mod_name}_category": "tools" 38 | } 39 | ) 40 | 41 | 42 | # Function to get wallpapers link from "r/wallpaper" subreddit 43 | async def fetch_wallpapers(query, limit=10): 44 | actual_limit = limit if limit <= 20 else 10 45 | url = f"https://nexa-apis.herokuapp.com/reddit?query={query}&subreddit=wallpaper" 46 | wall_list = [] 47 | async with ClientSession() as wall_client: 48 | getit = await wall_client.get(url) 49 | jsn = await getit.json() 50 | if not jsn["status"] == "Ok": 51 | return wall_list 52 | # Adding the image urls to the list 53 | for wall in jsn["data"]: 54 | if not len(wall_list) >= actual_limit: 55 | img = wall["image"] 56 | if img: 57 | wall_list.append(img) 58 | return wall_list 59 | 60 | # Function to make input media list 61 | async def make_input_media_list(image_paths: list): 62 | input_media_list = [] 63 | for path in image_paths: 64 | input_media_list.append( 65 | InputMediaDocument(path, caption=f"**Uploaded with ✨ Nexa Userbot!**") 66 | ) 67 | return input_media_list 68 | 69 | 70 | @nexaub.on_cmd(command=["wall", "wallpaper"]) 71 | async def gib_wallpapers(_, message: Message): 72 | wall_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 73 | r_msg = message.reply_to_message 74 | args = get_arg(message) 75 | # Defalut limit 76 | limit = 10 77 | if r_msg: 78 | if not r_msg.text: 79 | return await wall_msg.edit("`Give something to search!`") 80 | if args: 81 | limit = int(args) 82 | query = r_msg.text 83 | elif args: 84 | splitted = args.split(" ", 1) 85 | if len(splitted) >= 2: 86 | if splitted[0].isnumeric(): 87 | limit = int(splitted[0]) 88 | query = splitted[1] 89 | else: 90 | query = splitted[0] 91 | else: 92 | return await wall_msg.edit("`Give something to search!`") 93 | # Fetching the wallpapers from reddit api or Nexa-APis 94 | await wall_msg.edit("`Fetching wallpapers from the API...`") 95 | fetch_walls = await fetch_wallpapers(query, limit) 96 | if not fetch_walls: 97 | return await wall_msg.edit("`Ooops, Nothing found!`") 98 | # Downloading the wallpapers 99 | await wall_msg.edit("`Downloading the wallpapers. This may take a while! Until then go and drink some coffee ☕`") 100 | downld_walls = await download_images(fetch_walls) 101 | if not fetch_walls: 102 | return await wall_msg.edit("`Ooops, Download failed!`") 103 | # Uploading the wallpapers 104 | media_list = await make_input_media_list(downld_walls) 105 | await wall_msg.edit("`Uploading the wallpapers. This may take a while! Until then go and drink some coffee ☕`") 106 | # Splitting list if the lenght is greater than 10 107 | full_wall_list = [] 108 | if len(media_list) >= 10: 109 | full_wall_list.append(media_list[:10]) 110 | full_wall_list.append(media_list[10:]) 111 | if full_wall_list: 112 | for spl_list in full_wall_list: 113 | await wall_msg.reply_media_group(spl_list) 114 | else: 115 | await wall_msg.reply_media_group(media_list) 116 | await wall_msg.delete() 117 | shutil.rmtree("cache/NEXAUB_Image_Downloader") -------------------------------------------------------------------------------- /nexa_userbot/modules/afk.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | 5 | from pyrogram import filters 6 | from pyrogram.types import Message 7 | from datetime import datetime 8 | 9 | from nexa_userbot import NEXAUB, CMD_HELP 10 | from nexa_userbot.core.nexaub_database.nexaub_db_afk import me_afk, get_afk, me_online 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from config import Config 14 | 15 | 16 | # Help 17 | mod_name = os.path.basename(__file__)[:-3] 18 | 19 | CMD_HELP.update( 20 | { 21 | f"{mod_name}": f""" 22 | **Afk,** 23 | 24 | ✘ `afk` - To Activate Afk Module 25 | 26 | **Example:** 27 | 28 | ✘ `afk`, 29 | ⤷ Send with reason = `{Config.CMD_PREFIX}afk This is the reason` 30 | 31 | **Tip 💡,** 32 | ⤷ Send with `-del` flag to delete sent afk messages when you come back online = `{Config.CMD_PREFIX}afk -del This is the reason` 33 | """, 34 | f"{mod_name}_category": "utils" 35 | } 36 | ) 37 | 38 | 39 | # Dict to store messaged users details temporarily 40 | AFK_SPAMMER_DB = {} 41 | # List to store all afk messages that sent to chats 42 | AFK_MSGS_DB = {} 43 | 44 | 45 | # Check if afk 46 | async def u_afk_bro(filter, client, message): 47 | if_afk = await get_afk() 48 | if if_afk: 49 | return True 50 | else: 51 | return False 52 | 53 | # Creating a custom filter 54 | ya_afk = filters.create(func=u_afk_bro, name="is_ya_afk") 55 | 56 | 57 | @nexaub.on_cmd(command=["afk"]) 58 | async def me_goin_oflin(_, message: Message): 59 | afk_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 60 | get_afk_reason = get_arg(message) 61 | if get_afk_reason: 62 | splitted_txt = get_afk_reason.split(None, 1) 63 | if splitted_txt[0] == "-del": 64 | del_afk_msgs_af = True 65 | if len(splitted_txt) >= 2: 66 | afk_reason = splitted_txt[1] 67 | else: 68 | afk_reason = "I'm Busy For Now! Will Come Online Later :)" 69 | else: 70 | del_afk_msgs_af = False 71 | afk_reason = get_afk_reason 72 | else: 73 | afk_reason = "I'm Busy For Now! Will Come Online Later :)" 74 | del_afk_msgs_af = False 75 | afk_time = datetime.now().replace(microsecond=0) 76 | await me_afk(afk_time=afk_time, afk_reason=afk_reason, delete_afk_msgs=del_afk_msgs_af) 77 | await afk_msg.edit(f"**I'm Going AFK** \n\n**Reason:** `{afk_reason}`") 78 | 79 | 80 | @nexaub.on_cf( 81 | ya_afk 82 | & (filters.mentioned | filters.private) 83 | & ~filters.me 84 | & filters.incoming) 85 | async def me_afk_tho(_, message: Message): 86 | if not message: 87 | return 88 | if not message.from_user: 89 | return 90 | # Checking if user spammed before, if yes ub won't reply to that user again 91 | usr_id = message.from_user.id 92 | if usr_id in AFK_SPAMMER_DB: 93 | AFK_SPAMMER_DB[usr_id] += 1 94 | if AFK_SPAMMER_DB[usr_id] >= 6: 95 | return 96 | else: 97 | AFK_SPAMMER_DB[usr_id] = 1 98 | # If user messaged you 5 times bot'll send him a nice reply :) 99 | if AFK_SPAMMER_DB[usr_id] == 5: 100 | return await message.reply("`Enough! You've messaged my master 5 times, Go get some brain you dumb ass!`") 101 | s_time, a_reason, should_del_afks = await get_afk() 102 | now_time = datetime.now().replace(microsecond=0) 103 | afk_time = str((now_time - s_time)) 104 | afk_reply = await message.reply(f"**I'm AFK** \n\n**Last Online:** `{afk_time}` \n**Reason:** `{a_reason}`") 105 | # Saving current chat id and replied message id to a dict to delete when the user come back online 106 | if should_del_afks: 107 | afk_chat_id = message.chat.id 108 | if afk_chat_id in AFK_MSGS_DB: 109 | msg_list = AFK_MSGS_DB[afk_chat_id] 110 | msg_list.append(afk_reply.id) 111 | AFK_MSGS_DB[afk_chat_id] = msg_list 112 | else: 113 | AFK_MSGS_DB[afk_chat_id] = [afk_reply.id] 114 | 115 | @nexaub.on_cf( 116 | filters.me 117 | & filters.outgoing 118 | & ya_afk 119 | ) 120 | async def back_online_bois(_, message: Message): 121 | s_time, a_reason, should_del_afks = await get_afk() 122 | com_online = datetime.now().replace(microsecond=0) 123 | afk_time = str((com_online - s_time)) 124 | await me_online() 125 | await message.reply(f"**I'm No Longer AFK** \n\n**Afk Time:** `{afk_time}` \n**Reason:** `{a_reason}`") 126 | # Deleting send afk messages 127 | if should_del_afks: 128 | status_msg = await message.reply("`Deleting sent afk messages...`") 129 | for c_id, msgs_ids in AFK_MSGS_DB.items(): 130 | await NEXAUB.delete_messages(chat_id=c_id, message_ids=msgs_ids) 131 | await status_msg.delete() 132 | -------------------------------------------------------------------------------- /nexa_userbot/modules/paste.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | import re 6 | 7 | from pyrogram.types import Message 8 | from httpx import AsyncClient 9 | from nexa_userbot import CMD_HELP 10 | from nexa_userbot.helpers.pyrogram_help import get_arg 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Paste,** 22 | 23 | ✘ `paste` - To Paste Text to Hastebin / Nekobin or Spacebin 24 | 25 | **Example:** 26 | 27 | **Attention 🗞 ,** 28 | ⤷ Different pastebin services have different commands. The default pastebin service is nekobin. 29 | 30 | ⤷ `{Config.CMD_PREFIX}nekobin` - For nekobin 31 | ⤷ `{Config.CMD_PREFIX}hastebin` - For hastebin 32 | ⤷ `{Config.CMD_PREFIX}spacebin` - For spacebin 33 | 34 | ✘ Usage (if needed, replace `paste` with other commands), 35 | ⤷ Send text with command = `{Config.CMD_PREFIX}paste Paste this text` 36 | ⤷ Reply to a text file = `{Config.CMD_PREFIX}paste` (Reply to a text file) 37 | ⤷ Reply to a text message = `{Config.CMD_PREFIX}paste (Reply to a text message) 38 | """, 39 | f"{mod_name}_category": "tools" 40 | } 41 | ) 42 | 43 | 44 | # Pastebins 45 | class PasteBins: 46 | def __init__(self) -> None: 47 | # API Urls 48 | self.nekobin_api = "https://nekobin.com/api/documents" 49 | self.spacebin_api = "https://spaceb.in/api/v1/documents" 50 | self.hastebin_api = "https://www.toptal.com/developers/hastebin/documents" 51 | # Paste Urls 52 | self.nekobin = "https://nekobin.com" 53 | self.spacebin = "https://spaceb.in" 54 | self.hastebin = "https://www.toptal.com/developers/hastebin" 55 | 56 | async def paste_text(self, paste_bin, text): 57 | if paste_bin == "spacebin": 58 | return await self.paste_to_spacebin(text) 59 | elif paste_bin == "hastebin": 60 | return await self.paste_to_hastebin(text) 61 | elif paste_bin == "nekobin": 62 | return await self.paste_to_nekobin(text) 63 | else: 64 | return "`Invalid pastebin service selected!`" 65 | 66 | async def __check_status(self, resp_status, status_code: int = 201): 67 | if int(resp_status) != status_code: 68 | return "real shit" 69 | else: 70 | return "ok" 71 | 72 | async def paste_to_nekobin(self, text): 73 | async with AsyncClient() as nekoc: 74 | resp = await nekoc.post(self.nekobin_api, json={"content": str(text)}) 75 | chck = await self.__check_status(resp.status_code) 76 | if not chck == "ok": 77 | return None 78 | else: 79 | jsned = resp.json() 80 | return f"{self.nekobin}/{jsned['result']['key']}" 81 | 82 | async def paste_to_spacebin(self, text): 83 | async with AsyncClient() as spacbc: 84 | resp = await spacbc.post(self.spacebin_api, data={"content": str(text), "extension": "md"}) 85 | chck = await self.__check_status(resp.status_code) 86 | if not chck == "ok": 87 | return None 88 | else: 89 | jsned = resp.json() 90 | return f"{self.spacebin}/{jsned['payload']['id']}" 91 | 92 | async def paste_to_hastebin(self, text): 93 | async with AsyncClient() as spacbc: 94 | resp = await spacbc.post(self.hastebin_api, data=str(text)) 95 | chck = await self.__check_status(resp.status_code, 200) 96 | if not chck == "ok": 97 | return None 98 | else: 99 | jsned = resp.json() 100 | return f"{self.hastebin}/{jsned['key']}" 101 | 102 | 103 | async def get_pastebin_service(text: str): 104 | if re.search(r'\bhastebin\b', text): 105 | pastebin = "hastebin" 106 | elif re.search(r'\bspacebin\b', text): 107 | pastebin = "spacebin" 108 | elif re.search(r'\bnekobin\b', text): 109 | pastebin = "nekobin" 110 | else: 111 | pastebin = "spacebin" 112 | return pastebin 113 | 114 | @nexaub.on_cmd(command=["paste", "nekobin", "hastebin", "spacebin"]) 115 | async def paste_dis_text(_, message: Message): 116 | pstbin_serv = await get_pastebin_service(message.text.split(" ")[0]) 117 | paste_msg = await e_or_r(nexaub_message=message, msg_text=f"`Pasting to {pstbin_serv.capitalize()}...`") 118 | replied_msg = message.reply_to_message 119 | tex_t = get_arg(message) 120 | message_s = tex_t 121 | if not tex_t: 122 | if not replied_msg: 123 | return await paste_msg.edit("`Reply To File or Send This Command With Text!`") 124 | if not replied_msg.text: 125 | file = await replied_msg.download() 126 | m_list = open(file, "r").read() 127 | message_s = m_list 128 | os.remove(file) 129 | elif replied_msg.text: 130 | message_s = replied_msg.text 131 | paste_cls = PasteBins() 132 | pasted = await paste_cls.paste_text(pstbin_serv, message_s) 133 | if not pasted: 134 | return await paste_msg.edit("`Oops, Pasting failed! Please try changing the pastebin service!`") 135 | await paste_msg.edit(f"**Pasted to {pstbin_serv.capitalize()}!** \n\n**Url:** {pasted}", disable_web_page_preview=True) -------------------------------------------------------------------------------- /nexa_userbot/modules/hack.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | import asyncio 6 | 7 | from pyrogram.types import Message 8 | from nexa_userbot import CMD_HELP 9 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 10 | 11 | 12 | # Help 13 | mod_name = os.path.basename(__file__)[:-3] 14 | 15 | CMD_HELP.update( 16 | { 17 | f"{mod_name}": f""" 18 | **Hack** 19 | 20 | ✘ `hack` - To perform a hack prank 21 | """, 22 | f"{mod_name}_category": "unknown" 23 | } 24 | ) 25 | 26 | 27 | @nexaub.on_cmd(command=["hack", "heck"]) 28 | async def heck_dat(_, message: Message): 29 | r_msg = message.reply_to_message 30 | heck_msg = await e_or_r(nexaub_message=message, msg_text="**[root@Nexa-Ub]** `enable tg-hacker && clear`") 31 | if not r_msg: 32 | return await heck_msg.edit("`⚠ Reply to a telegram user to perform a hack!`") 33 | if not r_msg.from_user: 34 | return await heck_msg.edit("`⚠ Reply to a telegram user to perform a hack!`") 35 | # User info 36 | user_id = r_msg.from_user.id 37 | user_mention = r_msg.from_user.mention 38 | user_dc = r_msg.from_user.dc_id 39 | # Hack animation characters (stage 1) 40 | stage1_msg = "" 41 | hack_animation_stage1_chars = [ 42 | "**[root@Nexa-Ub]** `tg-hacker init` \n", 43 | "`>> Initializing telegram hacker...` \n\n", 44 | "**[root@Nexa-Ub]** `tg-hacker --check-tools` \n", 45 | "`>> Checking if the required tools are installed...` \n", 46 | "`>> Done Checking! All the tools are installed!` \n\n", 47 | f"**[root@Nexa-Ub]** `mkdir {user_id}` \n", 48 | f"`>> Creating Directory for the user...` \n", 49 | "`>> Successfully Created the Directory!` \n\n", 50 | f"**[root@Nexa-Ub]** `cd {user_id} && tg-hacker --set-config-user-path pwd && cd` \n", 51 | f"\n`Forwarding the process to stage 2`" 52 | ] 53 | # Hack animation characters (stage 2) 54 | stage2_msg = "" 55 | hack_animation_stage2_chars = [ 56 | "**[root@Nexa-Ub]** `tg-hacker --connect-to-server --most-stable` \n", 57 | "`>> Connecting to the telegram servers...` \n" 58 | "`>> Connected ✓` \n\n", 59 | "**[root@Nexa-Ub]** `tg-hacker --collect-user-info --less-verbose` \n" 60 | f"`>> Extracting the information about user id - {user_id}` \n", 61 | f"`>> Process completed ✓. Collected information about` {user_mention} . \n" 62 | "\n`Forwarding the process to stage 3`" 63 | ] 64 | # Hack animation characters (stage 3) 65 | stage3_msg = "" 66 | hack_animation_stage3_progress = [ 67 | "`▱▱▱▱▱▱▱▱▱▱▱▱▱ 0%` \n", 68 | "`▰▱▱▱▱▱▱▱▱▱▱▱▱ 5%` \n", 69 | "`▰▱▱▱▱▱▱▱▱▱▱▱▱ 14%` \n", 70 | "`▰▰▱▱▱▱▱▱▱▱▱▱▱ 23%`\n", 71 | "`▰▰▰▰▱▱▱▱▱▱▱▱▱ 31%` \n", 72 | "`▰▰▰▰▰▱▱▱▱▱▱▱▱ 43%` \n", 73 | "`▰▰▰▰▰▰▰▱▱▱▱▱▱ 59%` \n", 74 | "`▰▰▰▰▰▰▰▰▱▱▱▱▱ 65%` \n", 75 | "`▰▰▰▰▰▰▰▰▰▰▱▱▱ 78%` \n", 76 | "`▰▰▰▰▰▰▰▰▰▰▰▱▱ 89%` \n", 77 | "`▰▰▰▰▰▰▰▰▰▰▰▰▱ 94%` \n", 78 | "`▰▰▰▰▰▰▰▰▰▰▰▰▰ 100%` \n" 79 | ] 80 | hack_animation_stage3_chars = [ 81 | "**[root@Nexa-Ub]** `tg-hacker start --use-tg-brut --less-verbose --auto-cmd` \n", 82 | "`>> Starting the hack...` \n", 83 | "`>> Downloading Telegram-Bruteforce-8.3.2.tar.gz (1.9MiB)` \n" 84 | "`>> Download Completed ✓` \n\n", 85 | "**[root@Nexa-Ub]** `tg-hacker --check-config` \n", 86 | "`>> Checking user config file...` \n" 87 | f"`>> Found config file - {user_id}.conf` \n", 88 | "**[root@Nexa-Ub]** `tg-hacker --upload` \n", 89 | f"`>> Uploading the hacked accound details to telegram server - ID {user_dc if user_dc else 'Main'}` \n\n", 90 | ] 91 | # Hack animation characters (stage 4) 92 | stage4_msg = "" 93 | hack_animation_stage4_chars = [ 94 | "**[root@Nexa-Ub]** `tg-hacker check-if-completed` \n", 95 | "`>> Checking...` \n" 96 | "`>> Hacking completed ✓` \n\n", 97 | "**[root@Nexa-Ub]** `tg-hacker show --fix-for-tg-msg` \n\n\n", 98 | f"**Dear {user_mention}, Your telegram account has been hacked by me ☠! \nYou have to pay at least $98 to fix your telegram account!**" 99 | ] 100 | # Editing the message (stage 1) 101 | for char1 in hack_animation_stage1_chars: 102 | await asyncio.sleep(1) 103 | stage1_msg += char1 104 | await heck_msg.edit(stage1_msg) 105 | await asyncio.sleep(3) 106 | # Editing the message (stage 2) 107 | await heck_msg.edit(f"{stage1_msg} \n\n**[root@Nexa-Ub]** `clear`") 108 | for char2 in hack_animation_stage2_chars: 109 | await asyncio.sleep(2) 110 | stage2_msg += char2 111 | await heck_msg.edit(stage2_msg) 112 | await asyncio.sleep(4) 113 | # Editing the message (stage 3) 114 | await heck_msg.edit(f"{stage2_msg} \n\n**[root@Nexa-Ub]** `clear && tg-hacker --set-stage stage3`") 115 | for char3 in hack_animation_stage3_chars: 116 | await asyncio.sleep(3) 117 | stage3_msg += char3 118 | await heck_msg.edit(stage3_msg) 119 | await asyncio.sleep(3) 120 | for prgs in hack_animation_stage3_progress: 121 | await asyncio.sleep(3) 122 | actual_prgs_msg = stage3_msg + prgs 123 | await heck_msg.edit(actual_prgs_msg) 124 | await asyncio.sleep(4) 125 | # Editing the message (stage 4) 126 | await heck_msg.edit(f"{actual_prgs_msg} \n**[root@Nexa-Ub]** `clear && tg-hacker --set-stage stage4`") 127 | for char4 in hack_animation_stage4_chars: 128 | await asyncio.sleep(3) 129 | stage4_msg += char4 130 | await heck_msg.edit(stage4_msg) -------------------------------------------------------------------------------- /nexa_userbot/core/startup_checks.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | import asyncio 5 | import logging 6 | 7 | from pyrogram.errors import YouBlockedUser, PeerIdInvalid 8 | from nexa_userbot import NEXAUB 9 | from nexa_userbot.core.main_cmd import nexaub 10 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import set_log_channel, get_log_channel, set_arq_key, get_arq_key 11 | from nexa_userbot.core.nexaub_database.nexaub_db_sudos import get_custom_plugin_channels 12 | from config import Config 13 | 14 | 15 | # Log Channel Checker 16 | async def check_or_set_log_channel(): 17 | try: 18 | al_log_channel = await get_log_channel() 19 | if al_log_channel: 20 | return [True, al_log_channel] 21 | else: 22 | log_channel = await NEXAUB.create_channel(title="Nexa Userbot Logs", description="Logs of your Nexa Userbot") 23 | log_channel_id = log_channel.id 24 | await NEXAUB.set_chat_photo(chat_id=log_channel_id, photo="cache/NEXAUB.png") 25 | welcome_to_nexaub = f""" 26 | **Welcome to Nexa Userbot** 27 | Thanks for trying Nexa Userbot. If you found any error, bug or even a Feature Request please report it at **@NexaUB_Support** 28 | 29 | **⌲ Quick Start,** 30 | If you don't know how to use this Userbot please send `{Config.CMD_PREFIX}help` in any chat. It'll show all plugins your userbot has. You can use those plugin names to get info about how to use it. Also check out [Docs](https://nexaub.itz-fork.xyz/) 31 | 32 | 33 | **~ Nexa Userbot, Developers**""" 34 | await set_log_channel(log_channel_id) 35 | await NEXAUB.send_message(chat_id=log_channel_id, text=welcome_to_nexaub, disable_web_page_preview=True) 36 | return [True, log_channel_id] 37 | except Exception as e: 38 | logging.warn( 39 | f"Error: \n{e} \n\nPlease check all variables and try again! \nReport this with logs at @NexaUB_Support if the problem persists!") 40 | exit() 41 | 42 | 43 | # Plugin installer for channels 44 | async def search_and_download_plugs(channel, max_tries=2, counted=0): 45 | if counted >= max_tries: 46 | return 47 | try: 48 | async for plugin in NEXAUB.search_messages(chat_id=channel, query=".py", filter="document"): 49 | plugin_name = plugin.document.file_name 50 | if not os.path.exists(f"nexa_userbot/modules/Extras/{plugin_name}"): 51 | await NEXAUB.download_media(message=plugin, file_name=f"nexa_userbot/modules/Extras/{plugin_name}") 52 | except PeerIdInvalid: 53 | counted += 1 54 | await nexaub().resolve_peer(channel, max_tries=1) 55 | return await search_and_download_plugs(channel, counted=counted) 56 | 57 | async def download_plugins_in_channel(): 58 | plugin_channels = await get_custom_plugin_channels() 59 | if plugin_channels: 60 | for channel in plugin_channels: 61 | try: 62 | await search_and_download_plugs(channel) 63 | except BaseException as e: 64 | logging.warn( 65 | f"Error: \n{e} \n\nUnable to install plugins from custom plugin channels!") 66 | else: 67 | logging.info( 68 | "No Custom Plugin Channels were specified, Nexa-Userbot is running with default plugins only!") 69 | 70 | 71 | # Custom plugin collector 72 | async def install_custom_plugins(): 73 | custom_plugin_path = "nexa_userbot/modules/Extras" 74 | if os.path.isdir(custom_plugin_path): 75 | for plugin in os.listdir(custom_plugin_path): 76 | if str(plugin).startswith("__"): 77 | return 78 | if plugin.endswith(".py"): 79 | try: 80 | nexaub().import_plugin( 81 | (os.path.join(custom_plugin_path, plugin)).replace(".py", "")) 82 | except: 83 | logging.warn( 84 | f"Error happened while installing {os.path.join(custom_plugin_path, plugin)} plugin") 85 | try: 86 | os.remove(plugin) 87 | except: 88 | pass 89 | else: 90 | logging.info("No Custom Plugins were found to install!") 91 | 92 | 93 | # ARQ API KEY Checker 94 | async def check_arq_api(): 95 | try: 96 | try: 97 | await NEXAUB.send_message("ARQRobot", "/start") 98 | except YouBlockedUser: 99 | await NEXAUB.unblock_user("ARQRobot") 100 | await asyncio.sleep(0.2) 101 | await NEXAUB.send_message("ARQRobot", "/start") 102 | await asyncio.sleep(0.5) 103 | await NEXAUB.send_message("ARQRobot", "/get_key") 104 | get_h = (await NEXAUB.get_history("ARQRobot", 1))[0] 105 | g_history = get_h.text 106 | if "X-API-KEY:" not in g_history: 107 | nexaub_user = await NEXAUB.get_me() 108 | arq_acc_name = nexaub_user.first_name if nexaub_user.first_name else f"Unknown_{nexaub_user.id}" 109 | await asyncio.sleep(0.4) 110 | await NEXAUB.send_message("ARQRobot", f"{arq_acc_name}") 111 | await asyncio.sleep(0.3) 112 | gib_history = (await NEXAUB.get_history("ARQRobot", 1))[0] 113 | g_history = gib_history.text 114 | arq_api_key = g_history.replace("X-API-KEY: ", "") 115 | else: 116 | arq_api_key = g_history.replace("X-API-KEY: ", "") 117 | is_arqed = await get_arq_key() 118 | if is_arqed is None: 119 | await set_arq_key(arq_api_key) 120 | else: 121 | pass 122 | except Exception as e: 123 | logging.warn( 124 | f"Error: \n{e} \n\nThere was a problem while obtaining ARQ API KEY. However you can set it manually. Send, \n{Config.CMD_PREFIX}setvar ARQ_API_KEY your_api_key_here") 125 | -------------------------------------------------------------------------------- /nexa_userbot/modules/eval.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot 4 | 5 | import re 6 | import os 7 | import sys 8 | import traceback 9 | import subprocess 10 | 11 | from io import StringIO 12 | from nexa_userbot import NEXAUB, CMD_HELP 13 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 14 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import get_custom_var 15 | from config import Config 16 | 17 | 18 | # Help 19 | mod_name = os.path.basename(__file__)[:-3] 20 | 21 | CMD_HELP.update( 22 | { 23 | f"{mod_name}": f""" 24 | **Eval** 25 | 26 | ✘ `eval` - To Run Pyrogram Evaluations 27 | ✘ `sh` - To Run commands in shell 28 | 29 | **Example:** 30 | 31 | ✘ `eval`, 32 | ⤷ Send with pyrogram command = `{Config.CMD_PREFIX}eval await message.reply("Yo, wassup!")` 33 | 34 | ✘ `sh`, 35 | ⤷ Send with bash command = `{Config.CMD_PREFIX}sh pip3 install cowsay` 36 | """, 37 | f"{mod_name}_category": "dev" 38 | } 39 | ) 40 | 41 | 42 | async def aexec(code, client, message): 43 | exec( 44 | f"async def __aexec(client, message): " 45 | + "".join(f"\n {l}" for l in code.split("\n")) 46 | ) 47 | return await locals()["__aexec"](client, message) 48 | 49 | # Configs 50 | NON_DEV_WARN_MSG = f""" 51 | **Warning ⚠️!** 52 | 53 | `Be careful with the codes that you gonna run with this userbot as eval mode is the most powerful plugin and it can even delete your telegram account. Therefore it's only available for developers!` 54 | 55 | 56 | **If you want to enable it,** 57 | 58 | `{Config.CMD_PREFIX}setvar DEV_MODE True` 59 | 60 | 61 | __**Don't blame the developer after doing stupid things with this ❗**__ 62 | """ 63 | 64 | @nexaub.on_cmd(command=["eval"]) 65 | async def evaluate(client, message): 66 | status_message = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 67 | # Checks if the developer mode is enabled 68 | is_dev = await get_custom_var("DEV_MODE") 69 | if is_dev != "True": 70 | return await status_message.edit(NON_DEV_WARN_MSG) 71 | try: 72 | cmd = message.text.split(" ", maxsplit=1)[1] 73 | except IndexError: 74 | return await status_message.delete() 75 | reply_to_id = message.id 76 | if message.reply_to_message: 77 | reply_to_id = message.reply_to_message.id 78 | old_stderr = sys.stderr 79 | old_stdout = sys.stdout 80 | redirected_output = sys.stdout = StringIO() 81 | redirected_error = sys.stderr = StringIO() 82 | stdout, stderr, exc = None, None, None 83 | try: 84 | await aexec(cmd, client, message) 85 | except Exception: 86 | exc = traceback.format_exc() 87 | stdout = redirected_output.getvalue() 88 | stderr = redirected_error.getvalue() 89 | sys.stdout = old_stdout 90 | sys.stderr = old_stderr 91 | evaluation = "" 92 | if exc: 93 | evaluation = exc 94 | elif stderr: 95 | evaluation = stderr 96 | elif stdout: 97 | evaluation = stdout 98 | else: 99 | evaluation = "Success" 100 | final_output = f"**► Command:** \n`{cmd}` \n\n**► Response / Output:** \n`{evaluation.strip()}`" 101 | if len(final_output) > 4096: 102 | filename = "output.txt" 103 | with open(filename, "w+", encoding="utf8") as out_file: 104 | out_file.write(str(final_output)) 105 | await NEXAUB.send_document( 106 | chat_id=message.chat.id, 107 | document=filename, 108 | caption=f"**► Input:** \n`{cmd}`", 109 | disable_notification=True, 110 | reply_to_message_id=reply_to_id, 111 | ) 112 | os.remove(filename) 113 | await status_message.delete() 114 | else: 115 | await e_or_r(nexaub_message=status_message, msg_text=final_output) 116 | 117 | 118 | @nexaub.on_cmd(command=["sh"]) 119 | async def terminal(client, message): 120 | sh_eval_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 121 | if len(message.text.split()) == 1: 122 | await sh_eval_msg.edit(f"`Invalid Command!` \n\n**Example:** `{Config.CMD_PREFIX}sh echo Hello World`") 123 | return 124 | try: 125 | cmd = message.text.split(" ", maxsplit=1)[1] 126 | except IndexError: 127 | await message.delete() 128 | return 129 | args = message.text.split(None, 1) 130 | teks = args[1] 131 | if "\n" in teks: 132 | code = teks.split("\n") 133 | output = "" 134 | for x in code: 135 | shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", x) 136 | try: 137 | process = subprocess.Popen( 138 | shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE 139 | ) 140 | except Exception as err: 141 | print(err) 142 | await sh_eval_msg.edit( 143 | """ 144 | **► Error:** 145 | ```{}``` 146 | """.format( 147 | err 148 | ) 149 | ) 150 | output += "**{}**\n".format(code) 151 | output += process.stdout.read()[:-1].decode("utf-8") 152 | output += "\n" 153 | else: 154 | shell = re.split(""" (?=(?:[^'"]|'[^']*'|"[^"]*")*$)""", teks) 155 | for a in range(len(shell)): 156 | shell[a] = shell[a].replace('"', "") 157 | try: 158 | process = subprocess.Popen( 159 | shell, stdout=subprocess.PIPE, stderr=subprocess.PIPE 160 | ) 161 | except Exception as err: 162 | exc_type, exc_obj, exc_tb = sys.exc_info() 163 | errors = traceback.format_exception( 164 | etype=exc_type, value=exc_obj, tb=exc_tb 165 | ) 166 | await sh_eval_msg.edit("""**► Error:**\n```{}```""".format("".join(errors))) 167 | return 168 | output = process.stdout.read()[:-1].decode("utf-8") 169 | if str(output) == "\n": 170 | output = None 171 | if output: 172 | if len(output) > 4096: 173 | with open("output.txt", "w+") as file: 174 | file.write(output) 175 | await client.send_document( 176 | message.chat.id, 177 | "output.txt", 178 | reply_to_message_id=message.id, 179 | caption=f"**► Input:** \n`{cmd}`", 180 | ) 181 | os.remove("output.txt") 182 | return 183 | await sh_eval_msg.edit(f"**► Input:** \n`{cmd}` \n\n**► Output:**\n```{output}```", parse_mode="markdown") 184 | else: 185 | await sh_eval_msg.edit(f"**► Input:** \n`{cmd}` \n\n**► Output:**\n`No Output`") 186 | -------------------------------------------------------------------------------- /nexa_userbot/modules/sudos.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | 5 | from pyrogram.types import Message 6 | from nexa_userbot import CMD_HELP 7 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 8 | from nexa_userbot.helpers.pyrogram_help import get_arg 9 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import set_custom_var, get_custom_var, del_custom_var 10 | from nexa_userbot.core.nexaub_database.nexaub_db_sudos import add_sudo, remove_sudo, check_if_sudo, add_custom_plugin_channel, get_custom_plugin_channels, remove_custom_plugin_channel 11 | from .updater import restart_nexaub 12 | from config import Config 13 | 14 | 15 | # Help 16 | mod_name = os.path.basename(__file__)[:-3] 17 | 18 | CMD_HELP.update( 19 | { 20 | f"{mod_name}": f""" 21 | **Sudos,** 22 | 23 | ✘ `setvar` - To Set a Variable 24 | ✘ `getvar` - To Get value of a variable 25 | ✘ `delvar` - To Delete a variable 26 | ✘ `addsudo` - To Add a Sudo User 27 | ✘ `rsudo` - To Remove a Sudo User 28 | ✘ `add_plugin_channel` - To Add Custom Plugin Channel 29 | ✘ `rm_plugin_channel` - To Remove Custom Plugin Channel 30 | ✘ `get_plugin_channels` - To Get Custom Plugin Channels 31 | 32 | **Example:** 33 | 34 | ✘ `setvar`, 35 | ⤷ Send command with Var and Value = `{Config.CMD_PREFIX}setvar YOUR_VAR your_value` 36 | 37 | ✘ `getvar`, 38 | ⤷ Send command with Var = `{Config.CMD_PREFIX}getvar YOUR_VAR` 39 | 40 | ✘ `delvar`, 41 | ⤷ Send command with Var = `{Config.CMD_PREFIX}delvar YOUR_VAR` 42 | 43 | ✘ `addsudo`, 44 | ⤷ Send command with user id = `{Config.CMD_PREFIX}addsudo 1234567` 45 | ⤷ Reply to a user message = `{Config.CMD_PREFIX}addsudo` (Reply to a user message) 46 | 47 | ✘ `rsudo`, 48 | ⤷ Send command with sudo user id = `{Config.CMD_PREFIX}rsudo 1234567` 49 | ⤷ Reply to a sudo user message = `{Config.CMD_PREFIX}rsudo` (Reply to a user message) 50 | """, 51 | f"{mod_name}_category": "utils" 52 | } 53 | ) 54 | 55 | 56 | @nexaub.on_cmd(command=["addsudo"]) 57 | async def set_sudo(_, message: Message): 58 | sudo_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 59 | sudo_id = str(get_arg(message)) 60 | r_sudo_msg = message.reply_to_message 61 | if r_sudo_msg: 62 | sudo_user_id = str(r_sudo_msg.from_user.id) 63 | else: 64 | sudo_user_id = str(sudo_id) 65 | is_sudo = await check_if_sudo(sudo_user_id) 66 | if is_sudo is True: 67 | await sudo_msg.edit(f"**User** `{sudo_user_id}` **is already a sudo user**") 68 | return 69 | else: 70 | pass 71 | is_id_ok = sudo_user_id.isnumeric() 72 | if is_id_ok is True: 73 | await add_sudo(sudo_user_id) 74 | await sudo_msg.edit(f"**Successfully Added New Sudo User** \n\n**User ID:** `{sudo_user_id}` \n\nRestarting your bot to apply the changes!") 75 | await restart_nexaub() 76 | else: 77 | await sudo_msg.edit("`Please give a valid user id to add as a sudo user`") 78 | 79 | 80 | @nexaub.on_cmd(command=["rsudo"]) 81 | async def set_sudo(_, message: Message): 82 | sudo_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 83 | sudo_id = str(get_arg(message)) 84 | r_sudo_msg = message.reply_to_message 85 | if r_sudo_msg: 86 | sudo_user_id = str(r_sudo_msg.from_user.id) 87 | else: 88 | sudo_user_id = str(sudo_id) 89 | is_sudo = await check_if_sudo(sudo_user_id) 90 | if is_sudo is False: 91 | await sudo_msg.edit(f"**User** `{sudo_user_id}` **isn't a sudo user lol!**") 92 | return 93 | else: 94 | pass 95 | is_id_ok = sudo_user_id.isnumeric() 96 | if is_id_ok is True: 97 | await remove_sudo(sudo_user_id) 98 | await sudo_msg.edit(f"**Successfully Removed Sudo User** \n\n**User ID:** `{sudo_user_id}` \n\nRestarting your bot to apply the changes!") 99 | await restart_nexaub() 100 | else: 101 | await sudo_msg.edit("`Please give a valid user id to add as a sudo user`") 102 | 103 | 104 | @nexaub.on_cmd(command=["setvar"]) 105 | async def setmongovar(_, message: Message): 106 | setvr_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 107 | var_val = get_arg(message) 108 | if not var_val: 109 | return await setvr_msg.edit("`Give Variable and Value to set!`") 110 | else: 111 | s_var = var_val.split(" ", 1) 112 | await set_custom_var(var=s_var[0], value=s_var[1]) 113 | await setvr_msg.edit(f"**Successfully Added Custom Var** \n\n**Var:** `{s_var[0]}` \n**Val:** `{s_var[1]}`") 114 | 115 | @nexaub.on_cmd(command=["getvar"]) 116 | async def get_var(_, message: Message): 117 | g_var = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 118 | var_g = get_arg(message) 119 | if not var_g: 120 | return await g_var.edit("`Give Variable and Value to set!`") 121 | else: 122 | g_var_s = await get_custom_var(var=var_g) 123 | if g_var_s is None: 124 | return await g_var.edit("`Is that var exists?`") 125 | else: 126 | await g_var.edit(f"**Var:** `{var_g}` \n**Val:** `{g_var_s}`") 127 | 128 | @nexaub.on_cmd(command=["delvar"]) 129 | async def del_var(_, message: Message): 130 | d_var = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 131 | var_d = get_arg(message) 132 | if not var_d: 133 | return await d_var.edit("`Give Variable to delete!`") 134 | else: 135 | deld_var = await del_custom_var(var_d) 136 | if deld_var: 137 | await d_var.edit(f"**Successfully Deleted** `{var_d}` **Var from database!**") 138 | 139 | 140 | @nexaub.on_cmd(command=["add_plugin_channel", "a_p_c", "add_plugins"]) 141 | async def add_custom_plug(_, message: Message): 142 | acpc = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 143 | get_c_name = get_arg(message) 144 | if not get_c_name: 145 | return await acpc.edit("`Give a channel username to add it as a custom plugin channel!`") 146 | if get_c_name.isnumeric(): 147 | plug_channel = int(get_c_name) 148 | else: 149 | plug_channel = get_c_name.replace("@", "") 150 | custp_list = await get_custom_plugin_channels() 151 | if plug_channel in custp_list: 152 | return await acpc.edit("`Channel is already added!`") 153 | await add_custom_plugin_channel(plug_channel) 154 | await acpc.edit(f"**Successfully Added Custom Plugin Channel** \n\n**Channel:** {get_c_name}") 155 | 156 | @nexaub.on_cmd(command=["rm_plugin_channel", "rm_c", "rm_plugins"]) 157 | async def remove_custom_plug(_, message: Message): 158 | rmcpc = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 159 | rm_c_name = get_arg(message) 160 | if not rm_c_name: 161 | return await rmcpc.edit("`Give a channel username to remove it from custom plugin channel database!`") 162 | custp_list = await get_custom_plugin_channels() 163 | if rm_c_name not in custp_list: 164 | await rmcpc.edit("`First add custom plugin channel, then we can remove it :)`") 165 | await remove_custom_plugin_channel(rm_c_name) 166 | await rmcpc.edit(f"**Successfully Removed Custom Plugin Channel** \n\n**Channel:** {rm_c_name}") 167 | 168 | @nexaub.on_cmd(command=["get_plugin_channels", "get_c", "get_plugins"]) 169 | async def get_custom_plug(_, message: Message): 170 | getcpc = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 171 | channel_list = await get_custom_plugin_channels() 172 | if not channel_list: 173 | return await getcpc.edit("`Add some custom plugin channels!`") 174 | channel_str = "**Available Custom Plugin Channels!** \n\n" 175 | for ch in channel_list: 176 | channel_str += f" ➥ `{ch}` \n" 177 | await getcpc.edit(channel_str) -------------------------------------------------------------------------------- /nexa_userbot/modules/alive.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot | Nexa Userbot 4 | 5 | import os 6 | import time 7 | import json 8 | 9 | from sys import version_info 10 | from datetime import datetime 11 | from pyrogram import __version__ as pyrogram_version 12 | from pyrogram.types import Message 13 | 14 | from nexa_userbot import NEXAUB, CMD_HELP, StartTime 15 | from nexa_userbot.helpers.pyrogram_help import get_arg, convert_to_image 16 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import set_custom_alive_msg, get_custom_alive_msg, set_custom_var, get_custom_var 17 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 18 | from nexa_userbot.core.startup_checks import check_or_set_log_channel 19 | from .Extras import get_xtra_modules_names 20 | from .telegraph import upload_to_tgraph 21 | from . import __all__ as all_mods 22 | from config import Config 23 | 24 | 25 | # Help 26 | mod_name = os.path.basename(__file__)[:-3] 27 | 28 | CMD_HELP.update( 29 | { 30 | f"{mod_name}": f""" 31 | **Alive,** 32 | 33 | ✘ `alive` - To Check If Your Nexa Userbot Alive 34 | ✘ `ping` - To Check Ping Speed 35 | ✘ `setalive` - To Set Custom Alive Message 36 | ✘ `getalive` - To Get current alive message 37 | ✘ `setalivepic` - To Set Custom Alive Picture 38 | ✘ `getalivepic` - To Get Current Custom Alive Picture 39 | 40 | **Example:** 41 | 42 | ✘ `setalive`, 43 | ⤷ Send with alive text = `{Config.CMD_PREFIX}setalive This is the alive text` 44 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}setalive` 45 | 46 | ✘ `setalivepic`, 47 | ⤷ Reply to a picture/gif/sticker with `{Config.CMD_PREFIX}setalivepic` (Under 5MB) 48 | """, 49 | f"{mod_name}_category": "userbot" 50 | } 51 | ) 52 | 53 | 54 | # Get python version 55 | python_version = f"{version_info[0]}.{version_info[1]}.{version_info[2]}" 56 | # Conver time in to readable format 57 | def get_readable_time(seconds: int) -> str: 58 | count = 0 59 | ping_time = "" 60 | time_list = [] 61 | time_suffix_list = ["s", "m", "h", "days"] 62 | while count < 4: 63 | count += 1 64 | remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24) 65 | if seconds == 0 and remainder == 0: 66 | break 67 | time_list.append(int(result)) 68 | seconds = int(remainder) 69 | for x in range(len(time_list)): 70 | time_list[x] = str(time_list[x]) + time_suffix_list[x] 71 | if len(time_list) == 4: 72 | ping_time += time_list.pop() + ", " 73 | time_list.reverse() 74 | ping_time += ":".join(time_list) 75 | return ping_time 76 | 77 | # Get current version of Nexa Userbot 78 | async def get_nexaub_version(): 79 | with open("cache/nexaub_data.json", "r") as jsn_f: 80 | ver = json.load(jsn_f) 81 | return ver["version"] 82 | 83 | 84 | # Alive Message 85 | @nexaub.on_cmd(command=["alive"]) 86 | async def pyroalive(_, message: Message): 87 | uptime = get_readable_time((time.time() - StartTime)) 88 | alive_bef_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 89 | # Alive Message 90 | get_alive_msg = await get_custom_alive_msg() 91 | custom_alive_msg = get_alive_msg if get_alive_msg else "Heya, I'm Using Nexa Userbot" 92 | # Alive Pic 93 | g_al_pic = await get_custom_var(var="ALIVE_PIC") 94 | alive_pic = g_al_pic[1] if g_al_pic else "cache/NEXAUB.png" 95 | NEXAUB_VERSION = await get_nexaub_version() 96 | xtra_modules = await get_xtra_modules_names() 97 | alive_msg = f""" 98 | **{custom_alive_msg}** 99 | 100 | 101 | **✨ Nexa UserBot is Alive** 102 | 103 | **》 Nexa Userbot Version:** `{NEXAUB_VERSION}` 104 | **》 Python Version:** `{python_version}` 105 | **》 Pyrogram Version:** `{pyrogram_version}` 106 | **》 Uptime:** `{uptime}` 107 | **》 Loaded Plugins:** `{len(all_mods)}` 108 | **》 Loaded Custom Plugins:** `{len(xtra_modules)}` 109 | 110 | 111 | **Deploy Your Own: @NexaBotsUpdates**""" 112 | await alive_bef_msg.delete() 113 | if g_al_pic and g_al_pic[0] == "gif": 114 | await NEXAUB.send_animation(chat_id=message.chat.id, animation=alive_pic, caption=alive_msg) 115 | else: 116 | await NEXAUB.send_photo(chat_id=message.chat.id, photo=alive_pic, caption=alive_msg) 117 | 118 | # Ping 119 | @nexaub.on_cmd(command=["ping"], group=-1) 120 | async def pingme(_, message: Message): 121 | start = datetime.now() 122 | ping_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 123 | end = datetime.now() 124 | ping_time = (end - start).microseconds / 1000 125 | await ping_msg.edit(f"**Pong:** `{ping_time} ms` \n\n ~ **✨ Nexa-Userbot**", disable_web_page_preview=True) 126 | 127 | # Set custom alive message 128 | @nexaub.on_cmd(command=["setalive"]) 129 | async def set_alive(_, message: Message): 130 | alive_r_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 131 | c_alive_msg = get_arg(message) 132 | r_msg = message.reply_to_message 133 | if not c_alive_msg: 134 | if r_msg: 135 | c_alive_msg = r_msg.text 136 | else: 137 | return await alive_r_msg.edit("`Please reply to a text message!`") 138 | await set_custom_alive_msg(a_text=c_alive_msg) 139 | await alive_r_msg.edit("`Successfully Updated Custom Alive Message!`") 140 | 141 | # Get custom alive message 142 | @nexaub.on_cmd(command=["getalive"]) 143 | async def get_alive(_, message: Message): 144 | g_alive_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 145 | try: 146 | get_al = await get_custom_alive_msg() 147 | saved_alive_msg = get_al if get_al else "No Custom Message is saved!" 148 | await g_alive_msg.edit(f"**Current Alive Message:** \n{saved_alive_msg}") 149 | except Exception as e: 150 | print(e) 151 | 152 | # Set custom alive picture 153 | @nexaub.on_cmd(command=["setalivepic"]) 154 | async def set_alive_pic(_, message: Message): 155 | cust_alive = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 156 | r_msg = message.reply_to_message 157 | if r_msg.photo or r_msg.animation or r_msg.sticker: 158 | # Converts sticker into an image 159 | if r_msg.sticker: 160 | alive_pic = await convert_to_image(message=r_msg, client=NEXAUB) 161 | # Else it'll just download the photo/gif 162 | else: 163 | alive_pic = await r_msg.download() 164 | # Upload that shit to telegraph 165 | alive_url = await upload_to_tgraph(alive_pic) 166 | if r_msg.photo or r_msg.sticker: 167 | await set_custom_var(var="ALIVE_PIC", value=["photo", alive_url]) 168 | else: 169 | await set_custom_var(var="ALIVE_PIC", value=["gif", alive_url]) 170 | await cust_alive.edit(f"`Successfully Saved Custom Alive Picture!` \n\n**Preview:** [Click here]({alive_url})") 171 | else: 172 | await cust_alive.edit("`Reply to a photo, gif or sticker 😑!`") 173 | 174 | # Get custom alive picture 175 | @nexaub.on_cmd(command=["getalivepic"]) 176 | async def get_alive_pic(_, message: Message): 177 | get_pic_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 178 | g_al_pic = await get_custom_var(var="ALIVE_PIC") 179 | if g_al_pic: 180 | picture = g_al_pic[1] 181 | ptype = g_al_pic[0] 182 | await get_pic_msg.delete() 183 | if ptype == "gif": 184 | await NEXAUB.send_animation(chat_id=message.chat.id, animation=picture, caption=f"**Nexa-Userbot's Custom Alive Picture** \n\n**Type:** `{ptype}`") 185 | else: 186 | await NEXAUB.send_photo(chat_id=message.chat.id, photo=picture, caption=f"**Nexa-Userbot's Custom Alive Picture** \n\n**Type:** `{ptype}`") 187 | else: 188 | await get_pic_msg.edit("`Save a custom alive picture first!`") 189 | 190 | 191 | @nexaub.on_cmd(command=["clc"]) 192 | async def egg_clc(_, message: Message): 193 | clc_func = await check_or_set_log_channel() 194 | lc_id = clc_func[1] if clc_func[1] else None 195 | await e_or_r(nexaub_message=message, msg_text=f"**Is Log Channel Set?** `{clc_func[0]}` \n**Channel ID:** `{lc_id}`") 196 | -------------------------------------------------------------------------------- /nexa_userbot/modules/arq.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | from aiohttp import ClientSession 6 | from Python_ARQ import ARQ 7 | from pyrogram.types import Message 8 | 9 | from nexa_userbot import CMD_HELP 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 11 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import get_arq_key 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from config import Config 14 | 15 | 16 | # Help 17 | mod_name = os.path.basename(__file__)[:-3] 18 | 19 | CMD_HELP.update( 20 | { 21 | f"{mod_name}": f""" 22 | **ARQ,** 23 | 24 | ✘ `lyrics` - To Get Lyrics for Given Keyword 25 | ✘ `tr` - To Translate a word / sentence 26 | ✘ `wiki` - To Search Wiki 27 | ✘ `reddit` - To Search Reddit 28 | 29 | **Example:** 30 | 31 | ✘ `lyrics`, 32 | ⤷ Send with keyword = `{Config.CMD_PREFIX}lyrics your_song_name` 33 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}lyrics` 34 | 35 | ✘ `tr`, 36 | ⤷ Send with text = `{Config.CMD_PREFIX}tr hola!en` (Replace en with your dest. lang code) 37 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}tr en` (Replace en with your dest. lang code) 38 | 39 | ✘ `wiki`, 40 | ⤷ Send with keyword = `{Config.CMD_PREFIX}wiki google` 41 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}wiki` 42 | 43 | ✘ `reddit`, 44 | ⤷ Send with keyword = `{Config.CMD_PREFIX}reddit doge` 45 | ⤷ Reply to a text message with `{Config.CMD_PREFIX}reddit` 46 | """, 47 | f"{mod_name}_category": "tools" 48 | } 49 | ) 50 | 51 | 52 | # Do stuff with arq 53 | 54 | # Closing aiohttp session 55 | async def close_session(aiohtp_c): 56 | await aiohtp_c.close() 57 | 58 | async def ARQ_NEXAUB( 59 | keyword, 60 | dest_lang="en", 61 | is_lyrics=False, 62 | is_tr=False, 63 | is_wiki=False, 64 | is_reddit=False): 65 | try: 66 | # ARQ Client 67 | arq_aiohttp = ClientSession() 68 | arq_url = "http://thearq.tech/" 69 | arq_api = await get_arq_key() 70 | if arq_api is None: 71 | return print("ARQ_API_KEY isn't in database. Add it and Try Again!") 72 | arq_nexaub = ARQ(arq_url, arq_api, arq_aiohttp) 73 | # === Now do stuff with arq === # 74 | # lyrics module 75 | if is_lyrics: 76 | lyric = await arq_nexaub.lyrics(query=keyword) 77 | await close_session(arq_aiohttp) 78 | return lyric 79 | # Translator module 80 | if is_tr: 81 | transed = await arq_nexaub.translate(text=keyword, destLangCode=dest_lang) 82 | await close_session(arq_aiohttp) 83 | return transed.result 84 | # Wiki module 85 | if is_wiki: 86 | wiki_s = await arq_nexaub.wiki(query=keyword) 87 | await close_session(arq_aiohttp) 88 | return wiki_s.result 89 | # Reddit Module 90 | if is_reddit: 91 | reddit_s = await arq_nexaub.reddit(query=keyword) 92 | await close_session(arq_aiohttp) 93 | return reddit_s 94 | except Exception as e: 95 | print(e) 96 | 97 | # Lyrics 98 | @nexaub.on_cmd(command=["lyrics"]) 99 | async def arq_lyrics(_, message: Message): 100 | lyrics_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 101 | keyword = get_arg(message) 102 | r_keyword = message.reply_to_message 103 | if not keyword: 104 | if r_keyword: 105 | keyword = r_keyword.text 106 | else: 107 | return await lyrics_msg.edit("`Give a song name to get lyrics!`") 108 | else: 109 | keyword = keyword 110 | f_lyrics = await ARQ_NEXAUB(keyword=keyword, is_lyrics=True) 111 | nyc_lyrics = f_lyrics.result 112 | if len(nyc_lyrics) > 4096: 113 | await lyrics_msg.edit("`Wah!! Long Lyrics tho!, Wait I'm sending it as a file!`") 114 | lyric_file = open("lyrics_NEXAUB.txt", "w+") 115 | lyric_file.write(nyc_lyrics) 116 | lyric_file.close() 117 | await lyrics_msg.reply_document("lyrics_NEXAUB.txt") 118 | os.remove("lyrics_NEXAUB.txt") 119 | await lyrics_msg.delete() 120 | else: 121 | await lyrics_msg.edit(nyc_lyrics) 122 | 123 | # Translator 124 | @nexaub.on_cmd(command=["tr"]) 125 | async def arq_trans(_, message: Message): 126 | trans_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 127 | to_tr_text = get_arg(message) 128 | r_tr_text = message.reply_to_message 129 | if r_tr_text: 130 | trans_this = r_tr_text.text 131 | if not to_tr_text: 132 | dest_l = "en" 133 | else: 134 | dest_l = to_tr_text 135 | else: 136 | try: 137 | string_c = to_tr_text.split("!") 138 | trans_this = string_c[0] 139 | dest_l = string_c[1] 140 | except: 141 | return await trans_msg.edit(f"`Error Occured While Splitting Text! Please Read Examples in Help Page!` \n\n**Help:** `{Config.CMD_PREFIX}help arq`") 142 | translate_txt = await ARQ_NEXAUB(is_tr=True, keyword=trans_this, dest_lang=dest_l) 143 | translated_str = f""" 144 | **Translated,** 145 | 146 | **From:** `{translate_txt.src}` 147 | **To:** `{translate_txt.dest}` 148 | **Translation:** 149 | `{translate_txt.translatedText}` 150 | """ 151 | if len(translated_str) > 4096: 152 | await trans_msg.edit("`Wah!! Translated Text So Long Tho!, Give me a minute, I'm sending it as a file!`") 153 | tr_txt_file = open("translated_NEXAUB.txt", "w+") 154 | tr_txt_file.write(translated_str) 155 | tr_txt_file.close() 156 | await trans_msg.reply_document("translated_NEXAUB.txt") 157 | os.remove("translated_NEXAUB.txt") 158 | await trans_msg.delete() 159 | else: 160 | await trans_msg.edit(translated_str) 161 | 162 | # Wiki search 163 | @nexaub.on_cmd(command=["wiki"]) 164 | async def arq_wiki(_, message: Message): 165 | wiki_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 166 | wiki_key = get_arg(message) 167 | r_wiki_key = message.reply_to_message 168 | if not wiki_key: 169 | if r_wiki_key: 170 | wiki_this = r_wiki_key.text 171 | else: 172 | return await wiki_msg.edit("`Give something to search!`") 173 | else: 174 | wiki_this = wiki_key 175 | s_wiki = await ARQ_NEXAUB(is_wiki=True, keyword=wiki_this) 176 | wiki_txt = f""" 177 | **Title:** `{s_wiki.title}` 178 | **Answer:** 179 | `{s_wiki.answer}` 180 | """ 181 | if len(wiki_txt) > 4096: 182 | await wiki_msg.edit("`Big stuff to read!! Lemme send it as a text file :)`") 183 | wiki_txt_file = open("wiki_NEXAUB.txt", "w+") 184 | wiki_txt_file.write(wiki_txt) 185 | wiki_txt_file.close() 186 | await wiki_msg.reply_document("wiki_NEXAUB.txt") 187 | os.remove("wiki_NEXAUB.txt") 188 | await wiki_msg.delete() 189 | else: 190 | await wiki_msg.edit(wiki_txt) 191 | 192 | # Reddit 193 | @nexaub.on_cmd(command=["reddit"]) 194 | async def arq_reddit(_, message: Message): 195 | red_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 196 | reddit_key = get_arg(message) 197 | r_reddit_msg = message.reply_to_message 198 | if not reddit_key: 199 | if r_reddit_msg: 200 | reddit_this = r_reddit_msg.text 201 | else: 202 | return await red_msg.edit("`Give some text to quote!`") 203 | else: 204 | reddit_this = reddit_key 205 | reddit_now = await ARQ_NEXAUB(is_reddit=True, keyword=reddit_this) 206 | try: 207 | _reddit = reddit_now.result 208 | r_post = _reddit.postLink 209 | r_subreddit = _reddit.subreddit 210 | r_title = _reddit.title 211 | r_image = _reddit.url 212 | r_user = _reddit.author 213 | r_txt = f""" 214 | **Title:** `{r_title}` 215 | **Subreddit:** `{r_subreddit}` 216 | **Author:** `{r_user}` 217 | **Post Link:** `{r_post}` 218 | """ 219 | await red_msg.reply_photo(photo=r_image, caption=r_txt) 220 | await red_msg.delete() 221 | except Exception as e: 222 | await red_msg.edit("`Ooops!, Something went wrong; Check your keyword!`") 223 | -------------------------------------------------------------------------------- /nexa_userbot/modules/groups.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | import asyncio 5 | 6 | from . import nexaub_devs 7 | from pyrogram.types import Message 8 | from pyrogram.errors import FloodWait 9 | 10 | from nexa_userbot import NEXAUB, CMD_HELP 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from nexa_userbot.core.errors import Errors 14 | from config import Config 15 | 16 | 17 | # Help 18 | mod_name = os.path.basename(__file__)[:-3] 19 | 20 | CMD_HELP.update( 21 | { 22 | f"{mod_name}": f""" 23 | **Group Tools,** 24 | 25 | ✘ `purge` - To purge messages in a chat 26 | ✘ `ban` - To ban a member in a chat 27 | ✘ `kick` - To kick a member in a chat 28 | ✘ `unban` - To unban a member in a chat 29 | ✘ `pin` - To pin a message in a chat 30 | ✘ `unpin` - To unpin a message or messages in a chat 31 | ✘ `delall` - To delete all messages in a chat 32 | 33 | **Example:** 34 | 35 | ✘ `purge`, 36 | ⤷ reply to a message = `{Config.CMD_PREFIX}purge` 37 | 38 | ✘ `ban`, 39 | ⤷ reply to a message (ban) = `{Config.CMD_PREFIX}ban` 40 | ⤷ send with user id (ban) = `{Config.CMD_PREFIX}ban 1234567` 41 | 42 | ✘ `unban`, 43 | ⤷ Same logic and arguments as the ban 44 | 45 | ✘ `kick`, 46 | ⤷ Same logic and arguments as the ban 47 | 48 | **Tip 💡,** 49 | ⤷ You can also pass a custom kick time in sec. - `{Config.CMD_PREFIX}kick 1234567 4` 50 | 51 | ✘ `pin`, 52 | ⤷ reply to a message = `{Config.CMD_PREFIX}pin` 53 | ⤷ pin with no notification = `{Config.CMD_PREFIX}pin -dn` 54 | 55 | ✘ `unpin`, 56 | ⤷ reply to a message = `{Config.CMD_PREFIX}unpin` 57 | ⤷ unpin all messages = `{Config.CMD_PREFIX}unpin -all` 58 | """, 59 | f"{mod_name}_category": "utils" 60 | } 61 | ) 62 | 63 | 64 | # Purges 65 | @nexaub.on_cmd(command=["purge"], admins_only=True) 66 | async def purge_this(_, message: Message): 67 | p_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 68 | if not message.reply_to_message: 69 | return await p_msg.edit("`Reply to a message to starting purge from!`") 70 | await p_msg.delete() 71 | mid_list = [] 72 | for mid in range(message.reply_to_message.id, message.id): 73 | mid_list.append(mid) 74 | # If there are more than 100 messages ub'll start deleting 75 | if len(mid_list) == 100: 76 | await NEXAUB.delete_messages(chat_id=message.chat.id, message_ids=mid_list, revoke=True) # Docs says revoke Defaults to True but... 77 | mid_list = [] 78 | # Let's check if there are any other messages left to delete. Just like that 0.1% bacteria that can't be destroyed by soap 79 | if len(mid_list) > 0: 80 | await NEXAUB.delete_messages(chat_id=message.chat.id, message_ids=mid_list, revoke=True) 81 | 82 | 83 | # Bans 84 | @nexaub.on_cmd(command=["ban"], admins_only=True, only_groups=True) 85 | async def ban_usr(_, message: Message): 86 | ban_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 87 | r_msg = message.reply_to_message 88 | is_me = await NEXAUB.get_me() 89 | args = get_arg(message) 90 | # Getting user id 91 | if args: 92 | if args.isnumeric(): 93 | b_user_id = args 94 | else: 95 | b_user_id = args.replace("@", "") 96 | elif r_msg: 97 | if r_msg.from_user: 98 | b_user_id = r_msg.from_user.id 99 | else: 100 | return await ban_msg.edit("`Reply to a message from a user to ban!`") 101 | else: 102 | return await ban_msg.edit("`Give a user id / username or eply to a message from a user to ban!`") 103 | # User id checks 104 | if b_user_id in nexaub_devs: 105 | return await ban_msg.edit("`Lmao! Tryna ban my devs? Using me? 😂`") 106 | if b_user_id == is_me.id: 107 | return await ban_msg.edit("`Why should I ban my self?`") 108 | await message.chat.ban_member(user_id=int(b_user_id)) 109 | await ban_msg.edit(f"**Banned 👊** \n\n**User ID:** `{b_user_id}`") 110 | 111 | 112 | # Kick 113 | @nexaub.on_cmd(command=["kick"], admins_only=True, only_groups=True) 114 | async def kick_usr(_, message: Message): 115 | kick_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 116 | r_msg = message.reply_to_message 117 | is_me = await NEXAUB.get_me() 118 | args = get_arg(message) 119 | default_ban_time = 5 120 | # Getting user id 121 | if args: 122 | spl_args = args.split(" ") 123 | if len(spl_args) == 2: 124 | b_user_id = spl_args[0].replace("@", "") 125 | if spl_args[1].isnumeric(): 126 | default_ban_time = spl_args[1] 127 | elif len(spl_args) == 1: 128 | b_user_id = args.replace("@", "") 129 | else: 130 | return await kick_msg.edit("`Reply to a message from a user or give a user id to kick!`") 131 | elif r_msg: 132 | if r_msg.from_user: 133 | b_user_id = r_msg.from_user.id 134 | else: 135 | return await kick_msg.edit("`Reply to a message from a user to kick!`") 136 | if args and args.isnumeric(): 137 | default_ban_time = args 138 | else: 139 | return await kick_msg.edit("`Give a user id / username or eply to a message from a user to kick!`") 140 | # User id checks 141 | if b_user_id in nexaub_devs: 142 | return await kick_msg.edit("`Lmao! Tryna kick my devs? Using me? 😂`") 143 | if b_user_id == is_me.id: 144 | return await kick_msg.edit("`Why should I kick my self?`") 145 | # Kicking the user 146 | await message.chat.ban_member(user_id=int(b_user_id)) 147 | await kick_msg.edit(f"**Kicked ✊** \n\n**User ID:** `{b_user_id}` \n\n`⚠️ Unbanning after {default_ban_time} secs! ⚠️`") 148 | await asyncio.sleep(int(default_ban_time)) 149 | await message.chat.unban_member(user_id=int(b_user_id)) 150 | 151 | 152 | # Unbans 153 | @nexaub.on_cmd(command=["unban"], admins_only=True, only_groups=True) 154 | async def unban_usr(_, message: Message): 155 | u_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 156 | r_msg = message.reply_to_message 157 | u_arg = get_arg(message) 158 | if r_msg: 159 | u_usr_id = r_msg.from_user.id 160 | elif u_arg: 161 | u_usr_id = u_arg 162 | else: 163 | return await u_msg.edit("`Give a user id to unban!`") 164 | await message.chat.unban_member(user_id=int(u_usr_id)) 165 | await u_msg.edit(f"**Unbanned 🤝** \n\n**User ID:** `{u_usr_id}`") 166 | 167 | 168 | # Pin message 169 | @nexaub.on_cmd(command=["pin"], admins_only=True, only_groups=True) 170 | async def pin_msg(_, message: Message): 171 | pin_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 172 | r_msg = message.reply_to_message 173 | args = get_arg(message) 174 | if not r_msg: 175 | return await pin_msg.edit("`Reply to a message to pin it!`") 176 | if args and (args == "-dn"): 177 | await r_msg.pin(disable_notification=True) 178 | else: 179 | await r_msg.pin() 180 | await pin_msg.edit(f"[Message]({r_msg.link}) `Pinned successfully!`", disable_web_page_preview=True) 181 | 182 | 183 | # Unpin message 184 | @nexaub.on_cmd(command=["unpin"], admins_only=True, only_groups=True) 185 | async def unpin_msg(_, message: Message): 186 | unpin_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 187 | r_msg = message.reply_to_message 188 | args = get_arg(message) 189 | if args and (args == "-all"): 190 | chat_id = message.chat.id 191 | await NEXAUB.unpin_all_chat_messages(chat_id) 192 | await unpin_msg.edit("`Successfully unpinned all pinned messages in this chat!`") 193 | else: 194 | if not r_msg: 195 | return await unpin_msg.edit("`Reply to a pinned message to unpin it!`") 196 | await r_msg.unpin() 197 | await unpin_msg.edit(f"[Message]({r_msg.link}) `Unpinned successfully!`", disable_web_page_preview=True) 198 | 199 | 200 | # Delete all messages in a chat 201 | async def do_del_all(chat_id, message_ids): 202 | return await NEXAUB.delete_messages(chat_id, message_ids, True) 203 | 204 | async def collect_and_del(chat_id): 205 | msg_id_list = [] 206 | async for msg in NEXAUB.iter_history(chat_id): 207 | msg_id_list.append(msg.id) 208 | if len(msg_id_list) >= 100: 209 | await do_del_all(chat_id, msg_id_list) 210 | msg_id_list = [] 211 | await do_del_all(chat_id, msg_id_list) 212 | 213 | @nexaub.on_cmd(command=["delall"], admins_only=True) 214 | async def delete_all_msgs(_, message: Message): 215 | await e_or_r(nexaub_message=message, msg_text="`Processing...`") 216 | await collect_and_del(message.chat.id) 217 | try: 218 | await collect_and_del(message.chat.id) 219 | except: 220 | pass -------------------------------------------------------------------------------- /nexa_userbot/modules/updater.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Nexa Userbot | Zect Userbot 4 | 5 | import os 6 | import sys 7 | import asyncio 8 | import requests 9 | import heroku3 10 | 11 | from os import environ, execle, path, remove 12 | from git import Repo 13 | from git.exc import GitCommandError, InvalidGitRepositoryError 14 | 15 | from nexa_userbot import NEXAUB, CMD_HELP 16 | from config import Config 17 | from nexa_userbot.helpers.pyrogram_help import get_arg, rm_markdown 18 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 19 | 20 | 21 | # Help 22 | mod_name = os.path.basename(__file__)[:-3] 23 | 24 | CMD_HELP.update( 25 | { 26 | f"{mod_name}": """ 27 | **Updater** 28 | 29 | ✘ `update` - To Updater Your Userbot 30 | ✘ `restart` - To Restart Your Userbot 31 | ✘ `logs` - To Get Logs of Your Userbot (Heroku Only) 32 | """, 33 | f"{mod_name}_category": "userbot" 34 | } 35 | ) 36 | 37 | 38 | UPSTREAM_REPO_URL = "https://github.com/Itz-fork/Nexa-Userbot" 39 | requirements_path = path.join( 40 | path.dirname(path.dirname(path.dirname(__file__))), "requirements.txt" 41 | ) 42 | 43 | 44 | async def gen_chlog(repo, diff): 45 | ch_log = "" 46 | d_form = "On %d/%m/%y at %H:%M:%S" 47 | for c in repo.iter_commits(f"HEAD..upstream/{diff}", max_count=10): 48 | ch_log += f"**#{c.count()}** : {c.committed_datetime.strftime(d_form)} : [{c.summary}]({UPSTREAM_REPO_URL.rstrip('/')}/commit/{c}) by `{c.author}`\n" 49 | return ch_log 50 | 51 | 52 | async def updateme_requirements(): 53 | reqs = str(requirements_path) 54 | try: 55 | process = await asyncio.create_subprocess_shell( 56 | " ".join([sys.executable, "-m", "pip", "install", "-r", reqs]), 57 | stdout=asyncio.subprocess.PIPE, 58 | stderr=asyncio.subprocess.PIPE, 59 | ) 60 | await process.communicate() 61 | return process.returncode 62 | except Exception as e: 63 | return repr(e) 64 | 65 | 66 | @nexaub.on_cmd(command=["update"]) 67 | async def upstream(client, message): 68 | status = await e_or_r(nexaub_message=message, msg_text=f"`Checking For Updates from` [Nexa-Userbot]({UPSTREAM_REPO_URL}) `Repo...`") 69 | conf = get_arg(message) 70 | off_repo = UPSTREAM_REPO_URL 71 | txt = "`Oops! Updater Can't Continue...`" 72 | txt += "\n\n**LOGTRACE:**\n" 73 | try: 74 | repo = Repo(search_parent_directories=True) 75 | except InvalidGitRepositoryError as error: 76 | if conf != "now": 77 | pass 78 | repo = Repo.init() 79 | origin = repo.create_remote("upstream", off_repo) 80 | origin.fetch() 81 | repo.create_head("master", origin.refs.master) 82 | repo.heads.master.set_tracking_branch(origin.refs.master) 83 | repo.heads.master.checkout(True) 84 | ac_br = repo.active_branch.name 85 | if ac_br != "master": 86 | await status.edit(f""" 87 | `❌ Can't update your Nexa-Userbot becuase you're using a custom branch. ❌` 88 | 89 | **Default Branch:** `master` 90 | **You are on:** `{ac_br}` 91 | 92 | `Please change to master branch.`""" 93 | ) 94 | return repo.__del__() 95 | try: 96 | repo.create_remote("upstream", off_repo) 97 | except BaseException: 98 | pass 99 | ups_rem = repo.remote("upstream") 100 | ups_rem.fetch(ac_br) 101 | if "now" not in conf: 102 | changelog = await gen_chlog(repo, diff=ac_br) 103 | if changelog: 104 | req_ver = requests.get("https://raw.githubusercontent.com/Itz-fork/Nexa-Userbot/master/cache/nexaub_data.json") 105 | changelog_str = f""" 106 | **🌠 New Updates are available for Nexa Userbot 🌠** 107 | 108 | **🏠 Branch:** [{ac_br}]({UPSTREAM_REPO_URL}/tree/{ac_br}) 109 | **🕊 New version:** `{req_ver.json()["version"]}` 110 | **☘️ Changelog (last >10):** \n\n{changelog}""" 111 | if len(changelog_str) > 4096: 112 | clean_changelog_str = await rm_markdown(changelog_str) 113 | await status.edit("`Changelog is too big, sending it as a file!`") 114 | file = open("NEXAUB_git_commit_log.txt", "w+") 115 | file.write(clean_changelog_str) 116 | file.close() 117 | await NEXAUB.send_document( 118 | message.chat.id, 119 | "NEXAUB_git_commit_log.txt", 120 | caption=f"Do `{Config.CMD_PREFIX}update now` to update your Nexa-Userbot", 121 | reply_to_message_id=status.id, 122 | ) 123 | remove("NEXAUB_git_commit_log.txt") 124 | else: 125 | return await status.edit( 126 | f"{changelog_str}\n\nDo `.update now` to update your Nexa-Userbot", 127 | disable_web_page_preview=True, 128 | ) 129 | else: 130 | await status.edit( 131 | f"**✨ Nexa-Userbot is Up-to-date** \n\n**Branch:** [{ac_br}]({UPSTREAM_REPO_URL}/tree/{ac_br})\n", 132 | disable_web_page_preview=True, 133 | ) 134 | repo.__del__() 135 | return 136 | if Config.HEROKU_API_KEY is not None: 137 | heroku = heroku3.from_key(Config.HEROKU_API_KEY) 138 | heroku_app = None 139 | heroku_applications = heroku.apps() 140 | if not Config.HEROKU_APP_NAME: 141 | await status.edit("**Error:** `Please add HEROKU_APP_NAME variable to continue update!`") 142 | return repo.__del__() 143 | for app in heroku_applications: 144 | if app.name == Config.HEROKU_APP_NAME: 145 | heroku_app = app 146 | break 147 | if heroku_app is None: 148 | await status.edit(f"{txt}\n`Invalid Heroku credentials.`") 149 | return repo.__del__() 150 | await status.edit( 151 | "`Userbot Dyno Build is in Progress! Please wait...`" 152 | ) 153 | ups_rem.fetch(ac_br) 154 | repo.git.reset("--hard", "FETCH_HEAD") 155 | heroku_git_url = heroku_app.git_url.replace( 156 | "https://", "https://api:" + Config.HEROKU_API_KEY + "@" 157 | ) 158 | if "heroku" in repo.remotes: 159 | remote = repo.remote("heroku") 160 | remote.set_url(heroku_git_url) 161 | else: 162 | remote = repo.create_remote("heroku", heroku_git_url) 163 | try: 164 | remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) 165 | except GitCommandError: 166 | pass 167 | await status.edit("`🎉 Successfully Updated!` \n**Restarting Now...**") 168 | else: 169 | try: 170 | ups_rem.pull(ac_br) 171 | except GitCommandError: 172 | repo.git.reset("--hard", "FETCH_HEAD") 173 | await updateme_requirements() 174 | await status.edit("`🎉 Successfully Updated!` \n**Restarting Now...**",) 175 | args = [sys.executable, "-m" "nexa_userbot"] 176 | execle(sys.executable, *args, environ) 177 | return 178 | 179 | # Userbot restart module 180 | async def restart_nexaub(): 181 | if Config.HEROKU_API_KEY is not None: 182 | heroku_conn = heroku3.from_key(Config.HEROKU_API_KEY) 183 | server = heroku_conn.app(Config.HEROKU_APP_NAME) 184 | server.restart() 185 | else: 186 | args = [sys.executable, "-m" "nexa_userbot"] 187 | execle(sys.executable, *args, environ) 188 | exit() 189 | 190 | @nexaub.on_cmd(command=["restart"]) 191 | async def restart(client, message): 192 | restart_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 193 | await restart_msg.edit("`Nexa-Userbot is restarting! Please wait...`") 194 | try: 195 | await restart_nexaub() 196 | except Exception as e: 197 | await restart_msg.edit(f"**Error:** `{e}`") 198 | 199 | 200 | @nexaub.on_cmd(command=["logs"]) 201 | async def log(client, message): 202 | try: 203 | st_msg = await e_or_r(nexaub_message=message, msg_text="`Getting Logs...`") 204 | heroku_conn = heroku3.from_key(Config.HEROKU_API_KEY) 205 | server = heroku_conn.get_app_log(Config.HEROKU_APP_NAME, dyno='worker', lines=100, source='app', timeout=100) 206 | f_logs = server 207 | if len(f_logs) > 4096: 208 | file = open("logs.txt", "w+") 209 | file.write(f_logs) 210 | file.close() 211 | await st_msg.delete() 212 | await NEXAUB.send_document(message.chat.id, "logs.txt", caption=f"Logs of `{Config.HEROKU_APP_NAME}`") 213 | remove("logs.txt") 214 | except Exception as e: 215 | await message.edit(f"**Error:** `{e}`") -------------------------------------------------------------------------------- /nexa_userbot/helpers/pyrogram_help.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Developers Userbot & Friday Userbot 4 | 5 | import os 6 | import re 7 | import math 8 | import shlex 9 | import asyncio 10 | import subprocess 11 | 12 | from time import time 13 | from PIL import Image 14 | from pyrogram import enums 15 | from typing import Union, Tuple 16 | from aiohttp import ClientSession 17 | from aiofiles import open as open_image 18 | from nexa_userbot import NEXAUB 19 | 20 | 21 | # Credits: SpEcHiDe's AnyDL-Bot for Progress bar + Time formatter 22 | async def progress_for_pyrogram(current, total, ud_type, message, start): 23 | now = time() 24 | diff = now - start 25 | if round(diff % 10.00) == 0 or current == total: 26 | percentage = current * 100 / total 27 | speed = current / diff 28 | elapsed_time = round(diff) * 1000 29 | time_to_completion = round((total - current) / speed) * 1000 30 | estimated_total_time = elapsed_time + time_to_completion 31 | 32 | elapsed_time = TimeFormatter(milliseconds=elapsed_time) 33 | estimated_total_time = TimeFormatter(milliseconds=estimated_total_time) 34 | 35 | progress = "[{0}{1}] \n**📊 Process**: {2}%\n".format( 36 | ''.join(["█" for i in range(math.floor(percentage / 5))]), 37 | ''.join(["░" for i in range(20 - math.floor(percentage / 5))]), 38 | round(percentage, 2)) 39 | 40 | tmp = progress + "{0} of {1}\n**🏃 Speed:** {2}/s\n**⏳ ETA:** {3}\n".format( 41 | humanbytes(current), 42 | humanbytes(total), 43 | humanbytes(speed), 44 | estimated_total_time if estimated_total_time != '' else "0 s" 45 | ) 46 | try: 47 | await message.edit(text="{}\n {}".format(ud_type, tmp)) 48 | except: 49 | pass 50 | 51 | 52 | def humanbytes(size): 53 | if not size: 54 | return "" 55 | power = 2**10 56 | n = 0 57 | Dic_powerN = {0: ' ', 1: 'Ki', 2: 'Mi', 3: 'Gi', 4: 'Ti'} 58 | while size > power: 59 | size /= power 60 | n += 1 61 | return str(round(size, 2)) + " " + Dic_powerN[n] + 'B' 62 | 63 | 64 | def TimeFormatter(milliseconds: int) -> str: 65 | seconds, milliseconds = divmod(int(milliseconds), 1000) 66 | minutes, seconds = divmod(seconds, 60) 67 | hours, minutes = divmod(minutes, 60) 68 | days, hours = divmod(hours, 24) 69 | tmp = ((str(days) + "d, ") if days else "") + \ 70 | ((str(hours) + "h, ") if hours else "") + \ 71 | ((str(minutes) + "m, ") if minutes else "") + \ 72 | ((str(seconds) + "s, ") if seconds else "") + \ 73 | ((str(milliseconds) + "ms, ") if milliseconds else "") 74 | return tmp[:-2] 75 | 76 | 77 | async def run_cmd(cmd: str) -> Tuple[str, str, int, int]: 78 | """Run Commands""" 79 | args = shlex.split(cmd) 80 | process = await asyncio.create_subprocess_exec( 81 | *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE 82 | ) 83 | stdout, stderr = await process.communicate() 84 | return ( 85 | stdout.decode("utf-8", "replace").strip(), 86 | stderr.decode("utf-8", "replace").strip(), 87 | process.returncode, 88 | process.pid, 89 | ) 90 | 91 | # Just for my codes 92 | 93 | 94 | async def run_shell_cmds(command): 95 | run = subprocess.Popen(command, stdout=subprocess.PIPE, 96 | stderr=subprocess.PIPE, shell=True) 97 | shell_ouput = run.stdout.read()[:-1].decode("utf-8") 98 | return shell_ouput 99 | 100 | 101 | def get_arg(message): 102 | msg = message.text 103 | msg = msg.replace(" ", "", 1) if msg[1] == " " else msg 104 | split = msg[1:].replace("\n", " \n").split(" ") 105 | if " ".join(split[1:]).strip() == "": 106 | return "" 107 | return " ".join(split[1:]) 108 | 109 | 110 | def get_args(message): 111 | try: 112 | message = message.text 113 | except AttributeError: 114 | pass 115 | if not message: 116 | return False 117 | message = message.split(maxsplit=1) 118 | if len(message) <= 1: 119 | return [] 120 | message = message[1] 121 | try: 122 | split = shlex.split(message) 123 | except ValueError: 124 | return message # Cannot split, let's assume that it's just one long message 125 | return list(filter(lambda x: len(x) > 0, split)) 126 | 127 | 128 | # Convert to Image 129 | async def convert_to_image(message, client) -> Union[None, str]: 130 | """ 131 | Convert Most Media Formats To Raw Image 132 | """ 133 | if not message: 134 | return None 135 | if not message.reply_to_message: 136 | return None 137 | final_path = None 138 | if not ( 139 | message.reply_to_message.video 140 | or message.reply_to_message.photo 141 | or message.reply_to_message.sticker 142 | or message.reply_to_message.media 143 | or message.reply_to_message.animation 144 | or message.reply_to_message.audio 145 | ): 146 | return None 147 | if message.reply_to_message.photo: 148 | final_path = await message.reply_to_message.download() 149 | elif message.reply_to_message.sticker: 150 | if message.reply_to_message.sticker.mime_type == "image/webp": 151 | final_path = "webp_to_png_s_proton.png" 152 | path_s = await message.reply_to_message.download() 153 | im = Image.open(path_s) 154 | im.save(final_path, "PNG") 155 | else: 156 | path_s = await client.download_media(message.reply_to_message) 157 | final_path = "lottie_proton.png" 158 | cmd = ( 159 | f"lottie_convert.py --frame 0 -if lottie -of png {path_s} {final_path}" 160 | ) 161 | await run_cmd(cmd) 162 | elif message.reply_to_message.audio: 163 | thumb = message.reply_to_message.audio.thumbs[0].file_id 164 | final_path = await client.download_media(thumb) 165 | elif message.reply_to_message.video or message.reply_to_message.animation: 166 | final_path = "fetched_thumb.png" 167 | vid_path = await client.download_media(message.reply_to_message) 168 | await run_cmd(f"ffmpeg -i {vid_path} -filter:v scale=500:500 -an {final_path}") 169 | return final_path 170 | 171 | 172 | # Get Your Chats 173 | async def get_ma_chats(chat_types: list = [enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL], is_id_only=True): 174 | nexaub_chats = [] 175 | async for dialog in NEXAUB.iter_dialogs(): 176 | if dialog.chat.type in chat_types: 177 | if is_id_only: 178 | nexaub_chats.append(dialog.chat.id) 179 | else: 180 | nexaub_chats.append(dialog.chat) 181 | else: 182 | continue 183 | return nexaub_chats 184 | 185 | 186 | async def extract_url_from_txt(url): 187 | "Extracts url from given string" 188 | urls = re.findall(r'\b((?:https?://)?(?:(?:www\.)?(?:[\da-z\.-]+)\.(?:[a-z]{2,6})|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])))(?::[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])?(?:/[\w\.-]*)*/?)\b', str(url)) 189 | return urls 190 | 191 | 192 | async def rm_markdown(text: str): 193 | "Remove basic markdown syntax from a string" 194 | rmed = re.sub("[*`_]", "", text) 195 | return rmed 196 | 197 | 198 | # Function to download images in a list 199 | async def download_images(images: list): 200 | download_images = [] 201 | async with ClientSession() as image_dl: 202 | # Making dirs 203 | base_dir = "cache/NEXAUB_Image_Downloader" 204 | os.makedirs(base_dir) 205 | for image in images: 206 | req = await image_dl.get(image) 207 | if req.status == 200: 208 | file_name = f"{base_dir}/{os.path.basename(image)}" 209 | file = await open_image(file_name, mode="wb") 210 | await file.write(await req.read()) 211 | await file.close() 212 | download_images.append(file_name) 213 | else: 214 | continue 215 | return download_images -------------------------------------------------------------------------------- /nexa_userbot/modules/antifuncs.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from re import search 7 | from pyrogram.types import Message 8 | from pyrogram import filters, enums 9 | 10 | from nexa_userbot import NEXAUB, CMD_HELP 11 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from nexa_userbot.core.nexaub_database.nexaub_db_anti_functions import set_anti_func , get_anti_func, del_anti_func 14 | from nexa_userbot.helpers.regexes import REGEXES 15 | from config import Config 16 | 17 | 18 | # Help 19 | mod_name = os.path.basename(__file__)[:-3] 20 | 21 | CMD_HELP.update( 22 | { 23 | f"{mod_name}": f""" 24 | **Anti-Functions,** 25 | 26 | ✘ `antiarab` - To enable anti-arab function 27 | ✘ `antichinese` - To enable anti-chinese function 28 | ✘ `antijapanese` - To enable anti-japanese function 29 | ✘ `antirussian` - To enable anti-russian function 30 | 31 | **Example:** 32 | 33 | ✘ For all commands, 34 | ⤷ To on = `{Config.CMD_PREFIX}COMMAND_HERE on` 35 | ⤷ To off = `{Config.CMD_PREFIX}COMMAND_HERE off` 36 | 37 | 38 | **Ex:** 39 | ⤷ To on = `{Config.CMD_PREFIX}antiarab on` 40 | ⤷ To off = `{Config.CMD_PREFIX}antiarab off` 41 | """, 42 | f"{mod_name}_category": "tools" 43 | } 44 | ) 45 | 46 | 47 | # Enable anti-arab 48 | @nexaub.on_cmd(command=["antiarab"], admins_only=True, only_groups=True) 49 | async def on_off_antiarab(_, message: Message): 50 | antiarab_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 51 | args = get_arg(message) 52 | if not args: 53 | return await antiarab_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antiarab on` \n ⤷ To off = `{Config.CMD_PREFIX}antiarab off`") 54 | lower_args = args.lower() 55 | if lower_args == "on": 56 | await set_anti_func(message.chat.id, "on", "ar") 57 | elif lower_args == "off": 58 | await del_anti_func(message.chat.id) 59 | else: 60 | return await antiarab_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antiarab on` \n ⤷ To off = `{Config.CMD_PREFIX}antiarab off`") 61 | await antiarab_msg.edit(f"**Successfully** `{'Enabled' if lower_args=='on' else 'Disabled'}` **Anti Arabic module!**") 62 | 63 | # Enable anti-chinesee 64 | @nexaub.on_cmd(command=["antichinese"], admins_only=True, only_groups=True) 65 | async def on_off_antichinese(_, message: Message): 66 | antichinese_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 67 | args = get_arg(message) 68 | if not args: 69 | return await antichinese_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antichinese on` \n ⤷ To off = `{Config.CMD_PREFIX}antichinese off`") 70 | lower_args = args.lower() 71 | if lower_args == "on": 72 | await set_anti_func(message.chat.id, "on", "zh") 73 | elif lower_args == "off": 74 | await del_anti_func(message.chat.id) 75 | else: 76 | return await antichinese_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antichinese on` \n ⤷ To off = `{Config.CMD_PREFIX}antichinese off`") 77 | await antichinese_msg.edit(f"**Successfully** `{'Enabled' if lower_args=='on' else 'Disabled'}` **Anti Chinese module!**") 78 | 79 | # Enable anti-japanese 80 | @nexaub.on_cmd(command=["antijapanese"], admins_only=True, only_groups=True) 81 | async def on_off_antijapanese(_, message: Message): 82 | antijapanese_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 83 | args = get_arg(message) 84 | if not args: 85 | return await antijapanese_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antijapanese on` \n ⤷ To off = `{Config.CMD_PREFIX}antijapanese off`") 86 | lower_args = args.lower() 87 | if lower_args == "on": 88 | await set_anti_func(message.chat.id, "on", "jp") 89 | elif lower_args == "off": 90 | await del_anti_func(message.chat.id) 91 | else: 92 | return await antijapanese_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antijapanese on` \n ⤷ To off = `{Config.CMD_PREFIX}antijapanese off`") 93 | await antijapanese_msg.edit(f"**Successfully** `{'Enabled' if lower_args=='on' else 'Disabled'}` **Anti Japanese module!**") 94 | 95 | # Enable anti-russian 96 | @nexaub.on_cmd(command=["antirussian"], admins_only=True, only_groups=True) 97 | async def on_off_antirussian(_, message: Message): 98 | antirussian_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 99 | args = get_arg(message) 100 | if not args: 101 | return await antirussian_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antirussian on` \n ⤷ To off = `{Config.CMD_PREFIX}antirussian off`") 102 | lower_args = args.lower() 103 | if lower_args == "on": 104 | await set_anti_func(message.chat.id, "on", "rs") 105 | elif lower_args == "off": 106 | await del_anti_func(message.chat.id) 107 | else: 108 | return await antirussian_msg.edit(f"**Invalid Usage!** \n\n **⤷ To on = `{Config.CMD_PREFIX}antirussian on` \n ⤷ To off = `{Config.CMD_PREFIX}antirussian off`") 109 | await antirussian_msg.edit(f"**Successfully** `{'Enabled' if lower_args=='on' else 'Disabled'}` **Anti Russian module!**") 110 | 111 | 112 | # Listen to new members and checks 113 | ANTIF_WARNS_DB = {} 114 | ANTIF_TO_DEL = {} 115 | 116 | WARN_EVEN_TXT = """ 117 | **Warn Event❕** 118 | 119 | **User:** {} 120 | **Due to:** `Containing {} letters in the name / message` 121 | 122 | `Be careful ⚠️: You have {}/3 warns, after that you'll be banned forever!` 123 | """ 124 | BAN_EVENT_TXT = """ 125 | **Ban Event❗** 126 | 127 | **User:** {} 128 | **Due to:** `Containing {} letters in the name / message and warns exceeded!` 129 | """ 130 | 131 | FORM_AND_REGEXES = { 132 | "ar": [REGEXES.arab, "arabic"], 133 | "zh": [REGEXES.chinese, "chinese"], 134 | "jp": [REGEXES.japanese, "japanese"], 135 | "rs": [REGEXES.cyrillic, "russian"] 136 | } 137 | 138 | async def anti_func_handler(_, __, msg): 139 | chats = await get_anti_func(msg.chat.id) 140 | if chats: 141 | return True 142 | else: 143 | False 144 | 145 | # Function to check if the user is an admin 146 | async def check_admin(msg, user_id): 147 | if msg.chat.type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL]: 148 | how_usr = await msg.chat.get_member(user_id) 149 | if how_usr.status in [enums.ChatMemberStatus.OWNER, enums.ChatMemberStatus.ADMINISTRATOR]: 150 | return True 151 | else: 152 | return False 153 | else: 154 | return True 155 | 156 | # Function to save user's warns in a dict 157 | async def check_afdb(user_id): 158 | if user_id in ANTIF_WARNS_DB: 159 | ANTIF_WARNS_DB[user_id] += 1 160 | if ANTIF_WARNS_DB[user_id] >= 3: 161 | return True 162 | return False 163 | else: 164 | ANTIF_WARNS_DB[user_id] = 1 165 | return False 166 | 167 | # Function to warn or ban users 168 | async def warn_or_ban(message, mode): 169 | # Users list 170 | users = message.new_chat_members 171 | chat_id = message.chat.id 172 | # Obtaining user who sent the message 173 | tuser = message.from_user 174 | try: 175 | mdnrgx = FORM_AND_REGEXES[mode] 176 | if users: 177 | for user in users: 178 | if any(search(mdnrgx[0], name) for name in [user.first_name, user.last_name]): 179 | await NEXAUB.ban_chat_member(chat_id, user.id) 180 | await message.reply(BAN_EVENT_TXT.format(user.mention, mdnrgx[1])) 181 | elif message.text: 182 | if not tuser: 183 | return 184 | if search(mdnrgx[0], message.text): 185 | # Admins have the foking power 186 | if not await check_admin(message, tuser.id): 187 | # Ban the user if the warns are exceeded 188 | if await check_afdb(tuser.id): 189 | await NEXAUB.ban_chat_member(chat_id, tuser.id) 190 | await message.reply(BAN_EVENT_TXT.format(tuser.mention, mdnrgx[1])) 191 | await message.delete() 192 | rp = await message.reply(WARN_EVEN_TXT.format(tuser.mention, mdnrgx[1], ANTIF_WARNS_DB[tuser.id])) 193 | if chat_id in ANTIF_TO_DEL: 194 | await NEXAUB.delete_messages(chat_id=chat_id, message_ids=ANTIF_TO_DEL[chat_id]) 195 | ANTIF_TO_DEL[chat_id] = [rp.id] 196 | except: 197 | pass 198 | 199 | anti_chats = filters.create(func=anti_func_handler) 200 | 201 | 202 | @nexaub.on_cf(anti_chats & (filters.new_chat_members | filters.text)) 203 | async def check_anti_funcs(_, message: Message): 204 | anti_func_det = await get_anti_func(message.chat.id) 205 | # Checks if the functions are enabled for the chat 206 | if not anti_func_det: 207 | return 208 | if anti_func_det[0] != "on": 209 | return 210 | # Warns or ban the user from the chat 211 | await warn_or_ban(message, anti_func_det[1]) -------------------------------------------------------------------------------- /nexa_userbot/core/main_cmd.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | import logging 5 | import asyncio 6 | import importlib 7 | 8 | from pyrogram import filters, enums 9 | from pyrogram.handlers import MessageHandler 10 | from pyrogram.errors.exceptions.bad_request_400 import MessageIdInvalid 11 | 12 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import get_log_channel 13 | from nexa_userbot.core.nexaub_database.nexaub_db_sudos import get_sudos 14 | from nexa_userbot.helpers.pyrogram_help import rm_markdown 15 | from nexa_userbot import NEXAUB 16 | from config import Config 17 | 18 | 19 | # ================= MAIN ================= # 20 | # Log channel id 21 | log_cid_loop = asyncio.get_event_loop() 22 | LOG_CHANNEL_ID = log_cid_loop.run_until_complete(get_log_channel()) 23 | 24 | # Sudo users 25 | sudos = log_cid_loop.run_until_complete(get_sudos()) 26 | sudos.append("me") 27 | SUDO_IDS = sudos 28 | 29 | 30 | 31 | # Edit or reply 32 | async def e_or_r(nexaub_message, msg_text, parse_mode="md", disable_web_page_preview=True): 33 | """ 34 | Arguments: 35 | 36 | ``nexaub_message``: Message object 37 | ``msg_text``: Text that you want to perform the task 38 | ``parse_mode`` (optional): Parse mode (Defaults to markdown) 39 | ``disable_web_page_preview`` (optional): Pass False if you don't want to disable web page preview (Defaults to True) 40 | """ 41 | message = nexaub_message 42 | if not message: 43 | return await message.edit(msg_text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview) 44 | if not message.from_user: 45 | return await message.edit(msg_text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview) 46 | if message.from_user.id in SUDO_IDS: 47 | if message.reply_to_message: 48 | return await message.reply_to_message.reply_text(msg_text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview) 49 | else: 50 | return await message.reply_text(msg_text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview) 51 | else: 52 | return await message.edit(msg_text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview) 53 | 54 | 55 | class nexaub: 56 | """ 57 | ## Main class of Nexa Userbot 58 | 59 | ## Available Functions: 60 | 61 | ``on_cmd``: Main decorator 62 | ``on_cf``: Decorator to handle custom filters 63 | ``add_handler``: Add handler to userbot 64 | """ 65 | @classmethod 66 | def on_cmd( 67 | self, 68 | command: list, 69 | group: int = 0, 70 | admins_only: bool = False, 71 | only_pm: bool = False, 72 | only_groups: bool = False, 73 | no_sudos: bool = False 74 | ): 75 | """ 76 | ## Main decorator 77 | 78 | ### Arguments: 79 | 80 | ``command``: List of commands 81 | ``group`` (optional): Handler group (Defaults to 0) 82 | ``admins_only`` (optional): True if the command is only for admins (Defaults to False) 83 | ``only_pm`` (optional): True if the command is only for private chats (Defaults to False) 84 | ``only_groups`` (optional): True if the command is only for groups / supergroups (Defaults to False) 85 | ``no_sudos`` (optional): True if the command is restricted for sudo users (Defaults to False) 86 | """ 87 | if no_sudos: 88 | nexaub_filter = (filters.me & filters.command(command, Config.CMD_PREFIX) & ~filters.via_bot & ~filters.forwarded) 89 | else: 90 | nexaub_filter = (filters.user(SUDO_IDS) & filters.command(command, Config.CMD_PREFIX) & ~filters.via_bot & ~filters.forwarded) 91 | def decorate_nexaub(func): 92 | async def x_wrapper(client, message): 93 | nexaub_chat_type = message.chat.type 94 | if admins_only: 95 | if nexaub_chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL]: 96 | usr = await NEXAUB.get_me() 97 | how_usr = await message.chat.get_member(usr.id) 98 | if how_usr.status in ["creator", "administrator"]: 99 | pass 100 | else: 101 | return await e_or_r(nexaub_message=message, msg_text="`First you need to be an admin of this chat!`") 102 | # It's PM Bois! Everyone is an admin in PM! 103 | else: 104 | pass 105 | if only_pm and nexaub_chat_type != enums.ChatType.PRIVATE: 106 | return await e_or_r(nexaub_message=message, msg_text="`Yo, this command is only for PM!`") 107 | if only_groups and nexaub_chat_type not in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]: 108 | return await e_or_r(nexaub_message=message, msg_text="`Is this even a group?`") 109 | try: 110 | await func(client, message) 111 | except MessageIdInvalid: 112 | logging.warning("Don't delete message while processing. It may crash the bot!") 113 | except BaseException as e: 114 | logging.error(f"\nModule - {func.__module__} | Command: {command[0]} | Traceback: \n{e}") 115 | error_text = f""" 116 | **#ERROR** 117 | 118 | **Module:** `{func.__module__}` 119 | **Command:** `{Config.CMD_PREFIX + command[0]}` 120 | **Traceback:** 121 | `{e}` 122 | 123 | **Forward this to @NexaUB_Support** 124 | """ 125 | if len(error_text) > 4000: 126 | clean_error_text = await rm_markdown(error_text) 127 | file = open("error_nexaub.txt", "w+") 128 | file.write(clean_error_text) 129 | file.close() 130 | await NEXAUB.send_document(LOG_CHANNEL_ID, "error_nexaub.txt", caption="`Error of Nexa Userbot`") 131 | os.remove("error_nexaub.txt") 132 | else: 133 | await NEXAUB.send_message(chat_id=LOG_CHANNEL_ID, text=error_text) 134 | self.add_handler(x_wrapper, nexaub_filter, group) 135 | return x_wrapper 136 | return decorate_nexaub 137 | 138 | # Custom filter handling (Credits: Friday Userbot) 139 | @classmethod 140 | def on_cf(self, custom_filters, handler_group: int = 0): 141 | """ 142 | ## Decorator to handle custom filters 143 | 144 | ### Arguments: 145 | 146 | ``custom_filters``: Custom filters to handle 147 | ``handler_group`` (optional): Handler group (Defaults to 0) 148 | """ 149 | def decorate_nexaub_cf(func): 150 | async def x_wrapper_cf(client, message): 151 | try: 152 | await func(client, message) 153 | except MessageIdInvalid: 154 | logging.warning("Don't delete message while processing. It may crash the bot!") 155 | except BaseException as e: 156 | logging.error(f"\nModule - {func.__module__} | Command: (Noting, Custom Filter)") 157 | error_text = f""" 158 | **#ERROR** 159 | 160 | **Module:** `{func.__module__}` 161 | **Command:** `(Noting, Custom Filter)` 162 | **Traceback:** 163 | `{e}` 164 | 165 | **Forward this to @NexaUB_Support** 166 | """ 167 | if len(error_text) > 4000: 168 | clean_error_text = await rm_markdown(error_text) 169 | file = open("error_nexaub.txt", "w+") 170 | file.write(clean_error_text) 171 | file.close() 172 | await NEXAUB.send_document(LOG_CHANNEL_ID, "error_nexaub.txt", caption="`Error of Nexa Userbot`") 173 | os.remove("error_nexaub.txt") 174 | else: 175 | await NEXAUB.send_message(chat_id=LOG_CHANNEL_ID, text=error_text) 176 | message.continue_propagation() 177 | self.add_handler(x_wrapper_cf, custom_filters, handler_group) 178 | return x_wrapper_cf 179 | return decorate_nexaub_cf 180 | 181 | @classmethod 182 | def add_handler(self, x_wrapper, nexaub_filter, cmd_grp): 183 | """ 184 | ## Add handler to the userbot 185 | 186 | ### Arguments: 187 | 188 | ``x_wrapper``: Callback function 189 | ``nexaub_filter``: Filters 190 | ``cmd_grp``: Command Group 191 | """ 192 | NEXAUB.add_handler(MessageHandler(x_wrapper, filters=nexaub_filter), group=cmd_grp) 193 | 194 | # Thanks for Friday Userbot for the idea 195 | def import_plugin(self, p_path): 196 | """ 197 | ## Loads custom plugins 198 | 199 | ### Arguments: 200 | 201 | ``p_path``: Path to the plugin 202 | """ 203 | nexaub_xplugin = p_path.replace("/", ".") 204 | try: 205 | importlib.import_module(nexaub_xplugin) 206 | logging.info(f" LOADED PLUGIN: - {os.path.basename(p_path)}") 207 | except: 208 | logging.warn(f" FAILED TO LOAD PLUGIN: - {os.path.basename(p_path)}") 209 | 210 | async def resolve_peer(self, pr, max_tries=1, counted=0): 211 | """ 212 | ## Returns the InputPeer of a known peer id 213 | 214 | ### Arguments: 215 | 216 | ``pr``: Peer id 217 | ``max_tries`` (optional): Maximum number of times that userbot needs to try (Defaults to 1) 218 | ``counted`` (optional): Defaults to 0 (Don't pass any) 219 | """ 220 | tri_c = counted 221 | try: 222 | return await NEXAUB.resolve_peer(pr) 223 | except: 224 | tri_c += 1 225 | if not tri_c >= max_tries: 226 | return await self.resolve_peer(pr, counted=tri_c) -------------------------------------------------------------------------------- /nexa_userbot/modules/stickers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | # Credits: Friday Userbot | DevsExpo 4 | 5 | import os 6 | import math 7 | import asyncio 8 | import shutil 9 | 10 | from PIL import Image 11 | from pyrogram.types import Message 12 | from pyrogram.errors import StickersetInvalid, YouBlockedUser 13 | from pyrogram.raw.functions.messages import GetStickerSet 14 | from pyrogram.raw.types import InputStickerSetShortName 15 | 16 | from nexa_userbot import NEXAUB, CMD_HELP 17 | from config import Config 18 | from nexa_userbot.helpers.pyrogram_help import get_arg, convert_to_image 19 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 20 | 21 | 22 | # Help 23 | mod_name = os.path.basename(__file__)[:-3] 24 | 25 | CMD_HELP.update( 26 | { 27 | f"{mod_name}": f""" 28 | **Stickers,** 29 | 30 | ✘ `packinfo` - To Get Information about a Sticker Pack 31 | ✘ `kang` - To kang a Sticker 32 | 33 | **Example:** 34 | 35 | ✘ `packinfo`, 36 | ⤷ Reply to a sticker = `{Config.CMD_PREFIX}packinfo` (Reply to a sticker) 37 | 38 | ✘ `kang`, 39 | ⤷ Reply to a sticker = `{Config.CMD_PREFIX}kang` (Reply to a sticker) 40 | """, 41 | f"{mod_name}_category": "utils" 42 | } 43 | ) 44 | 45 | 46 | @nexaub.on_cmd(command=["packinfo"]) 47 | async def packinfo(client, message): 48 | pablo = await e_or_r(nexaub_message=message, msg_text="Processing...") 49 | if not message.reply_to_message: 50 | await pablo.edit("`Please Reply to a Sticker!`") 51 | return 52 | if not message.reply_to_message.sticker: 53 | return await pablo.edit("`Please Reply to a Sticker!`") 54 | if not message.reply_to_message.sticker.set_name: 55 | await pablo.delete() 56 | return 57 | stickerset = await client.send( 58 | GetStickerSet( 59 | stickerset=InputStickerSetShortName( 60 | short_name=message.reply_to_message.sticker.set_name 61 | ), 62 | hash=0 63 | ) 64 | ) 65 | emojis = [] 66 | for stucker in stickerset.packs: 67 | if stucker.emoticon not in emojis: 68 | emojis.append(stucker.emoticon) 69 | output = f"""**Sticker Pack Title **: `{stickerset.set.title}` 70 | **Sticker Pack Short Name:** `{stickerset.set.short_name}` 71 | **Stickers Count:** `{stickerset.set.count}` 72 | **Archived:** `{stickerset.set.archived}` 73 | **Official:** `{stickerset.set.official}` 74 | **Masks:** `{stickerset.set.masks}` 75 | **Animated:** `{stickerset.set.animated}` 76 | **Emojis In Pack:** `{' '.join(emojis)}` 77 | """ 78 | await pablo.edit(output) 79 | 80 | 81 | @nexaub.on_cmd(command=["kang"]) 82 | async def kang_stick(_, message: Message): 83 | kang_msg = await e_or_r(nexaub_message=message, msg_text="`Kanging This Sticker to My Pack...`") 84 | if not message.reply_to_message: 85 | return await kang_msg.edit("`Please Reply to a Sticker or a image!`") 86 | # if not message.reply_to_message.sticker: 87 | # return await kang_msg.edit("`Please Reply to a Sticker!`") 88 | a_emoji = get_arg(message) 89 | pack = 1 90 | nm = message.from_user.username 91 | packname = f"@{nm} Kang Pack {pack}" 92 | packshortname = f"NEXAUB_{message.from_user.id}_{pack}" 93 | emoji = "🤔" 94 | try: 95 | a_emoji = a_emoji.strip() 96 | if not a_emoji.isalpha(): 97 | if not a_emoji.isnumeric(): 98 | emoji = a_emoji 99 | else: 100 | emoji = "🤔" 101 | except: 102 | emoji = "🤔" 103 | exist = None 104 | is_anim = False 105 | if message.reply_to_message.sticker: 106 | if not a_emoji: 107 | emoji = message.reply_to_message.sticker.emoji or "🤔" 108 | is_anim = message.reply_to_message.sticker.is_animated 109 | if is_anim: 110 | packshortname += "_animated" 111 | packname += " Animated" 112 | if message.reply_to_message.sticker.mime_type == "application/x-tgsticker": 113 | file_name = await message.reply_to_message.download("AnimatedSticker.tgs") 114 | else: 115 | cool = await convert_to_image(message, NEXAUB) 116 | if not cool: 117 | return await kang_msg.edit("**Error:** `Unsupported Media`") 118 | file_name = resize_image(cool) 119 | elif message.reply_to_message.document: 120 | if message.reply_to_message.document.mime_type == "application/x-tgsticker": 121 | is_anim = True 122 | packshortname += "_animated" 123 | packname += " Animated" 124 | file_name = await message.reply_to_message.download("AnimatedSticker.tgs") 125 | else: 126 | cool = await convert_to_image(message, NEXAUB) 127 | if not cool: 128 | return await kang_msg.edit("**Error:** `Unsupported Media`") 129 | file_name = resize_image(cool) 130 | try: 131 | exist = await NEXAUB.send( 132 | GetStickerSet( 133 | stickerset=InputStickerSetShortName( 134 | short_name=packshortname 135 | ), 136 | hash=0 137 | ) 138 | ) 139 | except StickersetInvalid: 140 | pass 141 | if exist: 142 | try: 143 | await NEXAUB.send_message("Stickers", "/addsticker") 144 | except YouBlockedUser: 145 | await NEXAUB.edit("`Unblocking @Stickers ...`") 146 | await NEXAUB.unblock_user("Stickers") 147 | await NEXAUB.send_message("Stickers", "/addsticker") 148 | await NEXAUB.send_message("Stickers", packshortname) 149 | await asyncio.sleep(0.2) 150 | limit = "50" if is_anim else "120" 151 | messi = (await NEXAUB.get_history("Stickers", 1))[0] 152 | while limit in messi.text: 153 | pack += 1 154 | prev_pack = int(pack) - 1 155 | await kang_msg.edit(f"He he, Kang Pack Number `{prev_pack}` is Full Of Stickers! Now Switching to `{pack}` Pack!") 156 | packname = f"@{nm} Kang Pack {pack}" 157 | packshortname = f"NEXAUB_{message.from_user.id}_{pack}" 158 | if is_anim: 159 | packshortname += "_animated" 160 | packname += " Animated" 161 | await NEXAUB.send_message("Stickers", packshortname) 162 | await asyncio.sleep(0.2) 163 | messi = (await NEXAUB.get_history("Stickers", 1))[0] 164 | if messi.text == "Invalid pack selected.": 165 | if is_anim: 166 | await NEXAUB.send_message("Stickers", "/newanimated") 167 | else: 168 | await NEXAUB.send_message("Stickers", "/newpack") 169 | await asyncio.sleep(0.5) 170 | await NEXAUB.send_message("Stickers", packname) 171 | await asyncio.sleep(0.2) 172 | await NEXAUB.send_document("Stickers", file_name) 173 | await asyncio.sleep(1) 174 | await NEXAUB.send_message("Stickers", emoji) 175 | await asyncio.sleep(0.8) 176 | await NEXAUB.send_message("Stickers", "/publish") 177 | if is_anim: 178 | await NEXAUB.send_message("Stickers", f"<{packname}>") 179 | await NEXAUB.send_message("Stickers", "/skip") 180 | await asyncio.sleep(0.5) 181 | await NEXAUB.send_message("Stickers", packshortname) 182 | return await kang_msg.edit("**Sticker Kanged!** \n\n**Emoji:** {} \n**Pack:** [Here](https://t.me/addstickers/{})".format(emoji, packshortname)) 183 | await NEXAUB.send_document("Stickers", file_name) 184 | await asyncio.sleep(1) 185 | await NEXAUB.send_message("Stickers", emoji) 186 | await asyncio.sleep(0.5) 187 | await NEXAUB.send_message("Stickers", "/done") 188 | await kang_msg.edit("**Sticker Kanged!** \n\n**Emoji:** {} \n**Pack:** [Here](https://t.me/addstickers/{})".format(emoji, packshortname)) 189 | else: 190 | if is_anim: 191 | await NEXAUB.send_message("Stickers", "/newanimated") 192 | else: 193 | await NEXAUB.send_message("Stickers", "/newpack") 194 | await NEXAUB.send_message("Stickers", packname) 195 | await asyncio.sleep(0.2) 196 | await NEXAUB.send_document("Stickers", file_name) 197 | await asyncio.sleep(1) 198 | await NEXAUB.send_message("Stickers", emoji) 199 | await asyncio.sleep(0.5) 200 | await NEXAUB.send_message("Stickers", "/publish") 201 | await asyncio.sleep(0.5) 202 | if is_anim: 203 | await NEXAUB.send_message("Stickers", f"<{packname}>") 204 | await NEXAUB.send_message("Stickers", "/skip") 205 | await asyncio.sleep(0.5) 206 | await NEXAUB.send_message("Stickers", packshortname) 207 | await kang_msg.edit("**Sticker Kanged!** \n\n**Emoji:** {} \n**Pack:** [Here](https://t.me/addstickers/{})".format(emoji, packshortname)) 208 | try: 209 | if os.path.exists("Kanged_Sticker_NEXAUB.png"): 210 | os.remove("Kanged_Sticker_NEXAUB.png") 211 | downname = "./Downloads" 212 | if os.path.isdir(downname): 213 | shutil.rmtree(downname) 214 | except: 215 | print("Can't remove downloaded sticker files") 216 | return 217 | 218 | 219 | def resize_image(image): 220 | im = Image.open(image) 221 | maxsize = (512, 512) 222 | if (im.width and im.height) < 512: 223 | size1 = im.width 224 | size2 = im.height 225 | if im.width > im.height: 226 | scale = 512 / size1 227 | size1new = 512 228 | size2new = size2 * scale 229 | else: 230 | scale = 512 / size2 231 | size1new = size1 * scale 232 | size2new = 512 233 | size1new = math.floor(size1new) 234 | size2new = math.floor(size2new) 235 | sizenew = (size1new, size2new) 236 | im = im.resize(sizenew) 237 | else: 238 | im.thumbnail(maxsize) 239 | file_name = "Kanged_Sticker_NEXAUB.png" 240 | im.save(file_name, "PNG") 241 | if os.path.exists(image): 242 | os.remove(image) 243 | return file_name 244 | -------------------------------------------------------------------------------- /nexa_userbot/modules/pmguard.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | 4 | import os 5 | 6 | from pyrogram import filters, enums 7 | from pyrogram.types import Message 8 | from nexa_userbot import NEXAUB, CMD_HELP 9 | from nexa_userbot.core.main_cmd import nexaub, e_or_r 10 | from nexa_userbot.core.nexaub_database.nexaub_db_conf import set_custom_var, get_custom_var 11 | from nexa_userbot.core.nexaub_database.nexaub_db_pm import add_approved_user, rm_approved_user, check_user_approved 12 | from nexa_userbot.helpers.pyrogram_help import get_arg 13 | from .telegraph import upload_to_tgraph 14 | from config import Config 15 | 16 | 17 | # Help 18 | mod_name = os.path.basename(__file__)[:-3] 19 | 20 | CMD_HELP.update( 21 | { 22 | f"{mod_name}": f""" 23 | **Pm Guard,** 24 | 25 | ✘ `pmg` - To Enable or Disable Pm Guard 26 | ✘ `approve` - To Approve a User to Pm 27 | ✘ `disapprove` - To Disapprove a User to Pm 28 | ✘ `setpmtxt` - To Set Custom Pm Guard Text 29 | ✘ `setpmpic` - To Set Custom Pm Guard Picture 30 | ✘ `setpmwarns` - To Set Custom Amount of Warns 31 | 32 | **Example:** 33 | 34 | ✘ `pmg`, 35 | ⤷ To turn Pm Guard ON = `{Config.CMD_PREFIX}pmg on` 36 | ⤷ To turn Pm Guard OFF = `{Config.CMD_PREFIX}pmg off` 37 | 38 | ✘ `approve`, 39 | ⤷ Send in a private chat, if a group reply to user's message = `{Config.CMD_PREFIX}approve` 40 | 41 | ✘ `disapprove`, 42 | ⤷ Send in a private chat, if a group reply to user's message = `{Config.CMD_PREFIX}disapprove` 43 | 44 | ✘ `setpmtxt`, 45 | ⤷ Send with text = `{Config.CMD_PREFIX}setpmtxt This is the Pm Guard Text` 46 | ⤷ Reply to a message = `{Config.CMD_PREFIX}setpmtxt` 47 | 48 | ✘ `setpmpic`, 49 | ⤷ Reply to a message = `{Config.CMD_PREFIX}setpmpic` 50 | 51 | ✘ `setpmwarns`, 52 | ⤷ Send with text = `{Config.CMD_PREFIX}setpmwarns 4` 53 | 54 | """, 55 | f"{mod_name}_category": "utils" 56 | } 57 | ) 58 | 59 | 60 | # Configs 61 | PM_GUARD_WARNS_DB = {} 62 | PM_GUARD_MSGS_DB = {} 63 | DEFAULT_PM_TEXT = """ 64 | Because of the spam messages my master get all the time, he don't like to chat with "strangers" now! 65 | So kindly please wait for his approval 🤗! 66 | """ 67 | BASE_PM_TEXT = """ 68 | **Heya 👋, This is the PM Security of {} 👮!** 69 | 70 | {} 71 | 72 | `You have {}/{} of warns! Be careful, if you've exceeded warn limit you'll be blocked 🛑!` 73 | """ 74 | DEFAULT_PM_PIC = "https://telegra.ph//file/44b07848c13bfabd2c76c.jpg" 75 | DEFAULT_PM_MESSAGE_LIMIT = 5 76 | 77 | 78 | # Enable PM Guard 79 | @nexaub.on_cmd(command=["pmguard", "pmg"]) 80 | async def enable_disable_pm_guard_nexaub(_, message: Message): 81 | pmg_emsg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 82 | on_or_off = get_arg(message) 83 | if not on_or_off: 84 | return await pmg_emsg.edit(f"`What should I do?` \n\n**Ex:** \n ⤷ `{Config.CMD_PREFIX}pmg on` - To turn Pm Guard ON \n ⤷ `{Config.CMD_PREFIX}pmg off` - To turn Pm Guard OFF") 85 | is_already = await get_custom_var("ENABLE_PM_GUARD") 86 | if on_or_off.lower() == "on": 87 | if is_already: 88 | return await pmg_emsg.edit("`PM Guard is already enabled!`") 89 | await set_custom_var("ENABLE_PM_GUARD", True) 90 | await pmg_emsg.edit("**Successfully Enabled PM Guard!**") 91 | elif on_or_off.lower() == "off": 92 | if not is_already: 93 | return await pmg_emsg.edit("`PM Guard isn't even enabled!`") 94 | await set_custom_var("ENABLE_PM_GUARD", False) 95 | await pmg_emsg.edit("**Successfully Disabled PM Guard!**") 96 | else: 97 | await pmg_emsg.edit(f"`Wait what?` \n\n**Ex:** \n ⤷ `{Config.CMD_PREFIX}pmg on` - To turn Pm Guard ON \n ⤷ `{Config.CMD_PREFIX}pmg off` - To turn Pm Guard OFF") 98 | 99 | 100 | # Approve user 101 | @nexaub.on_cmd(command=["a", "approve"]) 102 | async def approve_user_to_pm(_, message: Message): 103 | apprv_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 104 | chat_type = message.chat.type 105 | if chat_type == "me": 106 | return await apprv_msg.edit("`Bruh, Why should I approve my self?`") 107 | elif chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]: 108 | if not message.reply_to_message.from_user: 109 | return await apprv_msg.edit("`Reply to a user id to approve that user!`") 110 | user_id = message.reply_to_message.from_user.id 111 | elif chat_type == enums.ChatType.PRIVATE: 112 | user_id = message.chat.id 113 | else: 114 | return 115 | already_apprvd = await check_user_approved(user_id) 116 | if already_apprvd: 117 | return await apprv_msg.edit("`This user is already approved to PM!`") 118 | await add_approved_user(user_id) 119 | if user_id in PM_GUARD_WARNS_DB: 120 | PM_GUARD_WARNS_DB.pop(user_id) 121 | try: 122 | await NEXAUB.delete_messages(chat_id=user_id, message_ids=PM_GUARD_MSGS_DB[user_id]) 123 | except: 124 | pass 125 | await apprv_msg.edit("**From now on, this user can PM my master!**") 126 | 127 | 128 | # Disapprove user 129 | @nexaub.on_cmd(command=["da", "disapprove"]) 130 | async def disapprove_user_to_pm(_, message: Message): 131 | dapprv_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 132 | chat_type = message.chat.type 133 | if chat_type in [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP]: 134 | if not message.reply_to_message.from_user: 135 | return await dapprv_msg.edit("`Reply to a user id to disapprove that user!`") 136 | user_id = message.reply_to_message.from_user.id 137 | elif chat_type == enums.ChatType.PRIVATE: 138 | user_id = message.chat.id 139 | else: 140 | return 141 | already_apprvd = await check_user_approved(user_id) 142 | if not already_apprvd: 143 | return await dapprv_msg.edit("`This user isn't even approved to PM!`") 144 | await rm_approved_user(user_id) 145 | await dapprv_msg.edit("**From now on, this user can't PM my master!**") 146 | 147 | # Set PM Guard text 148 | 149 | 150 | @nexaub.on_cmd(command=["setpmtxt"]) 151 | async def set_pm_guard_txt_nexaub(_, message: Message): 152 | st_pm_txt_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 153 | r_msg = message.reply_to_message 154 | args_txt = get_arg(message) 155 | if r_msg: 156 | if r_msg.text: 157 | pm_txt = r_msg.text 158 | else: 159 | return await st_pm_txt_msg.edit("`Reply to a text message!`") 160 | elif args_txt: 161 | pm_txt = args_txt 162 | else: 163 | return await st_pm_txt_msg.edit("`Reply to a text message or send this command with the text you want to set!`") 164 | await set_custom_var("CUSTOM_PM_TEXT", pm_txt) 165 | await st_pm_txt_msg.edit(f"**Successfully Added Custom PM Guard Text!** \n\n**New Message:** `{pm_txt}`") 166 | 167 | 168 | # Set PM Guard pic 169 | @nexaub.on_cmd(command=["setpmpic"]) 170 | async def set_pm_guard_pic_nexaub(_, message: Message): 171 | st_pm_pic_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 172 | r_msg = message.reply_to_message 173 | if r_msg: 174 | if r_msg.photo: 175 | pm_pic = await r_msg.download() 176 | elif r_msg.animation: 177 | pm_pic = await r_msg.download() 178 | else: 179 | return await st_pm_pic_msg.edit("`Reply to a picture or gif!`") 180 | else: 181 | return await st_pm_pic_msg.edit("`Reply to a picture or gif!`") 182 | pm_pic_link = await upload_to_tgraph(pm_pic) 183 | await set_custom_var("CUSTOM_PM_PIC", pm_pic_link) 184 | await st_pm_pic_msg.edit(f"**Successfully Added Custom PM Guard Pic!** \n\n**New Pic:** {pm_pic_link}") 185 | 186 | 187 | # Set PM Guard warn limit 188 | @nexaub.on_cmd(command=["setpmwarns"]) 189 | async def set_pm_guard_warns_nexaub(_, message: Message): 190 | st_pm_warns_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 191 | args_txt = get_arg(message) 192 | if args_txt: 193 | if args_txt.isnumeric(): 194 | pm_warns = int(args_txt) 195 | else: 196 | return await st_pm_warns_msg.edit(f"`Send this command with an integer!` \n\n**Ex:** `{Config.CMD_PREFIX}setpmwarns 4`") 197 | else: 198 | return await st_pm_warns_msg.edit(f"`Send this command with an integer!` \n\n**Ex:** `{Config.CMD_PREFIX}setpmwarns 4`") 199 | await set_custom_var("CUSTOM_PM_WARNS_LIMIT", pm_warns) 200 | await st_pm_warns_msg.edit(f"**Successfully Added Custom PM Guard Warn Limit to** `{args_txt}` *Warns!**") 201 | 202 | 203 | # Custom handler to handle icoming pms 204 | @nexaub.on_cf( 205 | (filters.private 206 | & filters.incoming 207 | & ~filters.me 208 | & ~filters.service 209 | & ~filters.bot), 210 | handler_group=-1 211 | ) 212 | async def handle_pm_guard(_, message: Message): 213 | # Checking if pm guard is enabled 214 | is_pm_guard_enabled = await get_custom_var("ENABLE_PM_GUARD") 215 | if not is_pm_guard_enabled: 216 | return 217 | # User 218 | in_user = message.from_user 219 | # Checking if user is approved to pm 220 | is_approved = await check_user_approved(in_user.id) 221 | if is_approved: 222 | return 223 | # Checking user's telegram status 224 | if in_user.is_fake or in_user.is_scam: 225 | await message.reply("`Damn looks like you're a spammer 🤔. Bye Bye!`") 226 | return await NEXAUB.block_user(in_user.id) 227 | if in_user.is_support or in_user.is_verified or in_user.is_self: 228 | return 229 | # Collecting Pm guard configs 230 | master = await NEXAUB.get_me() 231 | getc_pm_txt = await get_custom_var("CUSTOM_PM_TEXT") 232 | getc_pm_pic = await get_custom_var("CUSTOM_PM_PIC") 233 | getc_pm_warns = await get_custom_var("CUSTOM_PM_WARNS_LIMIT") 234 | custom_pm_txt = getc_pm_txt if getc_pm_txt else DEFAULT_PM_TEXT 235 | custom_pm_pic = getc_pm_pic if getc_pm_pic else DEFAULT_PM_PIC 236 | custom_pm_warns = getc_pm_warns if getc_pm_warns else DEFAULT_PM_MESSAGE_LIMIT 237 | # Checking user's warns 238 | if in_user.id in PM_GUARD_WARNS_DB: 239 | # Deleting old warn messages (Uses try except block cuz this is completely unwanted and in case of error process might be stopped) 240 | try: 241 | if message.chat.id in PM_GUARD_MSGS_DB: 242 | await NEXAUB.delete_messages(chat_id=message.chat.id, message_ids=PM_GUARD_MSGS_DB[message.chat.id]) 243 | except: 244 | pass 245 | # Giving warnings 246 | PM_GUARD_WARNS_DB[in_user.id] += 1 247 | if PM_GUARD_WARNS_DB[in_user.id] >= custom_pm_warns: 248 | await message.reply(f"`That's it! I told you {custom_pm_warns} times, DO NOT pm my master and you didn't it! Anyway I've blocked you 😑!`") 249 | return await NEXAUB.block_user(in_user.id) 250 | else: 251 | rplied_msg = await message.reply_photo(photo=custom_pm_pic, caption=BASE_PM_TEXT.format(master.mention, custom_pm_txt, PM_GUARD_WARNS_DB[in_user.id], custom_pm_warns)) 252 | else: 253 | PM_GUARD_WARNS_DB[in_user.id] = 1 254 | rplied_msg = await message.reply_photo(photo=custom_pm_pic, caption=BASE_PM_TEXT.format(master.mention, custom_pm_txt, PM_GUARD_WARNS_DB[in_user.id], custom_pm_warns)) 255 | PM_GUARD_MSGS_DB[message.chat.id] = [rplied_msg.id] 256 | # Logging details on the channel 257 | log_chnnel_id = await get_custom_var("LOG_CHANNEL_ID") 258 | copied = await message.forward(log_chnnel_id) 259 | await copied.reply(f"**#Pm_Guard_Log** \n\n**User:** {in_user.mention} \n**User ID:** `{in_user.id}`") 260 | -------------------------------------------------------------------------------- /nexa_userbot/modules/globals.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Itz-fork 2 | # Part of: Nexa-Userbot 3 | import os 4 | 5 | from pyrogram import filters, enums 6 | from pyrogram.types import Message 7 | 8 | from . import nexaub_devs 9 | from nexa_userbot import NEXAUB, CMD_HELP 10 | from nexa_userbot.core.main_cmd import nexaub, e_or_r, SUDO_IDS 11 | from nexa_userbot.helpers.pyrogram_help import get_arg 12 | from nexa_userbot.core.nexaub_database.nexaub_db_globals import gban_usr, get_gbanned, get_gban_reason, ungban_usr 13 | from nexa_userbot.helpers.pyrogram_help import get_ma_chats 14 | from config import Config 15 | 16 | # Help 17 | mod_name = os.path.basename(__file__)[:-3] 18 | 19 | CMD_HELP.update( 20 | { 21 | f"{mod_name}": f""" 22 | **Globals,** 23 | 24 | ✘ `gban` - To Gban a user (Reply to a user or send this command with user id) 25 | ✘ `ungban` - To UnGban a user 26 | ✘ `gbans` - To Get Gbanned User List 27 | ✘ `gpromote` - To Promote a user globally 28 | ✘ `gdemote` - To Demote a user globally 29 | 30 | **Example:** 31 | 32 | ✘ `gban`, 33 | ⤷ by Userid = `{Config.CMD_PREFIX}gban 1234567 Test Gban` 34 | ⤷ by Username = `{Config.CMD_PREFIX}gban @Spammer_Guy Test Gban` 35 | ⤷ Or Just Reply to a message from user with reason to Gban! 36 | 37 | ✘ `gban`, 38 | ⤷ by Userid = `{Config.CMD_PREFIX}ungban 1234567` 39 | ⤷ by Username = `{Config.CMD_PREFIX}ungban @Spammer_Guy` 40 | ⤷ Or Just Reply to a message from user to UnGban! 41 | 42 | ✘ `gpromote`, 43 | ⤷ by Userid / Username = `{Config.CMD_PREFIX}gpromote 1234567` 44 | ⤷ Or Just Reply to a message from user to Gpromote! 45 | 46 | **Tips 💡,** 47 | ⤷ Define which chat types the user needed to be promoted - `{Config.CMD_PREFIX}gpromote [group/channel/all]` 48 | ⤷ Define the user's permission role - `{Config.CMD_PREFIX}gpromote [basic/god]` 49 | 50 | ✘ `gdemote`, 51 | ⤷ Same arguments and logic as gpromote 52 | """, 53 | f"{mod_name}_category": "utils" 54 | } 55 | ) 56 | 57 | 58 | # Gban 59 | @nexaub.on_cmd(command=["gban"]) 60 | async def gbun_dis_usr(_, message: Message): 61 | gban_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 62 | r_msg = message.reply_to_message 63 | gban_rsn = get_arg(message) 64 | nexaub_owner = await NEXAUB.get_me() 65 | if r_msg: 66 | if gban_rsn: 67 | gban_rson = gban_rsn 68 | else: 69 | gban_rson = "That guy is a creepy scammer!" 70 | gban_uid = r_msg.from_user.id 71 | elif gban_rsn: 72 | gets_user_arg = gban_rsn.split(None) 73 | gban_rson = gets_user_arg[1] 74 | gban_uid = gets_user_arg[0] 75 | if gban_uid.isnumeric(): 76 | gban_uid = gban_uid 77 | else: 78 | if "@" in gban_uid: 79 | usr_name = gban_uid.replace("@", "").split(None)[0] 80 | else: 81 | usr_name = gban_uid 82 | get_usr_info = await NEXAUB.get_users(usr_name) 83 | gban_uid = get_usr_info.id 84 | else: 85 | return await gban_msg.edit("`Give a User ID, Username or Reply to a user message to Gban`") 86 | if gban_uid in nexaub_devs: 87 | return await gban_msg.edit("`Sorry I can't Gban Dev of me") 88 | if gban_uid == nexaub_owner.id: 89 | return await gban_msg.edit("`Wtf? You are trying to gban yourself?`") 90 | is_gbanned = await get_gban_reason(gban_uid) 91 | if is_gbanned: 92 | return await gban_msg.edit("`Lmao, That shit guy is already GBANNED!`") 93 | await gban_msg.edit("`Fetching Chats For Gban Process...`") 94 | f_chats = await get_ma_chats() 95 | if not f_chats: 96 | return await gban_msg.edit("`No Chats to Gban!`") 97 | total_f_chats = len(f_chats) 98 | for gokid in f_chats: 99 | ub_failed = 0 100 | try: 101 | await NEXAUB.ban_chat_member(chat_id=gokid, user_id=int(gban_uid)) 102 | except: 103 | ub_failed += 1 104 | await gban_usr(gban_id=gban_uid, gban_reason=gban_rson) 105 | await gban_msg.edit(f"**#USER_GBANNED** \n\n**User:** `{gban_uid}` \n**Reason:** `{gban_rson}` \n**Total Chats:** `{total_f_chats-ub_failed}`") 106 | 107 | 108 | # Ungban 109 | @nexaub.on_cmd(command=["ungban"]) 110 | async def ungbun_dis_usr(_, message: Message): 111 | ungban_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 112 | r_ug_msg = message.reply_to_message 113 | gban_usr = get_arg(message) 114 | if gban_usr: 115 | if gban_usr.isnumeric(): 116 | ungban_uid = gban_usr 117 | else: 118 | if "@" in gban_usr: 119 | usr_name = gban_usr.replace("@", "").split(None)[0] 120 | else: 121 | usr_name = gban_usr 122 | get_him = await NEXAUB.get_users(usr_name) 123 | ungban_uid = get_him.id 124 | else: 125 | if r_ug_msg: 126 | ungban_uid = r_ug_msg.from_user.id 127 | else: 128 | return await ungban_msg.edit("`Reply to a message from a user or give a user id to UnGban that user!`") 129 | await ungban_msg.edit("`Fetching Your Chats...`") 130 | ung_chats = await get_ma_chats() 131 | if not ung_chats: 132 | return await ungban_msg.edit("`No Chats to Gban!`") 133 | total_ung_chats = len(ung_chats) 134 | is_gbanned = await get_gban_reason(ungban_uid) 135 | if is_gbanned is None: 136 | return await ungban_msg.edit("`Is this user Gbanned?`") 137 | for good_boi in ung_chats: 138 | ub_failed = 0 139 | try: 140 | await NEXAUB.unban_chat_member(chat_id=good_boi, user_id=ungban_uid) 141 | except: 142 | ub_failed += 1 143 | await ungban_usr(ungban_uid) 144 | await ungban_msg.edit(f"**#USER_UNGBANNED** \n\n**User:** `{ungban_uid}` \n**Affected To:** `{total_ung_chats-ub_failed}` **Chats**") 145 | 146 | 147 | # Gbans 148 | @nexaub.on_cmd(command=["gbans"]) 149 | async def gbuns_in_whole_time(_, message: Message): 150 | glist_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 151 | gban_list = await get_gbanned() 152 | total_gbans = len(gban_list) 153 | gban_txt = "**#GBAN_LIST** \n\n" 154 | if total_gbans == 0: 155 | return await glist_msg.edit("`There aren't any Gbanned User!`") 156 | for gb in gban_list: 157 | gban_txt += f" ⤷ **User:** `{gb['gbanned_usr']}` \n ⤷ **Reason:** `{gb['reason_for_gban']}`" 158 | if len(gban_txt) > 4096: 159 | file = open("NEXAUB_Gban_List.txt", "w+") 160 | file.write(gban_txt) 161 | file.close() 162 | await NEXAUB.send_document( 163 | message.chat.id, 164 | "NEXAUB_Gban_List.txt", 165 | caption=f"Gban List" 166 | ) 167 | os.remove("NEXAUB_Gban_List.txt") 168 | else: 169 | await glist_msg.edit(gban_txt) 170 | 171 | 172 | # Gpromote 173 | @nexaub.on_cmd(command=["gpromote"]) 174 | async def gpromote_dis_usr(_, message: Message): 175 | gpromote_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 176 | r_msg = message.reply_to_message 177 | options_args = get_arg(message) 178 | nexaub_owner = await NEXAUB.get_me() 179 | # Getting user id and options 180 | if r_msg: 181 | # Parsing arguments 182 | if options_args: 183 | base_options = options_args.split(" ") 184 | if len(base_options) == 2: 185 | where = base_options[0] 186 | role = base_options[1] 187 | elif len(base_options) == 1: 188 | where = base_options[0] 189 | role = None 190 | else: 191 | return await gpromote_msg.edit("`Give user id or username to promote that user globally!") 192 | if message.from_user: 193 | uid = r_msg.from_user.id 194 | else: 195 | return await gpromote_msg.edit("`Reply to a message from a user!`") 196 | elif options_args: 197 | # Parsing arguments 198 | base_option_args = options_args.split(" ") 199 | if len(base_option_args) == 3: 200 | uid = base_option_args[0] 201 | where = base_option_args[1] 202 | role = base_option_args[2] 203 | elif len(base_option_args) == 2: 204 | uid = base_option_args[0] 205 | where = base_option_args[1] 206 | role = None 207 | elif len(base_option_args) == 1: 208 | uid = base_option_args[0] 209 | where = None 210 | role = None 211 | else: 212 | return await gpromote_msg.edit("`Give user id or username to promote that user globally!`") 213 | else: 214 | return await gpromote_msg.edit("`Give a User ID, Username or Reply to a user message to Gpromote!`") 215 | 216 | # Checking user id 217 | if not uid.isnumeric(): 218 | if "@" in uid: 219 | usrname = uid.replace("@", "") 220 | gp_user_id = (await NEXAUB.get_users(usrname)).id 221 | else: 222 | return await gpromote_msg.edit("`Give a user id or username to promote that user globally!`") 223 | else: 224 | gp_user_id = int(uid) 225 | # Checking gpromote places 226 | if where in ["group", "channel", "all"]: 227 | if where == "all": 228 | where_to_promote = [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL] 229 | elif where == "group": 230 | where_to_promote = [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP] 231 | else: 232 | where_to_promote = [enums.ChatType.CHANNEL] 233 | else: 234 | return await gpromote_msg.edit("`Invalid chat type!` \n\n**Use:**\n ⤷ `all` - All chat types (private, group and channel) \n ⤷ `group` - Groups only \n ⤷ `channel` - Channels only") 235 | # Checking role 236 | if not role: 237 | gp_role = "basic" 238 | elif role.lower() in ["basic", "god"]: 239 | gp_role = role.lower() 240 | else: 241 | return await gpromote_msg.edit("`Invalid gpromote role!` \n\n**Use:**\n ⤷ `basic` - User will able to manage chats/voice chats, post/pin messages and invite users. \n ⤷ `god` - Users will get all the permissions a admin can get.") 242 | if gp_user_id == nexaub_owner.id: 243 | return await gpromote_msg.edit("`Wtf? You are trying to gpromote yourself?`") 244 | # Fetching chats 245 | await gpromote_msg.edit("`Fetching Chats For Gpromote...`") 246 | gp_chats = await get_ma_chats(chat_types=where_to_promote) 247 | if not gp_chats: 248 | return await gpromote_msg.edit("`No Chats to Gpromote!`") 249 | total_gp_chats = len(gp_chats) 250 | # Promoting the user 251 | for gp_u_chat in gp_chats: 252 | ub_failed = 0 253 | try: 254 | if gp_role == "basic": 255 | await NEXAUB.promote_chat_member( 256 | chat_id=gp_u_chat, 257 | user_id=gp_user_id, 258 | can_manage_chat=True, 259 | can_manage_voice_chats=True, 260 | can_post_messages=True, 261 | can_pin_messages=True, 262 | can_invite_users=True 263 | ) 264 | else: 265 | await NEXAUB.promote_chat_member( 266 | chat_id=gp_u_chat, 267 | user_id=gp_user_id, 268 | can_manage_chat=True, 269 | can_change_info=True, 270 | can_post_messages=True, 271 | can_edit_messages=True, 272 | can_delete_messages=True, 273 | can_restrict_members=True, 274 | can_invite_users=True, 275 | can_pin_messages=True, 276 | can_promote_members=True, 277 | can_manage_voice_chats=True 278 | ) 279 | except: 280 | ub_failed += 1 281 | await gpromote_msg.edit(f"**#USER_GPROMOTED** \n\n**Globally promoted** {(await NEXAUB.get_users(gp_user_id)).mention} **in ** `{total_gp_chats - ub_failed}` **chats!**") 282 | 283 | 284 | # Gdemote 285 | @nexaub.on_cmd(command=["gdemote"]) 286 | async def gdemote_dis_usr(_, message: Message): 287 | gdemote_msg = await e_or_r(nexaub_message=message, msg_text="`Processing...`") 288 | r_msg = message.reply_to_message 289 | uid_args = get_arg(message) 290 | nexaub_owner = await NEXAUB.get_me() 291 | if r_msg: 292 | if message.from_user: 293 | uid = r_msg.from_user.id 294 | else: 295 | return await gdemote_msg.edit("`Reply to a message from a user!`") 296 | if uid_args: 297 | where = uid_args 298 | elif uid_args: 299 | base_args = uid_args.split(" ") 300 | if len(base_args) == 2: 301 | uid = base_args[0] 302 | where = base_args[1] 303 | elif len(base_args) == 1: 304 | uid = base_args[0] 305 | else: 306 | return await gdemote_msg.edit("`Give a User ID, Username or Reply to a user message to Gdemote!`") 307 | else: 308 | return await gdemote_msg.edit("`Give a User ID, Username or Reply to a user message to Gdemote!`") 309 | # Checking user id 310 | if not uid.isnumeric(): 311 | if "@" in uid: 312 | usrname = uid.replace("@", "") 313 | gd_user_id = (await NEXAUB.get_users(usrname)).id 314 | else: 315 | return await gdemote_msg.edit("`Give a user id or username to demote that user globally!`") 316 | else: 317 | gd_user_id = int(uid) 318 | if gd_user_id == nexaub_owner.id: 319 | return await gdemote_msg.edit("`Wtf? You are trying to gdemote yourself?`") 320 | # Checking gdemote places 321 | if where in ["group", "channel", "all"]: 322 | if where == "all": 323 | where_to_promote = [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL] 324 | elif where == "group": 325 | where_to_promote = [enums.ChatType.GROUP, enums.ChatType.SUPERGROUP] 326 | else: 327 | where_to_promote = [enums.ChatType.CHANNEL] 328 | else: 329 | return await gdemote_msg.edit("`Invalid chat type!` \n\n**Use:**\n ⤷ `all` - All chat types (private, group and channel) \n ⤷ `group` - Groups only \n ⤷ `channel` - Channels only") 330 | # Fetching chats 331 | await gdemote_msg.edit("`Fetching Chats For Gdemote...`") 332 | gp_chats = await get_ma_chats(chat_types=where_to_promote) 333 | if not gp_chats: 334 | return await gdemote_msg.edit("`No Chats to Gdemote!`") 335 | total_gp_chats = len(gp_chats) 336 | # Promoting the user 337 | for gd_u_chat in gp_chats: 338 | ub_failed = 0 339 | try: 340 | await NEXAUB.promote_chat_member( 341 | chat_id=gd_u_chat, 342 | user_id=gd_user_id, 343 | can_manage_chat=False, 344 | can_change_info=False, 345 | can_post_messages=False, 346 | can_edit_messages=False, 347 | can_delete_messages=False, 348 | can_restrict_members=False, 349 | can_invite_users=False, 350 | can_pin_messages=False, 351 | can_promote_members=False, 352 | can_manage_voice_chats=False 353 | ) 354 | except: 355 | ub_failed += 1 356 | await gdemote_msg.edit(f"**#USER_GDEMOTED** \n\n**Globally demoted** {(await NEXAUB.get_users(gd_user_id)).mention} **in ** `{total_gp_chats - ub_failed}` **chats!**") 357 | 358 | 359 | @nexaub.on_cf(filters.incoming & ~filters.me & ~filters.user(SUDO_IDS)) 360 | async def gbanner(_, message: Message): 361 | if not message: 362 | return 363 | if not message.from_user: 364 | return 365 | gbanned_usr_id = message.from_user.id 366 | if not gbanned_usr_id: 367 | return 368 | is_gbanned = await get_gban_reason(gbanned_usr_id) 369 | gban_chat_id = message.chat.id 370 | if is_gbanned: 371 | if message.chat.type == enums.ChatType.PRIVATE: 372 | await NEXAUB.block_user(gbanned_usr_id) 373 | else: 374 | try: 375 | await NEXAUB.ban_chat_member(chat_id=gban_chat_id, user_id=gbanned_usr_id) 376 | await NEXAUB.send_message(chat_id=gban_chat_id, text=f"**#GBAN_DB** \n`Gbanned User Joined to this chat. So I've Banned Him!` \n\n**User ID:** `{gbanned_usr_id}` \n**Reason:** `{is_gbanned}`") 377 | except: 378 | return await NEXAUB.send_message(chat_id=gban_chat_id, text=f"**#GBAN_DB** \n`Gbanned User Joined to this chat!` \n\n**User ID:** `{gbanned_usr_id}` \n**Reason:** `{is_gbanned}`") 379 | else: 380 | return 381 | --------------------------------------------------------------------------------