def _exec(): nonlocal msg, raw_args, self def send(text): return self.bot.loop.create_task(msg.respond(text)) exec(util.filter_code_block(raw_args))
async def get_text_input(self, msg, input_arg): if msg.is_reply: reply_msg = await msg.get_reply_message() if reply_msg.document: text = await util.msg_download_file(reply_msg, msg) elif reply_msg.text: text = reply_msg.text else: return ("error", "__Reply to a message with text or a text file, or provide text in command.__") else: if input_arg: text = util.filter_code_block(input_arg).encode() else: return ("error", "__Reply to a message or provide text in command.__") return ("success", text)
def parse_config(self, chat_id, input_cfg): target = 'MissRose_bot' rules = [ 'Rules:', "**Use common sense.** We're all people.", "**Don't spam.** Consider other people's notifications.", "**English only.** This is a universal chat — make sure everyone can understand your messages.", "**Search before asking questions.** It saves everyone's time, including yours.", "**Limit off-topic discussion.** While minor off-topic content is allowed, keep the chat's original topic in mind." ] default_rules_list = ', '.join(f'"{rule}"' for rule in rules) bracket_format = '{}' cfg_err = f'''**Invalid config.** The following options are supported: ``` # Bot to setup target = "{target}" # Default rules rules = [{default_rules_list}] extra_rules = [] # Add ":same" at the end of links to put buttons on the same line # "Rules" is always present as the first button [buttons] "XDA Thread" = "https://forum.xda-developers.com/" GitHub = "https://github.com/"``` {bracket_format}''' input_cfg = util.filter_code_block(input_cfg) if input_cfg.startswith('?') or input_cfg.startswith('help'): return cfg_err.format('') button_map = {'Rules': f'https://t.me/{target}?start=rules_{chat_id}'} if input_cfg: try: cfg = toml.loads(input_cfg) except Exception as e: return cfg_err.format(str(e)) if 'target' in cfg: target = cfg['target'] if 'rules' in cfg: rules = cfg['rules'] if 'extra_rules' in cfg: rules.extend(cfg['extra_rules']) if 'buttons' in cfg: button_map.update(cfg['buttons']) rule_str = '\n • '.join(rules) button_links = [ f'[{name}](buttonurl://{dest})' for name, dest in button_map.items() ] button_str = '\n'.join(button_links) return (target, rule_str, button_str, cfg)