예제 #1
0
파일: db.py 프로젝트: xballesta/PluralKit
async def create_member(conn, system_id: int, member_name: str,
                        member_hid: str) -> Member:
    logger.debug("Creating member (system={}, name={}, hid={})".format(
        system_id, member_name, member_hid))
    row = await conn.fetchrow(
        "insert into members (name, system, hid) values ($1, $2, $3) returning *",
        member_name, system_id, member_hid)
    return Member(**row) if row else None
예제 #2
0
async def member_card(conn, member: Member) -> discord.Embed:
    system = await member.fetch_system(conn)

    card = discord.Embed()
    card.colour = discord.Colour.blue()

    name_and_system = member.name
    if system.name:
        name_and_system += " ({})".format(system.name)

    card.set_author(name=truncate_field_name(name_and_system),
                    icon_url=member.avatar_url or discord.Embed.Empty)
    if member.avatar_url:
        card.set_thumbnail(url=member.avatar_url)

    if member.color:
        card.colour = int(member.color, 16)

    if member.birthday:
        card.add_field(name="Birthdate", value=member.birthday_string())

    if member.pronouns:
        card.add_field(name="Pronouns",
                       value=truncate_field_body(member.pronouns))

    message_count = await member.message_count(conn)
    if message_count > 0:
        card.add_field(name="Message Count",
                       value=str(message_count),
                       inline=True)

    if member.prefix or member.suffix:
        prefix = member.prefix or ""
        suffix = member.suffix or ""
        card.add_field(name="Proxy Tags",
                       value=truncate_field_body("{}text{}".format(
                           prefix, suffix)))

    if member.description:
        card.add_field(name="Description",
                       value=truncate_field_body(member.description),
                       inline=False)

    card.set_footer(
        text="System ID: {} | Member ID: {}".format(system.hid, member.hid))
    return card
예제 #3
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_all_members(conn, system_id: int) -> List[Member]:
    rows = await conn.fetch("select * from members where system = $1",
                            system_id)
    return [Member(**row) for row in rows]
예제 #4
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_members_exceeding(conn, system_id: int,
                                length: int) -> List[Member]:
    rows = await conn.fetch(
        "select * from members where system = $1 and length(name) > $2",
        system_id, length)
    return [Member(**row) for row in rows]
예제 #5
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_members(conn, members: list) -> List[Member]:
    rows = await conn.fetch("select * from members where id = any($1)",
                            members)
    return [Member(**row) for row in rows]
예제 #6
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_member(conn, member_id: int) -> Member:
    row = await conn.fetchrow("select * from members where id = $1", member_id)
    return Member(**row) if row else None
예제 #7
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_member_by_hid(conn, member_hid: str) -> Member:
    row = await conn.fetchrow("select * from members where hid = $1",
                              member_hid)
    return Member(**row) if row else None
예제 #8
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_member_by_hid_in_system(conn, system_id: int,
                                      member_hid: str) -> Member:
    row = await conn.fetchrow(
        "select * from members where system = $1 and hid = $2", system_id,
        member_hid)
    return Member(**row) if row else None
예제 #9
0
파일: db.py 프로젝트: xballesta/PluralKit
async def get_member_by_name(conn, system_id: int, member_name: str) -> Member:
    row = await conn.fetchrow(
        "select * from members where system = $1 and lower(name) = lower($2)",
        system_id, member_name)
    return Member(**row) if row else None