def confirm_transfer(self, update, context):
        user_data = context.user_data
        text = update.message.text

        if text == "Yes" or text == "Y":
            try:
                res = HmyClient.transfer(user_data['from_address'],
                                         user_data['to_address'],
                                         user_data['amount'])
                res = eval(res)
                if 'transaction-hash' in res:
                    update.message.reply_text(
                        f"Withdraw has been completed. Check here the receipt: {self.explorer_url}/tx/{res['transaction-hash']}"
                    )
                else:
                    update.message.reply_text(
                        "Withdraw has failed with an unknown error!")
            except Exception as ex:
                update.message.reply_text(
                    "Withdraw has failed! please try agian later.")
                print(ex)
        else:
            update.message.reply_text("Withdraw has failed!")

        user_data.clear()
        self.send_menu(update, context)
        return ConversationHandler.END
Ejemplo n.º 2
0
    def withdraw(self, text, sender_handle, sender_id):
        parts = text.split(" ")
        withdraw_address = ""
        amount = 0
        inputInValid = False
        reply_message = ""
        user_details = self.dataStore.getUserDetailsByTwitterHandle(
            f'@{sender_handle}')
        from_address = user_details['one_address']
        if len(parts) >= 3:
            if parts[0] == "!withdraw":
                print(text)
                try:
                    amount = float(parts[1])
                except Exception as ex:
                    inputInValid = True
                    reply_message = "Invalid withdrawal amount."
                    print(ex)
                if not inputInValid:
                    if amount < 0.00000000:
                        reply_message = f"Withdrawal amount cannot be negative."
                        print(reply_message)
                        inputInValid = True
                    else:
                        if HmyClient.getBalance(
                                from_address) + 0.00000021 < float(amount):
                            inputInValid = True
                            reply_message = f"Please make sure you have enough funds plus the necessary fees for the transfer."
                            print(reply_message)
                if not inputInValid:
                    withdraw_address = parts[2]
                    if not HmyClient.validateONEAdress(withdraw_address):
                        inputInValid = True
                        reply_message = "Invalid ONE address, transfer cancelled!"
                        print(reply_message)
        else:
            inputInValid = True
            reply_message = "Invalid withdraw command, please use !help get help"
        if not inputInValid:
            res = HmyClient.transfer(from_address, withdraw_address, amount)
            res = eval(res)
            if 'transaction-hash' in res:
                reply_message = f"Withdrawal completed! Receipt: {self.explorer_url}/tx/{res['transaction-hash']}"
            else:
                reply_message = "Withdrawal has failed with an unknown error."
        else:
            if reply_message == "":
                reply_message = "Unknown Error!"

        print(f'Withdraw reply :{reply_message}')
        self.api.send_direct_message(text=reply_message,
                                     recipient_id=sender_id)
 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)
Ejemplo n.º 4
0
 def process_tip(self, tweet_id, text, sender_handle, receiver):
     tip = 0
     success = "yes"
     failure_reason = ""
     tweet_type = "tweet"
     reply_text = ""
     print(text)
     print(f'@{self.bot_twitter_handle} !tip')
     if f'@{self.bot_twitter_handle} !tip' in text:
         if not self.dataStore.checkIftweetDataExists(tweet_id):
             sender_details = self.dataStore.getUserDetailsByTwitterHandle(
                 f'@{sender_handle}')
             if sender_details != None:
                 if 'twitter_handle_verified' in sender_details:
                     if sender_details['twitter_handle_verified'] == True:
                         parts = text.split(" ")
                         for i in range(0, len(parts)):
                             if parts[i] == "!tip":
                                 if i + 1 < len(parts):
                                     tip = float(parts[i + 1])
                                     break
                         from_address = sender_details['one_address']
                         sender = sender_handle
                         if receiver != "":
                             # Can't tip yourself
                             if sender != receiver:
                                 # Can't tip more than you have
                                 from_balance = HmyClient.getBalance(
                                     from_address)
                                 if tip + 0.00000021 > from_balance:
                                     reply_text = f'@{sender_handle}, your balance is too low to tip {tip} ONE.'
                                 else:
                                     receiver_details = self.dataStore.getUserDetailsByTwitterHandle(
                                         f'@{receiver}')
                                     if receiver_details == None:
                                         reply_text = f"@{sender_handle}, @{receiver} is not registered! Please register using Telegram the bot (https://t.me/onetippingbot)."
                                     else:
                                         if 'one_address' in receiver_details:
                                             res = HmyClient.transfer(
                                                 from_address,
                                                 receiver_details[
                                                     'one_address'], tip)
                                             res = eval(res)
                                             if 'transaction-hash' in res:
                                                 reply_text = f"Hi @{receiver}, @{sender_handle} just tipped you {tip} ONE."
                                             else:
                                                 print(
                                                     f"Tip failed from {sender} to {receiver} tip {tip} ONE."
                                                 )
                                         else:
                                             print(
                                                 'Receiver address is missing!'
                                             )
                             else:
                                 reply_text = f'@{sender_handle} You can\'t tip yourself!'
                         else:
                             reply_text = f'@{sender_handle} Please, mention a receiver when tipping! Check !help for more detailed instructions.'
                     else:
                         success = "no"
                         failure_reason = "twitter account not verified"
                         reply_text = f'@{sender_handle} Your twitter handle is not verified! Please verify using the Telegram bot (https://t.me/onetippingbot).'
                 else:
                     success = "no"
                     failure_reason = "twitter account not verified"
                     reply_text = f'@{sender_handle} Your twitter handle is not verified! Please verify using the Telegram bot (https://t.me/onetippingbot).'
             else:
                 success = "no"
                 failure_reason = "account does not exists"
                 reply_text = f'@{sender_handle} You are not registered! Please register using the Telegram bot (https://t.me/onetippingbot).'
             if reply_text != "":
                 self.api.update_status(status=reply_text,
                                        in_reply_to_status_id=tweet_id)
                 print(reply_text)
             tweetDetails = {
                 'tweet_id': tweet_id,
                 'sender': sender_handle,
                 'receiver': receiver,
                 'tip': tip,
                 'text': text,
                 'replied': "yes",
                 'success': success,
                 'failure_reason': failure_reason,
                 'tweet_type': tweet_type,
                 'reply_text': reply_text
             }
             self.dataStore.saveTweetDetails(tweetDetails)
         else:
             print("Tweet already served")
     else:
         print("Not a Tipping tweet")