diff options
| author | 2019-12-23 11:16:05 -0800 | |
|---|---|---|
| committer | 2019-12-23 11:30:57 -0800 | |
| commit | c0293abbea7a6a6bed66221b40c827d71ca5ee22 (patch) | |
| tree | 964a29ce3400450112448f8a4a5f62538c8b0f61 | |
| parent | Make FetchedUser a subclass of UserConverter (diff) | |
Create an alias for a Member + FetchedUser converter
| -rw-r--r-- | bot/cogs/alias.py | 10 | ||||
| -rw-r--r-- | bot/cogs/moderation/infractions.py | 16 | ||||
| -rw-r--r-- | bot/cogs/watchchannels/bigbrother.py | 6 | ||||
| -rw-r--r-- | bot/cogs/watchchannels/talentpool.py | 8 | ||||
| -rw-r--r-- | bot/converters.py | 3 | 
5 files changed, 23 insertions, 20 deletions
diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py index e709be85d..197155456 100644 --- a/bot/cogs/alias.py +++ b/bot/cogs/alias.py @@ -6,7 +6,7 @@ from discord.ext.commands import Cog, Command, Context, clean_content, command,  from bot.bot import Bot  from bot.cogs.extensions import Extension -from bot.converters import FetchedUser, TagNameConverter +from bot.converters import FetchedMember, TagNameConverter  from bot.pagination import LinePaginator  log = logging.getLogger(__name__) @@ -59,12 +59,12 @@ class Alias (Cog):          await self.invoke(ctx, "site tools")      @command(name="watch", hidden=True) -    async def bigbrother_watch_alias(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def bigbrother_watch_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """Alias for invoking <prefix>bigbrother watch [user] [reason]."""          await self.invoke(ctx, "bigbrother watch", user, reason=reason)      @command(name="unwatch", hidden=True) -    async def bigbrother_unwatch_alias(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def bigbrother_unwatch_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """Alias for invoking <prefix>bigbrother unwatch [user] [reason]."""          await self.invoke(ctx, "bigbrother unwatch", user, reason=reason) @@ -130,12 +130,12 @@ class Alias (Cog):          await self.invoke(ctx, "docs get", symbol)      @command(name="nominate", hidden=True) -    async def nomination_add_alias(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def nomination_add_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """Alias for invoking <prefix>talentpool add [user] [reason]."""          await self.invoke(ctx, "talentpool add", user, reason=reason)      @command(name="unnominate", hidden=True) -    async def nomination_end_alias(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def nomination_end_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """Alias for invoking <prefix>nomination end [user] [reason]."""          await self.invoke(ctx, "nomination end", user, reason=reason) diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py index 264d8bcf5..87407f26b 100644 --- a/bot/cogs/moderation/infractions.py +++ b/bot/cogs/moderation/infractions.py @@ -9,7 +9,7 @@ from discord.ext.commands import Context, command  from bot import constants  from bot.bot import Bot  from bot.constants import Event -from bot.converters import FetchedUser +from bot.converters import FetchedMember  from bot.decorators import respect_role_hierarchy  from bot.utils.checks import with_role_check  from . import utils @@ -66,7 +66,7 @@ class Infractions(InfractionScheduler, commands.Cog):          await self.apply_kick(ctx, user, reason, active=False)      @command() -    async def ban(self, ctx: Context, user: FetchedUser, *, reason: str = None) -> None: +    async def ban(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:          """Permanently ban a user for the given reason."""          await self.apply_ban(ctx, user, reason) @@ -93,7 +93,7 @@ class Infractions(InfractionScheduler, commands.Cog):          await self.apply_mute(ctx, user, reason, expires_at=duration)      @command() -    async def tempban(self, ctx: Context, user: FetchedUser, duration: utils.Expiry, *, reason: str = None) -> None: +    async def tempban(self, ctx: Context, user: FetchedMember, duration: utils.Expiry, *, reason: str = None) -> None:          """          Temporarily ban a user for the given reason and duration. @@ -115,7 +115,7 @@ class Infractions(InfractionScheduler, commands.Cog):      # region: Permanent shadow infractions      @command(hidden=True) -    async def note(self, ctx: Context, user: FetchedUser, *, reason: str = None) -> None: +    async def note(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:          """Create a private note for a user with the given reason without notifying the user."""          infraction = await utils.post_infraction(ctx, user, "note", reason, hidden=True, active=False)          if infraction is None: @@ -129,7 +129,7 @@ class Infractions(InfractionScheduler, commands.Cog):          await self.apply_kick(ctx, user, reason, hidden=True, active=False)      @command(hidden=True, aliases=['shadowban', 'sban']) -    async def shadow_ban(self, ctx: Context, user: FetchedUser, *, reason: str = None) -> None: +    async def shadow_ban(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:          """Permanently ban a user for the given reason without notifying the user."""          await self.apply_ban(ctx, user, reason, hidden=True) @@ -159,7 +159,7 @@ class Infractions(InfractionScheduler, commands.Cog):      async def shadow_tempban(          self,          ctx: Context, -        user: FetchedUser, +        user: FetchedMember,          duration: utils.Expiry,          *,          reason: str = None @@ -185,12 +185,12 @@ class Infractions(InfractionScheduler, commands.Cog):      # region: Remove infractions (un- commands)      @command() -    async def unmute(self, ctx: Context, user: FetchedUser) -> None: +    async def unmute(self, ctx: Context, user: FetchedMember) -> None:          """Prematurely end the active mute infraction for the user."""          await self.pardon_infraction(ctx, "mute", user)      @command() -    async def unban(self, ctx: Context, user: FetchedUser) -> None: +    async def unban(self, ctx: Context, user: FetchedMember) -> None:          """Prematurely end the active ban infraction for the user."""          await self.pardon_infraction(ctx, "ban", user) diff --git a/bot/cogs/watchchannels/bigbrother.py b/bot/cogs/watchchannels/bigbrother.py index b2cb99368..41f933247 100644 --- a/bot/cogs/watchchannels/bigbrother.py +++ b/bot/cogs/watchchannels/bigbrother.py @@ -6,7 +6,7 @@ from discord.ext.commands import Cog, Context, group  from bot.bot import Bot  from bot.cogs.moderation.utils import post_infraction  from bot.constants import Channels, MODERATION_ROLES, Webhooks -from bot.converters import FetchedUser +from bot.converters import FetchedMember  from bot.decorators import with_role  from .watchchannel import WatchChannel @@ -45,7 +45,7 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"):      @bigbrother_group.command(name='watch', aliases=('w',))      @with_role(*MODERATION_ROLES) -    async def watch_command(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def watch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """          Relay messages sent by the given `user` to the `#big-brother` channel. @@ -92,7 +92,7 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"):      @bigbrother_group.command(name='unwatch', aliases=('uw',))      @with_role(*MODERATION_ROLES) -    async def unwatch_command(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """Stop relaying messages by the given `user`."""          active_watches = await self.bot.api_client.get(              self.api_endpoint, diff --git a/bot/cogs/watchchannels/talentpool.py b/bot/cogs/watchchannels/talentpool.py index 776f0ea87..329a78af4 100644 --- a/bot/cogs/watchchannels/talentpool.py +++ b/bot/cogs/watchchannels/talentpool.py @@ -8,7 +8,7 @@ from discord.ext.commands import Cog, Context, group  from bot.api import ResponseCodeError  from bot.bot import Bot  from bot.constants import Channels, Guild, MODERATION_ROLES, STAFF_ROLES, Webhooks -from bot.converters import FetchedUser +from bot.converters import FetchedMember  from bot.decorators import with_role  from bot.pagination import LinePaginator  from bot.utils import time @@ -49,7 +49,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):      @nomination_group.command(name='watch', aliases=('w', 'add', 'a'))      @with_role(*STAFF_ROLES) -    async def watch_command(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def watch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """          Relay messages sent by the given `user` to the `#talent-pool` channel. @@ -114,7 +114,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):      @nomination_group.command(name='history', aliases=('info', 'search'))      @with_role(*MODERATION_ROLES) -    async def history_command(self, ctx: Context, user: FetchedUser) -> None: +    async def history_command(self, ctx: Context, user: FetchedMember) -> None:          """Shows the specified user's nomination history."""          result = await self.bot.api_client.get(              self.api_endpoint, @@ -143,7 +143,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):      @nomination_group.command(name='unwatch', aliases=('end', ))      @with_role(*MODERATION_ROLES) -    async def unwatch_command(self, ctx: Context, user: FetchedUser, *, reason: str) -> None: +    async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:          """          Ends the active nomination of the specified user with the given reason. diff --git a/bot/converters.py b/bot/converters.py index 4fb800a01..be972086d 100644 --- a/bot/converters.py +++ b/bot/converters.py @@ -346,3 +346,6 @@ class FetchedUser(UserConverter):              log.debug(f"Failed to fetch user {arg}: user does not exist.")              raise BadArgument(f"User `{arg}` does not exist") + + +FetchedMember = t.Union[discord.Member, FetchedUser]  |