From 16173e428b3434630197ee848ba2db310196360b Mon Sep 17 00:00:00 2001 From: Ske Date: Fri, 7 Sep 2018 17:39:01 +0200 Subject: [PATCH] Add message count to member card. Closes #12 --- src/pluralkit/bot/commands/__init__.py | 3 +-- src/pluralkit/bot/utils.py | 9 ++++++--- src/pluralkit/db.py | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pluralkit/bot/commands/__init__.py b/src/pluralkit/bot/commands/__init__.py index 6d7302eb..fed037e2 100644 --- a/src/pluralkit/bot/commands/__init__.py +++ b/src/pluralkit/bot/commands/__init__.py @@ -60,8 +60,7 @@ class CommandContext: system = await self.get_system() if not system: - raise CommandError( - embeds.error("No system registered to this account. Use `pk;system new` to register one.")) + raise CommandError("No system registered to this account. Use `pk;system new` to register one.") return system diff --git a/src/pluralkit/bot/utils.py b/src/pluralkit/bot/utils.py index dbeda265..ddf1b1af 100644 --- a/src/pluralkit/bot/utils.py +++ b/src/pluralkit/bot/utils.py @@ -152,6 +152,10 @@ async def generate_member_info_card(conn, member: Member) -> discord.Embed: if member.pronouns: card.add_field(name="Pronouns", value=member.pronouns) + message_count = await db.get_member_message_count(conn, member.id) + 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 "" @@ -162,6 +166,5 @@ async def generate_member_info_card(conn, member: Member) -> discord.Embed: card.add_field(name="Description", value=member.description, inline=False) - card.set_footer(text="System ID: {} | Member ID: {}".format( - system.hid, member.hid)) - return card \ No newline at end of file + card.set_footer(text="System ID: {} | Member ID: {}".format(system.hid, member.hid)) + return card diff --git a/src/pluralkit/db.py b/src/pluralkit/db.py index ae5e38ba..b0b8a982 100644 --- a/src/pluralkit/db.py +++ b/src/pluralkit/db.py @@ -259,6 +259,10 @@ async def delete_message(conn, message_id: str): logger.debug("Deleting message (id={})".format(message_id)) await conn.execute("delete from messages where mid = $1", int(message_id)) +@db_wrap +async def get_member_message_count(conn, member_id: int) -> int: + return await conn.fetchval("select count(*) from messages where member = $1", member_id) + @db_wrap async def front_history(conn, system_id: int, count: int): return await conn.fetch("""select