Stop logging message contents in the database for privacy reasons. Please remove the 'content' column in the 'messages' table:

This commit is contained in:
Ske 2018-09-16 13:59:37 +02:00
parent cae394b4e8
commit ca662bd502
3 changed files with 18 additions and 9 deletions

View File

@ -4,6 +4,17 @@ from pluralkit.bot.commands import *
logger = logging.getLogger("pluralkit.commands") 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): async def message_info(ctx: CommandContext):
mid_str = ctx.pop_str(CommandError("You must pass a message ID.", help=help.message_lookup)) 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) embed.add_field(name="Sent by", value=sender_name)
if message.content: # Content can be empty string if there's an attachment message_content = await get_message_contents(ctx.client, message.channel, message.mid)
embed.add_field(name="Content", value=message.content, inline=False) if message_content:
embed.description = message_content
embed.set_author(name=message.name, icon_url=message.avatar_url or discord.Embed.Empty) embed.set_author(name=message.name, icon_url=message.avatar_url or discord.Embed.Empty)

View File

@ -175,8 +175,7 @@ class Proxy:
# Report webhook stats to Influx # Report webhook stats to Influx
await self.stats.report_webhook(time.perf_counter() - time_before, True) 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, await db.add_message(conn, message["id"], message["channel_id"], member.id, original_message.author.id)
text or "")
try: try:
await self.client.delete_message(original_message) await self.client.delete_message(original_message)

View File

@ -171,10 +171,10 @@ async def delete_webhook(conn, channel_id: str):
await conn.execute("delete from webhooks where channel = $1", int(channel_id)) await conn.execute("delete from webhooks where channel = $1", int(channel_id))
@db_wrap @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( logger.debug("Adding new message (id={}, channel={}, member={}, sender={})".format(
message_id, channel_id, member_id, sender_id)) 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"])): class ProxyMember(namedtuple("ProxyMember", ["id", "hid", "prefix", "suffix", "color", "name", "avatar_url", "tag", "system_name", "system_hid"])):
id: int 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)) and members.system = systems.id""", int(account_id))
return [ProxyMember(**row) for row in rows] 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 mid: int
channel: int channel: int
member: int member: int
content: str
sender: int sender: int
name: str name: str
hid: str hid: str
@ -221,7 +220,6 @@ class MessageInfo(namedtuple("MemberInfo", ["mid", "channel", "member", "content
"member": self.hid, "member": self.hid,
"system": self.system_hid, "system": self.system_hid,
"message_sender": str(self.sender), "message_sender": str(self.sender),
"content": self.content,
"timestamp": snowflake_time(self.mid).isoformat() "timestamp": snowflake_time(self.mid).isoformat()
} }