def print(self) -> str: s = max(self._bet_ref['finish_time'] - utils.now(), 0) time_remaining_str = utils.print_time(self._lang.get(), s) lines = [tr(self._lang.get(), 'BET.TIME', time=time_remaining_str)] if self._info_changed: self._stored_info = [] # Sort bet data total_bet = self.get_bet_sum() + self._bot.get_bet() bets = list(self._bet_ref['bets'].values()) bets.append((self._bot.icon, self._bot.get_bet())) bets.sort(key=lambda x: x[1], reverse=True) # Jackpot a: str = tr(self._lang.get(), 'BET.JACKPOT', EMOJI_SPARKLE=Emoji.SPARKLE, money=utils.print_money(self._lang.get(), total_bet)) b: str = tr(self._lang.get(), 'BET.MAX_BET', money=utils.print_money(self._lang.get(), self._limit)) self._stored_info.append(f"{a}\n{b}") # Player+bot bets for single_bet in bets: money_str = utils.print_money(self._lang.get(), single_bet[1]) pct = single_bet[1] / total_bet self._stored_info.append( f"{single_bet[0]}: {money_str} ({pct:.0%})") self._info_changed = False return '\n'.join(lines + self._stored_info)
async def transfer(cmd: Command): if cmd.user.get_bank() == 0: await cmd.error(tr(cmd.lang, 'COMMAND.TRANSFER.EMPTY')) else: transferred = cmd.user.withdraw_bank() if transferred == 0: await cmd.error(tr(cmd.lang, 'COMMAND.TRANSFER.FULL')) else: await cmd.send_hidden( tr(cmd.lang, 'COMMAND.TRANSFER.EXECUTE', EMOJI_BANK=Emoji.BANK, money=utils.print_money(cmd.lang, transferred), total=utils.print_money(cmd.lang, cmd.user.get_money())))
def custom_print(lang: str, upg: UpgradeLink, f=lambda x: x, mobile: bool = False) -> str: s = f(upg.get_value()) if upg.is_max_level(): if mobile: return tr(lang, 'UPGRADE.SHORT_MAX', EMOJI_ICON=upg.get_icon(), name=upg.get_name(), level=upg.get_level(), max_word=tr(lang, 'UPGRADE.MAX')) else: return format_row([upg.get_name(), tr(lang, 'UPGRADE.MAX'), s]) else: s3 = upg.get_value(upg.get_level() + 1) s3 = f(s3) if mobile: return tr(lang, 'UPGRADE.SHORT', ICON_UPGRADE=upg.get_icon(), name=upg.get_name(), level=upg.get_level(), value=s, EMOJI_ARROW_RIGHT=Emoji.ARROW_RIGHT, next_value=s3, money=utils.print_money(lang, -upg.get_cost())) else: return format_row([ upg.get_name(), upg.get_level(), s, f"{utils.print_money(lang, -upg.get_cost())}", s3 ])
async def end_bet(self, ctx: SlashContext) -> None: assert self.is_active(), "Cannot stop an inactive bet" user_ids = [] weights = [] for user_id, single_bet in self._bet_ref['bets'].items(): user_ids.append(user_id) weights.append(single_bet[1]) user_ids.append('BOT') weights.append(self._bot.get_bet()) winner_id = random.choices(user_ids, weights=weights, k=1)[0] result = ['~ ' + tr(self._lang.get(), 'BET.FINISH') + ' ~'] total_bet = self.get_bet_sum() + self._bot.get_bet() money_str = utils.print_money(self._lang.get(), total_bet) if winner_id == 'BOT': result.append( tr(self._lang.get(), 'BET.BOT_WON', name=self._bot.icon, money=money_str)) else: result.append( tr(self._lang.get(), 'BET.WON', name=self._bet_ref['bets'][winner_id][0], money=money_str)) user = storage.get_user(self._db, winner_id) user.add_money(total_bet) await ctx.send('\n'.join(result)) self._bet_ref.set({}) self._stored_info = None
async def reward(self): user: User = random.choice(self.get_adventure().get_users()) if len(self.get_adventure().get_users()) == 1: await self.send_log( tr(self.get_lang(), 'REWARD.MONEY_YOU', money=utils.print_money(self.get_lang(), self.money))) else: await self.send_log( tr(self.get_lang(), 'REWARD.MONEY_SOMEONE', money=utils.print_money(self.get_lang(), self.money), name=user.get_name())) user.add_money(self.money) await self.end()
def buy(self, user: '******', slot: str) -> ActionResult: self._check_shop() slot_type: SlotType = Shop._get_slot_type(slot) if slot_type == SlotType.INVALID: return ActionResult(message='INVENTORY.INVALID_SLOT_TYPE') item_index: int = -1 item: Item = self._get_dict_ref(slot).get() if slot_type == SlotType.ITEMS: item_index = int(slot) if item_index not in self._last_valid_checks: return ActionResult(reload_shop=True) auto_equip: bool = False if user.has_money(item.get_price()): user_slot: str = user.inventory.get_empty_slot(slot_type) if isinstance(item, Equipment) and (user.inventory.get_equipment().get( item.get_desc().subtype) is None): # Equip directly user_slot = Inventory.EQUIPMENT_TYPE_TO_CHAR[ item.get_desc().subtype] auto_equip = True if user_slot is not None: user.remove_money(item.get_price()) if slot_type == SlotType.ITEMS: user.inventory.add_item(item, user_slot) transfer_guild_to_user(self._db, self._guild_id, item, user.id, user_slot) del self._shop_items[item_index] self._last_valid_checks.remove(item_index) elif slot_type == SlotType.POTION_BAG: new_item: Item = clone_item(self._db, item) create_user_item(self._db, user.id, new_item, user_slot) user.inventory.add_item(new_item, user_slot) self._restock_shop() if auto_equip: user.inventory.update_equipment() return ActionResult(message='SHOP.PURCHASE', success=True, EMOJI_PURCHASE=Emoji.PURCHASE, name=user.get_name(), item=item.print(), must_equip=True) else: return ActionResult(message='SHOP.PURCHASE', success=True, EMOJI_PURCHASE=Emoji.PURCHASE, name=user.get_name(), item=item.print()) return ActionResult(message='INVENTORY.FULL') else: return ActionResult(message='SHOP.LACK', money=utils.print_money( self.get_lang(), item.get_price()))
async def check(cmd: Command): money = cmd.guild.get_box() if money == 0: await cmd.send_hidden(tr(cmd.lang, 'CRATE.EMPTY', EMOJI_BOX=Emoji.BOX)) else: rate_str = cmd.guild.print_box_rate() if len(rate_str) > 0: await cmd.send( tr(cmd.lang, 'CRATE.SHOW_RATE', money=utils.print_money(cmd.lang, money), EMOJI_BOX=Emoji.BOX, EMOJI_CLOCK=Emoji.CLOCK, rate=rate_str)) else: await cmd.send( tr(cmd.lang, 'CRATE.SHOW', money=utils.print_money(cmd.lang, money), EMOJI_BOX=Emoji.BOX))
async def reward(self): users: list[User] = [ user for user in self.get_adventure().get_users() if user.inventory.get_empty_slot(SlotType.ITEMS) is not None ] if not users: users = self.get_adventure().get_users() user: User = random.choice(users) slot: Optional[str] = user.inventory.get_empty_slot(SlotType.ITEMS) if slot is not None: user.inventory.add_item(self.item, slot) if len(self.get_adventure().get_users()) == 1: await self.send_log( tr(self.get_lang(), 'REWARD.ITEM_YOU', item=self.item.print())) else: await self.send_log( tr(self.get_lang(), 'REWARD.ITEM_SOMEONE', item=self.item.print(), name=user.get_name())) else: money = Shop.get_sell_price(self.item) user.add_money(money) if len(self.get_adventure().get_users()) == 1: await self.send_log( tr(self.get_lang(), 'REWARD.ITEM_SOLD_YOU', item=self.item.print(), money=utils.print_money(self.get_lang(), money))) else: await self.send_log( tr(self.get_lang(), 'REWARD.ITEM_SOLD_SOMEONE', item=self.item.print(), name=user.get_name(), money=utils.print_money(self.get_lang(), money))) await self.end()
async def take(cmd: Command): if cmd.user.get_total_money_space() == 0: await cmd.error(tr(cmd.lang, 'CRATE.MAX')) else: took = cmd.guild.retrieve_box(cmd.user) if took > 0: await cmd.send( tr(cmd.lang, 'CRATE.TAKE', name=cmd.user.get_name(), money=utils.print_money(cmd.lang, took), EMOJI_BOX=Emoji.BOX)) else: await cmd.error(tr(cmd.lang, 'CRATE.EMPTY'))
async def place(cmd: Command, money: int): if money < Guild.TABLE_MIN: await cmd.error( tr(cmd.lang, 'CRATE.MIN', money=utils.print_money(cmd.lang, Guild.TABLE_MIN))) return placed = cmd.guild.place_box(cmd.user, money) if placed: rate_str = cmd.guild.print_box_rate() await cmd.send( tr(cmd.lang, 'CRATE.PLACE', EMOJI_BOX=Emoji.BOX, name=cmd.user.get_name(), money=utils.print_money(cmd.lang, money), rate=rate_str, EMOJI_CLOCK=Emoji.CLOCK)) else: await cmd.error( tr(cmd.lang, 'CRATE.LACK', money=utils.print_money(cmd.lang, money)))
def print_rate(self, lang: str) -> str: self.check() increment_str = utils.print_money(lang, self._time_slot.amount) return f"+{tr(lang, 'MISC.RATE', amount=increment_str, time=self._time_slot.metric_abbreviation(lang))}"
def pmw(value): return utils.print_money(lang, value)
def rhw(value): t: str = tr(lang, 'MISC.RATE', amount=utils.print_money(lang, value), time=utils.TimeMetric.HOUR.abbreviation(lang)) return f"+{t}"