""" Get the Bots in any chat* Syntax: .get_bot""" from telethon import events from telethon.tl.types import ChannelParticipantAdmin, ChannelParticipantsBots from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd("get_bot ?(.*)")) @indus.on(sudo_cmd("get_bot ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return mentions = "**Bots in this Channel**: \n" input_str = event.pattern_match.group(1) to_write_chat = await event.get_input_chat() chat = None if not input_str: chat = to_write_chat else: mentions = "Bots in {} channel: \n".format(input_str) try: chat = await borg.get_entity(input_str) except Exception as e: await event.edit(str(e)) return None try: async for x in borg.iter_participants(chat, filter=ChannelParticipantsBots): if isinstance(x.participant, ChannelParticipantAdmin): mentions += "\n ⚜️ [{}](tg://user?id={}) `{}`".format( x.first_name, x.id, x.id)
# GNU General Public License for more details. # """Remove.BG Plugin for @UniBorg Syntax: .remove.bg https://link.to/image.extension Syntax: .remove.bg as reply to a media""" import asyncio from datetime import datetime import io import os import requests from telethon import events from indus.utils import progress, admin_cmd, sudo_cmd, eor @indus.on(admin_cmd("rmbg ?(.*)", outgoing=True)) @indus.on(sudo_cmd("rmbg ?(.*)", allow_sudo=True)) async def _(event): HELP_STR = "`.remove.bg` as reply to a media, or give a link as an argument to this command" if event.fwd_from: return if Config.REM_BG_API_KEY is None: await event.edit("You need API token from remove.bg to use this plugin.") return False input_str = event.pattern_match.group(1) start = datetime.now() message_id = event.message.id if event.reply_to_msg_id: message_id = event.reply_to_msg_id reply_message = await event.get_reply_message() # check if media message ievent = await eor(event, "Processing...")
"""Get Administrators of any Chat* Syntax: .get_admin""" from telethon import events from telethon.tl.types import ChannelParticipantsAdmins, ChannelParticipantAdmin, ChannelParticipantCreator from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd("get_ad?(m)in ?(.*)")) @indus.on(sudo_cmd("get_ad?(m)in ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return mentions = "**Admins in this Channel**: \n" should_mention_admins = False reply_message = None pattern_match_str = event.pattern_match.group(1) if "m" in pattern_match_str: should_mention_admins = True if event.reply_to_msg_id: reply_message = await event.get_reply_message() input_str = event.pattern_match.group(2) to_write_chat = await event.get_input_chat() chat = None if not input_str: chat = to_write_chat else: mentions_heading = "Admins in {} channel: \n".format(input_str) mentions = mentions_heading try: chat = await borg.get_entity(input_str) except Exception as e:
import asyncio import os from datetime import datetime from pathlib import Path from indus import ALIVE_NAME from indus import bot as indus from indus.utils import admin_cmd, eor, load_module, remove_plugin, sudo_cmd DELETE_TIMEOUT = 5 thumb_image_path = "./indus.png" DEFAULTUSER = str(ALIVE_NAME) if ALIVE_NAME else "Indus" @indus.on(admin_cmd(pattern=r"send (?P<shortname>\w+)", outgoing=True)) @indus.on(sudo_cmd(pattern=r"send (?P<shortname>\w+)", allow_sudo=True)) async def send(event): if event.fwd_from: return hmm = bot.uid # pylint:disable=E0602 message_id = event.message.id thumb = thumb_image_path input_str = event.pattern_match.group(1) the_plugin_file = "./indus/plugins/{}.py".format(input_str) if os.path.exists(the_plugin_file): start = datetime.now() pro = await event.client.send_file( event.chat_id, the_plugin_file, force_document=True, allow_cache=False,
ExtractorError, GeoRestrictedError, MaxDownloadsReached, PostProcessingError, UnavailableVideoError, XAttrMetadataError, ) from indus import time from indus import CMD_HELP from indus.utils import admin_cmd, edit_or_reply, progress, sudo_cmd @indus.on(admin_cmd(pattern="yt(a|v) (.*)", outgoing=True)) @indus.on(sudo_cmd(pattern="yt(a|v) (.*)", allow_sudo=True)) async def download_video(v_url): """ For .ytdl command, download media from YouTube and many other sites. """ url = v_url.pattern_match.group(2) ytype = v_url.pattern_match.group(1).lower() v_url = await edit_or_reply(v_url, "`Preparing to download...`") if ytype == "a": opts = { "format": "bestaudio", "addmetadata": True, "key": "FFmpegMetadata", "writethumbnail": True,
async def _(event): if event.fwd_from: return input_str = event.pattern_match.group(1) sample_url = "https://da.gd/dns/{}".format(input_str) response_api = requests.get(sample_url).text if response_api: await eor(event, "DNS records of {} are \n{}".format(input_str, response_api)) else: await eor(event, "i can't seem to find {} on the internet".format(input_str)) @indus.on(admin_cmd("short (.*)", outgoing=True)) @indus.on(sudo_cmd("short (.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return input_str = event.pattern_match.group(1) sample_url = "https://da.gd/s?url={}".format(input_str) response_api = requests.get(sample_url).text if response_api: await eor(event, "Generated {} for {}.".format(response_api, input_str)) else: await eor(event, "something is wrong. please try again later.") @indus.on(admin_cmd("unshort (.*)", outgoing=True)) @indus.on(sudo_cmd("unshort (.*)", allow_sudo=True))
""" It does not do to dwell on dreams and forget to live Syntax: .getime""" import asyncio import os from datetime import datetime from PIL import Image, ImageDraw, ImageFont from indus.utils import admin_cmd, sudo_cmd, eor, edit_or_reply from var import Config import logging FONT_FILE_TO_USE = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf" @indus.on(admin_cmd("time ?(.*)")) # pylint:disable=E0602 @indus.on(sudo_cmd("time ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return current_time = datetime.now().strftime( "⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡ \nINDUS TIMEZONE \n LOCATION: India🇮🇳 \n Time: %H:%M:%S \n Date: %d.%m.%y \n⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡⚡" ) start = datetime.now() input_str = event.pattern_match.group(1) reply_msg_id = event.message.id if input_str: current_time = input_str elif event.reply_to_msg_id: previous_message = await event.get_reply_message() reply_msg_id = previous_message.id if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): # pylint:disable=E0602
from telethon import events, errors, functions, types import inspect import traceback import asyncio import sys import io from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd(pattern="exec", outgoing=True)) @indus.on(sudo_cmd(pattern="exec", allow_sudo=True)) async def _(event): if event.fwd_from: return await eor(event, "Processing ...") cmd = event.text.split(" ", maxsplit=1)[1] reply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id old_stderr = sys.stderr old_stdout = sys.stdout redirected_output = sys.stdout = io.StringIO() redirected_error = sys.stderr = io.StringIO() stdout, stderr, exc = None, None, None try: await aexec(cmd, event) except Exception: exc = traceback.format_exc()
from telethon import events from datetime import datetime from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd(pattern="ping", outgoing=True)) @indus.on(sudo_cmd(pattern="ping", allow_sudo=True)) async def _(event): if event.fwd_from: return start = datetime.now() end = datetime.now() ms = (end - start).microseconds / 1000 await eor(event, f"Pong! 🏓 {ms} ..")
from indus import CMD_LIST from indus.utils import admin_cmd, sudo_cmd, eor from indus import ALIVE_NAME from var import Var @indus.on(admin_cmd(pattern="help ?(.*)", outgoing=True)) @indus.on(sudo_cmd(pattern="help ?(.*)", allow_sudo=True)) async def cmd_list(event): if not event.text[0].isalpha() and event.text[0] not in ("/", "#", "@", "!"): tgbotusername = Var.TGBOT_USERNAME input_str = event.pattern_match.group(1) if tgbotusername is None or input_str == "text": string = "" for i in CMD_LIST: string += "ℹ️ " + i + "\n" for iter_list in CMD_LIST[i]: string += " `" + str(iter_list) + "`" string += "\n" string += "\n" if len(string) > 4095: with io.BytesIO(str.encode(string)) as out_file: out_file.name = "cmd.txt" await bot.send_file(event.chat_id, out_file, force_document=True, allow_cache=False, caption="**COMMANDS**", reply_to=reply_to_id) await event.delete()
.telegraph text as reply to a large text""" import os from PIL import Image from var import Config from telethon import events from datetime import datetime from indus.utils import admin_cmd, sudo_cmd, eor from telegraph import Telegraph, upload_file, exceptions telegraph = Telegraph() r = telegraph.create_account(short_name=Config.TELEGRAPH_SHORT_NAME) auth_url = r["auth_url"] @indus.on(admin_cmd("telegraph (media|text) ?(.*)")) @indus.on(sudo_cmd("telegraph (media|text) ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return if Config.PRIVATE_GROUP_BOT_API_ID is None: await eor( event, "Please set the required environment variable `PRIVATE_GROUP_BOT_API_ID` for this plugin to work" ) return if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY) await borg.send_message( Config.PRIVATE_GROUP_BOT_API_ID, "Created New Telegraph account {} for the current session. \n**Do not give this url to anyone, even if they say they are from Telegram!**" .format(auth_url))
"""Get ID of any Telegram media, or any user Syntax: .get_id""" from telethon import events from telethon.utils import pack_bot_file_id from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd("id")) @indus.on(sudo_cmd("id", allow_sudo=True)) async def _(event): if event.fwd_from: return if event.reply_to_msg_id: chat = await event.get_input_chat() r_msg = await event.get_reply_message() if r_msg.media: bot_api_file_id = pack_bot_file_id(r_msg.media) await eor( event, "Current Chat ID: `{}`\nFrom User ID: `{}`\nBot API File ID: `{}`" .format(str(event.chat_id), str(r_msg.sender_id), bot_api_file_id)) else: await eor( event, "Current Chat ID: `{}`\nFrom User ID: `{}`".format( str(event.chat_id), str(r_msg.sender_id))) else: await eor(event, "Current Chat ID: `{}`".format(str(event.chat_id)))
# # Licensed under the Raphielscape Public License, Version 1.c (the "License"); # you may not use this file except in compliance with the License. # """ Userbot module for purging unneeded messages(usually spam or ot). """ from asyncio import sleep from telethon.errors import rpcbaseerrors from indus import BOTLOG, BOTLOG_CHATID, CMD_HELP from indus.utils import register, errors_handler, admin_cmd, sudo_cmd, eor @indus.on(admin_cmd(outgoing=True, pattern="purge")) @indus.on(sudo_cmd(allow_sudo=True, pattern="purge")) @errors_handler async def fastpurger(purg): """ For .purge command, purge all messages starting from the reply. """ chat = await purg.get_input_chat() msgs = [] count = 0 async for msg in purg.client.iter_messages(chat, min_id=purg.reply_to_msg_id): msgs.append(msg) count = count + 1 msgs.append(purg.reply_to_msg_id) if len(msgs) == 100: await purg.client.delete_messages(chat, msgs) msgs = []
"""Get Telegram Profile Picture and other information Syntax: .whois @username""" import os import html from telethon.tl.functions.photos import GetUserPhotosRequest from telethon.tl.functions.users import GetFullUserRequest from telethon.tl.types import MessageEntityMentionName from telethon.utils import get_input_location from indus.utils import admin_cmd, sudo_cmd, edit_or_reply from indus import TEMP_DOWNLOAD_DIRECTORY @indus.on(admin_cmd(pattern="whois(?: |$)(.*)")) @indus.on(sudo_cmd(pattern="whois(?: |$)(.*)", allow_sudo=True)) async def who(event): ieve = await edit_or_reply(event, "`Fetching userinfo wait....`") if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY): os.makedirs(TEMP_DOWNLOAD_DIRECTORY) replied_user = await get_user(event) try: photo, caption = await fetch_info(replied_user, event) except AttributeError: await edit_or_reply(ieve, "`Could not fetch info of that user.`") return message_id_to_reply = event.message.reply_to_msg_id if not message_id_to_reply: message_id_to_reply = None try: await event.client.send_file( event.chat_id, photo,
import io import time import asyncio import subprocess from telethon import events from indus.utils import admin_cmd, sudo_cmd, eor from telethon.errors import MessageEmptyError, MessageTooLongError, MessageNotModifiedError @indus.on(admin_cmd(pattern="bash ?(.*)", outgoing=True)) @indus.on(sudo_cmd(pattern="bash ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return DELAY_BETWEEN_EDITS = 0.3 PROCESS_RUN_TIME = 100 cmd = event.pattern_match.group(1) reply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id start_time = time.time() + PROCESS_RUN_TIME process = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) stdout, stderr = await process.communicate() e = stderr.decode() if not e: e = "No Error" o = stdout.decode() if not o: o = "**Tip**: \n`If you want to see the results of your code, I suggest printing them to stdout.`" else:
from indus import CMD_HNDLR, SUDO_HNDLR @indus.on(admin_cmd("restart", outgoing=True)) async def _(event): if event.fwd_from: return await event.edit( f"Restarted. `{CMD_HNDLR}ping` or `{CMD_HNDLR}help` to check if I am online" ) await borg.disconnect() os.execl(sys.executable, sys.executable, *sys.argv) quit() @indus.on(sudo_cmd("restart", allow_sudo=True)) async def _(event): if event.fwd_from: return await eor( event, f"Restarted. `{SUDO_HNDLR}ping` or `{SUDO_HNDLR}help` to check if I am online" ) await borg.disconnect() os.execl(sys.executable, sys.executable, *sys.argv) quit() @indus.on(admin_cmd("shutdown", outgoing=True)) @indus.on(sudo_cmd("shutdown", allow_sudo=True)) async def _(event):
"""Take screenshot of any website Syntax: .screenlong <Website URL>""" import io import traceback from datetime import datetime from selenium import webdriver from telethon import events from indus.utils import admin_cmd, sudo_cmd, eor @indus.on(admin_cmd("screenlong (.*)")) @indus.on(sudo_cmd("screenlong (.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return if Config.GOOGLE_CHROME_BIN is None: await eor(event, "Need to install Google Chrome. Module Stopping.") return ievent = await eor(event, "Processing ...") start = datetime.now() try: chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument("--test-type") chrome_options.add_argument("--headless") # https://stackoverflow.com/a/53073789/4723940 chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.binary_location = Config.GOOGLE_CHROME_BIN await ievent.edit("Starting Google Chrome BIN")
KANGING_STR = [ "Using Witchery to kang this sticker...", "Plagiarising hehe...", "Inviting this sticker over to my pack...", "Kanging this sticker...", "Hey that's a nice sticker!\nMind if I kang?!..", "hehe me stel ur stikér\nhehe.", "Ay look over there (☉。☉)!→\nWhile I kang this...", "Roses are red violets are blue, kanging this sticker so my pacc looks cool", "Imprisoning this sticker...", "Mr.Steal Your Sticker is stealing this sticker... ", ] @indus.on(admin_cmd(pattern="kang ?(.*)")) @indus.on(sudo_cmd(pattern="kang ?(.*)", allow_sudo=True)) async def kang(args): """ For .kang command, kangs stickers or creates new ones. """ user = await bot.get_me() if not user.username: try: user.first_name.encode("utf-8").decode("ascii") user.username = user.first_name except UnicodeDecodeError: user.username = f"cat_{user.id}" message = await args.get_reply_message() photo = None emojibypass = False is_anim = False emoji = None if message and message.media:
from bs4 import BeautifulSoup from datetime import datetime from urllib.error import HTTPError from urllib.parse import quote_plus from gsearch.googlesearch import search from indus.utils import admin_cmd, sudo_cmd, eor from google_images_download import google_images_download def progress(current, total): logger.info("Downloaded {} of {}\nCompleted {}".format( current, total, (current / total) * 100)) @indus.on(admin_cmd("go (.*)", outgoing=True)) @indus.on(sudo_cmd("go (.*)", allow_sudo=True)) async def _(event): ievent = await eor(event, "`Processing... ✍️🙇`") match_ = event.pattern_match.group(1) match = quote_plus(match_) if not match: await ievent.edit("`I can't search nothing !!`") return plain_txt = get( f"https://www.startpage.com/do/search?cmd=process_search&query={match}", 'html').text soup = BeautifulSoup(plain_txt, "lxml") msg = "" for result in soup.find_all('a', {'class': 'w-gl__result-title'}): title = result.text link = result.get('href')
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import io import sys import inspect import asyncio import traceback from var import Config from indus.utils import admin_cmd, sudo_cmd, eor from telethon import events, errors, functions, types @indus.on(admin_cmd("eval", outgoing=True)) @indus.on(sudo_cmd("eval", allow_sudo=True)) async def _(event): if event.fwd_from: return await eor(event, "Processing ...") cmd = event.text.split(" ", maxsplit=1)[1] reply_to_id = event.message.id if event.reply_to_msg_id: reply_to_id = event.reply_to_msg_id old_stderr = sys.stderr old_stdout = sys.stdout redirected_output = sys.stdout = io.StringIO() redirected_error = sys.stderr = io.StringIO() stdout, stderr, exc = None, None, None
from telethon import events import asyncio from datetime import datetime import os import requests from indus.utils import admin_cmd, sudo_cmd, eor from var import Config def progress(current, total): logger.info("Downloaded {} of {}\nCompleted {}".format( current, total, (current / total) * 100)) @indus.on(admin_cmd("paste ?(.*)", outgoing=True)) @indus.on(sudo_cmd("paste ?(.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return start = datetime.now() if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY) input_str = event.pattern_match.group(1) message = "SYNTAX: `.paste <long text to include>`" if input_str: message = input_str elif event.reply_to_msg_id: previous_message = await event.get_reply_message() if previous_message.media: downloaded_file_name = await borg.download_media( previous_message,
int((0, metadata.get('duration').seconds)[metadata.has('duration')] / 2)), '-filter:v', 'scale={}:-1'.format(width), '-vframes', '1', output, ], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) if not p.returncode and os.path.lexists(file): return output @indus.on(admin_cmd("rename (.*)", outgoing=True)) @indus.on(sudo_cmd("rename (.*)", allow_sudo=True)) async def _(event): if event.fwd_from: return ievent = await eor(event, "Renaming in process 🙄") input_str = event.pattern_match.group(1) if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY): os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY) if event.reply_to_msg_id: start = datetime.now() file_name = input_str reply_message = await event.get_reply_message() c_time = time.time() to_download_directory = Config.TMP_DOWNLOAD_DIRECTORY downloaded_file_name = os.path.join(to_download_directory, file_name) downloaded_file_name = await borg.download_media(