Ejemplo n.º 1
0
def precheck_query_inline(q):
    # print("precheck_query_inline")
    # print(q)
    user = User(q.from_user.id, q.from_user.first_name, q.from_user.username)
    log.debug("%s is trying to create pre-check" % user)
    if not hlp.IsUserAdmin(user):  # non-admins cannot post votes
        log.error("Failed (not an admin)")
        hlp.SendHelpNonAdmin(q)
        bot.answer_callback_query(q.id)
        return
    if hlp.CanStartNewPrecheck():
        res = types.InlineQueryResultArticle(
            'precheck',
            title='Создать чек перед ВГ',
            description='🗓✅💤❌',
            input_message_content=types.InputTextMessageContent(
                "📝 *Чек перед ВГ*", parse_mode="markdown"),
            thumb_url="https://i.ibb.co/G79HtRG/precheck.png",
            reply_markup=kb.KEYBOARD_PRECHECK)
        bot.answer_inline_query(q.id, [res], is_personal=True, cache_time=2)
    else:
        log.error(
            "Trying to setup another pre-check while current is not finished")
        error_text = "Уже имеется активный чек"
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text=error_text,
                                switch_pm_parameter="existing_precheck")
Ejemplo n.º 2
0
def crystals_query_inline(q):
    # print("crystals_query_inline")
    # print(q)
    user = User(q.from_user.id, q.from_user.first_name, q.from_user.username)
    log.debug("%s is trying to create crystals check" % user)
    if not hlp.IsUserAdmin(user): # non-admins cannot post votes
        log.error("Failed (not an admin)")
        hlp.SendHelpNonAdmin(q)
        bot.answer_callback_query(q.id)
        return
    if hlp.CanStartNewCryscheck():
        ranges = common.settings.GetSetting("crystals_ranges")
        kb.SetupCrystalsKeyboard(maxvalue=ranges[0], step=ranges[1])
        res = types.InlineQueryResultArticle('cryscheck',
                                            title='Создать чек по кри',
                                            description='0 - %d, шаг %d' % ranges,
                                            input_message_content=types.InputTextMessageContent(ICON_CRYSTAL+" *Чек по кри*", parse_mode="markdown"),
                                            thumb_url="https://i.ibb.co/b7XSWQr/crystal.png",
                                            reply_markup=kb.KEYBOARD_CRYSTALS)
        bot.answer_inline_query(q.id, [res], is_personal=True, cache_time=2)
    else:
        log.error("Trying to setup another crystals check while current is not finished")
        error_text = "Уже имеется активный чек по кри"
        bot.answer_inline_query(q.id, [], is_personal=True, cache_time=2,
                                switch_pm_text=error_text, switch_pm_parameter="existing_crystals")
Ejemplo n.º 3
0
def numbers_query_inline(q):
    # print("numbers_query_inline")
    # print(q)
    user = User(q.from_user.id, q.from_user.first_name, q.from_user.username)
    log.debug("%s is trying to create numbers check" % user)
    if not hlp.IsUserAdmin(user):  # non-admins cannot post votes
        log.error("Failed (not an admin)")
        hlp.SendHelpNonAdmin(q)
        bot.answer_callback_query(q.id)
        return
    if hlp.CanStartNewBattle():
        log.error("Trying to setup numbers check with no current battle")
        error_text = "Отсутствует активный бой"
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text=error_text,
                                switch_pm_parameter="existing_battle")
        return
    res, numbers = hlp.IsNumbersQuery(q)
    if res:
        if hlp.CanStartNewNumbers():
            text = 'Добавить прогресс номеров'
            if len(numbers) == 1:
                text2 = 'по скринам (%s)' % numbers[0]
                kb.SetupNumbersKeyboard(count=int(numbers[0]))
            else:
                text2 = 'по игре (%s)' % ' '.join(str(num) for num in numbers)
                kb.SetupNumbersKeyboard(ingame_nums=numbers)
            res = types.InlineQueryResultArticle(
                'numbers',
                title=text,
                description=text2,
                input_message_content=types.InputTextMessageContent(
                    ICON_NUMBERS + " *Прогресс номеров*",
                    parse_mode="markdown"),
                thumb_url="https://i.ibb.co/JRRMLjv/numbers.png",
                reply_markup=kb.KEYBOARD_NUMBERS)
            bot.answer_inline_query(q.id, [res],
                                    is_personal=True,
                                    cache_time=2)
        elif not hlp.CanStartNewNumbers():
            log.error(
                "Trying to setup another numbers check while current has not reached 500/1000"
            )
            error_text = "Уже имеется активный чек номеров"
            bot.answer_inline_query(q.id, [],
                                    is_personal=True,
                                    cache_time=2,
                                    switch_pm_text=error_text,
                                    switch_pm_parameter="existing_numbers")
    else:
        log.error("Failed (invalid query)")
        error_text = "Неверный формат запроса"
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text=error_text,
                                switch_pm_parameter="existing_numbers")
Ejemplo n.º 4
0
def battle_query_inline(q):
    # print("battle_query_inline")
    # print(q)
    user = User(q.from_user.id, q.from_user.first_name, q.from_user.username)
    log.debug("%s is trying to create battle check" % user)
    if not hlp.IsUserAdmin(user):  # non-admins cannot post votes
        log.error("Failed (not an admin)")
        hlp.SendHelpNonAdmin(q)
        bot.answer_callback_query(q.id)
        return
    res, time, comment = hlp.IsCheckTimeQuery(q)
    if res:
        if hlp.CanStartNewBattle() or hlp.CanStopCurrentBattle():
            # stop current battle as the time is passed anyway
            # to help admin not doing exact battle stop but start another with auto-stopping the previous
            if hlp.CanStopCurrentBattle():
                q.data = kb.CHECK_CONTROL_OPTIONS[2]
                q.inline_message_id = common.current_battle.check_id
                battle_control(q)
            desc = ICON_CHECK + ICON_RAGE + ICON_FAST + ICON_ARS + ICON_THINK + ICON_CANCEL
            if comment:
                desc += "\n" + comment
            res = types.InlineQueryResultArticle(
                'battle',
                title='[%s] Создать чек на бой' % time,
                description=desc,
                input_message_content=types.InputTextMessageContent(
                    ICON_SWORDS + " *Бой*: %s" % time, parse_mode="markdown"),
                thumb_url="https://i.ibb.co/jb9nVCm/battle.png",
                reply_markup=kb.KEYBOARD_CHECK)
            bot.answer_inline_query(q.id, [res],
                                    is_personal=True,
                                    cache_time=2)
        else:
            log.error(
                "Trying to setup another battle while current is not finished")
            error_text = "Уже имеется активный бой в %0.2d:%0.2d" % (
                *common.current_battle.GetTime(start=True), )
            bot.answer_inline_query(q.id, [],
                                    is_personal=True,
                                    cache_time=2,
                                    switch_pm_text=error_text,
                                    switch_pm_parameter="existing_battle")
    else:
        log.error("Failed (invalid query)")
        error_text = "Неверный формат запроса"
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text=error_text,
                                switch_pm_parameter="existing_battle")
Ejemplo n.º 5
0
def arsenal_query_inline(q):
    # print("arsenal_query_inline")
    # print(q)
    user = User(q.from_user.id, q.from_user.first_name, q.from_user.username)
    log.debug("%s is trying to create arsenal check" % user)
    if not hlp.IsUserAdmin(user):  # non-admins cannot post votes
        log.error("Failed (not an admin)")
        hlp.SendHelpNonAdmin(q)
        bot.answer_callback_query(q.id)
        return
    if hlp.CanStartNewBattle():
        log.error("Trying to setup arsenal check with no current battle")
        error_text = "Отсутствует активный бой"
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text=error_text,
                                switch_pm_parameter="existing_battle")
        return
    res, time = hlp.IsArsQuery(q)
    if res:
        if hlp.CanStartNewArs():
            res = types.InlineQueryResultArticle(
                'arsenal',
                title='Добавить прогресс арсенала',
                description=ICON_ARS + ' |████--| Х/120\nЯрость в %s' % time,
                input_message_content=types.InputTextMessageContent(
                    ICON_ARS + " *Прогресс арсенала:* 0/120",
                    parse_mode="markdown"),
                thumb_url="https://i.ibb.co/WfxPRks/arsenal.png",
                reply_markup=kb.KEYBOARD_ARS)
            bot.answer_inline_query(q.id, [res],
                                    is_personal=True,
                                    cache_time=2)
        else:
            log.error(
                "Trying to setup another arsenal check while current has not been fired"
            )
            error_text = "Уже имеется активный чек арсенала"
            bot.answer_inline_query(q.id, [],
                                    is_personal=True,
                                    cache_time=2,
                                    switch_pm_text=error_text,
                                    switch_pm_parameter="existing_arsenal")
    else:
        bot.answer_inline_query(q.id, [],
                                is_personal=True,
                                cache_time=2,
                                switch_pm_text="Неверный формат запроса",
                                switch_pm_parameter="existing_arsenal")
Ejemplo n.º 6
0
def arsenal_control(call):
    # print("arsenal_control")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    log.debug("%s is trying to control arsenal check" % user)
    if not hlp.IsUserAdmin(user):
        bot.answer_callback_query(
            call.id, "Только офицеры могут управлять чеком арсенала!")
        log.error("Failed (not an admin)")
        return
    userChoice = call.data
    if userChoice == kb.ARS_CONTROL_OPTIONS[0]:  # stop
        if common.current_arscheck and message_id == common.current_arscheck.check_id:
            common.current_arscheck.DoEndArsenal()
            bot.edit_message_text(
                common.current_arscheck.GetText(),
                inline_message_id=common.current_arscheck.check_id,
                parse_mode="markdown")
            # unpin rage time message
            bot.unpin_all_chat_messages(common.warchat_id)
            bot.answer_callback_query(call.id, "🏁 Чек арсенала завершен")
            hlp.LogEvent("🏁 %s завершил чек арсенала" %
                         user.GetString(with_link=False))
            return
    log.error("Ars check not found!")
    bot.answer_callback_query(
        call.id, "Неверный чек арсенала! Пожалуйста, создайте новый")
Ejemplo n.º 7
0
def precheck_check_user(call):
    # print("precheck_check_user")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    userChoice = call.data
    log.debug("%s is trying to vote for pre-check (%s)" %
              (user, userChoice.replace(cb.PRECHECK_CALLBACK_PREFIX, "")))
    if not hlp.CanStartNewPrecheck():
        if message_id == common.current_precheck.check_id:
            ret = common.current_precheck.CheckUser(user, userChoice)
            if (ret):
                bot.edit_message_text(common.current_precheck.GetText(),
                                      inline_message_id=message_id,
                                      parse_mode="markdown",
                                      reply_markup=kb.KEYBOARD_PRECHECK)
                bot.answer_callback_query(
                    call.id,
                    common.current_precheck.GetVotedText(user, userChoice))
            else:
                log.error("Failed")
                bot.answer_callback_query(
                    call.id, "Вы уже проголосовали (%s)" %
                    userChoice.replace(cb.PRECHECK_CALLBACK_PREFIX, ""))
            return
    log.error("Pre-check not found!")
    bot.answer_callback_query(call.id)
Ejemplo n.º 8
0
def precheck_control(call):
    # print("precheck_control")
    # print(call)
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    log.debug("%s is trying to control pre-check" % user)
    if not hlp.IsUserAdmin(user):
        bot.answer_callback_query(call.id,
                                  "Только офицеры могут управлять чеком!")
        log.error("Failed (not an admin)")
        return
    userChoice = call.data
    if userChoice == kb.PRECHECK_CONTROL_OPTIONS[0]:  # stop
        common.current_precheck.DoEndPrecheck()
        bot.edit_message_text(
            common.current_precheck.GetText(),
            inline_message_id=common.current_precheck.check_id,
            parse_mode="markdown")
        bot.answer_callback_query(call.id, "🏁 Чек завершен")
        return
    log.error("Pre-check not found!",
              "Неверный чек ВГ! Пожалуйста, создайте новый")
Ejemplo n.º 9
0
def battle_control(call):
    # print("battle_control")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    log.debug("%s is trying to control battle" % user)
    if not hlp.IsUserAdmin(user):
        bot.answer_callback_query(call.id,
                                  "Только офицеры могут управлять боем!")
        log.error("Failed (not an admin)")
        return
    userChoice = call.data
    need_send_notification = True
    if common.current_battle and message_id == common.current_battle.check_id:
        notification_text = ""
        if userChoice == kb.CHECK_CONTROL_OPTIONS[0]:  # roll
            common.current_battle.DoRollBattle()
            notification_text = ICON_ROLL + " Крутит"
            bot.edit_message_text(
                common.current_battle.GetText(),
                inline_message_id=common.current_battle.check_id,
                parse_mode="markdown",
                reply_markup=common.current_battle.keyboard)
            common.current_battle.BattleRollNotifyActiveUsers(except_user=user)
        elif userChoice == kb.CHECK_CONTROL_OPTIONS[1]:  # start
            common.current_battle.DoStartBattle()
            notification_text = ICON_SWORDS + " Бой начался"
            bot.edit_message_text(
                common.current_battle.GetText(),
                inline_message_id=common.current_battle.check_id,
                parse_mode="markdown",
                reply_markup=common.current_battle.keyboard)
            common.current_battle.BattleStartNotifyActiveUsers(
                except_user=user)
        elif userChoice == kb.CHECK_CONTROL_OPTIONS[2]:  # stop
            if not common.current_battle.is_started:  # if battle was cancelled - do not send notification
                need_send_notification = False
                notification_text = ICON_CANCEL + " Бой отменен"
            else:  # unpin other battle messages
                bot.unpin_all_chat_messages(common.warchat_id)
                need_send_notification = False  # disable annoying useless message
                notification_text = ICON_FINISH + " Бой завершен"
            reset_battlechecks(call)
            # do not notify about roll / stop
        if need_send_notification:
            bot.send_message(common.warchat_id,
                             notification_text + " (%s)" % user.GetString(),
                             parse_mode="markdown")
            log.debug("Battle status notification posted: %s" %
                      notification_text)
        hlp.LogEvent(notification_text +
                     " (%s)" % user.GetString(with_link=False))
        bot.answer_callback_query(call.id, notification_text)
        return
    log.error("Battle not found!")
    bot.answer_callback_query(call.id,
                              "Неверный чек боя! Пожалуйста, создайте новый")
Ejemplo n.º 10
0
def arsenal_check_user(call):
    # print("arsenal_check_user")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    userChoice = call.data
    log.debug("%s is trying to vote for arsenal (%s)" %
              (user, userChoice.replace(cb.ARS_CALLBACK_PREFIX, "")))
    if common.current_arscheck and message_id == common.current_arscheck.check_id:
        is_guide_training = False
        battle_object = common.current_arscheck
    elif user._id in common.user_guiding.keys(
    ):  # guide battle example workaround
        is_guide_training = True
        if common.user_guiding[user._id].IsTrainingStage(
        ):  # using check is allowed only at several steps of guide
            battle_object = common.user_guiding[user._id].demonstration
        else:
            log.error("Not at training stage, aborting")
            bot.answer_callback_query(
                call.id, "На данный момент использование чека недоступно")
            return
    else:
        battle_object = None
    if battle_object:
        if battle_object.Increment(user,
                                   userChoice,
                                   notify=not is_guide_training):
            if is_guide_training:
                bot.edit_message_text(battle_object.GetText(),
                                      user._id,
                                      battle_object.check_id,
                                      parse_mode="markdown",
                                      reply_markup=kb.KEYBOARD_ARS)
            else:
                bot.edit_message_text(battle_object.GetText(),
                                      inline_message_id=message_id,
                                      parse_mode="markdown",
                                      reply_markup=kb.KEYBOARD_ARS)
        else:
            log.error("Failed")
        bot.answer_callback_query(call.id)
        return
    log.error("Ars check not found!")
    bot.answer_callback_query(
        call.id, "Неверный чек арсенала! Пожалуйста, создайте новый")
Ejemplo n.º 11
0
def numbers_check_user(call):
    # print("numbers_check_user")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    log.debug("%s is trying to vote for numbers (%s)" %
              (user, call.data.replace(cb.NUMBERS_CALLBACK_PREFIX, "")))
    if common.current_numcheck and message_id == common.current_numcheck.check_id:
        is_guide_training = False
        battle_object = common.current_numcheck
    elif user._id in common.user_guiding.keys(
    ):  # guide battle example workaround
        is_guide_training = True
        if common.user_guiding[user._id].IsTrainingStage(
        ):  # using check is allowed only at several steps of guide
            battle_object = common.user_guiding[user._id].demonstration
        else:
            log.error("Not at training stage, aborting")
            bot.answer_callback_query(
                call.id, "На данный момент использование чека недоступно")
            return
    else:
        battle_object = None
    if battle_object:
        if battle_object.CheckUser(user, call.data):
            if battle_object.Is1000(
            ):  # if reached 1000 - no need to continue numbers check
                battle_object.DoEndCheck()
            if is_guide_training:
                bot.edit_message_text(battle_object.GetText(),
                                      user._id,
                                      battle_object.check_id,
                                      parse_mode="markdown",
                                      reply_markup=battle_object.keyboard)
            else:
                bot.edit_message_text(battle_object.GetText(),
                                      inline_message_id=message_id,
                                      parse_mode="markdown",
                                      reply_markup=battle_object.keyboard)
                battle_object.CheckNotifyIfAchieved(user)
        bot.answer_callback_query(call.id)
        return
    log.error("Numbers check not found!")
    bot.answer_callback_query(
        call.id, "Неверный чек номеров! Пожалуйста, создайте новый")
Ejemplo n.º 12
0
def crystals_check_user(call):
    # print("crystals_check_user")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name, call.from_user.username)
    userChoice = call.data
    log.debug("%s is trying to vote for crystals (%s)" % (user, userChoice.replace(cb.CRYSTALS_CALLBACK_PREFIX, "")))
    if not hlp.CanStartNewCryscheck():
        if message_id == common.current_cryscheck.check_id:
            ret = common.current_cryscheck.CheckUser(user, userChoice)
            if (ret):
                bot.edit_message_text(common.current_cryscheck.GetText(), inline_message_id=message_id, 
                                    parse_mode="markdown", reply_markup=kb.KEYBOARD_CRYSTALS)
                bot.answer_callback_query(call.id, common.current_cryscheck.GetVotedText(user, userChoice))
            else:
                log.error("Failed")
                bot.answer_callback_query(call.id, "Вы уже проголосовали (%s)" % userChoice.replace(cb.CRYSTALS_CALLBACK_PREFIX, ""))
            return
    log.error("Crystals check not found!")
    bot.answer_callback_query(call.id, "Неверный чек по кри! Пожалуйста, создайте новый")
Ejemplo n.º 13
0
def numbers_control(call):
    # print("numbers_control")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    log.debug("%s is trying to control numbers check" % user)
    if not hlp.IsUserAdmin(user):
        bot.answer_callback_query(
            call.id, "Только офицеры могут управлять чеком номеров!")
        log.error("Failed (not an admin)")
        return
    userChoice = call.data
    if common.current_numcheck and message_id == common.current_numcheck.check_id:
        if userChoice == kb.NUMBERS_CONTROL_OPTIONS[0]:  # make 500
            common.current_numcheck.Do500()
            bot.edit_message_text(
                common.current_numcheck.GetText(),
                inline_message_id=common.current_numcheck.check_id,
                parse_mode="markdown",
                reply_markup=common.current_numcheck.keyboard)
            common.current_numcheck.CheckNotifyIfAchieved(user)
            bot.answer_callback_query(call.id, "Отмечено " + ICON_500)
            return
        elif userChoice == kb.NUMBERS_CONTROL_OPTIONS[1]:  # make 1000
            common.current_numcheck.Do1000()
            bot.edit_message_text(
                common.current_numcheck.GetText(),
                inline_message_id=common.current_numcheck.check_id,
                parse_mode="markdown",
                reply_markup=common.current_numcheck.keyboard)
            common.current_numcheck.CheckNotifyIfAchieved(user)
            bot.answer_callback_query(call.id, "Отмечено " + ICON_1000)
            return
        elif userChoice == kb.NUMBERS_CONTROL_OPTIONS[2]:  # stop
            common.current_numcheck.DoEndCheck()
            bot.edit_message_text(
                common.current_numcheck.GetText(),
                inline_message_id=common.current_numcheck.check_id,
                parse_mode="markdown")
            bot.answer_callback_query(call.id, "🏁 Чек номеров завершен")
            hlp.LogEvent("🏁 %s завершил чек номеров" %
                         user.GetString(with_link=False))
            return
        else:
            log.error("invalid action!")
            bot.answer_callback_query(
                call.id,
                "Неверныая команда! Пожалуйста, обратитесь к администратору бота"
            )
    log.error("Numbers check not found!")
    bot.answer_callback_query(
        call.id, "Неверный чек номеров! Пожалуйста, создайте новый")
Ejemplo n.º 14
0
def battle_check_user(call):
    # print("battle_check_user")
    # print(call)
    message_id = call.inline_message_id
    user = User(call.from_user.id, call.from_user.first_name,
                call.from_user.username)
    userChoice = call.data
    log.debug("%s is trying to vote for battle (%s)" %
              (user, userChoice.replace(cb.CHECK_CALLBACK_PREFIX, "")))
    if common.current_battle and message_id == common.current_battle.check_id:
        is_guide_training = False
        battle_object = common.current_battle
    elif user._id in common.user_guiding.keys(
    ):  # guide battle example workaround
        is_guide_training = True
        if common.user_guiding[user._id].IsTrainingStage(
        ):  # using check is allowed only at several steps of guide
            battle_object = common.user_guiding[user._id].demonstration
        else:
            log.error("Not at training stage, aborting")
            bot.answer_callback_query(
                call.id, "На данный момент использование чека недоступно")
            return
    else:
        battle_object = None
    if battle_object:
        ret = battle_object.CheckUser(user, userChoice)
        if ret or userChoice == cb.CHECK_LATE_CALLBACK:
            markup = kb.KEYBOARD_CHECK
            if battle_object.is_rolling:
                markup = kb.KEYBOARD_CHECK_ROLLED
            elif battle_object.is_started:
                markup = kb.KEYBOARD_LATE
            if is_guide_training:
                bot.edit_message_text(battle_object.GetText(),
                                      user._id,
                                      battle_object.check_id,
                                      parse_mode="markdown",
                                      reply_markup=markup)
            else:
                bot.edit_message_text(battle_object.GetText(),
                                      inline_message_id=message_id,
                                      parse_mode="markdown",
                                      reply_markup=markup)
            bot.answer_callback_query(call.id,
                                      battle_object.GetVotedText(userChoice))
            if userChoice == cb.CHECK_LATE_CALLBACK and ret and not is_guide_training:
                text = ICON_LATE + " %s пришел на бой!\n" % user.GetString()
                bot.send_message(common.warchat_id,
                                 text,
                                 parse_mode="markdown",
                                 disable_notification=True)
                log.debug("Battle user late notification posted")
        else:
            log.error("Failed")
            bot.answer_callback_query(
                call.id, "Вы уже проголосовали (%s)" %
                userChoice.replace(cb.CHECK_CALLBACK_PREFIX, ""))
        return
    log.error("Battle not found!")
    bot.answer_callback_query(call.id,
                              "Неверный чек боя! Пожалуйста, создайте новый")