Merge pull request #44 from Payphone-Bot/25-add-a-report-priority-system
feat(bot): ✨ Add a priority system to reports.
This commit is contained in:
@@ -637,8 +637,26 @@ class Calls(base.Cog):
|
|||||||
await ctx.send("❌ You have not participated in this call.")
|
await ctx.send("❌ You have not participated in this call.")
|
||||||
return
|
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(
|
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."
|
message = "✅ The call has been reported."
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ class Mods(base.Cog):
|
|||||||
|
|
||||||
report = (
|
report = (
|
||||||
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
||||||
.order_by("-id")
|
.order_by("-priority")
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first()
|
.first()
|
||||||
.select_related("call")
|
.select_related("call")
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class ReportView(discord.ui.View):
|
|||||||
|
|
||||||
next_report = (
|
next_report = (
|
||||||
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
||||||
.order_by("id")
|
.order_by("-priority")
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first()
|
.first()
|
||||||
.select_related("call")
|
.select_related("call")
|
||||||
@@ -207,7 +207,7 @@ class ReportView(discord.ui.View):
|
|||||||
|
|
||||||
report = (
|
report = (
|
||||||
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
await models.Report.filter(status=models.ReportStatus.ON_REVIEW)
|
||||||
.order_by("id")
|
.order_by("-priority")
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first()
|
.first()
|
||||||
.select_related("call")
|
.select_related("call")
|
||||||
|
|||||||
@@ -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;"""
|
||||||
@@ -337,7 +337,7 @@ class Report(models.Model):
|
|||||||
"models.User", null=True, on_delete=fields.OnDelete.CASCADE
|
"models.User", null=True, on_delete=fields.OnDelete.CASCADE
|
||||||
)
|
)
|
||||||
reason: str = fields.CharField(max_length=500)
|
reason: str = fields.CharField(max_length=500)
|
||||||
priority: int = fields.IntField()
|
priority: float = fields.FloatField()
|
||||||
status: ReportStatus = fields.IntEnumField(
|
status: ReportStatus = fields.IntEnumField(
|
||||||
ReportStatus, default=ReportStatus.ON_REVIEW, db_index=True
|
ReportStatus, default=ReportStatus.ON_REVIEW, db_index=True
|
||||||
)
|
)
|
||||||
@@ -361,4 +361,4 @@ class Ban(models.Model):
|
|||||||
expires_at: datetime | None = fields.DatetimeField(null=True)
|
expires_at: datetime | None = fields.DatetimeField(null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
indexes = [("user_id", "expires_at")]
|
indexes = [("user_id", "expires_at"), ("status", "priority")]
|
||||||
|
|||||||
Reference in New Issue
Block a user