Skip to content

Commit

Permalink
update subscription type to also use the subscription type data class
Browse files Browse the repository at this point in the history
  • Loading branch information
PumPum7 committed Aug 5, 2024
1 parent b89e1d1 commit 37f3c77
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tatsu/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ def to_dict(self):
}


class SubscriptionType:
SUBSCRIPTION_MAP = {
0: "None",
1: "Supporter",
2: "Supporter+",
3: "Supporter++",
}

def __init__(self, subscription_type: int):
self.subscription_type: int = subscription_type

def __str__(self):
subscription_str = self.SUBSCRIPTION_MAP.get(self.subscription_type, "Unknown")
return f"SubscriptionType(subscription_type={subscription_str})"

def __repr__(self):
subscription_str = self.SUBSCRIPTION_MAP.get(self.subscription_type, "Unknown")
return f"SubscriptionType(subscription_type={subscription_str!r})"

def __eq__(self, other):
if isinstance(other, SubscriptionType):
return self.subscription_type == other.subscription_type
return False

def to_dict(self):
return {
"subscription_type": self.subscription_type,
}


class GuildRankings:
def __init__(self, guild_id: int, rankings: list, original: dict):
self.guild_id: int = int(guild_id) if guild_id else guild_id
Expand Down
7 changes: 6 additions & 1 deletion tatsu/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ async def get_profile(self, user_id: int) -> ds.UserProfile:
if subscription_renewal_str
else None
)

# Map the subscription type to the subscription type object
subscription_type = result.get("subscription_type", 0)
subscription_type = ds.SubscriptionType(subscription_type)

user_profile_data = {
"avatar_hash": result.get("avatar_hash", None),
"avatar_url": result.get("avatar_url", None),
Expand All @@ -47,7 +52,7 @@ async def get_profile(self, user_id: int) -> ds.UserProfile:
"user_id": result.get("id", None),
"info_box": result.get("info_box", None),
"reputation": result.get("reputation", None),
"subscription_type": result.get("subscription_type", None),
"subscription_type": subscription_type,
"subscription_renewal": subscription_renewal,
"title": result.get("title", None),
"tokens": result.get("tokens", None),
Expand Down

0 comments on commit 37f3c77

Please sign in to comment.