Beispiel #1
0
    def _add_api_config_done(self, bot, update):
        """
        Adds configured api.
        """
        chat_id = update.message.chat_id

        try:
            chat, _ = Chat.get_or_create(id=chat_id,
                                         defaults={'last_transaction': None})

            config = Barrenero.get_token_or_register(
                url=self.tmp_config[chat_id]['url'],
                username=self.tmp_config[chat_id]['username'],
                password=self.tmp_config[chat_id]['password'],
                account=self.tmp_config[chat_id]['wallet'],
                api_password=self.tmp_config[chat_id]['api_password'],
            )

            API.create(name=self.tmp_config[chat_id]['name'],
                       url=self.tmp_config[chat_id]['url'],
                       token=config['token'],
                       superuser=config['superuser'],
                       chat=chat)
        except:
            self.logger.exception('Cannot register Barrenero API')
            update.message.reply_text('Cannot register Barrenero API')
        else:
            update.message.reply_text('Api stored successfully')

        return self.start(bot, update)
 def _save_chat(self):
     # Create or get the chat where the link was sent
     chat, was_created = Chat.get_or_create(
         id=self.update.message.chat_id,
         defaults={
             'name':
             self.update.message.chat.title
             or self.update.message.chat.username
             or self.update.message.chat.first_name
         })
     if was_created:
         Logger.log_db_operation(Logger.DBOperation.CREATE, chat)
     return chat