1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

Some stuff

This commit is contained in:
Steffo 2020-05-07 00:09:07 +02:00
parent 87569fd364
commit 8af65a029c
6 changed files with 15 additions and 36 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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]

View file

@ -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()

View file

@ -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]

View file

@ -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