import logging logger = logging.getLogger(__name__) HELP = HelpCategory("MATH") HELP.add_help( ["expr", "math"], "convert to LaTeX formula", "this command accepts sympy syntax and will spit out a LaTeX formula as image. " + "You can add the `-latex` argument and pass LaTeX directly.", args="[-latex] <expr>", public=True) @alemiBot.on_message(is_allowed & newFilterCommand( ["expr", "math"], list(alemiBot.prefixes), flags=["-latex"])) async def expr(client, message): args = message.command try: if "arg" not in args: return # nothing to do! expr = args["arg"] logger.info(f"Mathifying \'{expr}\'") await client.send_chat_action(message.chat.id, "upload_document") if "-latex" in args["flags"]: preview(expr, viewer='file', filename='expr.png', dvioptions=[ "-T", "bbox", "-D 300", "--truecolor", "-bg", "Transparent"
HELP.add_help( ["purge", "wipe", "clear"], "batch delete messages", "delete last <n> sent messages from <target> (`-t`). If <n> is not given, will default to 1. " + "If no target is given, only self messages will be deleted. Target can be `@all` and `@everyone`. " + "A keyword can be specified (`-k`) so that only messages containing that keyword will be deleted.", args="[-t <target>] [-k <keyword>] [<number>]", public=False) @alemiBot.on_message(filters.me & newFilterCommand(["purge", "wipe", "clear"], list(alemiBot.prefixes), options={ "target": ["-t"], "keyword": ["-k"] })) async def purge(client, message): args = message.command target = message.from_user.id number = 1 keyword = None try: if "arg" in args: if args["arg"].startswith("@"): # this to support older cmd usage tgt = args["cmd"][0] if tgt == "@me": pass elif tgt in {"@all", "@everyone"}:
traceback.print_exc() await edit_or_reply(message, "`[!] → ` " + str(e)) await client.set_offline() HELP.add_help( ["loc", "location"], "send a location", "send a location for specific latitude and longitude. Both has " + "to be given and are in range [-90, 90]. If a title is given with the `-t` " + "option, the location will be sent as venue.", args="[-t <title>] (<lat> <long> | <loc>)", public=True) @alemiBot.on_message(is_allowed & newFilterCommand( ["loc", "location"], list(alemiBot.prefixes), options={"title": ["-t"]})) async def location_cmd(client, message): args = message.command latitude = 0.0 longitude = 0.0 logger.info("Getting a location") if "arg" in args: try: coords = args["arg"].split(" ", 2) latitude = float(coords[0]) longitude = float(coords[1]) except (ValueError, IndexError): await client.send_chat_action(message.chat.id, "find_location") location = geolocator.geocode(args["arg"]) await client.send_chat_action(message.chat.id, "cancel") if location is None:
if message.reply_to_message is not None: msg = message.reply_to_message if msg.media: try: logger.info("Downloading media") fpath = await client.download_media(msg) await message.edit(get_text(message) + '\n` → ` saved file as {}'.format(fpath)) except Exception as e: await message.edit(get_text(message) + "\n`[!] → ` " + str(e)) else: await message.edit(get_text(message) + "\n`[!] → ` you need to attach or reply to a file, dummy") HELP.add_help("get", "request a file from server", "will upload a file from server to this chat. The path can be " + "global. Use flag `-log` to automatically include `/data/scraped_media`.", args="[-log] <path>") @alemiBot.on_message(filters.me & newFilterCommand("get", list(alemiBot.prefixes), flags=["-log"])) async def download(client, message): if "cmd" not in message.command: return await message.edit(message.text.markdown + "\n`[!] → ` No filename provided") try: logger.info("Uploading media") await client.send_chat_action(message.chat.id, "upload_document") name = message.command["cmd"][0] if "-log" in message.command["flags"]: name = "data/scraped_media/" + name await client.send_document(message.chat.id, name, reply_to_message_id=message.message_id, caption=f'` → {name}`') except Exception as e: await message.edit(message.text.markdown + "\n`[!] → ` " + str(e)) await client.send_chat_action(message.chat.id, "cancel")
f"\n` → ` archive size **{order_suffix(mediasize)}**") await client.set_offline() HELP.add_help( ["query", "q", "log"], "interact with db", "make queries to the underlying database (MongoDB) to request documents. " + "Filters, limits and fields can be configured with arguments.", args="[-l <n>] [-f <{filter}>] <{query}>") @alemiBot.on_message(filters.me & newFilterCommand(["query", "q", "log"], list(alemiBot.prefixes), options={ "limit": ["-l", "-limit"], "filter": ["-f", "-filter"] })) async def query_cmd(client, message): args = message.command try: if "arg" in args: buf = [] q = json.loads(args["arg"]) cursor = None lim = 10 if "limit" in args: lim = int(args["limit"]) lgr.info("Querying db : {args['arg']}") if "filter" in args:
FIGLET_FONTS = pyfiglet.FigletFont.getFonts() FIGLET_FONTS.sort() HELP.add_help( ["slow", "sl"], "make text appear slowly", "edit message adding batch of characters every time. If no batch size is " + "given, it will default to 1. If no time is given, it will default to 0.5s.", args="[-t <time>] [-b <batch>] <text>") @alemiBot.on_message(filters.me & newFilterCommand(["slow", "sl"], list(alemiBot.prefixes), options={ "time": ["-t"], "batch": ["-b"] }), group=2) async def slowtype(client, message): args = message.command if "arg" not in args: return logger.info(f"Making text appear slowly") interval = 0.5 batchsize = 1 if "time" in args: interval = float(args["time"]) if "batch" in args: batchsize = int(args["batch"]) msg = ""
reply_to_message_id=reply_to, caption=f'` → {extra_text} ` **{fname}**') HELP.add_help( "meme", "get a meme", "get a specific meme is a name is given, otherwise a random one. " + "Use argument `-list` to gett all meme names.", public=True, args="[-list] [<name>]") @alemiBot.on_message( is_allowed & newFilterCommand("meme", list(alemiBot.prefixes), flags=["-list"])) async def getmeme(client, message): args = message.command try: await client.send_chat_action(message.chat.id, "upload_photo") reply_to = message.message_id if is_me(message) and message.reply_to_message is not None: reply_to = message.reply_to_message.message_id if "-list" in args["flags"]: logger.info("Getting meme list") memes = os.listdir("data/memes") memes.sort() out = f"` → ` **Meme list** ({len(memes)} total) :\n[ " out += ", ".join(memes) out += "]" await edit_or_reply(message, out)
# ignore INTERRUPT = False HELP.add_help( ["censor", "c"], "immediately delete messages from users", "Start censoring someone in current chat. Use flag `-mass` to toggle mass censorship in current chat. " + "Add flag -free to stop istead stop censoring target. Use flag `-list` to get censored " + "users in current chat. Messages from self will never be censored. More than one target can be specified", args="[-list] [-i] [-mass] <targets>") @alemiBot.on_message(filters.me & newFilterCommand( ["censor", "c"], list(alemiBot.prefixes), flags=["-list", "-i", "-mass"])) async def censor_cmd(client, message): global censoring args = message.command out = message.text.markdown + "\n" changed = False try: if "-list" in args["flags"]: if message.chat.id not in censoring["SPEC"]: out += "` → ` Nothing to display\n" else: usr_list = await client.get_users( censoring["SPEC"][message.chat.id]) for u in usr_list: out += "` → ` {get_username(u)}\n" elif "-mass" in args["flags"]:
HELP.add_help( ["trigger", "trig"], "register a new trigger", "Add a new trigger sequence and corresponding message. Use " + "sigle quotes `'` to wrap triggers with spaces (no need to wrap message). " + "Use this command to list triggers (`-list`), add new (`-n`) and delete (`-d`). " + "Triggers will always work in private chats, but only work when mentioned in groups.", args="( -list | -d <trigger> | -n <trigger> <message> )") @alemiBot.on_message(filters.me & newFilterCommand(["trigger", "trig"], list(alemiBot.prefixes), options={ "new": ["-n", "-new"], "del": ["-d", "-del"] }, flags=["-list"])) async def trigger_cmd(client, message): args = message.command changed = False if "-list" in args["flags"]: logger.info("Listing triggers") out = "\n" for t in triggers: out += f"`'{t}' → ` {triggers[t]}\n" if out == "\n": out += "` → Nothing to display`" await message.edit(message.text.markdown + out)
HELP.add_help( ["translate", "tran", "tr"], "translate to/from", "translate text from a language (autodetected if not specified, `-s`) to another " + "specified lang (defaults to eng, `-d`). It will show the confidence for detected lang. This " + "uses google translate. The lang codes must be 2 letter long (en, ja...)", args="[-s <src>] [-d <des>]", public=True) @alemiBot.on_message(is_allowed & newFilterCommand(["translate", "tran", "tr"], list(alemiBot.prefixes), options={ "src": ["-s", "-src"], "dest": ["-d", "-dest"] })) async def translate_cmd(client, message): args = message.command if "arg" not in args: return await edit_or_reply(message, "`[!] → ` Nothing to translate") tr_options = {} # lmao I can probably pass **args directly if "src" in args: tr_options["src"] = args["src"] if "dest" in args: tr_options["dest"] = args["dest"] try: await client.send_chat_action(message.chat.id, "find_location") q = args["arg"]