feat(bot): ✨ Notify the reporter when their report has been accepted.
This commit is contained in:
@@ -146,6 +146,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
duration: timedelta | None,
|
duration: timedelta | None,
|
||||||
reason: str,
|
reason: str,
|
||||||
moderator: discord.User | discord.Member | models.User | int | None = None,
|
moderator: discord.User | discord.Member | models.User | int | None = None,
|
||||||
|
report_id: int | None = None
|
||||||
) -> models.Ban:
|
) -> models.Ban:
|
||||||
"""Bans a user from Payphone.
|
"""Bans a user from Payphone.
|
||||||
|
|
||||||
@@ -155,6 +156,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
reason (str): The reason of the ban.
|
reason (str): The reason of the ban.
|
||||||
moderator (discord.User | discord.Member | models.User | int | None, optional): The
|
moderator (discord.User | discord.Member | models.User | int | None, optional): The
|
||||||
moderator who performed the action.
|
moderator who performed the action.
|
||||||
|
report_id (int | None, optional): The ID of the report the ban is related to.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
models.Ban: The newly created ban.
|
models.Ban: The newly created ban.
|
||||||
@@ -198,6 +200,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
reason=reason,
|
reason=reason,
|
||||||
expires_at=until,
|
expires_at=until,
|
||||||
banned_by_id=mod_id,
|
banned_by_id=mod_id,
|
||||||
|
report_id=report_id
|
||||||
)
|
)
|
||||||
|
|
||||||
await redis.set(key, "1", ex=300)
|
await redis.set(key, "1", ex=300)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class BanUserModal(discord.ui.Modal):
|
|||||||
duration,
|
duration,
|
||||||
self.children[0].value,
|
self.children[0].value,
|
||||||
interaction.user.id,
|
interaction.user.id,
|
||||||
|
self.report_id
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import discord
|
import discord
|
||||||
|
from discord import errors
|
||||||
from discord.ext import pages
|
from discord.ext import pages
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ from tortoise import transactions
|
|||||||
|
|
||||||
from payphone import bot
|
from payphone import bot
|
||||||
from payphone.db import models
|
from payphone.db import models
|
||||||
from payphone.core import constants
|
from payphone.core import constants, formatting as fmt
|
||||||
from payphone.cogs.mods import modals, views, embeds
|
from payphone.cogs.mods import modals, views, embeds
|
||||||
|
|
||||||
|
|
||||||
@@ -139,7 +140,7 @@ class ReportView(discord.ui.View):
|
|||||||
report.status = models.ReportStatus.ACCEPTED
|
report.status = models.ReportStatus.ACCEPTED
|
||||||
await report.save()
|
await report.save()
|
||||||
|
|
||||||
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("id")
|
||||||
.limit(1)
|
.limit(1)
|
||||||
@@ -149,7 +150,35 @@ class ReportView(discord.ui.View):
|
|||||||
)
|
)
|
||||||
total = await models.Report.filter(status=models.ReportStatus.ON_REVIEW).count()
|
total = await models.Report.filter(status=models.ReportStatus.ON_REVIEW).count()
|
||||||
|
|
||||||
if report is None:
|
banned_user_ids = (
|
||||||
|
await models.Ban.filter(report=report)
|
||||||
|
.distinct()
|
||||||
|
.values_list("user_id", flat=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(banned_user_ids) > 0:
|
||||||
|
profiles = [rs.profile for rs in report.call.call_rss if rs.user_id in banned_user_ids]
|
||||||
|
|
||||||
|
try:
|
||||||
|
await (await self.bot.get_or_fetch_user(report.reported_by_id)).send(
|
||||||
|
f"🔔 Your report for call `{report.call_id}` helped us ban "
|
||||||
|
+ fmt.text_join(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
f"`{p.name}`"
|
||||||
|
if p.user_id != report.reported_by_id
|
||||||
|
else "`you`"
|
||||||
|
)
|
||||||
|
for p in profiles
|
||||||
|
]
|
||||||
|
)
|
||||||
|
+ ". Thank you for your report!"
|
||||||
|
)
|
||||||
|
|
||||||
|
except errors.DiscordException:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if next_report is None:
|
||||||
await interaction.response.edit_message(
|
await interaction.response.edit_message(
|
||||||
content="✅ No reports left, have this cookie 🍪 !!",
|
content="✅ No reports left, have this cookie 🍪 !!",
|
||||||
embed=None,
|
embed=None,
|
||||||
@@ -158,8 +187,8 @@ class ReportView(discord.ui.View):
|
|||||||
return
|
return
|
||||||
|
|
||||||
await interaction.response.edit_message(
|
await interaction.response.edit_message(
|
||||||
embed=embeds.ReportEmbed(self.bot, report),
|
embed=embeds.ReportEmbed(self.bot, next_report),
|
||||||
view=views.ReportView(self.bot, report, total),
|
view=views.ReportView(self.bot, next_report, total),
|
||||||
)
|
)
|
||||||
|
|
||||||
@discord.ui.button(label="Decline", style=discord.ButtonStyle.red, row=2)
|
@discord.ui.button(label="Decline", style=discord.ButtonStyle.red, row=2)
|
||||||
|
|||||||
Reference in New Issue
Block a user