async def buy_gem_skin(self, ctx: Context, user: discord.User, config: Config, item_data: dict): brawler = item_data["brawler"] cost = item_data["cost"] skin = item_data["skin"] gems = await config.user(user).gems() if gems < cost: await ctx.send(f"You do not have enough gems! ({gems}/{cost})") return False msg = await ctx.send( f"{user.mention} Buying **{skin} {brawler}**" f" skin will cost {emojis['gem']} {cost}. Continue?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, user) await ctx.bot.wait_for("reaction_add", check=pred) if pred.result: # User responded with tick pass else: # User responded with cross await ctx.send("Purchase cancelled.") return False async with config.user(user).brawlers() as brawlers: brawlers[brawler]["skins"].append(skin) await config.user(user).gems.set(gems - cost) await ctx.send(f"Bought {skin} {brawler} skin!") return True
async def user_cooldown_msg(ctx: Context, config: Config): """Return cooldown message with time remaining.""" async with config.user(ctx.author).cooldown() as cooldown: command = ctx.command.qualified_name per = cooldown[command]["per"] last = cooldown[command]["last"] + per now = utc_timestamp(datetime.utcnow()) return ("This command is on cooldown. Try again in {}.".format( humanize_timedelta(seconds=last - now) or "1 second"))
async def user_cooldown(rate: int, per: int, config: Config, ctx: Context): """Handle user cooldown""" async with config.user(ctx.author).cooldown() as cooldown: if ctx.command.qualified_name not in cooldown: cooldown[ctx.command.qualified_name] = { "last": utc_timestamp(datetime.utcnow()), "rate": rate, "per": per, "uses": 1 } return True else: if await check_user_cooldown(ctx, config, cooldown): return True return False
async def buy_brawlbox(self, ctx: Context, user: discord.User, config: Config, brawlers: dict): brawler_data = await config.user(user).brawlers() box = Box(brawlers, brawler_data) try: embed = await box.brawlbox(config.user(user), user) except Exception as exc: return await ctx.send( f"Error \"{exc}\" while opening a Brawl Box." " Please notify bot creator using `-report` command.") try: await ctx.send(embed=embed) except discord.Forbidden: await ctx.send( "I do not have the permission to embed a link." " Please give/ask someone to give me that permission.")
async def buy_starpower(self, ctx: Context, user: discord.User, config: Config, item_data: dict): brawler = item_data["brawler"] cost = item_data["cost"] sp = item_data["sp"] sp_name = item_data["sp_name"] gold = await config.user(user).gold() if gold < cost: await ctx.send(f"You do not have enough gold! ({gold}/{cost})") return False msg = await ctx.send( f"{user.mention} Buying {brawler}'s Star Power **{sp_name}**" f" will cost {emojis['gold']} {cost}. Continue?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, user) await ctx.bot.wait_for("reaction_add", check=pred) if pred.result: # User responded with tick pass else: # User responded with cross await ctx.send("Purchase cancelled.") return False async with config.user(user).brawlers() as brawlers: brawlers[brawler]["level"] = 10 brawlers[brawler][sp] = True await config.user(user).gold.set(gold - cost) await ctx.send(f"Bought {sp_name} Star Power!") return True
async def buy_powerpoint(self, ctx: Context, user: discord.User, config: Config, item_data: dict): brawler = item_data["brawler"] quantity = item_data["quantity"] cost = item_data["cost"] gold = await config.user(user).gold() if gold < cost: await ctx.send(f"You do not have enough gold! ({gold}/{cost})") return msg = await ctx.send( f"{user.mention} Buying {quantity} {brawler} power points" f" will cost {emojis['gold']} {cost}. Continue?") start_adding_reactions(msg, ReactionPredicate.YES_OR_NO_EMOJIS) pred = ReactionPredicate.yes_or_no(msg, user) await ctx.bot.wait_for("reaction_add", check=pred) if pred.result: # User responded with tick pass else: # User responded with cross await ctx.send("Purchase cancelled.") return False async with config.user(user).brawlers() as brawlers: brawlers[brawler]['powerpoints'] += quantity brawlers[brawler]['total_powerpoints'] += quantity await config.user(user).gold.set(gold - cost) await ctx.send(f"Bought {quantity} {brawler} power points!") return True