def register(self, update, context):
     try:
         sender = self.message.from_user
         # If they're not registered nor have they received any tips without an account
         if not self.dataStore.checkIfUserRecordExists(
                 sender.id, sender.username):
             new_one_address = HmyClient.regiterNewUser(sender.username)
             parts = new_one_address.split('\n')
             if len(parts) > 3:
                 if parts[3].startswith('ONE Address:'):
                     one_address = parts[3].replace('ONE Address: ', '')
                     user_data = {
                         'balance': 0,
                         'chat_id': sender.id,
                         'telegram_user_id': sender.username,
                         'name': sender.full_name,
                         'seed': parts[2],
                         'one_address': one_address
                     }
                     self.dataStore.saveUserDetails(user_data)
                     context.bot.send_message(
                         text=
                         f'Welcome aboard {sender.full_name}, you are successfully registered!',
                         chat_id=self.message.chat.id)
                     context.bot.send_message(
                         text=f'Your Deposit address is: {one_address}',
                         chat_id=self.message.chat.id)
                     context.bot.send_photo(
                         chat_id=self.message.chat.id,
                         photo=open(
                             Utility.getQRCodeImageFilePath(one_address),
                             'rb'))
                 else:
                     context.bot.send_message(
                         text=
                         'Registration failed due to error in wallet generation!',
                         chat_id=self.message.chat.id)
             else:
                 context.bot.send_message(text='Registration failed!',
                                          chat_id=self.message.chat.id)
         else:
             context.bot.send_message(text='You\'re already registered!',
                                      chat_id=self.message.chat.id)
         # Save the data
         self.pp.update_chat_data(self.message.chat.id, context.chat_data)
     except Exception as ex:
         print(ex)
         logging.error(ex)
     finally:
         self.send_menu(update, context)
 def tip(self, update, context, *args):
     try:
         reply = update.message.reply_to_message
         sender_details = self.dataStore.getUserDetails(
             update.message.from_user.id, update.message.from_user.username)
         if sender_details != None:
             from_address = sender_details['one_address']
             # If the sender isn't in the database, there's no way they have money
             reply = update.message.reply_to_message
             # These IDs will be used to look up the two people in the database
             sender = update.message.from_user.id
             if reply != None:
                 receiver = reply.from_user.id
                 # Can't tip yourself
                 if sender != receiver:
                     # The *args dict only stores strings, so we make it a number
                     tip = float(context.args[0])
                     # Can't tip more than you have
                     from_balance = HmyClient.getBalance(from_address)
                     if tip < GlobalVariables._minimumTip:
                         update.message.reply_text(
                             f'Sorry, tip should be greater than or equals to {GlobalVariables._minimumTip:.6f}'
                         )
                     elif tip + 0.00000021 > from_balance:
                         update.message.reply_text(
                             f'Sorry, your balance is low! tip {tip:.6f}')
                     else:
                         receiver_details = self.dataStore.getUserDetails(
                             reply.from_user.id, reply.from_user.username)
                         new_account = False
                         if receiver_details == None:
                             # Unregistered users get this and they will be registered automatically
                             new_one_address = HmyClient.regiterNewUser(
                                 reply.from_user.username)
                             parts = new_one_address.split('\n')
                             if len(parts) > 3:
                                 if parts[3].startswith('ONE Address:'):
                                     to_address = parts[3].replace(
                                         'ONE Address: ', '')
                                     receiver_details = {
                                         'balance': 0,
                                         'chat_id': reply.from_user.id,
                                         'telegram_user_id':
                                         reply.from_user.username,
                                         'name': reply.from_user.full_name,
                                         'seed': parts[2],
                                         'one_address': to_address
                                     }
                                     new_account = True
                                     self.dataStore.saveUserDetails(
                                         receiver_details)
                         if 'one_address' in receiver_details:
                             res = HmyClient.transfer(
                                 from_address,
                                 receiver_details['one_address'], tip)
                             res = eval(res)
                             if 'transaction-hash' in res:
                                 if new_account:
                                     update.message.reply_text(
                                         f"Hi @{reply.from_user.username}, @{update.message.from_user.username} has tip you {tip:.6f}, but seems your account is not active with us yet.\n Please click here {self.bot_name} to initiate your account and check your balance!"
                                     )
                                 else:
                                     update.message.reply_text(
                                         f"Hi @{reply.from_user.username}, @{update.message.from_user.username} just tipped you {tip:.6f} ONE"
                                     )
                             else:
                                 print(
                                     f"Tip failed from  {update.message.from_user.username} to {reply.from_user.username} tip {tip:.6f} ONE"
                                 )
                 else:
                     update.message.reply_text('You can\'t tip yourself!')
             else:
                 update.message.reply_text(
                     'Please reply to a message to tip.')
         else:
             update.message.reply_text(
                 f'You\'re not registered! Please register with @{self.bot_name} to tip.'
             )
         # This means the message doesn't contain a reply, which is required for the command
     except AttributeError as ae:
         print(ae)
         update.message.reply_text(
             'You must be replying to a message to tip someone!')
     self.pp.update_chat_data(update.message.chat.id, context.chat_data)