|
@@ -109,6 +109,7 @@ MarketTransitions = Config("rollcoin.market.transitions")
|
|
|
MarketMultipliers = Config("rollcoin.market.multipliers")
|
|
|
MarketMessages = Config("rollcoin.market.messages")
|
|
|
NameAPIKey = Config("rollcoin.gacha.name_api_key")
|
|
|
+GachaSleep = Config("rollcoin.gacha.sleep_time")
|
|
|
AppraiseChannel = Config("rollcoin.appraise.channel")
|
|
|
AppraiseAllowSelfLike = Config("rollcoin.appraise.allow_self")
|
|
|
AppraiseRequireOwnership = Config("rollcoin.appraise.require_own")
|
|
@@ -489,7 +490,7 @@ def pull_gacha_color():
|
|
|
return random.choice(NFT_COLORS) # nice%
|
|
|
|
|
|
|
|
|
-async def pull_gacha(req, name_api_key):
|
|
|
+async def pull_gacha(req, name_api_key, logger):
|
|
|
color1 = pull_gacha_color()
|
|
|
color2 = pull_gacha_color()
|
|
|
|
|
@@ -520,6 +521,9 @@ async def gacha(
|
|
|
get_sender_wallet: Lazy(SenderWallet), # used for re-querying to mitigate race condition
|
|
|
sender_id: Sender,
|
|
|
wallet_store: Data(RollcoinWallet),
|
|
|
+ get_state: Lazy(State),
|
|
|
+ state_store: Data(RollcoinState),
|
|
|
+ sleep_time: GachaSleep,
|
|
|
logger: Logger,
|
|
|
req: Request,
|
|
|
name_api_key: NameAPIKey,
|
|
@@ -537,22 +541,29 @@ async def gacha(
|
|
|
yield f"You only have {sender_wallet.balance} RollCoins available, and gacha pulls cost one each!", reply
|
|
|
return
|
|
|
|
|
|
- info, img = await pull_gacha(req, name_api_key)
|
|
|
+ info, img = await pull_gacha(req, name_api_key, logger)
|
|
|
pulled = [info]
|
|
|
if pulls == 1:
|
|
|
yield f"You received...\n\t{info}", img, reply
|
|
|
else:
|
|
|
yield f"You received (1/{pulls})...\n\t{info}", img, reply
|
|
|
for i in range(pulls - 1):
|
|
|
- await asyncio.sleep(1)
|
|
|
- info, img = await pull_gacha(req, name_api_key)
|
|
|
- yield f"You received ({i + 2}/{pulls})...\n\t{info}", img, reply
|
|
|
- pulled.append(info)
|
|
|
+ await asyncio.sleep(sleep_time)
|
|
|
+ try:
|
|
|
+ info, img = await pull_gacha(req, name_api_key, logger)
|
|
|
+ yield f"You received ({i + 2}/{pulls})...\n\t{info}", img, reply
|
|
|
+ pulled.append(info)
|
|
|
+ except:
|
|
|
+ logger.exception("Failed to pull")
|
|
|
+ yield f"Failed to pull from gachapon! You will not be charged the coin for this pull.", reply
|
|
|
|
|
|
sender_wallet = await get_sender_wallet()
|
|
|
- sender_wallet.balance -= pulls
|
|
|
+ sender_wallet.balance -= len(pulled)
|
|
|
sender_wallet.nfts += pulled
|
|
|
await wallet_store.save(sender_id, sender_wallet)
|
|
|
+ state = await get_state()
|
|
|
+ state.treasury += len(pulled)
|
|
|
+ await state_store.save(GLOBAL_STATE_KEY, state)
|
|
|
|
|
|
# ADMIN COMMANDS
|
|
|
|