[Docs] Mod Cog Guide (#4886)

* Initial commit

* Add some args

* bool prolog

* index

* Add more arguments

* more arguments, style fixes

* improve naming of arguments

* Fix up backlog

* Run black

* extra corrections from backlog

* Update tempban arg names

* backlog

* change prolog type

* Change kick argument prolog to member instead of user

* Update argument names

* missed a colon

* Update prolog to be friendly with non-positional args

* Edit through the decorator instead

* Add back docstring spacing

* black

* usage in decorator for name commands

* Fix command signature

* fixup docstring spacing

* style fixes

* Add spacing inside unban docstring

* Rename args instead of using usage

* black - simple

* Add labeler glob

* unify style

* rename variables instead of usage

* Update docstrings correspondingly

* run black

* update description in usage

* ehh this isn't necessary...

* fix up tags

* fix grammar and accuracy issues

* fix docstring too
This commit is contained in:
Kreusada
2021-05-18 22:10:30 +01:00
committed by GitHub
parent 5d905a93ac
commit 410b2419dd
6 changed files with 857 additions and 82 deletions

View File

@@ -290,7 +290,7 @@ class KickBanMixin(MixinMeta):
@commands.guild_only()
@commands.bot_has_permissions(kick_members=True)
@checks.admin_or_permissions(kick_members=True)
async def kick(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
async def kick(self, ctx: commands.Context, member: discord.Member, *, reason: str = None):
"""
Kick a user.
@@ -306,14 +306,14 @@ class KickBanMixin(MixinMeta):
author = ctx.author
guild = ctx.guild
if author == user:
if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {emoji}").format(
emoji="\N{PENSIVE FACE}"
)
)
return
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, user):
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, member):
await ctx.send(
_(
"I cannot let you do that. You are "
@@ -322,7 +322,7 @@ class KickBanMixin(MixinMeta):
)
)
return
elif ctx.guild.me.top_role <= user.top_role or user == ctx.guild.owner:
elif ctx.guild.me.top_role <= member.top_role or member == ctx.guild.owner:
await ctx.send(_("I cannot do that due to Discord hierarchy rules."))
return
audit_reason = get_audit_reason(author, reason, shorten=True)
@@ -331,23 +331,23 @@ class KickBanMixin(MixinMeta):
with contextlib.suppress(discord.HTTPException):
em = discord.Embed(
title=bold(_("You have been kicked from {guild}.").format(guild=guild)),
color=await self.bot.get_embed_color(user),
color=await self.bot.get_embed_color(member),
)
em.add_field(
name=_("**Reason**"),
value=reason if reason is not None else _("No reason was given."),
inline=False,
)
await user.send(embed=em)
await member.send(embed=em)
try:
await guild.kick(user, reason=audit_reason)
log.info("{}({}) kicked {}({})".format(author.name, author.id, user.name, user.id))
await guild.kick(member, reason=audit_reason)
log.info("{}({}) kicked {}({})".format(author.name, author.id, member.name, member.id))
except discord.errors.Forbidden:
await ctx.send(_("I'm not allowed to do that."))
except Exception:
log.exception(
"{}({}) attempted to kick {}({}), but an error occurred.".format(
author.name, author.id, user.name, user.id
author.name, author.id, member.name, member.id
)
)
else:
@@ -356,7 +356,7 @@ class KickBanMixin(MixinMeta):
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"kick",
user,
member,
author,
reason,
until=None,
@@ -420,7 +420,7 @@ class KickBanMixin(MixinMeta):
Example:
- `[p]massban 345628097929936898 57287406247743488 7 they broke all rules.`
This will ban all the added userids and delete 7 days of worth messages.
This will ban all the added userids and delete 7 days worth of their messages.
User IDs need to be provided in order to ban
using this command.
@@ -580,7 +580,7 @@ class KickBanMixin(MixinMeta):
async def tempban(
self,
ctx: commands.Context,
user: discord.Member,
member: discord.Member,
duration: Optional[commands.TimedeltaConverter] = None,
days: Optional[int] = None,
*,
@@ -602,12 +602,12 @@ class KickBanMixin(MixinMeta):
guild = ctx.guild
author = ctx.author
if author == user:
if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {}").format("\N{PENSIVE FACE}")
)
return
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, user):
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, member):
await ctx.send(
_(
"I cannot let you do that. You are "
@@ -616,7 +616,7 @@ class KickBanMixin(MixinMeta):
)
)
return
elif guild.me.top_role <= user.top_role or user == guild.owner:
elif guild.me.top_role <= member.top_role or member == guild.owner:
await ctx.send(_("I cannot do that due to Discord hierarchy rules."))
return
@@ -634,9 +634,9 @@ class KickBanMixin(MixinMeta):
if invite is None:
invite = ""
await self.config.member(user).banned_until.set(unban_time.timestamp())
await self.config.member(member).banned_until.set(unban_time.timestamp())
async with self.config.guild(guild).current_tempbans() as current_tempbans:
current_tempbans.append(user.id)
current_tempbans.append(member.id)
with contextlib.suppress(discord.HTTPException):
# We don't want blocked DMs preventing us from banning
@@ -647,12 +647,12 @@ class KickBanMixin(MixinMeta):
msg += _(" Here is an invite for when your ban expires: {invite_link}").format(
invite_link=invite
)
await user.send(msg)
await member.send(msg)
audit_reason = get_audit_reason(author, reason, shorten=True)
try:
await guild.ban(user, reason=audit_reason, delete_message_days=days)
await guild.ban(member, reason=audit_reason, delete_message_days=days)
except discord.Forbidden:
await ctx.send(_("I can't do that for some reason."))
except discord.HTTPException:
@@ -663,7 +663,7 @@ class KickBanMixin(MixinMeta):
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"tempban",
user,
member,
author,
reason,
unban_time,
@@ -674,19 +674,19 @@ class KickBanMixin(MixinMeta):
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)
@checks.admin_or_permissions(ban_members=True)
async def softban(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
async def softban(self, ctx: commands.Context, member: discord.Member, *, reason: str = None):
"""Kick a user and delete 1 day's worth of their messages."""
guild = ctx.guild
author = ctx.author
if author == user:
if author == member:
await ctx.send(
_("I cannot let you do that. Self-harm is bad {emoji}").format(
emoji="\N{PENSIVE FACE}"
)
)
return
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, user):
elif not await is_allowed_by_hierarchy(self.bot, self.config, guild, author, member):
await ctx.send(
_(
"I cannot let you do that. You are "
@@ -703,7 +703,7 @@ class KickBanMixin(MixinMeta):
invite = ""
try: # We don't want blocked DMs preventing us from banning
msg = await user.send(
msg = await member.send(
_(
"You have been banned and "
"then unbanned as a quick way to delete your messages.\n"
@@ -713,7 +713,7 @@ class KickBanMixin(MixinMeta):
except discord.HTTPException:
msg = None
try:
await guild.ban(user, reason=audit_reason, delete_message_days=1)
await guild.ban(member, reason=audit_reason, delete_message_days=1)
except discord.errors.Forbidden:
await ctx.send(_("My role is not high enough to softban that user."))
if msg is not None:
@@ -722,30 +722,30 @@ class KickBanMixin(MixinMeta):
except discord.HTTPException:
log.exception(
"{}({}) attempted to softban {}({}), but an error occurred trying to ban them.".format(
author.name, author.id, user.name, user.id
author.name, author.id, member.name, member.id
)
)
return
try:
await guild.unban(user)
await guild.unban(member)
except discord.HTTPException:
log.exception(
"{}({}) attempted to softban {}({}), but an error occurred trying to unban them.".format(
author.name, author.id, user.name, user.id
author.name, author.id, member.name, member.id
)
)
return
else:
log.info(
"{}({}) softbanned {}({}), deleting 1 day worth "
"of messages.".format(author.name, author.id, user.name, user.id)
"of messages.".format(author.name, author.id, member.name, member.id)
)
await modlog.create_case(
self.bot,
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"softban",
user,
member,
author,
reason,
until=None,
@@ -802,9 +802,11 @@ class KickBanMixin(MixinMeta):
@commands.command()
@commands.guild_only()
@checks.admin_or_permissions(mute_members=True, deafen_members=True)
async def voiceunban(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
async def voiceunban(
self, ctx: commands.Context, member: discord.Member, *, reason: str = None
):
"""Unban a user from speaking and listening in the server's voice channels."""
user_voice_state = user.voice
user_voice_state = member.voice
if (
await self._voice_perm_check(
ctx, user_voice_state, deafen_members=True, mute_members=True
@@ -816,11 +818,11 @@ class KickBanMixin(MixinMeta):
needs_undeafen = True if user_voice_state.deaf else False
audit_reason = get_audit_reason(ctx.author, reason, shorten=True)
if needs_unmute and needs_undeafen:
await user.edit(mute=False, deafen=False, reason=audit_reason)
await member.edit(mute=False, deafen=False, reason=audit_reason)
elif needs_unmute:
await user.edit(mute=False, reason=audit_reason)
await member.edit(mute=False, reason=audit_reason)
elif needs_undeafen:
await user.edit(deafen=False, reason=audit_reason)
await member.edit(deafen=False, reason=audit_reason)
else:
await ctx.send(_("That user isn't muted or deafened by the server."))
return
@@ -832,7 +834,7 @@ class KickBanMixin(MixinMeta):
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"voiceunban",
user,
member,
author,
reason,
until=None,
@@ -843,9 +845,9 @@ class KickBanMixin(MixinMeta):
@commands.command()
@commands.guild_only()
@checks.admin_or_permissions(mute_members=True, deafen_members=True)
async def voiceban(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
async def voiceban(self, ctx: commands.Context, member: discord.Member, *, reason: str = None):
"""Ban a user from speaking and listening in the server's voice channels."""
user_voice_state: discord.VoiceState = user.voice
user_voice_state: discord.VoiceState = member.voice
if (
await self._voice_perm_check(
ctx, user_voice_state, deafen_members=True, mute_members=True
@@ -859,11 +861,11 @@ class KickBanMixin(MixinMeta):
author = ctx.author
guild = ctx.guild
if needs_mute and needs_deafen:
await user.edit(mute=True, deafen=True, reason=audit_reason)
await member.edit(mute=True, deafen=True, reason=audit_reason)
elif needs_mute:
await user.edit(mute=True, reason=audit_reason)
await member.edit(mute=True, reason=audit_reason)
elif needs_deafen:
await user.edit(deafen=True, reason=audit_reason)
await member.edit(deafen=True, reason=audit_reason)
else:
await ctx.send(_("That user is already muted and deafened server-wide."))
return
@@ -873,7 +875,7 @@ class KickBanMixin(MixinMeta):
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"voiceban",
user,
member,
author,
reason,
until=None,

View File

@@ -32,8 +32,8 @@ class ModInfo(MixinMeta):
@commands.guild_only()
@commands.bot_has_permissions(manage_nicknames=True)
@checks.admin_or_permissions(manage_nicknames=True)
async def rename(self, ctx: commands.Context, user: discord.Member, *, nickname: str = ""):
"""Change a user's nickname.
async def rename(self, ctx: commands.Context, member: discord.Member, *, nickname: str = ""):
"""Change a member's nickname.
Leaving the nickname empty will remove it.
"""
@@ -46,8 +46,8 @@ class ModInfo(MixinMeta):
return
if not (
(me.guild_permissions.manage_nicknames or me.guild_permissions.administrator)
and me.top_role > user.top_role
and user != ctx.guild.owner
and me.top_role > member.top_role
and member != ctx.guild.owner
):
await ctx.send(
_(
@@ -57,7 +57,7 @@ class ModInfo(MixinMeta):
)
else:
try:
await user.edit(reason=get_audit_reason(ctx.author, None), nick=nickname)
await member.edit(reason=get_audit_reason(ctx.author, None), nick=nickname)
except discord.Forbidden:
# Just in case we missed something in the permissions check above
await ctx.send(_("I do not have permission to rename that member."))
@@ -160,58 +160,60 @@ class ModInfo(MixinMeta):
@commands.command()
@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
async def userinfo(self, ctx, *, user: discord.Member = None):
"""Show information about a user.
async def userinfo(self, ctx, *, member: discord.Member = None):
"""Show information about a member.
This includes fields for status, discord join date, server
join date, voice state and previous names/nicknames.
If the user has no roles, previous names or previous nicknames,
If the member has no roles, previous names or previous nicknames,
these fields will be omitted.
"""
author = ctx.author
guild = ctx.guild
if not user:
user = author
if not member:
member = author
# A special case for a special someone :^)
special_date = datetime(2016, 1, 10, 6, 8, 4, 443000)
is_special = user.id == 96130341705637888 and guild.id == 133049272517001216
is_special = member.id == 96130341705637888 and guild.id == 133049272517001216
roles = user.roles[-1:0:-1]
names, nicks = await self.get_names_and_nicks(user)
roles = member.roles[-1:0:-1]
names, nicks = await self.get_names_and_nicks(member)
joined_at = user.joined_at if not is_special else special_date
since_created = (ctx.message.created_at - user.created_at).days
joined_at = member.joined_at if not is_special else special_date
since_created = (ctx.message.created_at - member.created_at).days
if joined_at is not None:
since_joined = (ctx.message.created_at - joined_at).days
user_joined = joined_at.strftime("%d %b %Y %H:%M")
else:
since_joined = "?"
user_joined = _("Unknown")
user_created = user.created_at.strftime("%d %b %Y %H:%M")
voice_state = user.voice
user_created = member.created_at.strftime("%d %b %Y %H:%M")
voice_state = member.voice
member_number = (
sorted(guild.members, key=lambda m: m.joined_at or ctx.message.created_at).index(user)
sorted(guild.members, key=lambda m: m.joined_at or ctx.message.created_at).index(
member
)
+ 1
)
created_on = _("{}\n({} days ago)").format(user_created, since_created)
joined_on = _("{}\n({} days ago)").format(user_joined, since_joined)
if any(a.type is discord.ActivityType.streaming for a in user.activities):
if any(a.type is discord.ActivityType.streaming for a in member.activities):
statusemoji = "\N{LARGE PURPLE CIRCLE}"
elif user.status.name == "online":
elif member.status.name == "online":
statusemoji = "\N{LARGE GREEN CIRCLE}"
elif user.status.name == "offline":
elif member.status.name == "offline":
statusemoji = "\N{MEDIUM WHITE CIRCLE}\N{VARIATION SELECTOR-16}"
elif user.status.name == "dnd":
elif member.status.name == "dnd":
statusemoji = "\N{LARGE RED CIRCLE}"
elif user.status.name == "idle":
elif member.status.name == "idle":
statusemoji = "\N{LARGE ORANGE CIRCLE}"
activity = _("Chilling in {} status").format(user.status)
status_string = self.get_status_string(user)
activity = _("Chilling in {} status").format(member.status)
status_string = self.get_status_string(member)
if roles:
@@ -249,7 +251,7 @@ class ModInfo(MixinMeta):
else:
role_str = None
data = discord.Embed(description=status_string or activity, colour=user.colour)
data = discord.Embed(description=status_string or activity, colour=member.colour)
data.add_field(name=_("Joined Discord on"), value=created_on)
data.add_field(name=_("Joined this server on"), value=joined_on)
@@ -279,22 +281,22 @@ class ModInfo(MixinMeta):
value="{0.mention} ID: {0.id}".format(voice_state.channel),
inline=False,
)
data.set_footer(text=_("Member #{} | User ID: {}").format(member_number, user.id))
data.set_footer(text=_("Member #{} | User ID: {}").format(member_number, member.id))
name = str(user)
name = " ~ ".join((name, user.nick)) if user.nick else name
name = str(member)
name = " ~ ".join((name, member.nick)) if member.nick else name
name = filter_invites(name)
avatar = user.avatar_url_as(static_format="png")
avatar = member.avatar_url_as(static_format="png")
data.set_author(name=f"{statusemoji} {name}", url=avatar)
data.set_thumbnail(url=avatar)
await ctx.send(embed=data)
@commands.command()
async def names(self, ctx: commands.Context, *, user: discord.Member):
"""Show previous names and nicknames of a user."""
names, nicks = await self.get_names_and_nicks(user)
async def names(self, ctx: commands.Context, *, member: discord.Member):
"""Show previous names and nicknames of a member."""
names, nicks = await self.get_names_and_nicks(member)
msg = ""
if names:
msg += _("**Past 20 names**:")
@@ -310,4 +312,4 @@ class ModInfo(MixinMeta):
msg = filter_various_mentions(msg)
await ctx.send(msg)
else:
await ctx.send(_("That user doesn't have any recorded name or nickname change."))
await ctx.send(_("That member doesn't have any recorded name or nickname change."))