WIP: Refactor Aurora (3.0.0) #29
4 changed files with 11 additions and 27 deletions
|
@ -1,7 +1,6 @@
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
from async_property import async_cached_property
|
|
||||||
from discord import Forbidden, HTTPException, InvalidData, NotFound
|
from discord import Forbidden, HTTPException, InvalidData, NotFound
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
@ -39,19 +38,16 @@ class Moderation(AuroraBaseModel):
|
||||||
def type(self) -> str:
|
def type(self) -> str:
|
||||||
return self.moderation_type
|
return self.moderation_type
|
||||||
|
|
||||||
@async_cached_property
|
async def get_moderator(self) -> "PartialUser":
|
||||||
async def moderator(self) -> "PartialUser":
|
|
||||||
return await PartialUser.from_id(self.bot, self.moderator_id)
|
return await PartialUser.from_id(self.bot, self.moderator_id)
|
||||||
|
|
||||||
@async_cached_property
|
async def get_target(self) -> Union["PartialUser", "PartialChannel"]:
|
||||||
async def target(self) -> Union["PartialUser", "PartialChannel"]:
|
|
||||||
if self.target_type == "user":
|
if self.target_type == "user":
|
||||||
return await PartialUser.from_id(self.bot, self.target_id)
|
return await PartialUser.from_id(self.bot, self.target_id)
|
||||||
else:
|
else:
|
||||||
return await PartialChannel.from_id(self.bot, self.target_id)
|
return await PartialChannel.from_id(self.bot, self.target_id)
|
||||||
|
|
||||||
@async_cached_property
|
async def get_resolved_by(self) -> Optional["PartialUser"]:
|
||||||
async def resolved_by_user(self) -> Optional["PartialUser"]:
|
|
||||||
if self.resolved_by:
|
if self.resolved_by:
|
||||||
return await PartialUser.from_id(self.bot, self.resolved_by)
|
return await PartialUser.from_id(self.bot, self.resolved_by)
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# pylint: disable=cyclic-import
|
# pylint: disable=cyclic-import
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional, Union
|
from typing import Union
|
||||||
|
|
||||||
from discord import (Color, Embed, Guild, Interaction, InteractionMessage,
|
from discord import (Color, Embed, Guild, Interaction, InteractionMessage,
|
||||||
Member, Role, User)
|
Member, Role, User)
|
||||||
|
@ -8,7 +8,7 @@ from redbot.core import commands
|
||||||
from redbot.core.utils.chat_formatting import (bold, box, error,
|
from redbot.core.utils.chat_formatting import (bold, box, error,
|
||||||
humanize_timedelta, warning)
|
humanize_timedelta, warning)
|
||||||
|
|
||||||
from aurora.models import Moderation, PartialChannel, PartialUser
|
from aurora.models import Moderation
|
||||||
from aurora.utilities.config import config
|
from aurora.utilities.config import config
|
||||||
from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict,
|
from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict,
|
||||||
get_bool_emoji, get_next_case_number,
|
get_bool_emoji, get_next_case_number,
|
||||||
|
@ -104,19 +104,19 @@ async def log_factory(
|
||||||
"""This function creates a log embed from set parameters, meant for moderation logging.
|
"""This function creates a log embed from set parameters, meant for moderation logging.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (Interaction): The interaction object.
|
interaction (discord.Interaction): The interaction object.
|
||||||
case_dict (dict): The case dictionary.
|
moderation (aurora.models.Moderation): The moderation object.
|
||||||
resolved (bool, optional): Whether the case is resolved or not. Defaults to False.
|
resolved (bool, optional): Whether the case is resolved or not. Defaults to False.
|
||||||
"""
|
"""
|
||||||
target: Union[PartialUser, PartialChannel] = await moderation.target
|
target = await moderation.get_target()
|
||||||
moderator: PartialUser = await moderation.moderator
|
moderator = await moderation.get_moderator()
|
||||||
if resolved:
|
if resolved:
|
||||||
embed = Embed(
|
embed = Embed(
|
||||||
title=f"📕 Case #{moderation.id:,} Resolved",
|
title=f"📕 Case #{moderation.id:,} Resolved",
|
||||||
color=await interaction.client.get_embed_color(interaction.channel),
|
color=await interaction.client.get_embed_color(interaction.channel),
|
||||||
)
|
)
|
||||||
|
|
||||||
resolved_by: Optional[PartialUser] = await moderation.resolved_by_user
|
resolved_by = await moderation.get_resolved_by()
|
||||||
embed.description = f"**Type:** {str.title(moderation.moderation_type)}\n**Target:** {target.name} ({target.id})\n**Moderator:** {moderator.name} ({moderator.id})\n**Timestamp:** <t:{moderation.timestamp}> | <t:{moderation.timestamp}:R>"
|
embed.description = f"**Type:** {str.title(moderation.moderation_type)}\n**Target:** {target.name} ({target.id})\n**Moderator:** {moderator.name} ({moderator.id})\n**Timestamp:** <t:{moderation.timestamp}> | <t:{moderation.timestamp}:R>"
|
||||||
|
|
||||||
if moderation.duration is not None:
|
if moderation.duration is not None:
|
||||||
|
|
13
poetry.lock
generated
13
poetry.lock
generated
|
@ -206,17 +206,6 @@ files = [
|
||||||
{file = "astroid-3.1.0.tar.gz", hash = "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4"},
|
{file = "astroid-3.1.0.tar.gz", hash = "sha256:ac248253bfa4bd924a0de213707e7ebeeb3138abeb48d798784ead1e56d419d4"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-property"
|
|
||||||
version = "0.2.2"
|
|
||||||
description = "Python decorator for async properties."
|
|
||||||
optional = false
|
|
||||||
python-versions = "*"
|
|
||||||
files = [
|
|
||||||
{file = "async_property-0.2.2-py2.py3-none-any.whl", hash = "sha256:8924d792b5843994537f8ed411165700b27b2bd966cefc4daeefc1253442a9d7"},
|
|
||||||
{file = "async_property-0.2.2.tar.gz", hash = "sha256:17d9bd6ca67e27915a75d92549df64b5c7174e9dc806b30a3934dc4ff0506380"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "attrs"
|
name = "attrs"
|
||||||
version = "23.2.0"
|
version = "23.2.0"
|
||||||
|
@ -2556,4 +2545,4 @@ multidict = ">=4.0"
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = ">=3.11,<3.12"
|
python-versions = ">=3.11,<3.12"
|
||||||
content-hash = "05c89da1577b4a3507856338502218e0da92dd9785a5fc4a78d6cb59058d887f"
|
content-hash = "67eb5e616951979332b6f32bcb39d85171cbf8377f566ea1862c51b5068b52f3"
|
||||||
|
|
|
@ -15,7 +15,6 @@ websockets = "^12.0"
|
||||||
pillow = "^10.3.0"
|
pillow = "^10.3.0"
|
||||||
numpy = "^1.26.4"
|
numpy = "^1.26.4"
|
||||||
pydantic = "^2.7.1"
|
pydantic = "^2.7.1"
|
||||||
async-property = "^0.2.2"
|
|
||||||
|
|
||||||
[tool.poetry.group.dev]
|
[tool.poetry.group.dev]
|
||||||
optional = true
|
optional = true
|
||||||
|
|
Loading…
Reference in a new issue