async def balance(ctx, user: discord.User = None): """ PMs your tipjar balance """ err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="Your Tipjar Balance is") exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() if exists: pid = gen_paymentid(exists.address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() else: good_embed.description = "`{0:,.2f}` {1}".format( balance.amount / config['units'], config['symbol']) await client.send_message(ctx.message.author, embed=good_embed) else: err_embed.description = "You haven't registered a wallet!" err_embed.add_field( name="Help", value="Use `{}registerwallet <addr>` before trying to tip!".format( config['prefix'])) await client.say(embed=err_embed)
async def deposit(ctx, user: discord.User = None): """ .deposit - Get deposit information so you can start tipping """ err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="Your Tipjar Info") tipjar_addr = "ccx7Wga6b232eSVfy8KQmBjho5TRXxX8rZ2zoCTyixfvEBQTj1g2Ysz1hZKxQtw874W3w6BZkMFSn5h3gUenQemZ2xiyyjxBR7" exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() if exists: pid = gen_paymentid(exists.address) good_embed.description = "Deposit {} to start tipping! ,Send the funds you want to deposit to the address: ```{}``` (Pay to: in the GUI) and enter ```{}``` in the Payment ID field. CLI users just send a transfer to the same address and payment ID.".format( config['symbol'], tipjar_addr, pid) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() await client.send_message(ctx.message.author, embed=good_embed) else: err_embed.description = "You haven't registered a wallet!" err_embed.add_field( name="Help", value="Use `{}registerwallet <addr>` before trying to tip!".format( config['prefix'])) await client.say(embed=err_embed)
async def deposit(ctx, user: discord.User = None): """ PMs your deposit information for the tipjar """ err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="Your Tipjar Info") exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() tipjar_addr = rpc.getAddresses()['addresses'][0] if exists: pid = gen_paymentid(exists.address) good_embed.description = "Deposit {} to start tipping! ```transfer 3 {} <amount> -p {}```".format( config['symbol'], tipjar_addr, pid) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() await client.send_message(ctx.message.author, embed=good_embed) else: err_embed.description = "You haven't registered a wallet!" err_embed.add_field( name="Help", value="Use `{}registerwallet <addr>` before trying to tip!".format( config['prefix'])) await client.say(embed=err_embed)
async def registerwallet(ctx, address): """ Register your wallet in the DB """ address = address.strip() err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="{}'s Wallet".format( ctx.message.author.name), colour=discord.Colour(0xD4AF37)) if address is None: err_embed.description = "Please provide an address" await client.send_message(ctx.message.author, embed=err_embed) return exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() addr_exists = session.query(Wallet).filter( Wallet.address == address).first() if exists: good_embed.title = "Your wallet exists!".format(exists.address) good_embed.description = "```{}``` use `{}updatewallet <addr>` to change".format( exists.address, config['prefix']) await client.send_message(ctx.message.author, embed=good_embed) return if addr_exists: err_embed.description = "Address already registered by another user!" await client.send_message(ctx.message.author, embed=err_embed) return elif not exists and len(address) == config['addrLength']: w = Wallet(address, ctx.message.author.id, ctx.message.id) session.add(w) session.commit() good_embed.title = "Successfully registered your wallet" good_embed.description = "```{}```".format(address) await client.send_message(ctx.message.author, embed=good_embed) pid = gen_paymentid(address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) else: balance.paymentid = pid session.commit() tipjar_addr = rpc.getAddresses()['addresses'][0] good_embed.title = "Your Tipjar Info" good_embed.description = "Deposit {} to start tipping! ```transfer 3 {} <amount> -p {}```".format( config['symbol'], tipjar_addr, pid) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() await client.send_message(ctx.message.author, embed=good_embed) return elif len(address) > config['addrLength']: err_embed.description = "Your wallet must be {} characeters long, your entry was too long".format( config['addrLength']) elif len(address) < config['addrLength']: err_embed.description = "Your wallet must be {} characeters long, your entry was too short".format( config['addrLength']) await client.say(embed=err_embed)
async def registerwallet(ctx, address): """ .registerwallet <addr> - Register your wallet in the database """ err_embed = discord.Embed(title="Error", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="{}'s Wallet".format( ctx.message.author.name), colour=discord.Colour(0xD4AF37)) if address is None: err_embed.description = "Please provide an address" await client.send_message(ctx.message.author, embed=err_embed) return exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() addr_exists = session.query(Wallet).filter( Wallet.address == address).first() if exists: good_embed.title = "Your wallet exists!".format(exists.address) good_embed.description = "```{}``` use `{}updatewallet <addr>` to change".format( exists.address, config['prefix']) await client.send_message(ctx.message.author, embed=good_embed) return if addr_exists: err_embed.description = "Address already registered by another user!" await client.send_message(ctx.message.author, embed=err_embed) return elif not exists and len(address) == 98: w = Wallet(address, ctx.message.author.id, ctx.message.id) session.add(w) session.commit() good_embed.title = "Successfully registered your wallet" good_embed.description = "```{}```".format(address) await client.send_message(ctx.message.author, embed=good_embed) pid = gen_paymentid(address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) else: balance.paymentid = pid session.commit() tipjar_addr = "ccx7Wga6b232eSVfy8KQmBjho5TRXxX8rZ2zoCTyixfvEBQTj1g2Ysz1hZKxQtw874W3w6BZkMFSn5h3gUenQemZ2xiyyjxBR7" good_embed.title = "Your Tipjar Info" good_embed.description = "Deposit {} to start tipping! ```transfer 0 {} <amount> -p {}```".format( config['symbol'], tipjar_addr, pid) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() await client.send_message(ctx.message.author, embed=good_embed) return elif len(address) > 98: err_embed.description = "Your wallet must be 98 characeters long, your entry was too long" elif len(address) < 98: err_embed.description = "Your wallet must be 98 characeters long, your entry was too short" await client.say(embed=err_embed)
async def registerwallet(ctx, address): " Register your wallet in the DB " "" address = address.strip() err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="{}'s Wallet".format( ctx.message.author.name), colour=discord.Colour(0xD4AF37)) if address == None: err_embed.description = "Please provide an address" exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() if exists: good_embed.title = "Your wallet exists!".format(exists.address) good_embed.description = "```{}``` use `!updatewallet <addr>` to change".format( exists.address) await client.say(embed=good_embed) return elif not exists and len(address) == 99 and address.startswith("TRTL"): w = Wallet(address, ctx.message.author.id, ctx.message.id) session.add(w) session.commit() good_embed.title = "Successfully registered your wallet" good_embed.description = "```{}```".format(address) await client.say(embed=good_embed) pid = gen_paymentid(address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() else: balance.paymentid = pid return elif len(address) > 99: err_embed.description = "Your wallet must be 99 characeters long, your entry was too long" elif len(address) < 99: err_embed.description = "Your wallet must be 99 characeters long, your entry was too short" elif not address.startswith("TRTL"): err_embed.description = "Wallets start with `TRTL`" await client.say(embed=err_embed)
async def updatewallet(ctx, address): """ Updates your wallet address """ address = address.strip() err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="{}'s Updated Wallet".format( ctx.message.author.name), colour=discord.Colour(0xD4AF37)) exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() if not exists: err_embed.description = "You haven't registered a wallet!" elif exists and len(address) == 99 and address.startswith("TRTL"): old_pid = gen_paymentid(exists.address) old_balance = session.query(TipJar).filter( TipJar.paymentid == old_pid).first() exists.address = address session.commit() good_embed.title = "Successfully updated your wallet" good_embed.description = "```{}```".format(address) await client.say(embed=good_embed) pid = gen_paymentid(exists.address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() else: balance.paymentid = pid balance.amount += old_balance.amount return elif len(address) > 99: err_embed.description = "Your wallet must be 99 characeters long, your entry was too long" elif len(address) < 99: err_embed.description = "Your wallet must be 99 characeters long, your entry was too short" elif not address.startswith("TRTL"): err_embed.description = "Wallets start with `TRTL`" await client.say(embed=err_embed)
async def _tip(ctx, amount, sender: discord.User = None, receiver: discord.User = None): """ Tips a user <amount> of coin """ err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) good_embed = discord.Embed(title="You were tipped!", colour=discord.Colour(0xD4AF37)) request_desc = "Register with `{}registerwallet <youraddress>` to get started! To create a wallet head to https://turtlecoin.lol/wallet/".format( config['prefix']) request_embed = discord.Embed(title="{} wants to tip you".format( ctx.message.author.name), description=request_desc) if not sender: # regular tip sender = ctx.message.author if not receiver: tipees = ctx.message.mentions else: tipees = [ receiver, ] try: amount = int(round(float(amount) * config['units'])) except: await client.say("Amount must be a number > {}".format( 10 / config['units'])) return False if amount <= 10: err_embed.description = "`amount` must be greater than {}".format( 10 / config['units']) await client.say(embed=err_embed) return False fee = get_fee(amount) self_exists = session.query(Wallet).filter( Wallet.userid == sender.id).first() if not self_exists: err_embed.description = "You haven't registered a wallet!" err_embed.add_field( name="Help", value="Use `{}registerwallet <addr>` before trying to tip!".format( config['prefix'])) await client.send_message(sender, embed=err_embed) return False pid = gen_paymentid(self_exists.address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() if not balance: t = TipJar(pid, sender.id, 0) session.add(t) session.commit() err_embed.description = "You are now registered, please `{}deposit` to tip".format( config['prefix']) await client.send_message(sender, embed=err_embed) return False if balance.amount < 0: balance.amount = 0 session.commit() err_embed.description = "Your balance was negative!" await client.send_message(sender, embed=err_embed) madk = discord.utils.get(client.get_all_members(), id='200823661928644617') err_embed.title = "{} had a negative balance!!".format(sender.name) err_embed.description = "PID: {}".format(pid) await client.send_message(madk, embed=err_embed) return False if ((len(tipees) * (amount)) + fee) > balance.amount: err_embed.description = "Your balance is too low! Amount + Fee = `{}` {}".format( ((len(tipees) * (amount)) + fee) / config['units'], config['symbol']) await client.add_reaction(ctx.message, "\u274C") await client.send_message(sender, embed=err_embed) return False destinations = [] actual_users = [] failed = 0 for user in tipees: user_exists = session.query(Wallet).filter( Wallet.userid == user.id).first() if user_exists: destinations.append({ 'amount': amount, 'address': user_exists.address }) if user_exists.userid != sender.id: # multitip shouldn't tip self. actual_users.append(user) else: failed = failed + 1 await client.add_reaction(ctx.message, EMOJI_SOS) try: await client.send_message(user, embed=request_embed) except: continue if len(destinations) == 0: await client.add_reaction(ctx.message, EMOJI_SOS) return False transfer = build_transfer(amount, destinations, balance) print(transfer) result = rpc.sendTransaction(transfer) print(result) await client.add_reaction(ctx.message, EMOJI_MONEYBAGS) balance.amount -= ((len(actual_users) * amount) + fee) tx = Transaction(result['transactionHash'], (len(actual_users) * amount) + fee, balance.paymentid) session.add(tx) session.commit() good_embed.title = "Tip Sent!" good_embed.description = ( "Sent `{0:,.2f}` {1} to {2} users! With Transaction Hash ```{3}```". format(amount / config['units'], config['symbol'], len(actual_users), result['transactionHash'])) good_embed.url = ( "https://blocks.turtle.link/?hash={}#blockchain_transaction".format( result['transactionHash'])) good_embed.add_field(name="New Balance", value="`{:0,.2f}` {}".format( balance.amount / config['units'], config['symbol'])) good_embed.add_field( name="Transfer Info", value="Successfully sent to {0} users. {1} failed.".format( len(actual_users), failed)) try: await client.send_message(sender, embed=good_embed) except: pass for user in actual_users: good_embed = discord.Embed(title="You were tipped!", colour=discord.Colour(0xD4AF37)) good_embed.description = ( "{0} sent you `{1:,.2f}` {2} with Transaction Hash ```{3}```". format(sender.mention, amount / config['units'], config['symbol'], result['transactionHash'])) good_embed.url = ( "https://blocks.turtle.link/?hash={}#blockchain_transaction". format(result['transactionHash'])) try: await client.send_message(user, embed=good_embed) except: continue return True
async def tip(ctx, amount, user: discord.User = None): """ Tips a user <amount> TRTL """ if not user: await client.say("Usage: !tip <amount> @username") err_embed = discord.Embed(title=":x:Error:x:", colour=discord.Colour(0xf44242)) request_desc = "Register with `!registerwallet TRTLyourwallet` to get started!" request_embed = discord.Embed(title="{} wants to tip you".format( ctx.message.author.mention), description=request_desc) good_embed = discord.Embed(title="You were tipped!", colour=discord.Colour(0xD4AF37)) try: amount = int(round(float(amount) * 100)) except: if user: await client.say("Usage: !tip <amount> @username") else: await client.say("Usage: !tip <amount> @username") if amount <= 1: err_embed.description = "`amount` must be greater than 1" await client.say(ember=err_embed) return user_exists = session.query(Wallet).filter( Wallet.userid == user.id).first() self_exists = session.query(Wallet).filter( Wallet.userid == ctx.message.author.id).first() if user.id == ctx.message.author.id: err_embed.description = "You cannot tip yourself!" await client.say(embed=err_embed) return if self_exists and amount < 50000000 and user_exists: pid = gen_paymentid(self_exists.address) balance = session.query(TipJar).filter(TipJar.paymentid == pid).first() print(balance) if not balance: t = TipJar(pid, ctx.message.author.id, 0) session.add(t) session.commit() err_embed.description = "You are now registered, please `!deposit` to tip" await client.send_message(ctx.message.author, embed=err_embed) else: fee = get_fee(amount) if balance.amount < 0: balance.amount = 0 session.commit() err_embed.description = "Your balance was negative!" await client.send_message(ctx.message.author, "It has been reset to zero") return if amount + fee > balance.amount: err_embed.description = "Your balance is too low! Amount + Fee = `{}` TRTLs".format( (amount + fee) / 100) await client.send_message( ctx.message.author, "You have `{0:,.2f}` TRTLs".format(balance.amount / 100)) return else: transfer = build_transfer(user_exists.address, amount, self_exists.address, balance) print(transfer) result = rpc.sendTransaction(transfer) print(result) if (balance.amount - amount + fee) < 0: print("ERROR! Balance corrupted") balance.amount = 0 return try: session.commit() except: session.rollback() raise await client.say("Sent `{0:,.2f}` TRTLs".format(amount / 100)) good_embed.description = "{} sent you `{}` TRTLs with Transaction Hash ```{}```".format( ctx.message.author.mention, amount / 100, result['transactionHash']) good_embed.url = "https://blocks.turtle.link/?hash={}#blockchain_transaction".format( result['transactionHash']) await client.send_message(user, embed=good_embed) balance.amount -= amount + fee tx = Transaction(result['transactionHash']) session.add(tx) session.commit() return elif amount > int(rpc.getBalance()['availableBalance']): err_embed.description = "Too many coins are locked, please wait." elif amount > 50000000: err_embed.description = "Transactions must be under 500k TRTLs!" elif not user_exists: err_embed.description = "{} hasn't registered to be tipped!".format( user.name) await client.send_message(user, embed=request_embed) else: err_embed.description = "You haven't registered a wallet!" err_embed.add_field( name="Help", value="Use `!registerwallet <addr>` before trying to tip!") await client.say(embed=err_embed)