From ca662bd502b81826785aaf94ca7cd3c126c8c967 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 16 Sep 2018 13:59:37 +0200 Subject: [PATCH] Stop logging message contents in the database for privacy reasons. Please remove the 'content' column in the 'messages' table: --- src/pluralkit/bot/commands/message_commands.py | 16 ++++++++++++++-- src/pluralkit/bot/proxy.py | 3 +-- src/pluralkit/db.py | 8 +++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/pluralkit/bot/commands/message_commands.py b/src/pluralkit/bot/commands/message_commands.py index 5421ca5f..68909ef6 100644 --- a/src/pluralkit/bot/commands/message_commands.py +++ b/src/pluralkit/bot/commands/message_commands.py @@ -4,6 +4,17 @@ from pluralkit.bot.commands import * logger = logging.getLogger("pluralkit.commands") +async def get_message_contents(client: discord.Client, channel_id: int, message_id: int): + channel = client.get_channel(str(channel_id)) + if channel: + try: + original_message = await client.get_message(channel, str(message_id)) + return original_message.content or None + except (discord.errors.Forbidden, discord.errors.NotFound): + pass + + return None + async def message_info(ctx: CommandContext): mid_str = ctx.pop_str(CommandError("You must pass a message ID.", help=help.message_lookup)) @@ -43,8 +54,9 @@ async def message_info(ctx: CommandContext): embed.add_field(name="Sent by", value=sender_name) - if message.content: # Content can be empty string if there's an attachment - embed.add_field(name="Content", value=message.content, inline=False) + message_content = await get_message_contents(ctx.client, message.channel, message.mid) + if message_content: + embed.description = message_content embed.set_author(name=message.name, icon_url=message.avatar_url or discord.Embed.Empty) diff --git a/src/pluralkit/bot/proxy.py b/src/pluralkit/bot/proxy.py index 4dbb3e4b..447c851d 100644 --- a/src/pluralkit/bot/proxy.py +++ b/src/pluralkit/bot/proxy.py @@ -175,8 +175,7 @@ class Proxy: # Report webhook stats to Influx await self.stats.report_webhook(time.perf_counter() - time_before, True) - await db.add_message(conn, message["id"], message["channel_id"], member.id, original_message.author.id, - text or "") + await db.add_message(conn, message["id"], message["channel_id"], member.id, original_message.author.id) try: await self.client.delete_message(original_message) diff --git a/src/pluralkit/db.py b/src/pluralkit/db.py index 57da29af..36def8f9 100644 --- a/src/pluralkit/db.py +++ b/src/pluralkit/db.py @@ -171,10 +171,10 @@ async def delete_webhook(conn, channel_id: str): await conn.execute("delete from webhooks where channel = $1", int(channel_id)) @db_wrap -async def add_message(conn, message_id: str, channel_id: str, member_id: int, sender_id: str, content: str): +async def add_message(conn, message_id: str, channel_id: str, member_id: int, sender_id: str): logger.debug("Adding new message (id={}, channel={}, member={}, sender={})".format( message_id, channel_id, member_id, sender_id)) - await conn.execute("insert into messages (mid, channel, member, sender, content) values ($1, $2, $3, $4, $5)", int(message_id), int(channel_id), member_id, int(sender_id), content) + await conn.execute("insert into messages (mid, channel, member, sender) values ($1, $2, $3, $4)", int(message_id), int(channel_id), member_id, int(sender_id)) class ProxyMember(namedtuple("ProxyMember", ["id", "hid", "prefix", "suffix", "color", "name", "avatar_url", "tag", "system_name", "system_hid"])): id: int @@ -202,11 +202,10 @@ async def get_members_by_account(conn, account_id: str) -> List[ProxyMember]: and members.system = systems.id""", int(account_id)) return [ProxyMember(**row) for row in rows] -class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "content", "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"])): mid: int channel: int member: int - content: str sender: int name: str hid: str @@ -221,7 +220,6 @@ class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "content "member": self.hid, "system": self.system_hid, "message_sender": str(self.sender), - "content": self.content, "timestamp": snowflake_time(self.mid).isoformat() }