feat(bot): ✨ Keep track of who reviewed each report.
This commit is contained in:
@@ -140,6 +140,7 @@ class ReportView(discord.ui.View):
|
|||||||
report = self.report
|
report = self.report
|
||||||
|
|
||||||
report.status = models.ReportStatus.ACCEPTED
|
report.status = models.ReportStatus.ACCEPTED
|
||||||
|
report.reviewed_by_id = interaction.user.id
|
||||||
await report.save()
|
await report.save()
|
||||||
|
|
||||||
next_report = (
|
next_report = (
|
||||||
@@ -205,6 +206,7 @@ class ReportView(discord.ui.View):
|
|||||||
report = self.report
|
report = self.report
|
||||||
|
|
||||||
report.status = models.ReportStatus.DECLINED
|
report.status = models.ReportStatus.DECLINED
|
||||||
|
report.reviewed_by_id = interaction.user.id
|
||||||
await report.save()
|
await report.save()
|
||||||
|
|
||||||
report = (
|
report = (
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
from tortoise import BaseDBAsyncClient
|
||||||
|
|
||||||
|
|
||||||
|
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
DROP INDEX "idx_report_status_d6b157";
|
||||||
|
DROP INDEX "idx_ban_user_id_37a9cf";
|
||||||
|
ALTER TABLE "report" ADD "reviewed_by_id" BIGINT;
|
||||||
|
CREATE INDEX "idx_ban_user_id_37a9cf" ON "ban" ("user_id", "expires_at");;
|
||||||
|
CREATE INDEX "idx_report_status_d6b157" ON "report" ("status", "priority");;
|
||||||
|
ALTER TABLE "report" ADD CONSTRAINT "fk_report_user_67e68360" FOREIGN KEY ("reviewed_by_id") REFERENCES "user" ("id") ON DELETE SET NULL;"""
|
||||||
|
|
||||||
|
|
||||||
|
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
ALTER TABLE "report" DROP CONSTRAINT "fk_report_user_67e68360";
|
||||||
|
DROP INDEX "idx_report_status_d6b157";
|
||||||
|
DROP INDEX "idx_ban_user_id_37a9cf";
|
||||||
|
ALTER TABLE "report" DROP COLUMN "reviewed_by_id";
|
||||||
|
CREATE INDEX "idx_ban_user_id_37a9cf" ON "ban" ("user_id", "expires_at");;
|
||||||
|
CREATE INDEX "idx_report_status_d6b157" ON "report" ("status", "priority");;"""
|
||||||
@@ -368,6 +368,9 @@ class Report(models.Model):
|
|||||||
reported_by: fields.ForeignKeyNullableRelation["User"] = fields.ForeignKeyField(
|
reported_by: fields.ForeignKeyNullableRelation["User"] = fields.ForeignKeyField(
|
||||||
"models.User", null=True, on_delete=fields.OnDelete.CASCADE
|
"models.User", null=True, on_delete=fields.OnDelete.CASCADE
|
||||||
)
|
)
|
||||||
|
reviewed_by: fields.ForeignKeyNullableRelation["User"] = fields.ForeignKeyField(
|
||||||
|
"models.User", null=True, on_delete=fields.OnDelete.SET_NULL, related_name="reports_reviewed"
|
||||||
|
)
|
||||||
reason: str = fields.CharField(max_length=500)
|
reason: str = fields.CharField(max_length=500)
|
||||||
priority: float = fields.FloatField()
|
priority: float = fields.FloatField()
|
||||||
status: ReportStatus = fields.IntEnumField(
|
status: ReportStatus = fields.IntEnumField(
|
||||||
|
|||||||
+13
-13
@@ -1,5 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
|
|
||||||
from payphone.core import logging
|
from payphone.core import logging
|
||||||
|
|
||||||
|
|
||||||
@@ -30,10 +28,10 @@ async def flush():
|
|||||||
call_ids = [int(call_id) for call_id in call_ids]
|
call_ids = [int(call_id) for call_id in call_ids]
|
||||||
|
|
||||||
if len(call_ids) == 0:
|
if len(call_ids) == 0:
|
||||||
log.info("Skipping flushing. No calls to flush.")
|
log.debug("Skipping flushing. No calls to flush.")
|
||||||
return
|
return
|
||||||
|
|
||||||
log.info("Flushing messages for %s calls." % len(call_ids))
|
log.info("Flushing messages for %s calls." , len(call_ids))
|
||||||
|
|
||||||
pipe = redis.pipeline()
|
pipe = redis.pipeline()
|
||||||
|
|
||||||
@@ -81,8 +79,8 @@ async def flush():
|
|||||||
asyncpg.exceptions.InterfaceError,
|
asyncpg.exceptions.InterfaceError,
|
||||||
):
|
):
|
||||||
log.exception(
|
log.exception(
|
||||||
"[Call ID: %s] An error occured trying to flush messages for call ID."
|
"[Call ID: %s] An error occured trying to flush messages for call ID.",
|
||||||
% call_id
|
call_id,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -98,14 +96,16 @@ async def flush():
|
|||||||
asyncpg.exceptions.InterfaceError,
|
asyncpg.exceptions.InterfaceError,
|
||||||
):
|
):
|
||||||
log.exception(
|
log.exception(
|
||||||
"[Call ID: %s] An error occured trying to flush message contents."
|
"[Call ID: %s] An error occured trying to flush message contents.",
|
||||||
% call_id
|
call_id,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
log.info(
|
log.debug(
|
||||||
"[Call ID: %s] Flushed %s messages and %s message contents."
|
"[Call ID: %s] Flushed %s messages and %s message contents.",
|
||||||
% (call_id, len(messages), len(message_contents))
|
call_id,
|
||||||
|
len(messages),
|
||||||
|
len(message_contents),
|
||||||
)
|
)
|
||||||
|
|
||||||
log.info("Finished flushing messages.")
|
log.info("Finished flushing messages.")
|
||||||
@@ -126,5 +126,5 @@ async def loop() -> None:
|
|||||||
|
|
||||||
await flush()
|
await flush()
|
||||||
|
|
||||||
except (KeyboardInterrupt, asyncio.exceptions.CancelledError) as e:
|
except (KeyboardInterrupt, asyncio.exceptions.CancelledError):
|
||||||
log.exception('')
|
log.exception("")
|
||||||
|
|||||||
Reference in New Issue
Block a user