diff --git a/payphone/cogs/calls/cog.py b/payphone/cogs/calls/cog.py index a764e8f..093fad0 100644 --- a/payphone/cogs/calls/cog.py +++ b/payphone/cogs/calls/cog.py @@ -637,8 +637,26 @@ class Calls(base.Cog): await ctx.send("❌ You have not participated in this call.") return + reviewed_reports = await models.Report.filter( + reported_by_id=ctx.author.id, + status__in=[models.ReportStatus.ACCEPTED, models.ReportStatus.DECLINED], + ) + + priority = 0.5 + + if len(reviewed_reports) > 3: + accepted_reports = len( + [ + report + for report in reviewed_reports + if report.status == models.ReportStatus.ACCEPTED + ] + ) + + priority = accepted_reports / len(reviewed_reports) + await models.Report.create( - call_id=call_id, reported_by_id=user.id, reason=reason, priority=1 + call_id=call_id, reported_by_id=user.id, reason=reason, priority=priority ) message = "✅ The call has been reported." diff --git a/payphone/cogs/mods/cog.py b/payphone/cogs/mods/cog.py index e2f9861..effc62b 100644 --- a/payphone/cogs/mods/cog.py +++ b/payphone/cogs/mods/cog.py @@ -181,7 +181,7 @@ class Mods(base.Cog): report = ( await models.Report.filter(status=models.ReportStatus.ON_REVIEW) - .order_by("-id") + .order_by("-priority") .limit(1) .first() .select_related("call") diff --git a/payphone/cogs/mods/views.py b/payphone/cogs/mods/views.py index 2a0e1cf..41e36cf 100644 --- a/payphone/cogs/mods/views.py +++ b/payphone/cogs/mods/views.py @@ -142,7 +142,7 @@ class ReportView(discord.ui.View): next_report = ( await models.Report.filter(status=models.ReportStatus.ON_REVIEW) - .order_by("id") + .order_by("-priority") .limit(1) .first() .select_related("call") @@ -207,7 +207,7 @@ class ReportView(discord.ui.View): report = ( await models.Report.filter(status=models.ReportStatus.ON_REVIEW) - .order_by("id") + .order_by("-priority") .limit(1) .first() .select_related("call") diff --git a/payphone/db/migrations/models/14_20241023143325_update.py b/payphone/db/migrations/models/14_20241023143325_update.py new file mode 100644 index 0000000..643e7d5 --- /dev/null +++ b/payphone/db/migrations/models/14_20241023143325_update.py @@ -0,0 +1,11 @@ +from tortoise import BaseDBAsyncClient + + +async def upgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "report" ALTER COLUMN "priority" TYPE DOUBLE PRECISION USING "priority"::DOUBLE PRECISION;""" + + +async def downgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "report" ALTER COLUMN "priority" TYPE INT USING "priority"::INT;""" diff --git a/payphone/db/models.py b/payphone/db/models.py index f8b1d7f..950ba9a 100644 --- a/payphone/db/models.py +++ b/payphone/db/models.py @@ -337,7 +337,7 @@ class Report(models.Model): "models.User", null=True, on_delete=fields.OnDelete.CASCADE ) reason: str = fields.CharField(max_length=500) - priority: int = fields.IntField() + priority: float = fields.FloatField() status: ReportStatus = fields.IntEnumField( ReportStatus, default=ReportStatus.ON_REVIEW, db_index=True ) @@ -361,4 +361,4 @@ class Ban(models.Model): expires_at: datetime | None = fields.DatetimeField(null=True) class Meta: - indexes = [("user_id", "expires_at")] + indexes = [("user_id", "expires_at"), ("status", "priority")]