コード例 #1
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, "Неверный чек арсенала! Пожалуйста, создайте новый")
コード例 #2
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,
                              "Неверный чек боя! Пожалуйста, создайте новый")
コード例 #3
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, "Неверный чек номеров! Пожалуйста, создайте новый")
コード例 #4
0
 def CheckUser(self, user, value):
     ret = True
     try:
         number_to_check = int(value.replace(cb.NUMBERS_CALLBACK_PREFIX,
                                             ""))
     except:  # user hit Cancel
         ret = self.UncheckUser(user)
         if hlp.NeedCheckBackup(common.current_numcheck):
             common.current_numcheck.last_backup = datetime.datetime.now()
             hlp.AWSCheckBackup(common.current_numcheck)
         return ret
     log.info("%s voted for %d" % (user, number_to_check))
     oldValue = self.numbers[number_to_check]
     if oldValue == 0:  # can't set number below 0
         log.error("Vote failed - number is already empty")
         if hlp.NeedCheckBackup(common.current_numcheck):
             common.current_numcheck.last_backup = datetime.datetime.now()
             hlp.AWSCheckBackup(common.current_numcheck)
         return False
     # update number value
     self.numbers[number_to_check] = (oldValue - 1)
     # record user action
     done = False
     for _user in self.users:
         if _user == user:  # record exist
             oldRecord = self.users[user]
             oldRecord.append(number_to_check)
             self.users[user] = oldRecord
             done = True
             break
     # user record is new
     if not done:
         self.users[user] = [number_to_check]
     if common.current_numcheck and self.check_id == common.current_numcheck.check_id:
         hlp.LogEvent("%s снял звезду с %d\n(%s → %s)" %
                      (user.GetString(with_link=False), number_to_check,
                       ICON_STAR * oldValue, ICON_STAR *
                       (oldValue - 1) if oldValue - 1 > 0 else "пустой"))
     self.CheckAchievements()
     log.info("Vote successful")
     if hlp.NeedCheckBackup(common.current_numcheck):
         common.current_numcheck.last_backup = datetime.datetime.now()
         hlp.AWSCheckBackup(common.current_numcheck)
     return True
コード例 #5
0
 def CheckNotifyIfAchieved(self, user):
     text = None
     if self._1000["done"] and not self._1000["notified"]:
         text = "%s ❗" % ICON_1000
         self._1000["notified"] = True
     elif self._500["done"] and not self._500["notified"]:
         text = "%s ❗" % ICON_500
         self._500["notified"] = True
     if text:
         common.bot.send_message(common.warchat_id, text)
         if common.current_numcheck and self.check_id == common.current_numcheck.check_id:
             hlp.LogEvent("%s отметил %s" %
                          (user.GetString(with_link=False), text))
     # need to do backup here because notified field for achievement is updated here
     if not common.current_numcheck or common.DEBUG_MODE:  # guide case, debug case, ignore that
         pass
     elif common.current_numcheck.check_id == self.check_id:  # or that
         common.current_numcheck.last_backup = datetime.datetime.now()
         hlp.AWSCheckBackup(common.current_numcheck)
コード例 #6
0
 def CheckNotifyIfFired(self, except_user=None):
     if self.is_fired and not self.is_fire_notified:
         # get active users from battle check
         activeUsers = common.current_battle.GetActiveUsers()
         for user in self.done_users:
             activeUsers.add(user)
         log.debug(activeUsers)
         now = datetime.datetime.now()
         text = ICON_RAGE + " %0.2d:%0.2d ГОРИТ!" % (now.hour, now.minute)
         if common.current_arscheck and self.check_id == common.current_arscheck.check_id:
             hlp.LogEvent(text)
         for user in activeUsers:
             if user != except_user:
                 common.bot.send_message(user._id, text)
         self.is_fire_notified = True
         notification = common.bot.send_message(common.warchat_id,
                                                text).wait()
         if common.settings.GetSetting("pin") and not common.DEBUG_MODE:
             common.bot.pin_chat_message(notification.chat.id,
                                         notification.message_id)
         log.debug("Arsenal status notification posted")
         return True
     return False