def cmd_qr(self, _, update): query = get_command_args(update.message, help='usage: /qr <query>') self.state.run_async( self._run_script, update, 'query', [query], timeout=self.state.query_timeout )
def cmd_adel(self, _, update): id_ = get_command_args(update.message, help='usage: /adel <id>') id_ = int(id_) alias = Alias.get(id=id_) if alias is not None: alias.delete() return 'done', True return 'not found', True
def cmd_getuser(self, _, update): msg = update.message num = get_command_args(update.message, help='usage: /getuser <number>') if not is_phone_number(num): raise CommandError('invalid phone number') res = self._get_user_link(msg, num) if res is None: res = 'not found: ' + num return res, True, ParseMode.MARKDOWN
def cmd_give(self, _, update): usage = 'usage: /give <item> <count>' args = get_command_args(update.message, help=usage) args = args.split() if len(args) > 2: return usage, True item = int(args[0]) count = int(args[1]) if len(args) > 1 else None if not update.message.reply_to_message: return 'not a reply', True user = User.from_tg(update.message.reply_to_message.from_user) user.add_item(item, count) return 'done'
def cmd_aadd(self, _, update): help_ = 'usage: /aadd <regexp>=<string>' args = get_command_args(update.message, help=help_) match = self.RE_ALIAS.match(args) if match is None: return help_ expr, repl = match.groups() expr = expr.strip() repl = repl.strip() re.compile(expr) chat = Chat.from_tg(update.message.chat) Alias(chat=chat, regexp=expr, replace=repl) return 'done'
def cmd_q(self, _, update): query = get_command_args(update.message, help='usage: /q <query>') db_ = db.get_connection() cursor = db_.cursor() cursor.execute(query) row_count = cursor.rowcount db_.commit() rows = cursor.fetchall() res = '\n'.join(' '.join(repr(col) for col in row) for row in rows) if not res: res = '%s rows affected' % row_count else: res = trunc(res) return res, True
def cmd_stickerset(self, _, update): msg = update.message set_id = get_command_args(msg, help='usage: /stickerset <id>') set_id = int(set_id) set_ = StickerSet.get(id=set_id) if not set_: msg.reply_text('not found', quote=True) else: stickers = list(set_.stickers) if not stickers: msg.reply_text('empty set', quote=True) else: self.state.run_async(reply_sticker_set, update, stickers)
def cmd_qp(self, _, update): args = get_command_args( update.message, help='usage: /qp [plot type] <query>' ) args_ = args.split(maxsplit=1) if len(args_) == 1 or args_[0].lower() in ('select', 'with'): ptype = 'auto' query = args else: ptype = args_[0].lower() query = args_[1] self.state.run_async( self._run_script, update, 'qplot', ['-t', ptype, '-o', '{{TMP}}', query], return_image=True, timeout=self.state.query_timeout )
def cmd_roll(self, _, update): help_ = ('usage:\n' '/roll <dice> [message]\n' '/roll <string> || <string> [|| <string>...]\n') msg = get_command_args(update.message, help=help_) match = self.RE_DICE.match(msg) if match is None: settings = self.state.get_chat_settings(update.message.chat) separator = settings['roll_separator'] strings = [s for s in re.split(separator, msg, re.I) if s] if len(strings) < 2: return help_, True return random.choice(strings), True msg = match.group(1).strip() roll = int(dice.roll(msg)) return ( '<i>%s</i> → <b>%s</b>' % (msg, roll), True, ParseMode.HTML )
def cmd_b64d(self, bot, update): msg = get_command_args(update.message, help='usage: /b64d <base64>') msg = b64decode(msg.encode('utf-8'), validate=True).decode('utf-8') bot.send_message(chat_id=update.message.chat_id, text=msg)
def cmd_b64(self, _, update): msg = get_command_args(update.message, help='usage: /b64 <text>') msg = b64encode(msg.encode('utf-8')).decode('ascii') return msg, True
def cmd_eval(self, _, update): msg = get_command_args(update.message, help='usage: /eval <expression>') msg = safe_eval(msg) msg = re.sub(r'\.?0+$', '', '%.04f' % msg) return msg, True
def cmd_format(self, _, update): msg = get_command_args(update.message, help='usage: /format <text>') msg = self.state.formatter.format(msg) return msg, True, ParseMode.HTML
def cmd_echo(self, bot, update): msg = get_command_args(update.message, help='usage: /echo <text>') bot.send_message(chat_id=update.message.chat_id, text=msg)
def cmd_vid(self, _, update): query = get_command_args(update.message, help='usage: /vid <query>') query = remove_control_chars(query).replace('\n', ' ') query += ' site:youtube.com' self.state.run_async(self._search, update, query)
def cmd_pic(self, _, update): query = get_command_args(update.message, help='usage: /pic <query>') query = remove_control_chars(query).replace('\n', ' ') self.state.run_async(self._search, update, query)