def decorator(bot: telegram.Bot, update: telegram.Update): if update.message.from_user.is_bot: return User.add_user(update.message.from_user) UserStat.add( UserStat.parse_message_stat(update.message.from_user.id, update.message.chat_id, update.message, update.message.parse_entities())) ReplyTop.parse_message(update.message) IStatAddMessage.add_message(update.message) return func(bot, update)
def send_stats(bot, chat_id, chat_title, command, date, tag_salo=False, mat=False): users_count_caption = '' top_chart_caption = '' percent_needed = False salo = False fullstat = True if command: if command == CMDS['admins']['all_stat']['name']: users_count_caption = 'Активных пидоров' top_chart_caption = 'Все пидоры' if command == CMDS['admins']['top_stat']['name']: users_count_caption = 'Активных пидоров' top_chart_caption = 'Топ пидоры' fullstat = False percent_needed = True if command == CMDS['admins']['silent_guys']['name']: users_count_caption = 'Стесняш' top_chart_caption = 'Топ молчуны' percent_needed = True salo = True info = UserStat.get_chat(chat_id, date=date, fullstat=fullstat, salo=salo, tag_salo=tag_salo, mat=mat) percents = None if percent_needed: percents = info['percent'] msg = UserStat.stat_format(chat_title, info['msg_count'], info['users_count'], users_count_caption, info['top_chart'], top_chart_caption, percents) send_long(bot, chat_id, msg) logger.info(f'Group {chat_id} requested stats') if salo: cache.set(f'weekgoal:{chat_id}:salo_uids', info['uids'][0:3], time=MONTH) elif fullstat: cache.set(f'weekgoal:{chat_id}:top_pidori_uids', info['uids'][0:3], time=MONTH)
def make_row(cls, text_messages_count=0, text_messages_with_obscene_count=0, words_count=0, obscene_words_count=0): stat = UserStat(text_messages_count=text_messages_count, text_messages_with_obscene_count=text_messages_with_obscene_count, words_count=words_count, obscene_words_count=obscene_words_count) cls.user_count += 1 user = User(cls.user_count, cls.user_count, f'user{cls.user_count}', f'user{cls.user_count}') return stat, user
def get_top_igor(cls, cid, date=None): monday = cls.__get_current_monday( ) if date is None else cls.__get_date_monday(date) db = cls.__get_db(monday, cid) stats = UserStat.get_chat_stats(cid, date) # подсчитаем всех по отношению игорь-слов к общему количеству слов этого участника igor_by_count = {} for user_stat, user in stats: count = user_stat.all_messages_count # учитываем только тек, кто написал от 30 сообщений if count < 30 or user_stat.words_count < 500: continue if user.uid not in db: continue igor_by_count[user.uid] = db[user.uid] / count if len(igor_by_count) > 0: uid, _ = cls.__sort_dict(igor_by_count)[0] elif len(stats) == 0: return None else: _, user = random.choice(stats) uid = user.uid return uid
def send_all_stat_handler(bot: telegram.Bot, update: telegram.Update) -> None: message: telegram.Message = update.message chat_id = message.chat_id chat_stats = UserStat.get_chat_stats(chat_id) rs = RedisChatStatistician(chat_id) rs.load() text = rs.chat_statistician.show_chat_stat(chat_stats) bot.send_message(chat_id, text, parse_mode=ParseMode.HTML)
def send_whois(bot: telegram.Bot, update: telegram.Update, send_to_cid: int, find_in_cid: int) -> None: requestor_id = update.message.from_user.id msg_id = update.message.message_id text = update.message.text.split() reply_to_msg = update.message.reply_to_message bot.sendChatAction(send_to_cid, ChatAction.TYPING) if reply_to_msg: user_id = reply_to_msg.from_user.id username = '******' + reply_to_msg.from_user.username else: if len(text) < 2: bot.sendMessage(send_to_cid, 'Укажи имя, пидор.', reply_to_message_id=msg_id) return username = text[1] user_id = User.get_id_by_name(username) if not user_id: for entity, entity_text in update.message.parse_entities().items(): if entity.type == 'text_mention': user_id = entity.user.id if not user_id: bot.sendMessage(send_to_cid, f'Нет такого: {username}', reply_to_message_id=msg_id) return info = UserStat.get_user_position(user_id, find_in_cid, update.message.date) msg = UserStat.me_format_position(username, info['msg_count'], info['position'], user_id) msg_userstat = UserStat.me_format(update.message.date, user_id, find_in_cid) if msg_userstat != '': msg_userstat = f"\n\n{msg_userstat}" bot.sendMessage(send_to_cid, f'{msg}{msg_userstat}', reply_to_message_id=msg_id, parse_mode=ParseMode.HTML) logger.info(f'User {requestor_id} requested stats for user {user_id}')
def send_mystat(bot: telegram.Bot, update: telegram.Update, send_to_cid: int, find_in_cid: int) -> None: msg_id = update.message.message_id user_id = update.message.from_user.id username = update.message.from_user.username bot.sendChatAction(send_to_cid, ChatAction.TYPING) info = UserStat.get_user_position(user_id, find_in_cid, update.message.date) msg = UserStat.me_format_position(username, info['msg_count'], info['position'], user_id) msg_userstat = UserStat.me_format(update.message.date, user_id, find_in_cid) if msg_userstat != '': msg_userstat = f"\n\n{msg_userstat}" bot.sendMessage(send_to_cid, f'{msg}{msg_userstat}', reply_to_message_id=msg_id, parse_mode=ParseMode.HTML) logger.info(f'User {user_id} requested stats')
def send_top_kroshka(bot, chat_id, monday): kroshka = UserStat.get_top_kroshka(chat_id, monday) if not kroshka: return cache.set(f'weekgoal:{chat_id}:kroshka_uid', kroshka.uid, time=MONTH) emoj = ''.join(random.sample(list(emoji.UNICODE_EMOJI), 5)) she = 'Она' if kroshka.female else 'Он' msg = f'Замечательная крошка-картошка <a href="tg://user?id={kroshka.uid}">🥔</a> недели —\n\n<b>{kroshka.fullname}</b> ❤️❤️❤️\n\n{she} получает эти прекрасные эмодзи: {emoj}' try: send_long(bot, chat_id, msg) except Exception: msg = f'Замечательная крошка-картошка 🥔 недели —\n\n<b>{kroshka.fullname}</b> ❤️❤️❤️\n\n{she} получает эти прекрасные эмодзи: {emoj}' send_long(bot, chat_id, f'{msg}\n\n{kroshka.get_username_or_link()}')
def send_topmat(bot: telegram.Bot, send_to_cid: int, stats_from_cid: int, date=None) -> None: monday = get_current_monday() if date is None else get_date_monday(date) stats = UserStat.get_chat_stats(stats_from_cid, date) words = get_words_from_cache(monday, stats_from_cid) users_msg_stats = get_mat_users_msg_stats(stats) msg = format_msg( 'Стата по мату', { 'header_stats': get_header_stats(stats), 'users_msg_stats': users_msg_stats, 'users_words_stats': get_mat_users_words_stats(stats), 'words_stats': get_words_stats(words), }) set_top_mater(stats_from_cid, users_msg_stats) bot.send_message(send_to_cid, msg, parse_mode=telegram.ParseMode.HTML)
def year(bot: telegram.Bot, update: telegram.Update) -> None: uid = update.message.chat_id logger.info(f'id {uid} /year') if uid != CONFIG.get('debug_uid', None): return from src.models.user_stat import UserStat from src.modules.weeklystat import send_long bot.send_chat_action(uid, telegram.chataction.ChatAction.TYPING) cid = CONFIG.get('anon_chat_id') # cid = -48952907 year = 2017 info = UserStat.get_chat_year(cid, year) msg = f'<b>Rapture {year}</b>\n' \ f'Нас: {info["users_count"]}\n' \ f'Сообщений: {info["msg_count"]}\n' msg += '\n' msg += info['top_chart'].replace('<b>', '').replace('</b>', '') send_long(bot, CONFIG.get('anon_chat_id'), msg)