Beispiel #1
0
 def StepNext(self, repeat=False):
     if not repeat:
         self.step += 1
     if self.step in [
             1, 4, 8
     ]:  # check start, need to re-send message to bring it bottom
         bot.delete_message(self.userid, self.message_id).wait()
     self.DemonstrateStep()
     if self.step != 13:
         reply = kb.KEYBOARD_GUIDE_NEXT
     else:
         reply = kb.KEYBOARD_GUIDE_FINISH
     if self.step in [
             1, 4, 8
     ]:  # check start, need to re-send message to bring it bottom
         msg = bot.send_message(self.userid,
                                self.guideline[self.step],
                                parse_mode="markdown",
                                reply_markup=reply).wait()
         self.message_id = msg.message_id
     else:
         bot.edit_message_text(self.guideline[self.step],
                               self.userid,
                               self.message_id,
                               parse_mode="markdown",
                               reply_markup=reply)
Beispiel #2
0
def command_guide(m):
    global user_guiding
    # print("command_guide")
    # print(m)
    user = [m.from_user.id, m.from_user.username, m.from_user.first_name]
    log.debug("User %d (%s %s) is trying to start a guide" % (*user, ))
    if not hlp.IsInPrivateChat(m):
        bot.delete_message(m.chat.id, m.message_id)
        hlp.SendHelpWrongChat(user[0], "/guide", "начать обучение", True)
        return
    if user[0] not in user_guiding.keys():
        user_guiding[user[0]] = Guide(User(user[0], user[2], user[1]))
        user_guiding[user[0]].Start()
        log.debug("Successful start")
    else:
        # FIX: can we repeat last guide message or need to start over? (test sample check message repeating)
        user_guiding[user[0]].StepNext(repeat=True)
        log.debug("Already started, repeating last step")
Beispiel #3
0
def guide_step(call):
    # print("guide_step")
    # print(call)
    message_id = call.inline_message_id
    user = [
        call.from_user.id, call.from_user.username, call.from_user.first_name
    ]
    userChoice = call.data
    log.debug("User %d (%s %s) is trying step next for his guide" % (*user, ))
    if user[0] not in user_guiding.keys():
        bot.send_message(
            user[0],
            "Бот был перезапущен.\nПожалуйста, начните обучение заного, используя команду /guide."
        )
        log.error("Bot has been restarted, need to start over")
        return
    if call.data == kb.GUIDE_OPTIONS[-1]:  # finish
        bot.delete_message(user[0], user_guiding[user[0]].message_id)
        del user_guiding[user[0]]
        log.debug("Guide finish successful")
    else:
        user_guiding[user[0]].StepNext()
        log.debug("Guide next step")
Beispiel #4
0
 def DemonstrateStep(self):
     # sample users
     sampleUser1 = User(582244665, None, "Nagibator9000")
     sampleUser2 = User(187678932, "Alex", "alex_mech")
     if self.step in [1, 4, 8]:  # check start
         if self.demonstration:
             # FIX: do we need this?
             # if isinstance(self.demonstration, Battle):
             #     self.demonstration.DoEndBattle()
             # elif isinstance(self.demonstration, Arsenal):
             #     self.demonstration.DoEndArsenal()
             # else:
             #     self.demonstration.DoEndCheck()
             bot.delete_message(self.userid, self.demonstration.check_id)
             del self.demonstration
         if self.step == 1:  # battle check
             self.demonstration = Battle("09 15")
             self.demonstration.CheckUser(sampleUser1,
                                          cb.CHECK_CHECK_CALLBACK)
             reply = kb.KEYBOARD_CHECK
         elif self.step == 4:  # arsenal check
             self.demonstration = Arsenal("09 15")
             reply = kb.KEYBOARD_ARS
         elif self.step == 8:  # numbers check
             kb.SetupNumbersKeyboard(count=9)
             self.demonstration = NumbersCheck(9)
             reply = kb.KEYBOARD_NUMBERS
         msg = bot.send_message(self.userid,
                                self.demonstration.GetText(),
                                parse_mode="markdown",
                                reply_markup=reply).wait()
         self.demonstration.SetMessageID(msg.message_id)
     elif self.step in [3, 7, 12]:  # last check example step
         # undo all example changes in checks to let user try him/herself
         if isinstance(self.demonstration, Battle):
             # do not undo battle checks, let them be examples
             reply = kb.KEYBOARD_CHECK
         elif isinstance(self.demonstration, Arsenal):
             self.demonstration.Increment(sampleUser1,
                                          cb.ARS_CANCEL_CALLBACK)
             self.demonstration.Increment(sampleUser2,
                                          cb.ARS_CANCEL_CALLBACK)
             reply = kb.KEYBOARD_ARS
         else:
             # no need to undo numbers check, even thouh we cannot undo 500 (yet?)
             reply = kb.KEYBOARD_NUMBERS
             pass
         bot.edit_message_text(self.demonstration.GetText(),
                               self.userid,
                               self.demonstration.check_id,
                               parse_mode="markdown",
                               reply_markup=reply)
     elif self.step == 2:  # battle check [buttons example]
         self.demonstration.CheckUser(sampleUser2, cb.CHECK_ARS_CALLBACK)
         self.demonstration.CheckUser(sampleUser2, cb.CHECK_ARS_CALLBACK)
         bot.edit_message_text(self.demonstration.GetText(),
                               self.userid,
                               self.demonstration.check_id,
                               parse_mode="markdown",
                               reply_markup=kb.KEYBOARD_CHECK)
     elif self.step in [5, 6, 9, 10, 11]:
         if self.step == 5:  # arsenal check [buttons example]
             self.demonstration.Increment(sampleUser1,
                                          cb.ARS_36_CALLBACK,
                                          notify=False)
             reply = kb.KEYBOARD_ARS
         elif self.step == 6:  # arsenal check [rage example]
             self.demonstration.Increment(sampleUser2,
                                          cb.ARS_FULL_CALLBACK,
                                          notify=False)
             reply = kb.KEYBOARD_ARS
         elif self.step == 9:  # numbers check [buttons example]
             self.demonstration.CheckUser(sampleUser1,
                                          cb.NUMBERS_5_CALLBACK)
             reply = self.demonstration.keyboard
         elif self.step == 10:  # numbers check [empty example]
             self.demonstration.CheckUser(sampleUser1,
                                          cb.NUMBERS_5_CALLBACK)
             self.demonstration.CheckUser(sampleUser1,
                                          cb.NUMBERS_5_CALLBACK)
             reply = self.demonstration.keyboard
         elif self.step == 11:  # numbers check [500 example]
             self.demonstration.Do500()
             reply = self.demonstration.keyboard
         bot.edit_message_text(self.demonstration.GetText(),
                               self.userid,
                               self.demonstration.check_id,
                               parse_mode="markdown",
                               reply_markup=reply)
     elif self.step == 13:  # finish step
         self.demonstration.DoEndCheck()
         bot.delete_message(self.userid, self.demonstration.check_id)
         del self.demonstration
Beispiel #5
0
 def StepFinish(self):
     bot.delete_message(self.userid, self.message_id)