feat(shard): ✨ Ban people with over 3 warns, even if the moderator specifies a warn.
This commit is contained in:
@@ -115,6 +115,9 @@ class Admin(base.Cog):
|
||||
except discord.Forbidden:
|
||||
pass
|
||||
|
||||
user: models.User = await models.User.get(id=user.id)
|
||||
user.set_cache(self.bot.redis)
|
||||
|
||||
@commands.command(aliases=["sup"])
|
||||
@commands.is_owner()
|
||||
async def supporter(
|
||||
@@ -159,7 +162,11 @@ class Admin(base.Cog):
|
||||
- Bot Moderator
|
||||
"""
|
||||
|
||||
report = await models.Report.filter(resolved=False).select_related("reported_by").first()
|
||||
report = (
|
||||
await models.Report.filter(resolved=False)
|
||||
.select_related("reported_by")
|
||||
.first()
|
||||
)
|
||||
|
||||
if report is None:
|
||||
return await ctx.send("✅ No reports left, have this cookie 🍪 !!")
|
||||
|
||||
@@ -79,7 +79,7 @@ class ReportView(discord.ui.View):
|
||||
|
||||
user = await models.User.get_cache_or_db(self.bot.redis, self.report.user_id)
|
||||
|
||||
if select.values[0] == "warn":
|
||||
if select.values[0] == "warn" and user.warns_count < 3:
|
||||
user.warns_count += 1
|
||||
await user.save(force_update=True)
|
||||
await user.set_cache(self.bot.redis)
|
||||
@@ -104,6 +104,13 @@ class ReportView(discord.ui.View):
|
||||
),
|
||||
)
|
||||
|
||||
warn = models.Warn(
|
||||
user_id=self.report.user_id,
|
||||
report=self.report,
|
||||
created_by_id=interaction.user.id,
|
||||
)
|
||||
await warn.save()
|
||||
|
||||
try:
|
||||
await (await self.bot.get_or_fetch_user(self.report.user_id)).send(
|
||||
embed=embed
|
||||
@@ -156,7 +163,7 @@ class ReportView(discord.ui.View):
|
||||
|
||||
expires_at = None
|
||||
|
||||
if select.values[0] == "ban":
|
||||
if select.values[0] in ["ban", "warn"]:
|
||||
expiry_times = {
|
||||
1: datetime.now(timezone.utc) + timedelta(days=1),
|
||||
2: datetime.now(timezone.utc) + timedelta(days=7),
|
||||
|
||||
@@ -2,6 +2,8 @@ from dataclasses import dataclass
|
||||
|
||||
import orjson
|
||||
|
||||
import discord
|
||||
|
||||
from payphone.db import models
|
||||
from payphone.bot import Payphone
|
||||
from payphone.core import masks
|
||||
@@ -551,7 +553,7 @@ class CallHandler:
|
||||
return
|
||||
|
||||
for webhook in await channel.webhooks():
|
||||
if webhook.name == "Payphone" and webhook.token is not None:
|
||||
if webhook.user == self.bot.user and webhook.token is not None:
|
||||
await self.bot.redis.hset(
|
||||
"calls:channels:webhooks", channel_id, webhook.url
|
||||
)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS "warn" (
|
||||
"id" SERIAL NOT NULL PRIMARY KEY,
|
||||
"user_id" BIGINT NOT NULL,
|
||||
"reason" TEXT,
|
||||
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"created_by_id" BIGINT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE,
|
||||
"report_id" BIGINT REFERENCES "report" ("id") ON DELETE CASCADE
|
||||
);
|
||||
COMMENT ON TABLE "warn" IS 'A warn.';"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
DROP TABLE IF EXISTS "warn";"""
|
||||
@@ -144,6 +144,16 @@ class User(models.Model):
|
||||
)
|
||||
|
||||
|
||||
class Warn(models.Model):
|
||||
"""A warn."""
|
||||
|
||||
user_id = fields.BigIntField()
|
||||
report = fields.ForeignKeyField("models.Report", null=True)
|
||||
reason = fields.TextField(null=True, default=None)
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
created_by = fields.ForeignKeyField("models.User", related_name="created_warns")
|
||||
|
||||
|
||||
class Ban(models.Model):
|
||||
"""
|
||||
A ban.
|
||||
|
||||
Reference in New Issue
Block a user