def embed(self) -> CustomEmbed: nonce_data = 'Bettor rolls: {}, dealer rolls: {}'.format( ', '.join(['({0[result]}, {0[nonce]})'.format(i) for i in self.bettor_random]), ', '.join(['({0[result]}, {0[nonce]})'.format(i) for i in self.dealer_random]) ) card_values = [ ', '.join(self.bettor_hand) + '\n' + self.display_value_of_hand(self.bettor_hand), ', '.join(self.dealer_hand) + '\n' + self.display_value_of_hand(self.dealer_hand), ] if self.dealer_turn == False: nonce_data = 'Bettor rolls: {}, dealer rolls: {}'.format( ', '.join(['({0[result]}, {0[nonce]})'.format(i) for i in self.bettor_random]), '({0[result]}, {0[nonce]})'.format(self.dealer_random[0]) ) card_values[1] = ', '.join([self.dealer_hand[0], CARD_BACK]) + '\n' + self.display_value_of_hand([self.dealer_hand[0], CARD_BACK]) user = {True: self.dealer, False: self.bettor}[self.dealer_turn] role = {True: 'dealer', False: 'bettor'}[self.dealer_turn] colour = {True: 0x325c95, False: 0x2d5a1e}[self.dealer_turn] # with CustomEmbed(colour=0x325c95) as e: e = CustomEmbed(colour=colour) e.description = 'Use the `hit` or `stand` commands to continue, <@{}> ({})'.format(user, role) e.add_new_field('Bettor Hand', card_values[0]) e.add_new_field('House Hand', card_values[1]) e.set_footer(text=nonce_data) return e
async def roll_dice(self, ctx:Context, prediction:str): ''' Rolls a dice, betting for a particular segment ''' # Get their die die = await self.bot.aget_die(ctx.author.id) roll = die.get_random() # The "who won" functions segfunc = { 'HOT': lambda x: x in ['RED', 'ORANGE', 'YELLOW'], 'COLD': lambda x: x in ['BLUE', 'PASTEL', 'PURPLE'], 'RAINBOW': lambda x: x in ['RAINBOW'] }.get(prediction, lambda x: x == prediction) all_colours = ['RED', 'ORANGE', 'YELLOW', 'BLUE', 'PASTEL', 'PURPLE', 'RAINBOW'] rolled_flower = random_from_list(roll['result'], all_colours) won_bool = segfunc(rolled_flower) # Boolean, whether or not they won # Outputs desc = 'You picked **{0}** and {1} the pot.'.format( rolled_flower.lower(), {True:'won',False:'lost'}.get(won_bool) ) with CustomEmbed() as e: e.description = desc e.set_thumbnail(url=self.flower_colours.get(rolled_flower)) e.set_footer(text='Roll: {}; Nonce: {}'.format(roll['result'], roll['nonce'])) await ctx.send(embed=e) async with self.bot.database() as db: await db.store_die(die)
async def wallet(self, ctx: Context, other_user: Member = None): ''' Gives you your current balance ''' user = ctx.author if not other_user else other_user user_id = user.id async with self.bot.database() as db: x = await db('SELECT * FROM user_data WHERE user_id=$1', user_id) # Other user is set, specified user is not author, private wallet, and not cashier if other_user and other_user.id != ctx.author.id and x[0][ 'visibility'] != 'public' and 'Cashier' not in [ i.name for i in ctx.author.roles ]: await ctx.send( 'You do not have permission to see that person\'s wallet.') return with CustomEmbed() as e: if other_user: e.set_author_to_user(user) e.add_new_field('RS3', money_displayer(x[0]['newscape'])) e.add_new_field('07scape', money_displayer(x[0]['oldscape'])) if x[0]['visibility'] == 'public': await ctx.send(embed=e) else: await ctx.author.send(embed=e) await ctx.message.add_reaction( '\N{ENVELOPE WITH DOWNWARDS ARROW ABOVE}')
async def enddice(self, ctx:Context): ''' Gets the unhashed server seed and invalidates your current dice ''' d = self.bot.get_die(ctx.author.id) d.valid = False async with self.bot.database() as db: sql = 'DELETE FROM dice WHERE user_id=$1' await db(sql, ctx.author.id) url = 'https://dicesites.com/primedice/verifier?' params = { 'ss': d.server_seed, 'ssh': d.server_seed_hash, 'cs': d.client_seed, 'ln': d.nonce } url = url + '&'.join(['{}={}'.format(i, o) for i, o in params.items()]) with CustomEmbed() as e: e.set_author(name='Click Here', url=url) await ctx.send( 'Your server seed is `{0.server_seed}`, hash is `{0.server_seed_hash}`, and your client seed is `{0.client_seed}`. Your die has now been invalidated.'.format(d), embed=e )
async def mydice(self, ctx:Context): ''' Gives you the stats of your dice ''' d = self.bot.get_die(ctx.author.id) with CustomEmbed() as e: e.add_new_field('Server Seed Hash', d.server_seed_hash) e.add_new_field('Client Seed', d.client_seed) e.add_new_field('Latest Nonce', d.nonce) await ctx.send( 'To see the unhashed seed, you need to invalidate the dice with the `enddice` command.', embed=e )
async def roll(self, ctx:Context, segment:str=None, amount:str=None): ''' Rolls a die for you ''' # Get the user's currency async with self.bot.database() as db: currency_type = await db.get_user_currency_mode(ctx.author) # Check both amount and segment are defined if type(segment) == str and amount == None and money_fetcher(segment): amount = money_fetcher(segment) segment = 'HIGH' elif segment != None and amount == None: pass elif segment != None and amount != None: if segment[0].isnumeric(): amount, segment = segment, amount amount = money_fetcher(amount) else: segment = 'HIGH' amount = None # Make sure the user has enough money to lose async with self.bot.database() as db: current_wallet = await db.get_user_currency(ctx.author, currency_type) if amount and amount > current_wallet: await ctx.send('You don\'t have enough money to make that bet.') return # See if segment is valid try: segment = { 'high': 'HIGH', 'h': 'HIGH', 'hi': 'HIGH', 'middle': 'MID', 'mid': 'MID', 'medium': 'MID', 'm': 'MID', 'low': 'LOW', 'l': 'LOW', 'bottom': 'LOW', 'bot': 'LOW' }[segment.lower()] except KeyError: await ctx.send('I can\'t work out what you\'re trying to bet on.') return segfunc = { 'HIGH': lambda x: x >= 55 and x < 101, 'MID': lambda x: x >= 45 and x < 55, 'LOW': lambda x: x >= 0 and x < 45 }[segment] # Get and roll their die die = self.bot.get_die(ctx.author.id) provenfair = die.get_random() # See if they won or lost roll_result = provenfair['result'] wonroll = segfunc(roll_result) # See how much to modify by if amount: modamount = amount if wonroll else -amount if segment == 'MID' and wonroll: modamount = 3.5 * amount # See if they have any raffle tickets rafflemod = self.bot.config['Ticket Thresholds'][str(currency_type)] if amount: new_tickets = amount // rafflemod else: new_tickets = 0 # Generate an output for the user desc = '**' if new_tickets: desc += 'Along with their {0} new raffle tickets, '.format(new_tickets) desc += '{0.mention} has rolled a {1} on the percentile die and {2} the pot'.format( ctx.author, roll_result, {True: 'won', False: 'lost'}[wonroll] ) if amount and modamount > 0: desc += ' of {}**'.format(money_displayer(modamount + amount)) else: desc += '**' # Store it in the database async with self.bot.database() as db: if amount: await db.modify_user_currency(ctx.author, modamount, currency_type) await db.log_user_mod( message=ctx.message, to=ctx.author, amount=modamount, currency=currency_type, reason='ROLL' ) if new_tickets: await db.add_tickets_for_user(ctx.author, new_tickets) await db.store_die(die) # Send an embed with the data with CustomEmbed() as e: e.description = desc e.set_thumbnail(url='https://vignette.wikia.nocookie.net/runescape2/images/f/f2/Dice_bag_detail.png/revision/latest/scale-to-width-down/100?cb=20111120013858') e.set_footer(text='Nonce: {}'.format(provenfair['nonce']) + '. To see all random stats, run the mydice command.') await ctx.send(embed=e)
async def diceduel(self, ctx:Context, user:Member, user_two:str=None, amount:int=0): ''' Runs a dice duel of one (against the host) or two users ''' ''' Possible invocation scenarios: |user*|user2|amount dd|@user|50 | dd|@user|@user| dd|@user| | dd|@user|@user|50 ''' # Validate who's duelling who and for what if amount: user_one = user user_two = ctx.guild.get_member(int(''.join([i for i in user_two if i.isdigit()]))) elif user_two: if user_two.isdigit(): amount = int(user_two) user_one, user_two = ctx.author, user else: user_one = user user_two = ctx.guild.get_member(int(''.join([i for i in user_two if i.isdigit()]))) else: user_one, user_two = ctx.author, user # Get the dice of the two users user_one_dice = await self.bot.aget_die(user_one.id) user_two_dice = await self.bot.aget_die(user_two.id) # Roll their dice user_one_rolls = [user_one_dice.get_random() for i in range(2)] user_two_rolls = [user_two_dice.get_random() for i in range(2)] # Convert to dice user_one_diceroll = [get_dice_roll(i['result']) for i in user_one_rolls] user_two_diceroll = [get_dice_roll(i['result']) for i in user_two_rolls] # Embed it nonce_data = '{}\'s rolls: {}, {}\'s rolls: {}'.format( user_one.name, ', '.join(['({0[result]}, {0[nonce]})'.format(i) for i in user_one_rolls]), user_two.name, ', '.join(['({0[result]}, {0[nonce]})'.format(i) for i in user_two_rolls]) ) with CustomEmbed() as e: e.add_new_field( user_one.name + ' rolls', '**{0}** ({1[0]} and {1[1]})'.format(sum(user_one_diceroll), user_one_diceroll) ) e.add_new_field( user_two.name + ' rolls', '**{0}** ({1[0]} and {1[1]})'.format(sum(user_two_diceroll), user_two_diceroll) ) e.set_footer(text=nonce_data) # Check who won if sum(user_one_diceroll) == sum(user_two_diceroll): if [i for i in user_one.roles if i.name == 'Host']: winner = user_one else: winner = user_two else: winner = user_one if sum(user_one_diceroll) > sum(user_two_diceroll) else user_two text = 'The winner is {0.mention}!'.format(winner) await ctx.send(text, embed=e) # Store rolled dice async with self.bot.database() as db: await db.store_die(user_one_dice) await db.store_die(user_two_dice)
async def run_giveaway(self): ''' Runs the giveaway ie the channel sending and tracking ''' remaining_time = lambda x: 'Giveaway of **{} RS3**! Type a message within the next {} seconds to be entered!'.format( money_displayer(self.amount), x) # Get the channel self.regen_config() channel = self.bot.get_channel(self.channel_id) # Tell the users about it with CustomEmbed() as e: e.description = remaining_time(self.duration) e.colour = GREEN message = await channel.send(embed=e) self.running = True # For the on_message flag self.lastrun = dt.now() # Wait for messages to roll in current_users = 0 running_duration = 0 edited = False duration_editor = 5 # Change the embed every x seconds while dt.now() < self.lastrun + timedelta(seconds=self.duration): # Check to see if the thing should be edited working_running_duration = ( dt.now() - (self.lastrun + timedelta(seconds=self.duration))).total_seconds() working_running_duration = int(running_duration / duration_editor) if working_running_duration > running_duration: running_duration = working_running_duration e.description = remaining_time(self.duration - (working_running_duration * duration_editor)) edited = True # Check if the entered users is larger than what's displayed if len(self.counted) > current_users: current_users = len(self.counted) try: e.set_field_at(0, name='Entered Users', value=current_users) except Exception: e.add_new_field('Entered Users', current_users) edited = True # Whether or not to edit if edited: await message.edit(embed=e) await sleep(1) self.running = False # Generate a random number users = list(self.counted) # Change the embed e.description = 'Giveaway over!' e.colour = RED # Check that *someone* entered if users: chosen_user = choice(users) async with self.bot.database() as db: await db.modify_user_currency(chosen_user, self.amount, NewScape()) await db.log_user_mod(message=message, to=chosen_user, amount=self.amount, currency=NewScape(), reason='GIVEAWAY') self.counted = set() # Tell them about it await message.edit(embed=e) await channel.send('<@{}> you just won **{} RS3**!'.format( chosen_user, money_displayer(self.amount))) return # Nobody entered await message.edit(content='Guess nobody wants any free money then :/', embed=e) return