예제 #1
0
def manage_all(bot: Bot, update: Update, session, chat_data, job_queue):
    add_user(update.message.from_user, session)
    if update.message.chat.type in ['group', 'supergroup', 'channel']:
        squad = session.query(Squad).filter_by(
            chat_id=update.message.chat.id).first()
        admin = session.query(Admin).filter(
            Admin.user_id == update.message.from_user.id and
            Admin.admin_group in [update.message.chat.id, 0]).first()

        if squad is not None and admin is None and battle_time():
            bot.delete_message(update.message.chat.id,
                               update.message.message_id)

        if not update.message.text:
            return

        text = update.message.text.lower()

        if text.startswith('приветствие:'):
            set_welcome(bot, update)
        elif text == 'помощь':
            help_msg(bot, update)
        elif text == 'покажи приветствие':
            show_welcome(bot, update)
        elif text == 'включи приветствие':
            enable_welcome(bot, update)
        elif text == 'выключи приветствие':
            disable_welcome(bot, update)
        elif text.startswith('затриггерь:'):
            set_trigger(bot, update)
        elif text.startswith('разтриггерь:'):
            del_trigger(bot, update)
        elif text == 'список триггеров':
            list_triggers(bot, update)
        elif text == 'список админов':
            list_admins(bot, update)
        elif text == 'пинг':
            ping(bot, update)
        elif text == 'статистика за день':
            day_activity(bot, update)
        elif text == 'статистика за неделю':
            week_activity(bot, update)
        elif text == 'статистика за бой':
            battle_activity(bot, update)
        elif text == 'разрешить триггерить всем':
            enable_trigger_all(bot, update)
        elif text == 'запретить триггерить всем':
            disable_trigger_all(bot, update)
        elif text in ['админы', 'офицер']:
            admins_for_users(bot, update)
        elif text == 'пинят все':
            pin_all(bot, update)
        elif text == 'хорош пинить':
            not_pin_all(bot, update)
        elif text in ['бандит', 'краб']:
            boss_leader(bot, update)
        elif text in ['жало', 'королева роя']:
            boss_zhalo(bot, update)
        elif text in ['циклоп', 'борода']:
            boss_monoeye(bot, update)
        elif text in ['гидра', 'лич']:
            boss_hydra(bot, update)
        elif text == 'открыть набор':
            open_hiring(bot, update)
        elif text == 'закрыть набор':
            close_hiring(bot, update)
        elif update.message.reply_to_message is not None:
            if text == 'пин':
                pin(bot, update)
            elif text == 'сайлентпин':
                silent_pin(bot, update)
            elif text == 'удоли':
                delete_msg(bot, update)
            elif text == 'свали':
                delete_user(bot, update)
            else:
                trigger_show(bot, update)
        elif 'твои результаты в бою:' in text:
            if update.message.forward_from.id == CWBOT_ID:
                report_received(bot, update)
        else:
            trigger_show(bot, update)

    elif update.message.chat.type == 'private':
        admin = session.query(Admin).filter_by(user_id=update.message.from_user.id).all()
        is_admin = False
        for _ in admin:
            is_admin = True
            break

        if 'order_wait' in chat_data and chat_data['order_wait']:
            order(bot, update, chat_data)

        elif update.message.text:
            text = update.message.text.lower()

            if text == ADMIN_COMMAND_STATUS.lower():
                send_status(bot, update)
            elif text == USER_COMMAND_BACK.lower():
                user_panel(bot, update)
            elif text == USER_COMMAND_SQUAD_REQUEST.lower():
                squad_request(bot, update)
            elif text == ADMIN_COMMAND_RECRUIT.lower():
                list_squad_requests(bot, update)
            elif text == ADMIN_COMMAND_ORDER.lower():
                orders(bot, update, chat_data)
            elif text == ADMIN_COMMAND_SQUAD_LIST.lower():
                squad_list(bot, update)
            elif text == ADMIN_COMMAND_GROUPS.lower():
                group_list(bot, update)
            elif text == ADMIN_COMMAND_FIRE_UP.lower():
                remove_from_squad(bot, update)
            elif text == USER_COMMAND_ME.lower():
                char_show(bot, update)
            elif text == USER_COMMAND_TOP.lower():
                top_about(bot, update)
            elif text == TOP_COMMAND_ATTACK.lower():
                attack_top(bot, update)
            elif text == TOP_COMMAND_DEFENCE.lower():
                def_top(bot, update)
            elif text == TOP_COMMAND_EXP.lower():
                exp_top(bot, update)
            elif text == USER_COMMAND_BUILD.lower():
                send_async(bot,
                           chat_id=update.message.chat.id,
                           text=MSG_IN_DEV,
                           parse_mode=ParseMode.HTML)
            elif text == USER_COMMAND_STATISTICS.lower():
                statistic_about(bot, update)
            elif text == STATISTICS_COMMAND_EXP.lower():
                exp_statistic(bot, update)
            elif text == USER_COMMAND_SQUAD.lower():
                squad_about(bot, update)
            elif text == USER_COMMAND_SQUAD_LEAVE.lower():
                leave_squad(bot, update)
            elif text == USER_COMMAND_CONTACTS.lower():
                send_async(bot,
                           chat_id=update.message.chat.id,
                           text=MSG_IN_DEV,
                           parse_mode=ParseMode.HTML)
            elif 'wait_group_name' in chat_data and chat_data['wait_group_name']:
                add_group(bot, update, chat_data)

            elif update.message.forward_from:
                from_id = update.message.forward_from.id

                if from_id == CWBOT_ID:
                    if text.startswith('📦содержимое склада'):
                        stock_compare(bot, update, chat_data)
                    elif re.search(PROFILE, update.message.text) or re.search(HERO, update.message.text):
                        char_update(bot, update)
                    elif re.search(REPORT, update.message.text):
                        report_received(bot, update)
                    elif re.search(BUILD_REPORT, update.message.text):
                        build_report_received(bot, update)
                    elif re.search(REPAIR_REPORT, update.message.text):
                        repair_report_received(bot, update)
                elif from_id == TRADEBOT_ID:
                    if '📦твой склад с материалами:' in text:
                        trade_compare(bot, update, chat_data)
            elif not is_admin:
                user_panel(bot, update)
            else:
                order(bot, update, chat_data)
        elif not is_admin:
            user_panel(bot, update)
        else:
            order(bot, update, chat_data)
예제 #2
0
def manage_all(bot: Bot, update: Update, session, chat_data, job_queue):
    add_user(update.message.from_user, session)
    if update.message.chat.type in ['group', 'supergroup', 'channel']:
        squad = session.query(Squad).filter_by(
            chat_id=update.message.chat.id).first()
        admin = session.query(Admin).filter(
            Admin.user_id == update.message.from_user.id
            and Admin.admin_group in [update.message.chat.id, 0]).first()

        if squad is not None and admin is None and battle_time():
            bot.delete_message(update.message.chat.id,
                               update.message.message_id)

        if not update.message.text:
            return

        text = update.message.text.lower()

        if text.startswith(CC_SET_WELCOME):
            set_welcome(bot, update)
        elif text == CC_HELP:
            help_msg(bot, update)
        elif text == CC_SQUAD:
            call_squad(bot, update)
        elif text == CC_SHOW_WELCOME:
            show_welcome(bot, update)
        elif text == CC_TURN_ON_WELCOME:
            enable_welcome(bot, update)
        elif text == CC_TURN_OFF_WELCOME:
            disable_welcome(bot, update)
        elif text.startswith(CC_SET_TRIGGER):
            set_trigger(bot, update)
        elif text.startswith(CC_UNSET_TRIGGER):
            del_trigger(bot, update)
        elif text == CC_TRIGGER_LIST:
            list_triggers(bot, update)
        elif text == CC_ADMIN_LIST:
            list_admins(bot, update)
        elif text == CC_PING:
            ping(bot, update)
        elif text == CC_DAY_STATISTICS:
            day_activity(bot, update)
        elif text == CC_WEEK_STATISTICS:
            week_activity(bot, update)
        elif text == CC_BATTLE_STATISTICS:
            battle_activity(bot, update)
        elif text == CC_ALLOW_TRIGGER_ALL:
            enable_trigger_all(bot, update)
        elif text == CC_DISALLOW_TRIGGER_ALL:
            disable_trigger_all(bot, update)
        elif text in CC_ADMINS:
            admins_for_users(bot, update)
        elif text == CC_ALLOW_PIN_ALL:
            pin_all(bot, update)
        elif text == CC_DISALLOW_PIN_ALL:
            not_pin_all(bot, update)
        elif text in CC_BOSS_1:
            boss_leader(bot, update)
        elif text in CC_BOSS_2:
            boss_zhalo(bot, update)
        elif text in CC_BOSS_3:
            boss_monoeye(bot, update)
        elif text in CC_BOSS_4:
            boss_hydra(bot, update)
        elif text == CC_OPEN_HIRING:
            open_hiring(bot, update)
        elif text == CC_CLOSE_HIRING:
            close_hiring(bot, update)
        elif update.message.reply_to_message is not None:
            if text == CC_PIN:
                pin(bot, update)
            elif text == CC_SILENT_PIN:
                silent_pin(bot, update)
            elif text == CC_DELETE:
                delete_msg(bot, update)
            elif text == CC_KICK:
                delete_user(bot, update)
            else:
                trigger_show(bot, update)
        elif re.search(REPORT, update.message.text):
            if update.message.forward_from.id == CWBOT_ID:
                report_received(bot, update)
        else:
            trigger_show(bot, update)

    elif update.message.chat.type == 'private':
        admin = session.query(Admin).filter_by(
            user_id=update.message.from_user.id).all()
        is_admin = False
        for _ in admin:
            is_admin = True
            break

        if 'order_wait' in chat_data and chat_data['order_wait']:
            order(bot, update, chat_data)

        elif update.message.text:
            text = update.message.text.lower()

            if text == ADMIN_COMMAND_STATUS.lower():
                send_status(bot, update)
            elif text == USER_COMMAND_BACK.lower():
                user_panel(bot, update)
            elif text == USER_COMMAND_SQUAD_REQUEST.lower():
                squad_request(bot, update)
            elif text == ADMIN_COMMAND_RECRUIT.lower():
                list_squad_requests(bot, update)
            elif text == ADMIN_COMMAND_ORDER.lower():
                orders(bot, update, chat_data)
            elif text == ADMIN_COMMAND_SQUAD_LIST.lower():
                squad_list(bot, update)
            elif text == ADMIN_COMMAND_GROUPS.lower():
                group_list(bot, update)
            elif text == ADMIN_COMMAND_REPORTS.lower():
                battle_reports_show(bot, update)
            elif text == ADMIN_COMMAND_FIRE_UP.lower():
                remove_from_squad(bot, update)
            elif text == USER_COMMAND_ME.lower():
                char_show(bot, update)
            elif text == USER_COMMAND_TOP.lower():
                top_about(bot, update)
            elif text == TOP_COMMAND_ATTACK.lower():
                attack_top(bot, update)
            elif text == TOP_COMMAND_DEFENCE.lower():
                def_top(bot, update)
            elif text == TOP_COMMAND_EXP.lower():
                exp_top(bot, update)
            elif text == TOP_COMMAND_BUILD.lower():
                week_build_top(bot, update)
            elif text == TOP_COMMAND_BATTLES.lower():
                week_battle_top(bot, update)
            elif text == USER_COMMAND_BUILD.lower():
                send_async(bot,
                           chat_id=update.message.chat.id,
                           text=MSG_IN_DEV,
                           parse_mode=ParseMode.HTML)
            elif text == USER_COMMAND_STATISTICS.lower():
                statistic_about(bot, update)
            elif text == STATISTICS_COMMAND_EXP.lower():
                exp_statistic(bot, update)
            elif text == USER_COMMAND_SQUAD.lower():
                squad_about(bot, update)
            elif text == USER_COMMAND_SQUAD_LEAVE.lower():
                leave_squad_request(bot, update)
            elif text == USER_COMMAND_CONTACTS.lower():
                web_auth(bot, update)
            elif text == ADMIN_COMMAND_ADMINPANEL.lower():
                admin_panel(bot, update)
            elif 'wait_group_name' in chat_data and chat_data[
                    'wait_group_name']:
                add_group(bot, update, chat_data)

            elif update.message.forward_from:
                from_id = update.message.forward_from.id

                if from_id == CWBOT_ID:
                    if text.startswith(STOCK):
                        stock_compare(bot, update, chat_data)
                    elif re.search(PROFILE, update.message.text) or re.search(
                            HERO, update.message.text):
                        char_update(bot, update)
                    elif re.search(REPORT, update.message.text):
                        report_received(bot, update)
                    elif re.search(BUILD_REPORT, update.message.text):
                        build_report_received(bot, update)
                    elif re.search(REPAIR_REPORT, update.message.text):
                        repair_report_received(bot, update)
                elif from_id == TRADEBOT_ID:
                    if TRADE_BOT in text:
                        trade_compare(bot, update, chat_data)
            elif not is_admin:
                user_panel(bot, update)
            else:
                order(bot, update, chat_data)
        elif not is_admin:
            user_panel(bot, update)
        else:
            order(bot, update, chat_data)
예제 #3
0
def manage_all(bot: Bot, update: Update, chat_data, job_queue):
    try:
        add_user(update.message.from_user)
        if update.message.chat.type in ['group', 'supergroup', 'channel']:
            session = Session()
            squad = session.query(Squad).filter_by(
                chat_id=update.message.chat.id).first()
            admin = session.query(Admin).filter(
                Admin.user_id == update.message.from_user.id
                and Admin.admin_group in [update.message.chat.id, 0]).first()
            if squad is not None and admin is None and battle_time():
                bot.delete_message(update.message.chat.id,
                                   update.message.message_id)
            if update.message.text and update.message.text.upper().startswith(
                    'Приветствие:'.upper()):
                set_welcome(bot, update)
            elif update.message.text and 'Твои результаты в бою:' in update.message.text and \
                    update.message.forward_from and update.message.forward_from.id == 265204902:
                job_queue.run_once(
                    del_msg, 2,
                    (update.message.chat.id, update.message.message_id))
            elif update.message.text and update.message.text.upper(
            ) == 'Помощь'.upper():
                help_msg(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Покажи приветствие'.upper():
                show_welcome(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Включи приветствие'.upper():
                enable_welcome(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Выключи приветствие'.upper():
                disable_welcome(bot, update)
            elif update.message.text and update.message.text.upper(
            ).startswith('Затриггерь:'.upper()):
                set_trigger(bot, update)
            elif update.message.text and update.message.text.upper(
            ).startswith('Разтриггерь:'.upper()):
                del_trigger(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Список триггеров'.upper():
                list_triggers(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Список админов'.upper():
                list_admins(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Пинг'.upper():
                ping(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Статистика за день'.upper():
                day_activity(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Статистика за неделю'.upper():
                week_activity(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Статистика за бой'.upper():
                battle_activity(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Разрешить триггерить всем'.upper():
                enable_trigger_all(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Запретить триггерить всем'.upper():
                disable_trigger_all(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'Админы'.upper(), 'офицер'.upper()
            ]:
                admins_for_users(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Пинят все'.upper():
                pin_all(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Хорош пинить'.upper():
                not_pin_all(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'Пин'.upper() and update.message.reply_to_message is not None:
                pin(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'сайлентпин'.upper(
            ) and update.message.reply_to_message is not None:
                silent_pin(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'бандит'.upper(), 'краб'.upper()
            ]:
                boss_leader(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'жало'.upper(), 'королева роя'.upper()
            ]:
                boss_zhalo(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'циклоп'.upper(), 'борода'.upper()
            ]:
                boss_monoeye(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'гидра'.upper(), 'лич'.upper()
            ]:
                boss_hydra(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'открыть набор'.upper():
                open_hiring(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'закрыть набор'.upper():
                close_hiring(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'удоли'.upper(
            ) and update.message.reply_to_message is not None:
                delete_msg(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'свали'.upper(
            ) and update.message.reply_to_message is not None:
                delete_user(bot, update)
            elif update.message.text:
                trigger_show(bot, update)
        elif update.message.chat.type == 'private':
            if update.message.text and update.message.text.upper(
            ) == 'Статус'.upper():
                send_status(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'хочу в отряд'.upper():
                squad_request(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'заявки в отряд'.upper():
                list_squad_requests(bot, update)
            elif update.message.text and update.message.text.upper() in [
                    'Приказы'.upper(), 'пин'.upper()
            ]:
                orders(bot, update, chat_data)
            elif update.message.text and update.message.text.upper() in [
                    'список отряда'.upper(), 'список'.upper()
            ]:
                Thread(target=squad_list, args=(bot, update)).start()
            elif update.message.text and update.message.text.upper(
            ) == 'Группы'.upper():
                group_list(bot, update)
            elif update.message.text and update.message.text.upper(
            ) == 'чистка отряда'.upper():
                remove_from_squad(bot, update)
            elif update.message.forward_from and update.message.forward_from.id == 265204902 and \
                    update.message.text.startswith('📦Содержимое склада'):
                stock_compare(bot, update, chat_data)
            elif update.message.forward_from and update.message.forward_from.id == 278525885 and \
                            '📦Твой склад с материалами:' in update.message.text:
                trade_compare(bot, update, chat_data)
            elif 'wait_group_name' in chat_data and chat_data[
                    'wait_group_name']:
                add_group(bot, update, chat_data)
            elif update.message.text and update.message.forward_from and update.message.forward_from.id == 265204902 and \
                    (re.search(profile, update.message.text) or re.search(hero, update.message.text)):
                char_update(bot, update)
            else:
                order(bot, update, chat_data)
    except Exception as e:
        Session.rollback()