Add viewing member pronouns on message query. Closes #73.

This commit is contained in:
Ske 2019-04-14 22:13:43 +02:00
parent e1c1ea2bca
commit 6c3c6eae4d
3 changed files with 10 additions and 6 deletions

View File

@ -185,7 +185,7 @@ async def get_message_contents(client: discord.Client, channel_id: int, message_
return None return None
async def message_card(client: discord.Client, message: db.MessageInfo): async def message_card(client: discord.Client, message: db.MessageInfo, include_pronouns: bool = False):
# Get the original sender of the messages # Get the original sender of the messages
try: try:
original_sender = await client.get_user_info(message.sender) original_sender = await client.get_user_info(message.sender)
@ -203,7 +203,10 @@ async def message_card(client: discord.Client, message: db.MessageInfo):
system_value = "`{}`".format(message.system_hid) system_value = "`{}`".format(message.system_hid)
embed.add_field(name="System", value=system_value) embed.add_field(name="System", value=system_value)
embed.add_field(name="Member", value="{} (`{}`)".format(message.name, message.hid)) if include_pronouns and message.pronouns:
embed.add_field(name="Member", value="{} (`{}`)\n*(pronouns: **{}**)*".format(message.name, message.hid, message.pronouns))
else:
embed.add_field(name="Member", value="{} (`{}`)".format(message.name, message.hid))
if original_sender: if original_sender:
sender_name = "{}#{}".format(original_sender.name, original_sender.discriminator) sender_name = "{}#{}".format(original_sender.name, original_sender.discriminator)

View File

@ -240,7 +240,7 @@ async def do_query_message(conn, client: discord.Client, queryer_id: int, messag
return False return False
# Then DM the queryer the message embed # Then DM the queryer the message embed
card = await embeds.message_card(client, msg) card = await embeds.message_card(client, msg, include_pronouns=True)
user = client.get_user(queryer_id) user = client.get_user(queryer_id)
if not user: if not user:
# We couldn't find this user in the cache - bail # We couldn't find this user in the cache - bail

View File

@ -203,7 +203,7 @@ async def get_members_by_account(conn, account_id: int) -> List[ProxyMember]:
and members.system = systems.id""", account_id) and members.system = systems.id""", account_id)
return [ProxyMember(**row) for row in rows] return [ProxyMember(**row) for row in rows]
class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "sender", "name", "hid", "avatar_url", "system_name", "system_hid"])): class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "sender", "name", "hid", "avatar_url", "system_name", "system_hid", "pronouns"])):
mid: int mid: int
channel: int channel: int
member: int member: int
@ -213,6 +213,7 @@ class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "sender"
avatar_url: str avatar_url: str
system_name: str system_name: str
system_hid: str system_hid: str
pronouns: str
def to_json(self): def to_json(self):
return { return {
@ -228,7 +229,7 @@ class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "sender"
async def get_message_by_sender_and_id(conn, message_id: int, sender_id: int) -> MessageInfo: async def get_message_by_sender_and_id(conn, message_id: int, sender_id: int) -> MessageInfo:
row = await conn.fetchrow("""select row = await conn.fetchrow("""select
messages.*, messages.*,
members.name, members.hid, members.avatar_url, members.name, members.hid, members.avatar_url, members.pronouns,
systems.name as system_name, systems.hid as system_hid systems.name as system_name, systems.hid as system_hid
from from
messages, members, systems messages, members, systems
@ -244,7 +245,7 @@ async def get_message_by_sender_and_id(conn, message_id: int, sender_id: int) ->
async def get_message(conn, message_id: int) -> MessageInfo: async def get_message(conn, message_id: int) -> MessageInfo:
row = await conn.fetchrow("""select row = await conn.fetchrow("""select
messages.*, messages.*,
members.name, members.hid, members.avatar_url, members.name, members.hid, members.avatar_url, members.pronouns,
systems.name as system_name, systems.hid as system_hid systems.name as system_name, systems.hid as system_hid
from from
messages, members, systems messages, members, systems