Skip to content

Commit

Permalink
Refactor tatsu wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Iqrar99 committed Jan 26, 2024
1 parent 52521ff commit f221bd2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions bot/module/tatsu/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ async def get_guild_rankings(self, guild_id, timeframe="all", offset=0) -> ds.Gu
)
return rankings

async def add_score(self, guild_id: int, user_id: int, amount: int) -> ds.GuildScoreObject:
async def _modify_score(
self, action_type: int, guild_id: int, user_id: int, amount: int
) -> ds.GuildScoreObject:
url = f"/guilds/{guild_id}/members/{user_id}/score"
payload = {'action': 0, 'amount': amount}
payload = {'action': action_type, 'amount': amount}

try:
result = await self.patch(url, payload)
Expand All @@ -127,18 +129,8 @@ async def add_score(self, guild_id: int, user_id: int, amount: int) -> ds.GuildS
)
return score

async def subtract_score(self, guild_id: int, user_id: int, amount: int) -> ds.GuildScoreObject:
url = f"/guilds/{guild_id}/members/{user_id}/score"
payload = {'action': 1, 'amount': amount}

try:
result = await self.patch(url, payload)
except Exception as e:
raise e
async def add_score(self, guild_id: int, user_id: int, amount: int) -> ds.GuildScoreObject:
return await self._modify_score(0, guild_id, user_id, amount)

score = ds.GuildScoreObject(
guild_id=result.get('guild_id'),
score=result.get('score'),
user_id=result.get('user_id'),
)
return score
async def remove_score(self, guild_id: int, user_id: int, amount: int) -> ds.GuildScoreObject:
return await self._modify_score(1, guild_id, user_id, amount)

0 comments on commit f221bd2

Please sign in to comment.