(lion): Add more properties, and default tags.

Added `Lion.guild`.
Added `Lion.ctx`.
Added `Lion.profile_tags`, with defaults.
This commit is contained in:
2022-01-24 10:40:29 +02:00
parent a6283c9bc6
commit b5a4a17239

View File

@@ -7,6 +7,8 @@ from meta import client
from data import tables as tb from data import tables as tb
from settings import UserSettings, GuildSettings from settings import UserSettings, GuildSettings
from LionContext import LionContext
class Lion: class Lion:
""" """
@@ -63,7 +65,11 @@ class Lion:
return (self.guildid, self.userid) return (self.guildid, self.userid)
@property @property
def member(self): def guild(self) -> discord.Guild:
return client.get_guild(self.guildid)
@property
def member(self) -> discord.Member:
""" """
The discord `Member` corresponding to this user. The discord `Member` corresponding to this user.
May be `None` if the member is no longer in the guild or the caches aren't populated. May be `None` if the member is no longer in the guild or the caches aren't populated.
@@ -110,6 +116,15 @@ class Lion:
""" """
return GuildSettings(self.guildid) return GuildSettings(self.guildid)
@property
def ctx(self) -> LionContext:
"""
Manufacture a `LionContext` with the lion member as an author.
Useful for accessing member context utilities.
Be aware that `author` may be `None` if the member was not cached.
"""
return LionContext(client, guild=self.guild, author=self.member)
@property @property
def time(self): def time(self):
""" """
@@ -246,6 +261,20 @@ class Lion:
return remaining return remaining
@property
def profile_tags(self):
"""
Returns a list of profile tags, or the default tags.
"""
tags = tb.profile_tags.queries.get_tags_for(self.guildid, self.userid)
prefix = self.ctx.best_prefix
return tags or [
f"Use {prefix}setprofile",
"and add your tags",
"to this section",
f"See {prefix}help setprofile for more"
]
@property @property
def name(self): def name(self):
""" """
@@ -260,7 +289,6 @@ class Lion:
return name return name
def update_saved_data(self, member: discord.Member): def update_saved_data(self, member: discord.Member):
""" """
Update the stored discord data from the givem member. Update the stored discord data from the givem member.