async def daily(self, ctx): """Claim your daily Jenny with this command!""" now = datetime.utcnow() user = User(ctx.author.id) min = 50 max = 100 if user.is_premium: min *= 2 max *= 2 if ctx.guild and Guild(ctx.guild.id).is_premium: min *= 2 max *= 2 daily = randint(min, max) if user.is_entitled_to_double_jenny: daily *= 2 if str(user.daily_cooldown) < str(now): user.claim_daily() user.add_jenny(daily) await ctx.send( f'You claimed your {daily} daily Jenny and hold now on to {user.jenny}' ) else: cooldown = f"<t:{int(user.daily_cooldown.timestamp())}:R>" await ctx.send( f'You can claim your daily Jenny the next time in {cooldown}')
async def _eval_outcome(self, winlose: int, choice1, choice2, player1: discord.Member, player2: discord.Member) -> discord.Message: """Evaluates the outcome, informs the players and handles the points """ p1 = User(player1.id) p2 = User(player2.id) if winlose == -1: if self.points: p1.add_jenny(self.points) if player2 != self.ctx.me: p2.remove_jenny(self.points) return await self.ctx.send( f'{self.emotes[choice1]} > {self.emotes[choice2]}: {player1.mention} won against {player2.mention} winning {self.points} Jenny which adds to a total of {p1.jenny}' ) else: return await self.ctx.send( f'{self.emotes[choice1]} > {self.emotes[choice2]}: {player1.mention} won against {player2.mention}' ) elif winlose == 0: return await self.ctx.send( f'{self.emotes[choice1]} = {self.emotes[choice2]}: {player1.mention} tied against {player2.mention}' ) elif winlose == 1: if self.points: p1.remove_jenny(self.points) if player2 != self.ctx.me: p2.add_jenny(self.points) return await self.ctx.send( f'{self.emotes[choice1]} < {self.emotes[choice2]}: {player1.mention} lost against {player2.mention} losing {self.points} Jenny which leaves them a total of {p1.jenny}' ) else: return await self.ctx.send( f'{self.emotes[choice1]} < {self.emotes[choice2]}: {player1.mention} lost against {player2.mention}' )
async def sell(self, ctx, item:int, amount=1): """Sell any amount of cards you own""" user = User(ctx.author.id) if amount < 1: amount = 1 if len(user.all_cards) == 0: return await ctx.send('You don\'t have any cards yet!') try: card = Card(item) except CardNotFound: return await ctx.send(f'A card with the id `{item}` does not exist', allowed_mentions=discord.AllowedMentions.none()) in_possesion = user.count_card(card.id, including_fakes=False) if in_possesion < amount: return await ctx.send(f'Seems you don\'t own enough copies of this card. You own {in_possesion} cop{"y" if in_possesion == 1 else "ies"} of this card') if item == 0: return await ctx.send("You cannot sell this card!") jenny = int((PRICES[card.rank]*amount)/10) if user.is_entitled_to_double_jenny: jenny *= 2 view = ConfirmButton(ctx.author.id, timeout=80) msg = await ctx.send(f"You will receive {jenny} Jenny for selling {'this card' if amount == 1 else 'those cards'}, do you want to proceed?", view=view) await view.wait() await view.disable(msg) if not view.value: if view.timed_out: return await ctx.send(f'Timed out!') else: return await ctx.send(f"Successfully canceled!") card_amount = user.count_card(item, False) if not card_amount >= amount: return await ctx.send('Seems like you don\'t own enough non-fake copies of this card you try to sell') else: for i in range(amount): user.remove_card(item, False) user.add_jenny(jenny) await ctx.send(f'Successfully sold {amount} cop{"y" if amount == 1 else "ies"} of card number {item} for {jenny} Jenny!')
async def send_result(self) -> None: """Sends the result of the trivia and hands out jenny as rewards""" if self.failed: return elif self.timed_out: await self.ctx.send("Timed out!", reference=self.msg) elif self.result != self.correct_index: await self.ctx.send( f"Sadly not the right answer! The answer was {self.correct_index+1}) {self.options[self.correct_index]}" ) else: user = User(self.ctx.author.id) rew = random.randint(*self.rewards[self.difficulty]) if user.is_entitled_to_double_jenny: rew *= 2 user.add_jenny(rew) await self.ctx.send(f"Correct! Here are {rew} Jenny as a reward!")
async def handle_vote(self, data: dict) -> None: user_id = data["user"] if "user" in data else data["id"] user = User(int(user_id)) user.add_vote() reward = self._get_reward( user, data["isWeekend"] if hasattr(data, "isWeekend") else False) if reward < 100: user.add_lootbox(reward) text = f"Thank you for voting for Killua! This time you get a :sparkles: special :sparkles: reward: the lootbox {LOOTBOXES[reward]['emoji']} {LOOTBOXES[reward]['name']}. Open it with `k!open`" else: text = f"Thank you for voting for Killua! Here take {reward} Jenny as a sign of my gratitude. {5-user.votes%5} vote{'s' if 5-user.votes%5 > 1 else ''} away from a :sparkles: special :sparkles: reward" user.add_jenny(reward) usr = self.client.get_user(user_id) or await self.client.fetch_user( user_id) try: await usr.send(text) except discord.HTTPException: pass
async def gain(self, ctx, t:str, item:str): """An owner restricted command allowing the user to obtain any card or amount of jenny or any lootbox""" user = User(ctx.author.id) if not t.lower() in ["jenny", "card", "lootbox"]: return await ctx.send(f'You need to provide a valid type! `{self.client.command_prefix(self.client, ctx.message)[2]}gain <jenny/card/lootbox> <amount/id>`', allowed_mentions=discord.AllowedMentions.none()) if t.lower() == 'card': try: item = int(item) card = Card(item) except CardNotFound: return await ctx.send('Invalid card id') if card.id == 0: return await ctx.send("No") if len(card.owners) >= card.limit * ALLOWED_AMOUNT_MULTIPLE: return await ctx.send('Sorry! Global card limit reached!') if len(user.fs_cards) >= FREE_SLOTS and (item > 99 or item in [x[0] for x in user.rs_cards]): return await ctx.send('Seems like you have no space left in your free slots!') user.add_card(item) return await ctx.send(f'Added card "{card.name}" to your inventory') if t.lower() == 'jenny': if not item.isdigit(): return await ctx.send('Please provide a valid amount of jenny!') item = int(item) if item < 1: return await ctx.send('Please provide a valid amount of jenny!') if item > 69420: return await ctx.send('Be reasonable.') user.add_jenny(item) return await ctx.send(f'Added {item} Jenny to your account') if t.lower() == "lootbox": if not item.isdigit() or not int(item) in list(LOOTBOXES.keys()): return await ctx.send("Invalid lootbox!") user.add_lootbox(int(item)) return await ctx.send(f"Done! Added lootbox \"{LOOTBOXES[int(item)]['name']}\" to your inventory")
class CountGame: """A game where you have to remember numbers and type them in the right order""" def __init__(self, ctx, difficulty: str): self.ctx = ctx self.user = User(ctx.author.id) self.difficulty = difficulty self.level = 1 def _handle_reward(self) -> int: """Creates a jenny reward based on the level and difficulty""" return ((2 if self.user.is_entitled_to_double_jenny else 1) * int( random.randint(20, 30) * self.level * (0.5 if self.difficulty == "easy" else 1)) ) if self.level > 1 else 0 def _assign_until_unique(self, already_assigned: List[int]) -> int: """Picks one random free spot to put the next number in""" r = random.randint(1, 25) if r in already_assigned: return self._assign_until_unique(already_assigned) else: return r def _create_solutions(self, keep_used: bool) -> None: """Creates the solution dictionary""" res: dict = (self.solutions if hasattr(self, "solutions") else {}) if keep_used else {} for i in range(1 if keep_used else self.level): res[len(res) + 1 if keep_used else i + 1] = self._assign_until_unique(list(res.values())) self.solutions = res async def _send_solutions(self, msg: discord.Message = None) -> discord.Message: """Sends the solutions before hiding them""" view = View(self.ctx.author.id) view.stage = 1 for i in range(25): view.add_item( discord.ui.Button(label=str( [k for k, v in self.solutions.items() if v - 1 == i][0]) if i + 1 in list(self.solutions.values()) else " ", disabled=True, style=discord.ButtonStyle.grey)) if not msg: msg = await self.ctx.bot.send_message( self.ctx, content= "Press the buttons in the order displayed as soon as the time starts. Good luck!", view=view) else: await msg.edit("One more button to remember. Get ready!", view=view) await asyncio.sleep(3 if self.level == 1 else ( self.level * 2 * (0.5 if self.difficulty == "easy" else 1))) return msg async def _handle_game(self, msg: discord.Message) -> discord.Message: """The core of the game, creates the buttons and waits until the buttons return a result and handles it""" view = View(self.ctx.author.id, timeout=self.level * 10 * (0.5 if self.difficulty == "easy" else 1)) view.stage = 1 for i in range(25): view.add_item(CountButtons(self.solutions, i + 1, label=" ")) await msg.edit(content="Can you remember?", view=view) await view.wait() if not hasattr( view, "correct" ) or not view.correct: # This happens when the user has lost the game or it timed out reward = self._handle_reward() resp = "Too slow!" if not hasattr(view, "correct") else "Wrong choice!" for child in view.children: child.disabled = True await msg.edit(view=view) self.user.add_jenny(reward) return await self.ctx.send( resp + " But well done, you made it to level " + str(self.level) + " which brings you a reward of " + str(reward) + " Jenny!") self.level += 1 if self.level == 26: reward = self._handle_reward() return await self.ctx.send( "Well done, you completed the game! Your reward is " + str(reward) + " Jenny. Keep up the great work!") await asyncio.sleep(5) self._create_solutions(self.difficulty == "easy") new_msg = await self._send_solutions(msg) await self._handle_game(new_msg) async def start(self): """The function to call to start the game""" self._create_solutions(self.difficulty == "easy") msg = await self._send_solutions() await self._handle_game(msg)