Skip to content

Commit

Permalink
[waicolle] better drop logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Dec 4, 2024
1 parent dd07392 commit 92553e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
18 changes: 12 additions & 6 deletions nanachan/extensions/waicolle.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ async def _register_mode(self, mode: PLAYER_MERGE_GAME_MODE,
assert isinstance(interaction.channel, discord.TextChannel)
async with interaction.channel.typing():
resp3 = await get_nanapi().waicolle.waicolle_player_roll(
interaction.user.id, nb=10)
interaction.user.id, nb=10, reason='register'
)
if not success(resp3):
raise RuntimeError(resp3.result)
assert resp3.code == 201
Expand Down Expand Up @@ -424,7 +425,8 @@ async def drop(self,

for member in members:
asyncio.create_task(
self._drop(member, 'Event drop', replyable=ctx, nb=nb))
self._drop(member, 'Event drop', replyable=ctx, nb=nb, rollop_reason='event')
)

async def _drop(self,
member: UserType,
Expand All @@ -434,7 +436,8 @@ async def _drop(self,
roll_id: str | None = None,
coupon_code: str | None = None,
nb: int | None = 1,
pool_player: UserType | None = None):
pool_player: UserType | None = None,
rollop_reason: str | None = None):
if member.bot:
return

Expand All @@ -452,7 +455,8 @@ async def _drop(self,
roll_id=roll_id,
coupon_code=coupon_code,
nb=nb,
pool_discord_id=pool_player.id)
pool_discord_id=pool_player.id,
reason=rollop_reason)

match resp:
case Error(code=404 | 409):
Expand Down Expand Up @@ -2362,7 +2366,7 @@ async def reward_drop(self, user: discord.User, nb: int, reason: str):
if user.bot:
return

await self._drop(user, reason, nb=nb)
await self._drop(user, reason, nb=nb, rollop_reason=reason.casefold())

async def reward_coins(self,
user: UserType,
Expand Down Expand Up @@ -2543,7 +2547,9 @@ async def drop_on_message(self, ctx, force: bool = False):
user = await listener.queue.get()

dropped = True
asyncio.create_task(self._drop(user, 'Random drop'))
asyncio.create_task(
self._drop(user, 'Random drop', rollop_reason='random')
)

if dropped:
self.next_drop[ctx.guild.id] = RNG.integers(1,
Expand Down
2 changes: 2 additions & 0 deletions nanachan/nanapi/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4008,6 +4008,7 @@ async def waicolle_player_roll(
coupon_code: str | None = None,
nb: int | None = None,
pool_discord_id: int | None = None,
reason: str | None = None,
client_id: UUID | None = None,
) -> (
Success[Literal[201], list[WaifuSelectResult]]
Expand All @@ -4025,6 +4026,7 @@ async def waicolle_player_roll(
'coupon_code': coupon_code,
'nb': nb,
'pool_discord_id': pool_discord_id,
'reason': reason,
'client_id': client_id,
}
params = prep_serialization(params)
Expand Down
2 changes: 1 addition & 1 deletion nanachan/nanapi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,10 +1722,10 @@ class TradeSelectResult(BaseModel):
received: list['TradeSelectResultReceived']
offeree: 'TradeSelectResultOfferee'
offered: list['TradeSelectResultOffered']
id: UUID
blood_shards: int
completed_at: datetime | None
created_at: datetime
id: UUID


class TradeSelectResultAuthor(BaseModel):
Expand Down
5 changes: 3 additions & 2 deletions nanachan/utils/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,10 @@ async def send_reward(self, ctx: MultiplexingContext, nb: int):
embed=ctx.message.quote_embed)
await self.waifu_cog._drop(
self.user,
f"Conditional drop: {ctx.author} {self.word.action}",
f'Conditional drop: {ctx.author} {self.word.action}',
nb=nb,
pool_player=ctx.author
pool_player=ctx.author,
rollop_reason='conditional',
)
self.__class__.available_instances += 1

Expand Down

0 comments on commit 92553e5

Please sign in to comment.