def send_activity_logs(bot, update, args=None, level=Statistic.INFO): num = 200 if args: try: num = int(args[0]) num = min(num, 500) except: pass uid = update.effective_user.id recent_statistic = Statistic.select().order_by(Statistic.date.desc()).limit(num) recent_statistic = list(reversed(recent_statistic)) step_size = 30 for i in range(0, len(recent_statistic), step_size): items = recent_statistic[i : i + step_size] text = "\n".join(x.md_str() for x in items) bot.formatter.send_message(uid, text)
def send_statistic(bot, update): interesting_actions = [ "explore", "menu", "command", "request", "made changes to their suggestion:", "issued deletion of conversation in BotListChat", ] stats = ( Statistic.select(Statistic, fn.COUNT(Statistic.entity).alias("count")) .where(Statistic.action << interesting_actions) .group_by(Statistic.action, Statistic.entity) ) maxlen = max(len(str(x.count)) for x in stats) text = "\n".join( "`{}▪️` {} {}".format(str(s.count).ljust(maxlen), s.action.title(), s.entity) for s in stats ) bot.formatter.send_message(update.effective_chat.id, text, parse_mode="markdown")