Skip to content

Commit

Permalink
fix: Caselog
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Aug 12, 2023
1 parent 401bd38 commit 2d1a395
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/zibot/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import operator
from decimal import Decimal
from html.parser import HTMLParser
from typing import Optional, Tuple
from typing import Any, Optional, Tuple

import discord
from pyparsing import (
Expand Down Expand Up @@ -299,8 +299,15 @@ async def doCaselog(
targetId: int,
reason: str,
) -> Optional[int]:
q = await db.CaseLog.filter(guild_id=guildId).annotate(caseNum=Max("caseId")).first()
caseNum = (q.caseNum or 0) + 1 # type: ignore
# I had to use .values() instead of .first() because of a known Tortoise issue
# REF: https://github.com/tortoise/tortoise-orm/issues/794
q: list[dict[str, Any]] = await db.CaseLog.filter(guild_id=guildId).annotate(caseNum=Max("caseId")).values() # type: ignore

try:
caseNum = q[0]["caseNum"]
except (IndexError, KeyError):
caseNum = 0
caseNum += 1

if caseNum:
await db.CaseLog.create(
Expand Down

0 comments on commit 2d1a395

Please sign in to comment.