await client.send_message(message.chat.id, a, **kwargs) @Client.on_message(Filters.command("fadmin", prefixes=".") & Filters.me) async def fadmin(client, message): await message.delete() splitted = message.text.split(' ', 1) if len(splitted) < 2: a = '@admin' else: a = splitted[1] async for x in client.iter_chat_members(message.chat.id, filter='administrators'): if x.user.is_bot == False and x.user.is_deleted == False: a += f"[{char}](tg://user?id={x.user.id})" kwargs = {} if message.reply_to_message: kwargs['reply_to_message_id'] = message.reply_to_message.message_id await client.send_message(message.chat.id, a, **kwargs) cmds.update({ '.tagall': 'Mark all online members of the group', '.ftagall': 'Mark all members of the group', '.admin': 'Mark all online admins of the group', '.fadmin': 'Mark all admins of the group' })
import asyncio from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("cmd", prefixes=".") & Filters.me) async def cmd(client, message): text = message.text[5:] proc = await asyncio.create_subprocess_shell( text, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT) ex = await proc.communicate() res = ex[0].decode().rstrip() or 'Comando executado' await message.edit(res) cmds.update({'.cmd': 'Execute a command in the CMD'})
from pyrogram import Client, Filters from config import cmds from utils import meval import traceback import html @Client.on_message(Filters.command("eval", prefixes=".") & Filters.me) async def evals(client, message): text = message.text[6:] try: res = await meval(text, locals()) except: ev = traceback.format_exc() await message.edit(ev) return else: try: await message.edit(f"<code>{html.escape(str(res))}</code>") except Exception as e: await message.edit(e) cmds.update({'.eval': 'Run commands on eval'})
up1 = time.time() a = f'Sending...' await message.edit(a) loc = downloader.get_dest() try: await client.send_document(message.chat.id, loc,caption=url, progress=progress, progress_args=(client, message, a)) except Exception as e: await message.edit(f'an error has occurred: {e}') os.remove('dl/'+name) return up2 = time.time() dw = round(dw2-dw1, 3) up = round(up2-up1, 3) to = round(up2-dw1, 3) await message.edit(f'Status:\nDownload: `{dw}`s\nUpload: `{up}`s\nTotal: `{to}`s') os.remove('dl/'+name) async def progress(current, total, c, m, a): global last_edit temp = current * 100 / total if last_edit + 3 < time.time(): await c.send_chat_action(m.chat.id, 'UPLOAD_VIDEO') try: await m.edit(a + '\n' + "{:.1f}%".format(temp)) except MessageNotModified: pass finally: last_edit = time.time() cmds.update({'.dl':'Download files and send to telegram'})
if note_obj['type'] == 'text': text = note_obj['value'] msg = await message.edit(text) if text.startswith('.exec'): from plugins.execs import execs await execs(client, msg) elif text.startswith('.cmd'): from plugins.cmd import cmd await cmd(client, msg) elif note_obj['type'] == 'media': await message.delete() await client.send_cached_media( message.chat.id, note_obj['value']['file_id'], reply_to_message_id=(message.reply_to_message.message_id if message.reply_to_message else None)) cmds.update({ ".note": "Add/update a note. Pass the name of the note as second parameter and the value after (or reply to a message to use its contents)", ".notes": "List the saved notes.", ".notes backup": "Backup the notes into Saved Messages", ".notes remove": "Remove the specified note", "#<note>": html.escape("Get a note. Replace '<note>' with the note key") })
from config import cmds from db import db, save @Client.on_message(Filters.command("upgrade", prefixes=".") & Filters.me) async def upgrade(client, message): branch = 'master' parts = message.text.split(' ', 1) if len(parts) == 2: branch = parts[1] await message.edit(f"Upgrading source from branch '{branch}'...") proc = await asyncio.create_subprocess_shell(f"git pull --no-edit origin {branch}", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT) stdout = (await proc.communicate())[0] if proc.returncode == 0: if "Already up to date." in stdout.decode(): await message.edit(f"There's nothing to upgrade from branch '{branch}'.") else: await message.edit(("Restarting...")) db["restart"] = {'cid': message.chat.id, 'mid': message.message_id, 'branch': branch} save(db) os.execl(sys.executable, sys.executable, *sys.argv) else: await message.edit(f"Upgrade from branch '{branch}' failed (process exited with {proc.returncode}):\n{stdout.decode()}") proc = await asyncio.create_subprocess_shell("git merge --abort") await proc.communicate() cmds.update({'.upgrade':'Upgrade the userbot source'})
await message.edit( f'<a href="tg://user?id={usr.id}">{usr.first_name}</a> is on') elif not usr.last_online_date: await message.edit('This person has disabled his last seen') else: c = int(time.time() - usr.last_online_date) date = datetime.utcfromtimestamp(c).strftime( '{"year":"%y","months":"%-m","days":"%-d","hours":"%-H","minutes":"%-M","seconds":"%-S"}' ) frase = f'<a href="tg://user?id={usr.id}">{usr.first_name}</a> is off for: \n' date = json.loads(date) date["year"] = int(date["year"][1]) date["days"] = int(date["days"]) - 1 date["months"] = int(date["months"]) - 1 if date["year"] != 0: frase += f' » **{date["year"]}** year\n' if date["months"] != 0: frase += f' » **{date["months"]}** months\n' if date["days"] != 0: frase += f' » **{date["days"]}** Days\n' if date["hours"] != "0": frase += f' » **{date["hours"]}** Hours\n' if date["minutes"] != "0": frase += f' » **{date["minutes"]}** Minutes\n' if date["seconds"] != "0": frase += f' » **{date["seconds"]}** Seconds' await message.edit(frase) cmds.update({'.on': 'Check if the person is online'})
import html from config import cmds from pyrogram import Client, Filters @Client.on_message(Filters.command("help", prefixes=".") & Filters.me) async def chelp(client, message): if message.text[6:]: a = message.text[6:] if a in cmds: await message.edit(f'<code>{html.escape(a)}</code>: {cmds[a]}') else: await message.edit( f'Command \'<code>{html.escape(a)}</code>\' not found.') else: a = [ '<code>{}</code>: {}'.format(html.escape(i), cmds[i]) for i in cmds ] await message.edit('\n'.join(a)) cmds.update({'.help': 'List all the commands'})
return f'./{ctime}.png' async def create_pack(anim, message, client, st, packnick, photo, emoji, packname): await message.edit('criando novo pack') # Create pack if not anim: await client.send_message(st, '/newpack') else: await client.send_message(st, '/newanimated') # Set a name for it await client.send_message(st, packnick) # Send the first sticker of the pack await client.send_document(st, photo) # Send the emoji for the first sticker await client.send_message(st, emoji) time.sleep(0.8) # Publish the sticker pack await client.send_message(st, '/publish') if anim: await client.send_message(st, '<'+packnick+'>') # Skip setting sticker pack icon await client.send_message(st, '/skip') # Set sticker pack url await client.send_message(st, packname) await message.edit(f'[kibed](http://t.me/addstickers/{packname})') os.remove(photo) cmds.update({'.kibe':'Kibe a image or sticker'})
import asyncio from config import cmds from pyrogram import Client, Filters @Client.on_message(Filters.command("text", prefixes=".") & Filters.me) async def text(client, message): ch = '' txt = message.text.split(' ', 1)[1] ms = await message.edit('`|`') for i in txt: ch += i ms = await ms.edit(f'`{ch}|`') await asyncio.sleep(0.1) ms = await ms.edit(f'`{ch.strip()}`') await asyncio.sleep(0.1) cmds.update({'.text': 'Show text being typed'})
import os import re import time from config import cmds import chromeprinter from pyrogram import Client, Filters a = chromeprinter.Client() @Client.on_message(Filters.command("print", prefixes=".") & Filters.me) async def prints(client, message): url = message.text.split(' ', 1)[1] await message.edit(f'printing: {url}') ctime = time.time() if re.match(r'^[a-z]+://', url): url = url else: url = 'http://' + url a.make_screenshot(url, f'{ctime}.png') try: await client.send_photo(message.chat.id, f"{ctime}.png") finally: os.remove(f'{ctime}.png') await message.delete() cmds.update({'.print': 'Submit a print of a website'})
txt = a if not langs: langs = 'pt-BR' if not txt and message.reply_to_message: if message.reply_to_message.text: txt = message.reply_to_message.text elif message.reply_to_message.document: path = await message.reply_to_message.download( f'{message.message_id}_{message.reply_to_message.message_id}_tts' ) with open(path) as fp: txt = fp.read() os.remove(fp.name) else: return await message.edit('Nothing to use') gtts = gTTS(txt, lang=langs) ctime = time.time() gtts.save(f'{ctime}.mp3') await message.delete() if message.reply_to_message: await client.send_voice( message.chat.id, f'{ctime}.mp3', reply_to_message_id=message.reply_to_message.message_id) else: await client.send_voice(message.chat.id, f'{ctime}.mp3') os.remove(f'{ctime}.mp3') cmds.update({'.tts': 'Convert text to speech with Google APIs'})
import dicioinformal from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("dicio", prefixes=".") & Filters.me) async def dicio(client, message): txt = message.text.split(' ', 1)[1] a = dicioinformal.definicao(txt)['results'] if a: frase = f'{a[0]["title"]}:\n{a[0]["tit"]}\n\n__{a[0]["desc"]}__' else: frase = 'sem resultado' await message.edit(frase) cmds.update({'.dicio': 'Search from dicioinformal'})
import os import sys from pyrogram import Client, Filters from db import db, save from config import cmds @Client.on_message(Filters.command("restart", prefixes=".") & Filters.me) async def restart(client, message): await message.edit('Reiniciando...') db["restart"] = {'cid': message.chat.id, 'mid': message.message_id} save(db) os.execl(sys.executable, sys.executable, *sys.argv) cmds.update({'.restart': 'Restart a bot'})
from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("save", prefixes=".") & Filters.me) async def save(client, message): if message.reply_to_message: a = await message.reply_to_message.forward("me") if message.text.split(' ', 1)[1]: await a.reply(message.text.split(' ', 1)[1]) elif message.text.split(' ', 1)[1]: await client.send_message(message.from_user.id, message.text.split(' ', 1)[1]) await message.edit('saved') cmds.update({'.save': 'Save a message'})
from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("doc", prefixes=".") & Filters.me) async def doc(client, message): docf = message.text.split(' ', 1)[1] await client.send_document(message.chat.id, docf) await message.delete() cmds.update({'.doc': 'Uploads a locally stored file to the chat'})
import traceback from contextlib import redirect_stdout from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("exec", prefixes=".") & Filters.me) async def execs(client, message): strio = io.StringIO() code = re.split(r"[\n ]+", message.text, 1)[1] exec('async def __ex(client, message): ' + ' '.join('\n ' + l for l in code.split('\n'))) with redirect_stdout(strio): try: await locals()["__ex"](client, message) except: return await message.reply_text(html.escape( traceback.format_exc()), parse_mode="HTML") if strio.getvalue(): out = f"<code>{html.escape(strio.getvalue())}</code>" else: out = "Command executed." await message.edit(out, parse_mode="HTML") cmds.update({'.exec': 'Run commands on python'})
import os import utils from pyrogram import Client, Filters from config import cmds @Client.on_message(Filters.command("backup", prefixes='.') & Filters.me) async def backup(client, message): await message.edit('Ok...') arq = await utils.backup_sources() await client.send_document(chat_id="me", document=arq) await message.edit('Completed') os.remove(arq) cmds.update({'.backup': 'Make a backup'})
if note_obj['type'] == 'text': text = note_obj['value'] message.text = message.text.replace(match[0], html.escape(text)) if changed: await message.edit(message.text) @Client.on_message(Filters.regex(r'.*<ev>.+</ev>') & Filters.me) async def evtag(client, message): for match in re.finditer(r'<ev>(.+?)</ev>', message.text): try: res = (await meval(match[1], locals())) or '<ev></ev>' except: return await message.reply_text(traceback.format_exc()) else: message.text = message.text.replace(match[0], html.escape(str(res))) await message.edit(message.text) cmds.update({ '<py>': 'Run the python code inside the tag and replace it with the result', '<sh>': 'Run the shell command inside the tag and replace it with the result', '<ev>': 'Evaluate the inner content with Python and replace the tag with the result', '<#%note>': "Search for a note named %note (replace with the name of the wanted note) and replace the tag with it", })
import wikipedia @Client.on_message(Filters.command("dwiki", prefixes='.') & Filters.me) async def dwiki(client, message): txt = message.text[7:] a = desciclopedia.search(txt) if a: a = desciclopedia.page(a[0]) await message.edit(f'[{a.title}]({a.url}):\n\n{a.content[:910]+"..."}') else: await message.edit(f"No results found for \"`{txt}`\"") @Client.on_message(Filters.command("wiki", prefixes='.') & Filters.me) async def wiki(client, message): txt = message.text[6:] a = wikipedia.search(txt) wikipedia.set_lang('pt') if a: a = wikipedia.page(a[0]) await message.edit(f'[{a.title}]({a.url}):\n\n{a.content[:910]+"..."}') else: await message.edit(f"No results found for \"`{txt}`\"") cmds.update({ '.wiki': 'Search meaning of a word on wikipedia', '.dwiki': 'Search meaning of a word on desciclopedia' })
if vid: await client.send_video(message.chat.id, filename, width=int(1920), height=int(1080), caption=yt["title"], duration=yt['duration'], thumb=f'{ctime}.png', progress=progress, progress_args=(client, message, a)) else: if ' - ' in yt["title"]: performer, title = yt["title"].rsplit(' - ', 1) else: performer = yt.get('creator') or yt.get('uploader') title = yt["title"] await client.send_audio(message.chat.id, filename, title=title, performer=performer, duration=yt['duration'], thumb=f'{ctime}.png', progress=progress, progress_args=(client, message, a)) await message.delete() os.remove(filename) os.remove(f'{ctime}.png') async def progress(current, total, c, m, a): global last_edit temp = current * 100 / total if last_edit + 3 < time.time(): await c.send_chat_action(m.chat.id, 'UPLOAD_VIDEO') try: await m.edit(a + '\n' + "{:.1f}%".format(temp)) except MessageNotModified: pass finally: last_edit = time.time() cmds.update({'.ytdl':'Download a youtube video'})