feat(aurora): added a resolve function to the Moderation model
This commit is contained in:
parent
dcda128f11
commit
d375716fbf
1 changed files with 45 additions and 0 deletions
|
@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Any, Dict, List, Literal, Optional, Union
|
from typing import Any, Dict, List, Literal, Optional, Union
|
||||||
|
|
||||||
|
import discord
|
||||||
from discord import Forbidden, HTTPException, InvalidData, NotFound
|
from discord import Forbidden, HTTPException, InvalidData, NotFound
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
@ -81,6 +82,50 @@ class Moderation(AuroraGuildModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.moderation_type} {self.target_type} {self.target_id} {self.reason}"
|
return f"{self.moderation_type} {self.target_type} {self.target_id} {self.reason}"
|
||||||
|
|
||||||
|
async def resolve(self, resolved_by: int, reason: str):
|
||||||
|
if self.resolved:
|
||||||
|
raise ValueError("Case is already resolved!")
|
||||||
|
|
||||||
|
self.resolved = True
|
||||||
|
self.resolved_by = resolved_by
|
||||||
|
self.resolve_reason = reason
|
||||||
|
|
||||||
|
if self.type == "MUTE":
|
||||||
|
try:
|
||||||
|
guild: discord.Guild = await self.bot.fetch_guild(self.guild_id)
|
||||||
|
member = await guild.fetch_member(self.target_id)
|
||||||
|
|
||||||
|
await member.timeout(
|
||||||
|
None, reason=f"Case {self.moderation_id} resolved by {resolved_by}{" for" + reason if reason else ""}"
|
||||||
|
)
|
||||||
|
except NotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if self.type in ["BAN", "TEMPBAN"]:
|
||||||
|
try:
|
||||||
|
guild: discord.Guild = await self.bot.fetch_guild(self.guild_id)
|
||||||
|
await guild.unban(await self.get_target(), reason=f"Case {self.moderation_id} resolved by {resolved_by}{" for" + reason if reason else ""}")
|
||||||
|
except NotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not self.changes:
|
||||||
|
self.changes.append(Change.from_dict(self.bot, {
|
||||||
|
"type": "ORIGINAL",
|
||||||
|
"timestamp": self.timestamp,
|
||||||
|
"reason": self.reason,
|
||||||
|
"user_id": self.moderator_id,
|
||||||
|
"duration": self.duration,
|
||||||
|
"end_timestamp": self.end_timestamp,
|
||||||
|
}))
|
||||||
|
self.changes.append(Change.from_dict(self.bot, {
|
||||||
|
"type": "RESOLVE",
|
||||||
|
"timestamp": datetime.now(),
|
||||||
|
"reason": reason,
|
||||||
|
"user_id": resolved_by,
|
||||||
|
}))
|
||||||
|
|
||||||
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
from aurora.utilities.database import connect
|
from aurora.utilities.database import connect
|
||||||
from aurora.utilities.json import dumps
|
from aurora.utilities.json import dumps
|
||||||
|
|
Loading…
Reference in a new issue