Skip to content

Commit bae792b

Browse files
committed
refactor: log commands piccolo
1 parent 1764aaf commit bae792b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

botbase/exts/log_commands.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from piccolo.querystring import Unquoted
4+
35
from ..botbase import BotBase
46
from ..db import CommandLog
57
from ..models import CogBase
@@ -18,18 +20,24 @@ async def on_application_command_completion(self, inter: MyInter):
1820
channel = inter.channel.id if inter.guild is not None else None
1921
member = inter.user.id
2022

21-
# Incrementing amount without funky sub queries is not possible.
22-
await CommandLog.raw(
23-
"""
24-
INSERT INTO command_log (command, guild, channel, member, amount)
25-
VALUES ({}, {}, {}, {}, 1)
26-
ON CONFLICT (command, guild, channel, member)
27-
DO UPDATE SET amount = command_log.amount + 1;
28-
""",
29-
cmd,
30-
guild,
31-
channel,
32-
member,
23+
await CommandLog.insert(
24+
CommandLog(
25+
{
26+
CommandLog.command: cmd,
27+
CommandLog.guild: guild,
28+
CommandLog.channel: channel,
29+
CommandLog.member: member,
30+
}
31+
)
32+
).on_conflict(
33+
(
34+
CommandLog.command,
35+
CommandLog.guild,
36+
CommandLog.channel,
37+
CommandLog.member,
38+
),
39+
"DO UPDATE",
40+
((CommandLog.amount, Unquoted("command_log.amount + 1")),),
3341
)
3442

3543

0 commit comments

Comments
 (0)