Beispiel #1
0
async def new_system(ctx: CommandContext, args: List[str]):
    if ctx.system:
        return embeds.error(
            "You already have a system registered. To delete your system, use `pk;system delete`, or to unlink your system from this account, use `pk;system unlink`."
        )

    system_name = None
    if len(args) > 0:
        system_name = " ".join(args)

    async with ctx.conn.transaction():
        # TODO: figure out what to do if this errors out on collision on generate_hid
        hid = utils.generate_hid()

        system = await db.create_system(ctx.conn,
                                        system_name=system_name,
                                        system_hid=hid)

        # Link account
        await db.link_account(ctx.conn,
                              system_id=system.id,
                              account_id=ctx.message.author.id)
        return embeds.success(
            "System registered! To begin adding members, use `pk;member new <name>`."
        )
Beispiel #2
0
    async def create_member(self, conn, member_name: str) -> Member:
        # TODO: figure out what to do if this errors out on collision on generate_hid
        new_hid = generate_hid()

        if len(member_name) > self.get_member_name_limit():
            raise errors.MemberNameTooLongError(tag_present=bool(self.tag))

        member = await db.create_member(conn, self.id, member_name, new_hid)
        return member
Beispiel #3
0
    async def create_system(conn, account_id: str, system_name: Optional[str] = None) -> "System":
        existing_system = await System.get_by_account(conn, account_id)
        if existing_system:
            raise errors.ExistingSystemError()

        new_hid = generate_hid()

        async with conn.transaction():
            new_system = await db.create_system(conn, system_name, new_hid)
            await db.link_account(conn, new_system.id, account_id)

        return new_system