From 784ef034f57a975c423661d535985aae444605a8 Mon Sep 17 00:00:00 2001 From: io mintz Date: Tue, 6 Apr 2021 04:20:06 +0000 Subject: [PATCH] make guild count nullable --- bot.py | 2 +- schema.sql | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index a3e6745..fb79485 100755 --- a/bot.py +++ b/bot.py @@ -64,7 +64,7 @@ class Bot(Bot): user_id_md5 = hashlib.md5(ctx.author.id.to_bytes(8, byteorder='big'), usedforsecurity=False).digest() await self.pool.execute( 'INSERT INTO invokes (guild_id, user_id_md5, command) VALUES ($1, $2, $3)', - ctx.guild.id, user_id_md5, ctx.command.qualified_name, + getattr(ctx.guild, 'id', None), user_id_md5, ctx.command.qualified_name, ) # we use on_shard_ready rather than on_ready because the latter is a bit less reliable diff --git a/schema.sql b/schema.sql index 363b4ed..ce00388 100644 --- a/schema.sql +++ b/schema.sql @@ -2,7 +2,8 @@ SET TIME ZONE 'UTC'; -- inserted for every time a command is invoked CREATE TABLE invokes ( - guild_id BIGINT NOT NULL, + -- nullable because it may be invoked in DMs + guild_id BIGINT, -- hashed for privacy user_id_md5 BYTEA NOT NULL, -- the qualified name of the command invoked (https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=qualified_name#discord.ext.commands.Command.qualified_name)