aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-12-23 11:16:51 -0800
committerGravatar MarkKoz <[email protected]>2019-12-23 11:34:23 -0800
commit1b52d13ac313eda420a54de829750882cf2bb2ab (patch)
treeea4ecb9b345b8856695ce023013f5c1acb405b00
parentCreate an alias for a Member + FetchedUser converter (diff)
Refactor user type aliases
-rw-r--r--bot/cogs/moderation/infractions.py4
-rw-r--r--bot/cogs/moderation/modlog.py3
-rw-r--r--bot/cogs/moderation/scheduler.py6
-rw-r--r--bot/cogs/moderation/utils.py17
4 files changed, 15 insertions, 15 deletions
diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py
index 87407f26b..d7201bdb1 100644
--- a/bot/cogs/moderation/infractions.py
+++ b/bot/cogs/moderation/infractions.py
@@ -14,7 +14,7 @@ from bot.decorators import respect_role_hierarchy
from bot.utils.checks import with_role_check
from . import utils
from .scheduler import InfractionScheduler
-from .utils import MemberObject
+from .utils import UserSnowflake
log = logging.getLogger(__name__)
@@ -229,7 +229,7 @@ class Infractions(InfractionScheduler, commands.Cog):
await self.apply_infraction(ctx, infraction, user, action)
@respect_role_hierarchy()
- async def apply_ban(self, ctx: Context, user: MemberObject, reason: str, **kwargs) -> None:
+ async def apply_ban(self, ctx: Context, user: UserSnowflake, reason: str, **kwargs) -> None:
"""Apply a ban infraction with kwargs passed to `post_infraction`."""
if await utils.has_active_infraction(ctx, user, "ban"):
return
diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py
index 35ef6cbcc..1e031443c 100644
--- a/bot/cogs/moderation/modlog.py
+++ b/bot/cogs/moderation/modlog.py
@@ -15,7 +15,6 @@ from discord.ext.commands import Cog, Context
from bot.bot import Bot
from bot.constants import Channels, Colours, Emojis, Event, Guild as GuildConstant, Icons, URLs
from bot.utils.time import humanize_delta
-from .utils import UserTypes
log = logging.getLogger(__name__)
@@ -355,7 +354,7 @@ class ModLog(Cog, name="ModLog"):
)
@Cog.listener()
- async def on_member_ban(self, guild: discord.Guild, member: UserTypes) -> None:
+ async def on_member_ban(self, guild: discord.Guild, member: discord.Member) -> None:
"""Log ban event to user log."""
if guild.id != GuildConstant.id:
return
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py
index 732091c17..e14c302cb 100644
--- a/bot/cogs/moderation/scheduler.py
+++ b/bot/cogs/moderation/scheduler.py
@@ -17,7 +17,7 @@ from bot.utils import time
from bot.utils.scheduling import Scheduler
from . import utils
from .modlog import ModLog
-from .utils import MemberObject
+from .utils import UserSnowflake
log = logging.getLogger(__name__)
@@ -77,7 +77,7 @@ class InfractionScheduler(Scheduler):
self,
ctx: Context,
infraction: utils.Infraction,
- user: MemberObject,
+ user: UserSnowflake,
action_coro: t.Optional[t.Awaitable] = None
) -> None:
"""Apply an infraction to the user, log the infraction, and optionally notify the user."""
@@ -189,7 +189,7 @@ class InfractionScheduler(Scheduler):
log.info(f"Applied {infr_type} infraction #{id_} to {user}.")
- async def pardon_infraction(self, ctx: Context, infr_type: str, user: MemberObject) -> None:
+ async def pardon_infraction(self, ctx: Context, infr_type: str, user: UserSnowflake) -> None:
"""Prematurely end an infraction for a user and log the action in the mod log."""
log.trace(f"Pardoning {infr_type} infraction for {user}.")
diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py
index 6f7ea9771..79555369c 100644
--- a/bot/cogs/moderation/utils.py
+++ b/bot/cogs/moderation/utils.py
@@ -24,13 +24,14 @@ INFRACTION_ICONS = {
RULES_URL = "https://pythondiscord.com/pages/rules"
APPEALABLE_INFRACTIONS = ("ban", "mute")
-UserTypes = t.Union[discord.Member, discord.User]
-MemberObject = t.Union[UserTypes, discord.Object]
+# Type aliases
+UserObject = t.Union[discord.Member, discord.User]
+UserSnowflake = t.Union[UserObject, discord.Object]
Infraction = t.Dict[str, t.Union[str, int, bool]]
Expiry = t.Union[Duration, ISODateTime]
-async def post_user(ctx: Context, user: MemberObject) -> t.Optional[dict]:
+async def post_user(ctx: Context, user: UserSnowflake) -> t.Optional[dict]:
"""
Create a new user in the database.
@@ -61,7 +62,7 @@ async def post_user(ctx: Context, user: MemberObject) -> t.Optional[dict]:
async def post_infraction(
ctx: Context,
- user: MemberObject,
+ user: UserSnowflake,
infr_type: str,
reason: str,
expires_at: datetime = None,
@@ -98,7 +99,7 @@ async def post_infraction(
return
-async def has_active_infraction(ctx: Context, user: MemberObject, infr_type: str) -> bool:
+async def has_active_infraction(ctx: Context, user: UserSnowflake, infr_type: str) -> bool:
"""Checks if a user already has an active infraction of the given type."""
log.trace(f"Checking if {user} has active infractions of type {infr_type}.")
@@ -123,7 +124,7 @@ async def has_active_infraction(ctx: Context, user: MemberObject, infr_type: str
async def notify_infraction(
- user: UserTypes,
+ user: UserObject,
infr_type: str,
expires_at: t.Optional[str] = None,
reason: t.Optional[str] = None,
@@ -154,7 +155,7 @@ async def notify_infraction(
async def notify_pardon(
- user: UserTypes,
+ user: UserObject,
title: str,
content: str,
icon_url: str = Icons.user_verified
@@ -172,7 +173,7 @@ async def notify_pardon(
return await send_private_embed(user, embed)
-async def send_private_embed(user: UserTypes, embed: discord.Embed) -> bool:
+async def send_private_embed(user: UserObject, embed: discord.Embed) -> bool:
"""
A helper method for sending an embed to a user's DMs.