示例#1
0
 def final_state(self, message, entry=False):
     texts = self.get_texts()
     user = self.get_user(message)
     if entry:
         if self.botType == "fi":
             messId = message.chat.id
             keybd = keyboards2
         elif self.botType == "sec":
             messId = message.from_user.id
             keybd = keyboards
         else:
             messId = ""
             keybd = ""
         bot = BotProfile.objects(id=self.bot_id).first()
         text = Payment.objects(
             id=user.payment.id).first().answer_text.replace(
                 '#wallet#', bot.wallet)
         self._bot.send_message(
             messId,
             text,
             reply_markup=keybd.set_keyboard(texts, [],
                                             back_btn=True,
                                             done_btn=True))
     else:
         if self.botType == "fi":
             messText = message.text
         elif self.botType == "sec":
             messText = message.data
         else:
             messText = ""
         if messText == texts['done_btn']:
             methods.create_order(self, user)
             self._go_to_state(message, self.districts_state)
         elif messText == texts['back_btn']:
             self._go_to_state(message, self.payment_state)
         else:
             if self.botType == "fi":
                 messId = message.chat.id
                 keybd = keyboards2
             elif self.botType == "sec":
                 messId = message.from_user.id
                 keybd = keyboards
             else:
                 messId = ""
                 keybd = ""
             text = Payment.objects(
                 id=user.payment.id).first().answer_on_payment
             self._bot.send_message(messId,
                                    text,
                                    reply_markup=keybd.set_keyboard(
                                        texts, [], back_btn=True))
             user.code = messText
             user.save()
             methods.create_order(self, user)
示例#2
0
 def payment_state(self, message, entry=False):
     print("9999")
     texts = self.get_texts()
     user = self.get_user(message)
     payments = group_by(Payment.objects(bot_id=str(self.bot_id)),
                         'payment_name')
     if entry:
         if self.botType == "fi":
             messId = message.chat.id
             keybd = keyboards2
         elif self.botType == "sec":
             messId = message.from_user.id
             keybd = keyboards
         else:
             messId = ""
             keybd = ""
         self._bot.send_message(messId,
                                texts['choose_payment_msg'],
                                reply_markup=keybd.set_keyboard(
                                    texts, payments.keys(), back_btn=True))
     else:
         if self.botType == "fi":
             messText = message.text
         elif self.botType == "sec":
             messText = message.data
         else:
             messText = ""
         if payments.get(messText):
             user.payment = payments.get(messText)
             user.save()
             self._go_to_state(message, self.final_state)
         elif messText == texts['back_btn']:
             self._go_to_state(message, self.districts_state)
         else:
             if self.botType == "fi":
                 messId = message.chat.id
                 keybd = keyboards2
             elif self.botType == "sec":
                 messId = message.from_user.id
                 keybd = keyboards
             else:
                 messId = ""
                 keybd = ""
             self._bot.send_message(messId,
                                    texts['use_buttons_msg'],
                                    reply_markup=keybd.set_keyboard(
                                        texts,
                                        payments.keys(),
                                        back_btn=True))
示例#3
0
    def create_dub(self, bot_id, bot_2):
        try:
            telebot.TeleBot(bot_2).get_me()
        except Exception:
            return 'ERROR, go back'
        bot_2 = loads(
            BotProfile.objects(token=bot_2).first().to_json())['_id']['$oid']

        text = Texts.objects(bot_id=bot_id).first()

        if not (text is None):
            text_dict = loads(text.to_json())

            dub_text = {}

            for key in text_dict:
                if key != '_id':
                    dub_text.update({key: text_dict[key]})

            dub_text['bot_id'] = bot_2

            new_text = Texts(**dub_text)
            new_text.save()

        cities = City.objects(bot_id=bot_id)

        if cities is not None:
            for city in cities:
                if not (city is None):
                    city_dict = loads(city.to_json())

                    dub_city = {}

                    for key in city_dict:
                        if key != '_id':
                            dub_city.update({key: city_dict[key]})

                    dub_city['bot_id'] = bot_2

                    new_city = City(**dub_city)
                    new_city.save()
                    goods = Good.objects(city_id=city.id.binary.hex())

                    for good in goods:
                        if good is not None:
                            Good(name=good.name,
                                 city_id=new_city.id.binary.hex(),
                                 price=good.price,
                                 description=good.description,
                                 photo=good.photo,
                                 districts=good.districts).save()

        payment = Payment.objects(bot_id=bot_id).first()

        if not (payment is None):
            payment_dict = loads(payment.to_json())

            dub_payment = {}

            for key in payment_dict:
                if key != '_id':
                    dub_payment.update({key: payment_dict[key]})

            dub_payment['bot_id'] = bot_2

            new_payment = Payment(**dub_payment)
            new_payment.save()
        return str(bot_2)