def PriceForHypeStacks(self, user: user_pb2.User, num_stacks: int) -> int: """Returns the price for user to purchase num_stacks. Hypestacks cost 1k each, plus 20% of the cost of the previous stack. The formula for the cost of the nth hypestack is y = 1000*1.2**(n-1), which leads to the formula for the total cost of the mth to nth hypestacks as sum(f(i) for i in range(m, n+1)). Solving for the closed form gives us the formula in TotalHypeStackPrice, plus truncation since hypecoins only come in integer values. Args: user: The user to fetch the price for. num_stacks: How many new stacks the user is looking to purchase. Returns: The total cost in hypecoins for user to purcase num_stacks. """ def TotalHypeStackPrice(num_stacks: int) -> int: return int(6000 * 1.2**(num_stacks - 1) - 5000) recent_stacks = util_lib.SafeCast( self._store.GetValue(user.user_id, self._RECENT_STACKS_SUBKEY), int, 0) num_stacks += recent_stacks return TotalHypeStackPrice(num_stacks) - TotalHypeStackPrice(recent_stacks)
def GetUserBalances(self, plebs_only=False, account=None): """Returns dict of users mapping to their balance for all users.""" user_balances = self._store.GetSubkey(self._BALANCE_SUBKEY) return {user: util_lib.SafeCast(balance, int, 0) for user, balance in user_balances if (not plebs_only or user not in HYPECENTS) and (not account or IsSubAccount(user, account))}
def GetUserBalances(self, plebs_only=False): """Returns dict of user_ids mapping to their balance for all users.""" user_balances = self._store.GetSubkey(self._BALANCE_SUBKEY) # pylint: disable=g-complex-comprehension return { user_id: util_lib.SafeCast(balance, int, 0) for user_id, balance in user_balances if (not plebs_only or user_id not in HYPECENTS) and not user_id.startswith('http') }
def _Handle(self, channel: channel_pb2.Channel, user: user_pb2.User, raw_cl: Text, env: Text) -> hype_types.CommandResponse: if raw_cl: raw_cl = raw_cl.strip('@') cl = util_lib.SafeCast(raw_cl, int, -1) if self._core.deployment_manager.RequestSchemaUpdate( user, cl, env.lower()): return 'Setting schema for %s storage' % env else: self._DeployActionInProgress(channel)
def _Handle(self, channel: Channel, user: str, raw_cl: str, env: str) -> hypecore.MessageType: if raw_cl: raw_cl = raw_cl.strip('@') cl = util_lib.SafeCast(raw_cl, int, -1) if self._core.deployment_manager.RequestSchemaUpdate(user, cl, env.lower()): return 'Setting schema for %s storage' % env else: self._DeployActionInProgress(channel)
def _Handle(self, channel: channel_pb2.Channel, user: user_pb2.User, raw_cl: Text, raw_bot: Text) -> hype_types.CommandResponse: """Validate and parse raw CL number and bot name.""" if raw_cl: raw_cl = raw_cl.strip('@') cl = util_lib.SafeCast(raw_cl, int, -1) if raw_bot is None: return 'Please supply a bot name to build!' bot_name = raw_bot.lower() if self._core.deployment_manager.IsValidBot(bot_name): return self._HandleParsed(channel, user, cl, bot_name) return 'I don\'t recognize %s, sorry.' % bot_name
def _Handle(self, channel: Channel, user: str, stack_amount: str) -> hypecore.MessageType: num_stacks = util_lib.SafeCast(stack_amount, int, 0) if not num_stacks: self._core.bets.FineUser(user, 1, 'You must buy at least one HypeStack.', self._Reply) return hypecoin_amount = self._core.hypestacks.PriceForHypeStacks( user, num_stacks) if not hypecoin_amount: return summary = 'purchase of %s for %s' % (inflect_lib.Plural( num_stacks, 'HypeStack'), util_lib.FormatHypecoins(hypecoin_amount)) purchase_details = { 'num_stacks': num_stacks, 'summary': summary, 'cost': hypecoin_amount } self._core.request_tracker.RequestConfirmation( user, summary, purchase_details, self._core.hypestacks.PurchaseStacks)
def GetHypeStacks(self, user: str) -> int: """Returns the number of HypeStacks user currently has accumulated.""" stacks = self._store.GetValue(user, self._STACK_COUNT_SUBKEY) return util_lib.SafeCast(stacks, int, 0)
def _Handle(self, channel, user, level, champ_name): level = util_lib.SafeCast(level, int, 0) return self._core.game.GetChampStatsAtLevelText(champ_name, level)
def GetBalance(self, user): balance = self._store.GetValue(user.user_id, self._BALANCE_SUBKEY) if not balance: return 0 return util_lib.SafeCast(balance, int, 0)