diff --git a/royalnet/backpack/commands/royalnetaliases.py b/royalnet/backpack/commands/royalnetaliases.py index 3ddab36f..63c2f5e7 100644 --- a/royalnet/backpack/commands/royalnetaliases.py +++ b/royalnet/backpack/commands/royalnetaliases.py @@ -2,8 +2,7 @@ from typing import * import royalnet import royalnet.commands as rc import royalnet.utils as ru -from ..tables.telegram import Telegram -from ..tables.discord import Discord +from ..tables import User class RoyalnetaliasesCommand(rc.Command): @@ -14,11 +13,14 @@ class RoyalnetaliasesCommand(rc.Command): syntax: str = "" async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - author = await data.get_author(error_if_none=True) + if name := args.optional(0) is not None: + user = await User.find(alchemy=self.alchemy, session=data.session, alias=name) + else: + user = await data.get_author(error_if_none=True) msg = [ "👤 You currently have these aliases:", - *list(map(lambda r: f"- {r}", author.aliases)) + *list(map(lambda r: f"- {r}", user.aliases)) ] await data.reply("\n".join(msg)) diff --git a/royalnet/backpack/commands/royalnetroles.py b/royalnet/backpack/commands/royalnetroles.py index cef7918e..6873b2c2 100644 --- a/royalnet/backpack/commands/royalnetroles.py +++ b/royalnet/backpack/commands/royalnetroles.py @@ -2,8 +2,7 @@ from typing import * import royalnet import royalnet.commands as rc import royalnet.utils as ru -from ..tables.telegram import Telegram -from ..tables.discord import Discord +from ..tables import User class RoyalnetrolesCommand(rc.Command): @@ -14,11 +13,14 @@ class RoyalnetrolesCommand(rc.Command): syntax: str = "" async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - author = await data.get_author(error_if_none=True) + if name := args.optional(0) is not None: + user = await User.find(alchemy=self.alchemy, session=data.session, alias=name) + else: + user = await data.get_author(error_if_none=True) msg = [ "👤 You currently have these roles:", - *list(map(lambda r: f"- {r}", author.roles)) + *list(map(lambda r: f"- {r}", user.roles)) ] await data.reply("\n".join(msg)) diff --git a/royalnet/backpack/stars/api_alias_list.py b/royalnet/backpack/stars/api_alias_list.py deleted file mode 100644 index 66f73c18..00000000 --- a/royalnet/backpack/stars/api_alias_list.py +++ /dev/null @@ -1,25 +0,0 @@ -from starlette.responses import * -from royalnet.utils import * -from royalnet.backpack.tables import * -from royalnet.constellation.api import * - - -class ApiAliasListStar(ApiStar): - path = "/api/alias/list/v1" - - summary = "Get all aliases of the specified user." - - tags = ["alias"] - - parameters = { - "user_id": "The id of the user to get the aliases of." - } - - async def api(self, data: ApiData) -> JSON: - aliases: typing.List[Alias] = await asyncify( - data.session - .query(self.alchemy.get(Alias)) - .filter_by(user_id=data["user_id"]) - .all - ) - return [alias.alias for alias in aliases] diff --git a/royalnet/backpack/stars/api_user_find.py b/royalnet/backpack/stars/api_user_find.py index 009b8721..8d0ae3f2 100644 --- a/royalnet/backpack/stars/api_user_find.py +++ b/royalnet/backpack/stars/api_user_find.py @@ -15,7 +15,7 @@ class ApiUserFindStar(ApiStar): } async def api(self, data: ApiData) -> dict: - user = await Alias.find_user(self.alchemy, data.session, data["alias"]) + user = await User.find(self.alchemy, data.session, data["alias"]) if user is None: raise NotFoundError("No such user.") return user.json() diff --git a/royalnet/backpack/stars/api_user_list.py b/royalnet/backpack/stars/api_user_list.py index fd9053ed..8c822356 100644 --- a/royalnet/backpack/stars/api_user_list.py +++ b/royalnet/backpack/stars/api_user_list.py @@ -11,6 +11,6 @@ class ApiUserListStar(ApiStar): tags = ["user"] - async def api(self, data: ApiData) -> dict: + async def api(self, data: ApiData) -> JSON: users: typing.List[User] = await asyncify(data.session.query(self.alchemy.get(User)).all) return [user.json() for user in users] diff --git a/royalnet/backpack/tables/users.py b/royalnet/backpack/tables/users.py index d267efa3..c4e042be 100644 --- a/royalnet/backpack/tables/users.py +++ b/royalnet/backpack/tables/users.py @@ -37,7 +37,7 @@ class User: return Column(String) @staticmethod - async def find_user(alchemy, session, alias: Union[str, int]): + async def find(alchemy, session, alias: Union[str, int]): result = await ru.asyncify(session.query(alchemy.get(Alias)).filter_by(alias=alias.lower()).one_or_none) if result is not None: result = result.user