async def accept(self, ctx): """Accept the Pawer terms, run deposit first""" user = User(ctx.author.id) user_info = user.info() # if accepted, say when and gives address if user_info: if user_info['accept']: msg = "Your :bis: address is `{}`".format(user_info['address']) em = discord.Embed(description=msg, colour=discord.Colour.orange()) em.set_author( name="{}, you already accepted the terms on {}".format( ctx.author.display_name, ts_to_string(user_info['accept']))) await ctx.send(embed=em) return # If not, creates wallet and stores accepted. address = user.create_wallet() info = {"accept": int(time.time()), "address": address} user.save(info) self.bot.tip_module.add_user(address, ctx.author.id, ctx.author.display_name) # TODO: safety, store an encrypted backup of the wallet elsewhere. msg = "Your {} address is `{}`".format(EMOJIS['Bismuth'], info['address']) em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author( name="{}: Terms accepted".format(ctx.author.display_name)) await ctx.send(embed=em)
async def list(self, ctx): """List games for current user""" user = User(ctx.message.author.id) user_info = user.info() address = user_info['address'] # await self.bot.say("Eggs of {}".format(address)) hashes = await async_get("http://autogame.bismuth.live:6060/api/seed/{}".format(address), is_json=True) msg = "" if hashes is None or len(hashes) == 0: msg = 'You are not registered to any game yet :(' for hash in hashes: info = await async_get("http://autogame.bismuth.live:6060/api/db/{}".format(hash), is_json=True) try: if info['finished']: url = "http://autogame.bismuth.live:6060/replay/{}".format(hash) about = f"Finished - {info['league']}, start block {info['block_start']}, Experience {info['experience']} - {url}" else: url = "http://autogame.bismuth.live:6060/unfinished/{}".format(hash) about = f"*Ongoing* {info['league']}, start block {info['block_start']}, Experience {info['experience']} - {url}" except: about = 'N/A'; msg += "- {} - {}\n".format(hash, about) em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author(name="Games of {}".format(address)) await self.bot.say(embed=em)
async def sign(self, ctx, message: str): """Sign a message from your wallet, for off-chain use""" try: user = User(ctx.author.id) user_info = user.info() if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough res = user.sign_message(message) sign = res['sign'] # print("sign", sign) if sign: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up await ctx.send("Signature is `{}`.".format(sign)) else: await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(res['error'])) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(e))
async def claim(self, ctx): user = User(ctx.message.author.id) user_info = user.info() data = await async_get( "https://dragginator.com/api/info.php?type=calendar&address={}".format(user_info['address']), is_json=True) colour = discord.Colour.red() if int(data[1]) == 0: msg = "Sorry, but you don't own any egg" elif int(data[2]) > 0: msg = "Sorry, but you already claimed an egg today" elif user_info['address'][:2] in data[0]: msg = "Your address matches with one of today seeds\n" if float(user.balance()) >= 0.01: txid = user.send_bis_to(0, "9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", operation="dragg:claim")["txid"] msg += "txid: {}".format(txid) colour = discord.Colour.green() else: msg += "Not enough Bis to afford the fees ;(" else: msg = "Sorry, but your address doesn't match with any of today's seeds" em = discord.Embed(description=msg, colour=colour) em.set_author(name="Advent calendar") await self.bot.say(embed=em)
async def eggdrop(self, ctx): """Register to the current eggdrop (only if you don't have any egg)""" user = User(ctx.author.id) user_info = user.info() data = await async_get( "https://dragginator.com/api/info.php?address={}&type=eggdrop". format(user_info['address']), is_json=True) if data[0] == "registered": msg = "You are already registered to the eggdrop" elif data[0]: msg = "The word is {}\n".format(data[1]) if float(user.balance()) >= 0.01: result = user.send_bis_to( 0, "9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", data=data[1]) msg += "txid: {}".format(result['txid']) else: msg += "Not enough Bis to afford the fees ;(" else: msg = "Sorry, but you already own {} eggs".format(str(data[1])) em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author(name="Eggdrop") await ctx.send(embed=em)
async def watch(self, ctx, hypernode: str = ''): """Adds a hn to watch, print the current list""" try: user = User(ctx.message.author.id) user_info = user.info() msg = '' if hypernode: hn_status = await self._hn_status() if hypernode not in hn_status: # unknown ip msg = "No known Hypernode with ip {}".format(hypernode) em = discord.Embed(description=msg, colour=discord.Colour.red()) em.set_author(name="Error") await self.bot.say(embed=em) return # add the hhn to the list if hypernode not in user_info.get('hn_watch', []): watch = user_info.get('hn_watch', []) watch.append(hypernode) # TODO: add to reverse index user_info['hn_watch'] = watch msg = "Added {}\n".format(hypernode) user.save(user_info) watch_list = await self.hn_watch_list(user_info, for_print=True) msg += watch_list em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author(name="You're watching...") await self.bot.say(embed=em) except Exception as e: print(e) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
async def freebismuth(self, ctx, tweet_url: str): """Register your #Bismuth tweet and get free bismuth""" try: amount = float(0) # amount has to be 0 operation = 'twitter' user = User(ctx.author.id) user_info = user.info() address = user_info['address'] #validate tweet url. # TODO: Validate tweet likes and retweets as per freebismuth spec if not validators.url(tweet_url): print("tweet url error") await ctx.message.add_reaction('😟') await ctx.send( "Link to the tweet does not look ok. Command is `Pawer freebismuth <tweet_url>`" ) return if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough balance = float(user.balance()) tweet_id = re.search('/status/(\d+)', tweet_url).group(1) # Extract tweet ID msg = "{} freebismuth, tweet ID is {} ".format( ctx.author.display_name, tweet_id) fees = BismuthUtil.fee_for_tx(tweet_id) print(msg) if balance < amount + fees: print("balance too low") await ctx.message.add_reaction('😟') await ctx.send( "Not enough balance to cover fee ({} Fees)".format( fees)) return send = user.send_bis_to(amount, address, data=tweet_id, operation=operation) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up await ctx.send( "Your tweet has been registered. Txid is {}.".format( txid)) else: await ctx.message.add_reaction('👎') # Thumb down await ctx.send( "Can't register your tweet. Error {}".format( send['error'])) return except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Can't register your tweet. Error {}".format(e))
async def tip(self, ctx, who_to_tip: discord.Member, amount: str='1'): """Tip a user, default 1 bis, min 0.1, max 50 BIS""" try: amount = float(amount) if amount > 50: amount = 50 await ctx.send("Maw tip amount too high, lowering to 50 {}".format(EMOJIS['Bismuth'])) if amount < 0.1: amount = 0.1 user = User(ctx.author.id) user_info = user.info() # print(ctx.author.id, user_info) if user_info and user_info['address']: # User exists and validated the terms, has an address # We could get a custom default tip value here from the info # Make sure balance is enough balance = float(user.balance()) msg = "{} tip {}, balance is {} ".format(ctx.author.display_name, amount, balance) print(msg) if balance < amount + 0.01: print("balance too low") await ctx.message.add_reaction('😟') # await ctx.message.add_reaction('⚖️') return user_to_tip_info = User(who_to_tip.id).info() print("to_tip", user_to_tip_info) if not user_to_tip_info or not user_to_tip_info['address']: print("user has no wallet") await ctx.message.add_reaction('🤔') # Thinking face purse message = "Hi {}, {} wanted to tip you, but you do not have a Discord Bismuth wallet yet.\n"\ .format(who_to_tip.display_name, ctx.author.display_name) message += "It's easy, you just have to type `Pawer deposit` here to read and accept the terms.\n" message += "Then you'll have an address of yours and be able to receive tips and play with me.\n" message += "Use `Pawer help` to get a full list of what I can do." await self.safe_send_message(who_to_tip, message) return send = user.send_bis_to(amount, user_to_tip_info['address']) self.bot.tip_module.tip(user_info['address'], user_to_tip_info['address'], amount) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up message = "Yeah! You've been tipped {:0.2f} {} by {} ({}) from the Bismuth discord!"\ .format(amount, EMOJIS['Bismuth'], ctx.author, ctx.author.display_name) await self.safe_send_message(who_to_tip, message) else: await ctx.message.add_reaction('👎') return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down
async def operation(self, ctx, operation: str, address: str, amount: str, message: str = ''): # TODO: too much code in common with withdraw, factorize somehow. try: amount = float(amount) user = User(ctx.message.author.id) user_info = user.info() # Check the address looks ok if not BismuthUtil.valid_address(address): print("address error") await self.bot.add_reaction(ctx.message, '😟') await self.bot.say( "Address does not look ok. Command is `Pawer operation <operation> <address> <amount> [message]`" ) return if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough balance = float(user.balance()) msg = "{} withdraw {}, balance is {} ".format( ctx.message.author.display_name, amount, balance) fees = BismuthUtil.fee_for_tx(message) print(msg) if balance < amount + 0.01: print("balance too low") await self.bot.add_reaction(ctx.message, '😟') await self.bot.say( "Not enough balance to cover amount + fee ({} Fees)". format(fees)) return send = user.send_bis_to(amount, address, data=message, operation=operation) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await self.bot.add_reaction(ctx.message, '👍') # Thumb up await self.bot.say("Done, txid is {}.".format(txid)) else: await self.bot.add_reaction(ctx.message, '👎') # Thumb down await self.bot.say("Error {}".format(send['error'])) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await self.bot.say(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await self.bot.add_reaction(ctx.message, '👎') # Thumb down await self.bot.say("Error {}".format(e))
async def get_user_info(cls, ctx, user_id=None, send_message=True): user = User(user_id if user_id else ctx.author.id) user_info = user.info() #print(ctx.author.id, user_info) if user_info: if user_info['accept']: return user, user_info if send_message: em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.dark_orange()) em.set_author(name="Terms:") await ctx.send(embed=em) return user, None
async def withdraw(self, ctx, address: str, amount: str, *message): """Send BIS from your wallet to any BIS address, with an optional message""" try: amount = float(amount) openfield_data = ' '.join(filter(None, message)) user = User(ctx.author.id) user_info = user.info() # Check the address looks ok if not BismuthUtil.valid_address(address): print("address error") await ctx.message.add_reaction('😟') await ctx.send( "Address does not look ok. Command is `Pawer withdraw <address> <amount> [message]`" ) return if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough balance = float(user.balance()) msg = "{} withdraw {}, balance is {} ".format( ctx.author.display_name, amount, balance) fees = BismuthUtil.fee_for_tx(openfield_data) print(msg) if balance < amount + 0.01: print("balance too low") await ctx.message.add_reaction('😟') await ctx.send( "Not enough balance to cover amount + fee ({} Fees)". format(fees)) return send = user.send_bis_to(amount, address, data=openfield_data) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up await ctx.send("Done, txid is {}.".format(txid)) else: await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(send['error'])) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(e))
async def zirco(self, ctx, amount: str, bet: str): """Play ZircoDice from your pawer wallet, with any amount less than 100 along with your bet """ try: amount = float(amount) zirco_service_address = '340c195f768be515488a6efedb958e135150b2ef3e53573a7017ac7d' user = User(ctx.author.id) user_info = user.info() # Check the bet field if bet.lower() not in ('odd', 'even'): print("OpenField data error") await ctx.message.add_reaction('😟') await ctx.send("Your bet does not look ok. Command is `Pawer zirco <amount> <odd/even>`") return # Check the bet amount if (amount - float(100)) > 0.01 : print("Bet amount too high") await ctx.message.add_reaction('😟') await ctx.send("You are betting too high. Recommended amount is less than 100`") return if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough balance = float(user.balance()) msg = "{} zirco {}, balance is {} ".format(ctx.author.display_name, amount, balance) fees = BismuthUtil.fee_for_tx(bet) print(msg) if balance < amount + 0.01004: print("balance too low") await ctx.message.add_reaction('😟') await ctx.send("Not enough balance to cover amount + fee ({} Fees)".format(fees)) return send = user.send_bis_to(amount, zirco_service_address, data=bet) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up await ctx.send("Your bet has been placed. Txid is {}".format(txid)) await self.bot.remove_reaction(ctx.message, '⏳', self.bot.user) await self.get_zirco_status(ctx.author, txid) else: await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Can't place your bet. Error {}".format(send['error'])) return except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Can't place your bet. Error {}".format(e))
async def cup(self, ctx): """Give information about the cup""" user = User(ctx.author.id) user_info = user.info() data = await async_get( "https://dragginator.com/api/cup/address/?address={}&raw=1".format( user_info['address']), is_json=True) em = discord.Embed(description=data["message"], colour=discord.Colour.green()) em.set_author(name=data["title"]) await ctx.send(embed=em)
async def leagues(self, ctx, *dna): """Gives information about the leagues""" user = User(ctx.author.id) user_info = user.info() if len(dna) and dna[0] == "register": result = user.send_bis_to( 0, "9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", data=dna[1], operation="dragg:leagues", check_balance=True) if result["txid"]: em = discord.Embed( description="The Dna is now registered!\n Txid: {}".format( result["txid"]), colour=discord.Colour.green()) elif result["error"] == "LOW_BALANCE": em = discord.Embed( description= "Sorry, but you don't have enough Bis to afford the fees", colour=discord.Colour.red()) elif result["error"] == "NO_WALLET": em = discord.Embed( description= "Sorry, but you have to create a wallet first: type `Pawer deposit`", colour=discord.Colour.red()) else: em = discord.Embed( description= "Something went wrong, Try again to see what append", colour=discord.Colour.red()) em.set_author(name="") await ctx.send(embed=em) return if len(dna): dna = dna[0] else: dna = "" data = await async_get( "https://dragginator.com/api/pawer/leagues_api.php?address={}&dna={}" .format(user_info['address'], dna), is_json=True) em = discord.Embed(description=data["message"], colour=discord.Colour.green()) em.set_author(name=data["title"]) await ctx.send(embed=em)
async def list(self, ctx): """List eggs for current user""" user = User(ctx.message.author.id) user_info = user.info() address = user_info['address'] # await self.bot.say("Eggs of {}".format(address)) eggs = await async_get("https://dragginator.com/api/info.php?address={}&type=list".format(address), is_json=True) msg = "" for egg in eggs: msg += "- {}\n".format(egg["dna"]) em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author(name="Eggs of {}".format(address)) await self.bot.say(embed=em)
async def user_count(message): try: registered_members = 0 for member in bot.get_all_members(): if not member.bot: current_user = User(member.id) user_info = current_user.info() if user_info and user_info["address"]: registered_members += 1 # bot.tip_module.add_user(user_info["address"], member.id, member.display_name) await message.channel.send( "{} users have a pawer account".format(registered_members)) except Exception as e: print(str(e))
async def eligibility(message): try: registered_members = 0 for member in bot.get_all_members(): if str(member.status) != "offline" and not member.bot: current_user = User(member.id) user_info = current_user.info() if user_info and user_info["address"]: registered_members += 1 await message.channel.send( "{} users are connected and have a pawer account".format( registered_members)) except Exception as e: print(str(e))
async def deposit(self, ctx): """Shows or creates a BIS deposit address""" user = User(ctx.author.id) user_info = user.info() print(ctx.author.id, user_info) if user_info: if user_info['accept']: msg = "{}, your {} address is `{}`".\ format(ctx.author.display_name, EMOJIS['Bismuth'], user_info['address']) em = discord.Embed(description=msg, colour=discord.Colour.green()) await ctx.send(embed=em) return em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.dark_orange()) em.set_author(name="Terms:") await ctx.send(embed=em)
async def unwatch(self, ctx, hypernode: str = ''): """Adds a hn to watch, print the current list""" user = User(ctx.message.author.id) user_info = user.info() msg = '' if hypernode: # add the hhn to the list if hypernode in user_info.get('hn_watch', []): watch = user_info.get('hn_watch', []) watch = [hn for hn in watch if hn != hypernode] # TODO: add to reverse index user_info['hn_watch'] = watch msg = "Removed {}\n".format(hypernode) user.save(user_info) watch_list = await self.hn_watch_list(user_info, for_print=True) msg += watch_list em = discord.Embed(description=msg, colour=discord.Colour.green()) em.set_author(name="You're watching...") await self.bot.say(embed=em)
async def balance(self, ctx): """Displays your current BIS balance""" try: # TODO: several types of balance (bis, usd, eur?) or by reactions rather than message ;) user = User(ctx.author.id) user_info = user.info() # print(ctx.author.id, user_info) if user_info and user_info['address']: # User exists and validated the terms, has an address balance = user.balance() msg = "{}, your balance is {} {}".\ format(ctx.author.display_name, balance, EMOJIS['Bismuth']) em = discord.Embed(description=msg, colour=discord.Colour.green()) await ctx.send(embed=em) return em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down
async def register(self, ctx, *dna): """Registers a dna to the cup""" message = "" title = "Registering {}".format(dna) if dna: dna = dna[0] title = "Registering {}".format(dna) user = User(ctx.author.id) user_info = user.info() if user_info and user_info['address']: data = await async_get( "https://dragginator.com/api/cup/register/{}/?raw=1". format(dna), is_json=True) res = user.sign_message(data["message"]) signed = res['sign'] if signed: data = await async_get( "https://dragginator.com/api/cup/register/{}/{}/{}/?raw=1" .format(dna, data["cup"], signed), is_json=True) if not data["signature_result"]: message = "Invalid signature! Are you sure you own this dna?" else: if data["can_join_cup"]: message = "Dna successfully registered!" else: message = "This dna can't join this cup." else: message = "Failed to sign the message." else: message = "You don't have a pawer account yet." else: message = "Usage: Pawer dragg register a_dna_you_own" em = discord.Embed(description=message, colour=discord.Colour.green()) em.set_author(name=title) await ctx.send(embed=em)
async def buy(self, ctx): """Buy an egg with Bis""" user = User(ctx.message.author.id) user_info = user.info() result = user.send_bis_to(EGG_PRICE, "9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", check_balance=True) if result["txid"]: em = discord.Embed(description="Your egg is generating...\n Txid: {}".format(result["txid"]), colour=discord.Colour.green()) elif result["error"] == "LOW_BALANCE": em = discord.Embed( description="Sorry, but you don't have enough Bis to buy an egg ;( Current price is {} $BIS.".format( EGG_PRICE), colour=discord.Colour.red()) elif result["error"] == "NO_WALLET": em = discord.Embed(description="Sorry, but you have to create a wallet first: type `Pawer deposit`", colour=discord.Colour.red()) else: em = discord.Embed(description="Something went wrong, Try again to see what append", colour=discord.Colour.red()) em.set_author(name="Get an egg with Bis") await self.bot.say(embed=em)
async def eggrain(self, ctx, how_many_users: str = '5'): try: how_many_users = int(how_many_users) if how_many_users > 100: how_many_users = 100 if how_many_users < 1: how_many_users = 1 user = User(ctx.message.author.id) user_info = user.info() if user_info and user_info['address']: balance = float(user.balance()) msg = "{} rain {} eggs to {} users, balance is {} ".format(ctx.message.author.display_name, how_many_users, how_many_users, balance) print(msg) if balance < how_many_users * (EGG_PRICE + 0.011): print("balance too low") await self.bot.add_reaction(ctx.message, '😟') return registered_members = [] unregistered_members = [] for member in self.bot.get_all_members(): if str(member.status) != "offline" and not member.bot and member.name != ctx.message.author.name: # print(member.name, member.status, member.bot) current_user = User(member.id) member_info = current_user.info() if member_info and member_info["address"]: registered_members.append(member) else: unregistered_members.append(member) how_many_real_users = (min(how_many_users, len(registered_members))) shuffle(registered_members) shuffle(unregistered_members) message = "Yeah! You got a draggon egg from the rain of {} ({}) from the Bismuth discord!" \ .format(ctx.message.author, ctx.message.author.display_name) final_message = "{} sent a draggon egg to: ".format(ctx.message.author.mention) self.bot.tip_module.start_rain(user_info['address'], how_many_real_users, how_many_real_users, "eggrain") for current_member in registered_members[:how_many_real_users]: user.send_bis_to(EGG_PRICE, "9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", operation="dragg:gift", data=User(current_member.id).info()['address']) self.bot.tip_module.tip(user_info['address'], User(current_member.id).info()['address'], 1, "eggrain") final_message += current_member.mention + " " await self.safe_send_message(current_member, message) await self.bot.say(final_message) await self.bot.add_reaction(ctx.message, '👍') # Thumb up for current_member in unregistered_members[:10]: message = "Hi {}, {} launched a draggon eggs rain, but you do not have a Discord Bismuth wallet yet.\n" \ .format(current_member.display_name, ctx.message.author.display_name) message += "It's easy, you just have to type `Pawer deposit` here to read and accept the terms.\n" message += "Then you'll have an address of yours and be able to receive tips and play with me.\n" message += "Use `Pawer help` to get a full list of what I can do." await self.safe_send_message(current_member, message) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await self.bot.say(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await self.bot.add_reaction(ctx.message, '👎') # Thumb down
async def bisurl(self, ctx, bisurl: str, send: str = 'NO'): """Decode a transaction from a BIS URL. Append SEND to effectively send the tx.""" # TODO: too much code in common with withdraw, factorize somehow. try: try: decode = BismuthUtil.read_url(bisurl) except Exception as e: await ctx.message.add_reaction('😢') # Crying await ctx.send("Does not look like a proper BIS URL") return amount = float(decode['amount']) address = decode['recipient'] operation = decode['operation'] message = decode['openfield'] fees = BismuthUtil.fee_for_tx(message) decoded = "▸ Recipient: {}\n".format(address) decoded += "▸ Amount: {:.2f} $BIS\n".format(amount) decoded += "▸ Operation: {}\n".format(operation) decoded += "▸ Message: {}\n".format(message) decoded += "▸ Fees: {} $BIS\n".format(fees) if send == 'SEND': title = "Decoded BIS URL:" em = discord.Embed(description=decoded, colour=discord.Colour.green()) em.set_author(name=title) await ctx.send(embed=em) else: title = "Decoded BIS URL: (**not** sent)" decoded += " \nPaste this command again and append ` SEND` if you want to send that transaction.\n" em = discord.Embed(description=decoded, colour=discord.Colour.green()) em.set_author(name=title) await ctx.send(embed=em) return user = User(ctx.author.id) user_info = user.info() # Check the address looks ok if not BismuthUtil.valid_address(decode['recipient']): print("address error") await ctx.message.add_reaction('😟') await ctx.send( "Address does not look ok. Command is `Pawer operation <operation> <address> <amount> [message]`" ) return if user_info and user_info['address']: # User exists and validated the terms, has an address # Make sure balance is enough balance = float(user.balance()) msg = "{} withdraw {}, balance is {} ".format( ctx.author.display_name, amount, balance) fees = BismuthUtil.fee_for_tx(message) print(msg) if balance < amount + 0.01: print("balance too low") await ctx.message.add_reaction('😟') await ctx.send( "Not enough balance to cover amount + fee ({} Fees)". format(fees)) return send = user.send_bis_to(amount, address, data=message, operation=operation) txid = send['txid'] print("txid", txid) if txid: # answer by reaction not to pollute await ctx.message.add_reaction('👍') # Thumb up await ctx.send("Done, txid is {}.".format(txid)) else: await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(send['error'])) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down await ctx.send("Error {}".format(e))
async def rain(self, ctx, total_amount: str = '10', how_many_users: str = '10'): """Distribute a given amount between n users""" try: if "/" in total_amount: data = total_amount.split("/") total_amount = float(data[0]) how_many_users = float(data[1]) total_amount = float(total_amount) how_many_users = int(how_many_users) if total_amount < 0 or how_many_users < 0: return if how_many_users > 100: how_many_users = 100 if how_many_users < 1: how_many_users = 1 if total_amount > 1000: total_amount = 1000 if total_amount < 0.1 * how_many_users: how_many_users = int(total_amount / 0.1) individual_amount = total_amount / how_many_users user = User(ctx.author.id) user_info = user.info() if user_info and user_info['address']: balance = float(user.balance()) msg = "{} rain {} bis to {} users, balance is {} ".format( ctx.author.display_name, total_amount, how_many_users, balance) print(msg) if balance < total_amount + 0.01 * how_many_users: print("balance too low") await ctx.message.add_reaction('😟') return registered_members = [] unregistered_members = [] for member in self.bot.get_all_members(): if str( member.status ) != "offline" and not member.bot and member.name != ctx.author.name: #print(member.name, member.status, member.bot) current_user = User(member.id) member_info = current_user.info() if member_info and member_info["address"]: registered_members.append(member) else: unregistered_members.append(member) how_many_real_users = int( min(how_many_users, len(registered_members))) shuffle(registered_members) shuffle(unregistered_members) message = "Yeah! You got {:0.2f} {} from the rain of {} ({}) from the Bismuth discord!" \ .format(individual_amount, EMOJIS['Bismuth'], ctx.author, ctx.author.display_name) final_message = "{} sent {:0.2f} {} each to: ".format( ctx.author.mention, individual_amount, EMOJIS['Bismuth']) self.bot.tip_module.start_rain( user_info['address'], individual_amount * how_many_real_users, how_many_real_users, "rain") for current_member in registered_members[:how_many_real_users]: to_address = User(current_member.id).info()['address'] user.send_bis_to(individual_amount, to_address) self.bot.tip_module.tip(user_info['address'], to_address, individual_amount, "rain") final_message += current_member.mention + " " await self.safe_send_message(current_member, message) await ctx.send(final_message) await ctx.message.add_reaction('👍') # Thumb up for current_member in unregistered_members[:10]: message = "Hi {}, {} launched a rain, but you do not have a Discord Bismuth wallet yet.\n" \ .format(current_member.display_name, ctx.author.display_name) message += "It's easy, you just have to type `Pawer deposit` here to read and accept the terms.\n" message += "Then you'll have an address of yours and be able to receive tips and play with me.\n" message += "Use `Pawer help` to get a full list of what I can do." await self.safe_send_message(current_member, message) return # Depending on channel, say or send PM em = discord.Embed(description=DISCLAIMER, colour=discord.Colour.red()) em.set_author(name="You have to create your address first:") await ctx.send(embed=em) except Exception as e: print(str(e)) # Send a PM to the sender or answer if dedicated channel await ctx.message.add_reaction('👎') # Thumb down