def test_parse_donate_amount(self): self.assertTrue( helper.parse_amount("donate ", "donate 1.0 xmr", 0) == "1.0") self.assertTrue( helper.parse_amount("donate ", "donate 1xmr", 0) == "1") self.assertTrue( helper.parse_amount("donate ", "donate 1 mxmr", 0) == "0.001") self.assertTrue( helper.parse_amount("donate ", "donate 1mxmr", 0) == "0.001") self.assertTrue( helper.parse_amount("donate ", "donate 100% of my balance", 1) == "1.0") self.assertTrue( helper.parse_amount("donate ", "donate 50% of my balance", 1) == "0.5") self.assertTrue( helper.parse_amount("donate ", "donate 0% of my balance", 1) == "0.0") self.assertTrue( helper.parse_amount("donate ", "donate 1.0$", 0) == str( get_xmr_val(1))) self.assertTrue( helper.parse_amount("donate ", "donate $1", 0) == str( get_xmr_val(1)))
def handle_tip_request(author, body, comment): """ Handles the tipping interaction, called by a Redditor's comment Replies to the user if the response is not None Sends user a message if message is not None :param body: The contents of a comment that called the bot :param author: The username of the entity that created the comment :param comment: The comment itself that called the bot """ recipient = get_tip_recipient(comment) amount = helper.parse_amount(f'/u/{helper.botname.lower()} (tip )?', body) if recipient is None or amount is None: reply = "Nothing interesting happens.\n\n*In case you were trying to tip, I didn't understand you.*" elif Decimal(amount) < Decimal(0.0001): reply = helper.get_below_threshold_message() else: tipper_logger.log(f'{author} is sending {recipient} {amount} XMR.') generate_wallet_if_doesnt_exist(recipient.lower()) res = tip(sender=author, recipient=recipient, amount=amount) reply = f'{res["response"]}' tipper_logger.log("The response is: " + reply) if res["message"] is not None: helper.praw.redditor(author).message( subject="Your tip", message=f"Regarding your tip here: {comment.context}\n\n" + res["message"] + get_signature()) helper.praw.comment(str(comment)).reply(reply + get_signature())
def test_parse_anontip_amount(self): self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} 1 xmr") == "1") self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} 1xmr") == "1") self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} 1 mxmr") == "0.001") self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} 1mxmr") == "0.001") self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} 1$") == str( get_xmr_val(1))) self.assertTrue( helper.parse_amount(f"anonymous tip {helper.botname} ", f"anonymous tip {helper.botname} $1.0") == str( get_xmr_val(1)))
def handle_donation(author, subject): """ Allows Reddit users to donate a portion of their balance directly to the CCS CCS can be seen at: https://ccs.getmonero.org/ :param author: Reddit account to withdraw from :param subject: Subject line of the message, telling how much to withdraw """ sender_rpc_n_wallet = SafeWallet(port=helper.ports.donation_sender_port, wallet_name=author.lower(), wallet_password=helper.password) amount = Decimal( helper.parse_amount('donate ', subject, balance=sender_rpc_n_wallet.wallet.balance())) try: generate_transaction( sender_wallet=sender_rpc_n_wallet.wallet, recipient_address=helper.get_general_fund_address(), amount=amount, split_size=1) helper.praw.redditor(author).message( subject="Your donation to the General Dev Fund", message= f'Thank you for donating {format_decimal(amount)} of your XMR balance to the CCS!\n\nYou will soon have your total donations broadcasted to the wiki :) {get_signature()}' ) helper.praw.redditor("OsrsNeedsF2P").message( subject=f'{author} donated {amount} to the CCS!', message= f"Update table here: https://old.reddit.com/r/{helper.botname}/wiki/index#wiki_donating_to_the_ccs" ) tipper_logger.log( f'{author} donated {format_decimal(amount)} to the CCS.') except Exception as e: helper.praw.redditor(author).message( subject="Your donation to the CCS failed", message=f'Please send the following to /u/OsrsNeedsF2P:\n\n' + str(e) + get_signature()) tipper_logger.log("Caught an error during a donation to CCS: " + str(e)) sender_rpc_n_wallet.kill_rpc()
def handle_withdraw_request(author, subject, contents): """ Handles the withdrawal request, setting up RPC and calling the withdraw function :param author: Wallet to withdraw from :param subject: The withdrawl request string :param contents: The address to withdraw to :return: Response message about withdrawl request """ amount = helper.parse_amount("withdraw ", subject) if amount is None: helper.praw.redditor(author).message(subject="I didn't understand your withdrawal!", message=f'You sent: "{subject}", but I couldn\'t figure out how much you wanted to send. See [this](https://www.reddit.com/r/{helper.botname}/wiki/index#wiki_withdrawing) guide if you need help, or click "Report a Bug" under "Get Started" if you think there\'s a bug!' + get_signature()) return None sender_rpc_n_wallet = SafeWallet(port=helper.ports.withdraw_sender_port, wallet_name=author.lower(), wallet_password=helper.password) res = str(handle_withdraw(sender_rpc_n_wallet.wallet, author, contents, amount)) sender_rpc_n_wallet.kill_rpc() helper.praw.redditor(author).message(subject="Your withdrawl", message=res + get_signature()) tipper_logger.log("Told " + author + " their withdrawl status (" + res + ")")
def test_parse_withdrawal_amount(self): self.assertTrue( helper.parse_amount("withdraw ", "withdraw 1xmr") == "1") self.assertTrue( helper.parse_amount("withdraw ", "withdraw 1.0 xmr") == "1.0") self.assertTrue( helper.parse_amount("withdraw ", "withdraw 1 mxmr") == "0.001") self.assertTrue( helper.parse_amount("withdraw ", "withdraw 1mxmr") == "0.001") self.assertTrue( helper.parse_amount("withdraw ", "withdraw 1.0$") == str( helper.get_xmr_val(1))) self.assertTrue( helper.parse_amount("withdraw ", "withdraw $1") == str( helper.get_xmr_val(1)))
def test_parse_tip_amount(self): prefix = f"/u/{helper.botname} (tip )?" self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 1.0 xmr") == "1.0") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 1xmr") == "1") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 5 xmr") == "5") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} tip 1 xmr") == "1") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} tip 1xmr") == "1") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 1 mxmr") == "0.001") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 1mxmr") == "0.001") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} tip 1 mxmr") == "0.001") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} tip 1mxmr") == "0.001") self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} 1.0$") == str( get_xmr_val(1))) self.assertTrue( helper.parse_amount(prefix, f"/u/{helper.botname} $1") == str( get_xmr_val(1))) self.assertTrue( helper.parse_amount( prefix, f"Here's some stuff to throw the bot off:\n If you want to peer to peer trade Monero instead of using an exchange, check out LocalMonero: http://localmonero.co/\n/u/{helper.botname} 0.001 XMR" ) == "0.001")
def test_parse_amount(self): self.assertTrue(helper.parse_amount("donate ", "donate 5 xmr", 2) == "5") self.assertTrue(helper.parse_amount("donate ", "donate 5$", 2) == helper.get_xmr_val(5)) self.assertTrue(float(helper.parse_amount("donate ", "donate 50% of my balance", 2)) == float(1)) self.assertTrue(float(helper.parse_amount("donate ", "donate 0.1% of my balance", 100)) == float(0.1))