def random_khaleesi(bot, update):
    text = update.message.text
    if text is None:
        return
    chat_id = update.message.chat_id
    if not is_command_enabled_for_chat(chat_id, 'random_khaleesi', True):
        return
    if not is_command_enabled_for_chat(chat_id, CMDS['common']['khaleesi']['name']) \
            and not is_command_enabled_for_chat(chat_id, 'random_khaleesi', False):
        return
    if RandomKhaleesi.is_its_time_for_khaleesi(
            chat_id) and RandomKhaleesi.is_good_for_khaleesi(text):
        khaleesed = Khaleesi.khaleesi(text, last_sentense=True)
        RandomKhaleesi.increase_khaleesi_time(chat_id)
        bot.sendMessage(chat_id,
                        '{} 🐉'.format(khaleesed),
                        reply_to_message_id=update.message.message_id)
Beispiel #2
0
def message_reactions(bot: telegram.Bot, update: telegram.Update) -> None:
    """
    Реакция на текст в сообщении
    """
    msg = update.message.text
    if msg is None:
        return

    chat_id = update.message.chat_id
    msg_lower = msg.lower()
    msg_id = update.message.message_id
    user_id = update.message.from_user.id
    if msg_lower == 'сы':
        send_random_sticker(bot, chat_id, [
            'BQADAgADpAADbUmmAAGH7b4k7tGlngI',
            'BQADAgADoAADbUmmAAF4FOlT87nh6wI',
        ])
        return
    if msg_lower == 'без':
        send_random_sticker(bot, chat_id, [
            'BQADAgADXgADRd4ECHiiriOI0A51Ag',
            'BQADAgADWgADRd4ECHfSw52J6tn5Ag',
            'BQADAgADXAADRd4ECC4HwcwErfUcAg',
            'BQADAgADzQADRd4ECNFByeY4RuioAg',
        ])
        return
    if msg_lower == 'кек':
        send_random_sticker_from_stickerset(bot, chat_id, 'Kekopack')
        return
    if is_command_enabled_for_chat(chat_id,
                                   'suicide') and re_suicide.search(msg_lower):
        bot.send_sticker(chat_id, 'CAADAgAD3wEAAsBnlArDbqe-dxMlpgI')
        return
    if is_command_enabled_for_chat(chat_id, CMDS['common']['orzik']['name']) \
            and not check_command_is_off(chat_id, CMDS['common']['orzik']['name']) \
            and 'орзик' in msg_lower:
        orzik_correction(bot, update)
    if is_command_enabled_for_chat(chat_id, CMDS['common']['gdeleha']['name']) \
            and re_gdeleha.search(msg_lower):
        send_gdeleha(bot, chat_id, msg_id, user_id)
        return

    words_lower = msg_lower.split()
    if 'пидор' in words_lower and is_command_enabled_for_chat(
            chat_id, 'пидор'):
        send_pidor(bot, update)
Beispiel #3
0
def photo_reactions(bot: telegram.Bot, update: telegram.Update, img_url=None):
    """
    Вычисляем объекты на фотке.

    """
    if not is_command_enabled_for_chat(update.message.chat_id,
                                       'photo_reactions'):
        return

    key_media_group = f'media_group_reacted:{update.message.media_group_id}'
    if update.message.media_group_id and cache.get(key_media_group):
        return

    if config.google_vision_client:
        call_cats_vision_api(bot, update, key_media_group, img_url)

    if is_command_enabled_for_chat(update.message.chat_id, 'osenya'):
        call_osenya(bot, update, key_media_group, img_url)
Beispiel #4
0
 def check(cls, bot: telegram.Bot, update: telegram.Update) -> None:
     chat_id = update.message.chat_id
     if not is_command_enabled_for_chat(chat_id, 'bayanometer'):
         return
     if update.message.text:
         URL.message_handler(bot, update)
         return
     if len(update.message.photo) > 0:
         Photo.message_handler(bot, update)
         return
Beispiel #5
0
def weekly_stats(bot: telegram.Bot, _) -> None:
    today = datetime.today()
    # эта штука запускается в понедельник ночью, поэтому мы откладываем неделю назад
    prev_monday = (today - timedelta(days=today.weekday() + 7)).replace(
        hour=0, minute=0, second=0, microsecond=0)
    for chat in config.get_config_chats():
        if not is_command_enabled_for_chat(chat.chat_id, 'weeklystat'):
            continue
        send_weekly_for_chat(bot, chat.chat_id, chat.disabled_commands,
                             chat.enabled_commands, prev_monday)
Beispiel #6
0
 def decorator(bot, update):
     chat_id = update.message.chat_id
     cmd_name = get_command_name(update.message.text)
     if not is_command_enabled_for_chat(chat_id, cmd_name):
         return
     if check_user_is_plohish(update):
         return
     if check_command_is_off(chat_id, cmd_name):
         return
     return func(bot, update)
Beispiel #7
0
def daily_midnight(bot: telegram.Bot, _):
    # особый режим сегодняшнего дня
    DayOfManager.midnight(bot)

    # для каждого чата
    for chat in get_config_chats():
        if 'daily_full_moon_check' in chat.enabled_commands:
            send_alert_if_full_moon(bot, chat.chat_id)

    for chat in get_config_chats():
        if is_command_enabled_for_chat(chat.chat_id, 'weeklystat'):
            ReplyDumper.dump(chat.chat_id)
def photo_reactions(bot: telegram.Bot, update: telegram.Update, img_url=None):
    """
    Вычисляем объекты на фотке.

    Используется google vision api:
    * https://cloud.google.com/vision/
    * https://cloud.google.com/vision/docs/reference/libraries
    * https://googlecloudplatform.github.io/google-cloud-python/latest/vision/index.html
    """
    if config.google_vision_client is None:
        return

    if not is_command_enabled_for_chat(update.message.chat_id,
                                       'photo_reactions'):
        return

    key_media_group = f'media_group_reacted:{update.message.media_group_id}'
    if update.message.media_group_id and cache.get(key_media_group):
        return

    call_cats_vision_api(bot, update, key_media_group, img_url)
Beispiel #9
0
def send_welcome(bot: telegram.Bot,
                 chat_id: int,
                 user_id: int,
                 show_errors: bool = False,
                 msg_id=None) -> None:
    cmd_name = 'welcome'
    if not is_command_enabled_for_chat(chat_id, cmd_name):
        return

    cmd_config = CommandConfig(chat_id, cmd_name)
    text = cmd_config.get('text')
    if not text:
        if show_errors:
            bot.send_message(
                chat_id,
                'Приветственный текст еще не указан. Свяжись с разрабом бота',
                reply_to_message_id=msg_id)
        return

    user = User.get(user_id)
    username = user.get_username_or_link()
    msg = text.replace('{username}', username)
    bot.send_message(chat_id, msg, parse_mode=telegram.ParseMode.HTML)
Beispiel #10
0
def twitter_video(bot: telegram.Bot, update: telegram.Update) -> None:
    if not is_command_enabled_for_chat(update.message.chat_id,
                                       'twitter_video'):
        return
    process_message_for_twitter(update.effective_message)
Beispiel #11
0
def instagram_video(bot: telegram.Bot, update: telegram.Update) -> None:
    if not is_command_enabled_for_chat(update.message.chat_id, 'instagram'):
        return
    process_message_for_instagram(update.effective_message)
Beispiel #12
0
 def __get_commands(chat_id, section_name):
     return [
         f"/{cmd['name']} — {cmd['description']}\n"
         for key, cmd in CMDS[section_name].items()
         if is_command_enabled_for_chat(chat_id, cmd['name'])
     ]