Exemplo n.º 1
0
 def Increment(self, user, value, notify=True):
     arsValue = value.replace(cb.ARS_CALLBACK_PREFIX, "")
     inc = 0
     user_fired = False  # this variable is needed in order to count ars value for user even if ars is already fired now
     user_newcount = 1
     log.info("%s voted for %s" % (user, arsValue))
     if arsValue == "Cancel":
         if user in self.done_users:
             self.UndoIncrement(user)
             if hlp.NeedCheckBackup(common.current_arscheck):
                 common.current_arscheck.last_backup = datetime.datetime.now(
                 )
                 hlp.AWSCheckBackup(common.current_arscheck)
             return True
         log.error("Vote failed - user already reverted his votes")
         if hlp.NeedCheckBackup(common.current_arscheck):
             common.current_arscheck.last_backup = datetime.datetime.now()
             hlp.AWSCheckBackup(common.current_arscheck)
         return False
     if arsValue == "Full":
         if not self.is_fired:
             user_fired = True
             inc = 120 - self.progress
         else:
             user_newcount = 0
     else:
         inc = int(arsValue)
         if inc > 14:
             user_newcount = 3
     if user_fired:
         self.progress = 120
         self.is_postponed = True
     else:
         self.progress += inc
     if self.progress >= 120:
         user_fired = True
         self.is_fired = True
         self.is_postponed = True
     user_oldvalue = 0
     user_oldcount = 0
     if user in self.done_users:
         user_oldvalue = self.done_users[user][0]
         user_oldcount = self.done_users[user][1]
     user_record = [
         user_oldvalue + inc, user_oldcount + user_newcount, user_fired
     ]
     log.debug("%s total impact: %s" % (user, str(user_record)))
     self.done_users[user] = user_record
     log.info("Vote successful")
     if notify:
         try:
             if not self.CheckNotifyIfFired(except_user=user) and inc != 0:
                 self.CheckNotifyIfCritical()
         except:
             pass  # guide case, do nothing
     if hlp.NeedCheckBackup(common.current_arscheck):
         common.current_arscheck.last_backup = datetime.datetime.now()
         hlp.AWSCheckBackup(common.current_arscheck)
     return True
Exemplo n.º 2
0
 def CheckUser(self, user, action):
     ret = True
     log.info("%s voted for %s" %
              (user, action.replace(cb.CHECK_CALLBACK_PREFIX, "")))
     if action == cb.CHECK_CHECK_CALLBACK:
         self.SetCheck(user)
     elif action == cb.CHECK_RAGE_CALLBACK:
         self.SetRageOnly(user)
     elif action == cb.CHECK_FAST_CALLBACK:
         self.SetFast(user)
     elif action == cb.CHECK_ARS_CALLBACK:
         self.SetArsenalOnly(user)
     elif action == cb.CHECK_THINK_CALLBACK:
         ret = self.SetThinking(user)
     elif action == cb.CHECK_CANCEL_CALLBACK:
         ret = self.SetCancel(user)
     elif action == cb.CHECK_LATE_CALLBACK:
         ret = self.SetLate(user)
     # SetLate() always successful, return value indicates
     # that user has corrected his previous vote with +1 (not actually late)
     if ret:
         log.info("Vote successful")
     elif action != cb.CHECK_LATE_CALLBACK:
         log.error("Vote failed")
     if hlp.NeedCheckBackup(common.current_battle):
         common.current_battle.last_backup = datetime.datetime.now()
         hlp.AWSCheckBackup(common.current_battle)
     return ret
Exemplo n.º 3
0
 def DoEndArsenal(self):
     self.is_postponed = True
     if not common.DEBUG_MODE:
         common.statistics.Update(self.CollectStatistic())
     log.info("Arsenal check stopped")
     # force backup
     common.current_arscheck.last_backup = datetime.datetime.now()
     hlp.AWSCheckBackup(common.current_arscheck)
Exemplo n.º 4
0
 def DoRollBattle(self):
     self.time["roll"] = datetime.datetime.now()
     self.is_rolling = True
     self.keyboard = kb.KEYBOARD_CHECK_ROLLED
     log.warning("Battle rolled at %0.2d:%0.2d" %
                 (self.time["roll"].hour, self.time["roll"].minute))
     # force backup
     common.current_battle.last_backup = self.time["roll"]
     hlp.AWSCheckBackup(common.current_battle)
 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
Exemplo n.º 6
0
 def DoStartBattle(self):
     self.time["start"] = datetime.datetime.now()
     self.is_started = True
     self.is_rolling = False
     self.keyboard = kb.KEYBOARD_LATE
     log.warning("Battle started at %0.2d:%0.2d" %
                 (self.time["start"].hour, self.time["start"].minute))
     # force backup
     common.current_battle.last_backup = self.time["start"]
     hlp.AWSCheckBackup(common.current_battle)
 def Do500(self):
     if self._500["done"]:
         return
     # for number, value in self.numbers.items():
     #     if value == 3:
     #         self.numbers[number] = value - 1
     self._500["time"] = datetime.datetime.now()
     self._500["done"] = True
     if hlp.NeedCheckBackup(common.current_numcheck):
         common.current_numcheck.last_backup = self._500["time"]
         hlp.AWSCheckBackup(common.current_numcheck)
 def DoEndCheck(self):
     self.is_postponed = True
     self.keyboard = None
     if not common.DEBUG_MODE:
         common.statistics.Update(self.CollectStatistic())
     log.info("Numbers check stopped")
     # force backup
     if not common.current_numcheck:  # guide 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)
Exemplo n.º 9
0
 def DoEndBattle(self):
     # if more than 1 hour (max battle time) passed
     if hlp.CanStopCurrentBattle():
         self.time["end"] = self.time["start"].replace(
             hour=self.time["start"].hour + 1)
     else:
         self.time["end"] = datetime.datetime.now()
     self.is_postponed = True
     self.is_rolling = False
     self.keyboard = None
     if self.is_started and not common.DEBUG_MODE:
         common.statistics.Update(self.CollectStatistic())
     log.warning("Battle ended at %0.2d:%0.2d" %
                 (self.time["end"].hour, self.time["end"].minute))
     # force backup
     common.current_battle.last_backup = self.time["end"]
     hlp.AWSCheckBackup(common.current_battle)
Exemplo n.º 10
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)