def stat(bot, update): chat_id = update.message.chat_id user_id = update.message.from_user.id chat_type = update.message.chat.type chat_title = update.message.chat.title last_call = cache.get('last_{}'.format(chat_id)) # First request if not last_call: cache.set('last_{}'.format(chat_id), int(time.time()) - 5) last_call = int(time.time()) - 5 # If last request was over 5 seconds ago if (int(time.time()) - last_call) >= 5: if chat_type == 'group' or chat_type == 'supergroup': # Get stats for group info = Stats.get_chat(chat_id) # Get msg text for /stat msg = Stats.stat_format(chat_id, info['msg_count'], info['current_users'], info['top_users'], chat_title) bot.sendMessage(chat_id, msg, parse_mode=ParseMode.MARKDOWN) # Update last call cache.set('last_{}'.format(chat_id), int(time.time())) logger.info('Group {} requested stats'.format(chat_id))