示例#1
0
def stats(message):
    users_count = len(my_data.list_users())
    alerts_count = 0

    for user in my_data.data.values():
        alerts_count += len(user.get('alert_users', []))

    with open(config.FileLocation.bot_logs, 'r', encoding='utf-8') as file:
        file_text = file.read()

    user_commands = re.findall('(?:User )(\d+)(?:.*called)', file_text)
    user_callbacks = re.findall('(?:User )(\d+)(?:.*callbacked)', file_text)
    commands = re.findall('(?:User.*called )(/\w*)(?:\s)', file_text)

    user_commands_counter = Counter(user_commands)
    user_callbacks_counter = Counter(user_callbacks)

    user_id = str(message.from_user.id)
    user_commands_count = user_commands_counter[user_id]
    user_callbacks_count = user_callbacks_counter[user_id]

    user_pos = user_commands_counter.most_common().index(
        (user_id, user_commands_count)) + 1
    all_commands_count = sum(user_commands_counter.values())
    all_callbacks_count = sum(user_callbacks_counter.values())

    days_from_birthday = (datetime.today() -
                          datetime(year=2018, month=2, day=9)).days

    text = f'Бот родился 9 февраля 2018 и сегодня его {bold(days_from_birthday)} день!\n' \
           f'Пользователей бота: {bold(users_count)}\n' \
           f'Команд вызвано: {bold(all_commands_count)}\n' \
           f'Суммарно отслеживаемых сотрудников: {bold(alerts_count)}\n\n'

    text += 'Вы использовали {} команд и находитесь на {} месте, вызвав {}% команд\n\n' \
            ''.format(bold(user_commands_count),
                      bold(user_pos),
                      bold(round(100 * user_commands_count / all_commands_count, 2)))

    text += 'Вами нажато кнопок: {}, всеми: {}\n\n'.format(
        bold(user_callbacks_count), bold(all_callbacks_count))

    top_count = 5
    commands_counter = Counter(commands)
    commands_most = commands_counter.most_common(top_count)
    text += f'Топ {top_count} команд по вызовам:\n'
    for i in range(top_count):
        text += f'  {i+1}. {commands_most[i][0]} — {bold(commands_most[i][1])}\n'

    my_bot.reply_to(message, text, parse_mode='HTML')
示例#2
0
def command_notify_all_test(message):
    user_action_log(message, 'called ' + message.text)
    split = message.text.split(' ', 1)
    if len(split) > 1:
        subs_notify([message.from_user.id],
                    '{}\n\n{}'.format(bold('Оповещение пользователей бота'),
                                      split[1]))
示例#3
0
def command_notify_all(message):
    user_action_log(message, 'called ' + message.text)
    split = message.text.split(' ', 1)
    if len(split) > 1:
        subs_notify(my_data.list_users(),
                    '{}\n\n{}'.format(bold('Оповещение пользователей бота'),
                                      split[1]),
                    me=message.from_user.id)

    else:
        my_bot.reply_to(message, 'Использование: /notify_all [ваше сообщение]')
示例#4
0
def on_vacation_now(message):
    vacations = _on_vacation_get(datetime.date(datetime.today()))
    if vacations:
        text = '🌴 {}:\n'.format(bold('Сейчас в отпуске'))
        for item in vacations:
            text += '{} — до {}\n'.format(code(item[0]),
                                          item[1].strftime('%d.%m'))
    else:
        text = '💻️ Сейчас нет сотрудников в отпуске!\n'

    my_bot.reply_to(message, text, parse_mode='HTML')
示例#5
0
    def register_user(self, message):
        if not self.is_registered(message):
            sent = my_bot.send_message(message.from_user.id,
                                       bold('❗️ Авторизация') +
                                       '\n\nВведи пароль:',
                                       parse_mode='HTML')
            my_bot.register_next_step_handler(sent, self.check_password)
            return

        sent = my_bot.send_message(
            message.from_user.id,
            '❓ Твой номер в {}?\nНапример: 5059, 5060 и т.д.'.format(
                self.asc_link),
            parse_mode='HTML')
        my_bot.register_next_step_handler(sent, self.set_user_name)
示例#6
0
def command_reply(message):
    user_action_log(message, 'called ' + message.text)
    if hasattr(message, 'reply_to_message'):
        split = message.text.split(' ', 1)
        if len(split) > 1:
            replying_msg = message.reply_to_message
            if hasattr(replying_msg, 'entities'):
                user_ids = [
                    x.user.id for x in replying_msg.entities
                    if x.type == 'text_mention'
                ]
                if len(user_ids) == 1:
                    my_bot.send_message(user_ids[0],
                                        '{}: {}'.format(
                                            bold('Разработчик'), split[1]),
                                        parse_mode='HTML')
                    my_bot.reply_to(message, 'Сообщение отправлено!')
                    return
    my_bot.reply_to(message,
                    'Использовать с ответом на фидбек: /reply [ваш ответ]')
示例#7
0
 def in_office_now_text(self, user_id=0):
     in_office_txt = self._make_in_office_request()
     for alert_user in my_data.data.get(str(user_id), {}).get('alert_users', []):
         in_office_txt = in_office_txt.replace(alert_user, bold(alert_user))
     return '👥 ' + in_office_txt