Skip to content

Commit d48fc0c

Browse files
authored
Merge pull request #54 from Cog-Creators/V3/develop
Mod cog: Option to show an extra field with custom content on the ban…
2 parents afb6567 + 3fd23d4 commit d48fc0c

File tree

4 files changed

+206
-11
lines changed

4 files changed

+206
-11
lines changed

docs/cog_guides/mod.rst

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,23 @@ modset dm
253253

254254
.. code-block:: none
255255
256-
[p]modset dm [enabled]
256+
[p]modset dm
257+
258+
**Description**
259+
260+
Settings for messaging the user when being kicked or banned.
261+
262+
.. _mod-command-modset-dm-sendmessage:
263+
264+
"""""""""""""""""""""
265+
modset dm sendmessage
266+
"""""""""""""""""""""
267+
268+
**Syntax**
269+
270+
.. code-block:: none
271+
272+
[p]modset dm sendmessage [enabled]
257273
258274
**Description**
259275

@@ -266,6 +282,72 @@ and reason as to why they were kicked/banned.
266282

267283
* ``[enabled]``: Whether a message should be sent to a user when they are kicked/banned. |bool-input|
268284

285+
.. _mod-command-modset-banshowextrafield:
286+
287+
"""""""""""""""""""""""""""
288+
modset dm banshowextrafield
289+
"""""""""""""""""""""""""""
290+
291+
**Syntax**
292+
293+
.. code-block:: none
294+
295+
[p]modset dm banshowextrafield [enabled]
296+
297+
**Description**
298+
299+
Toggle whether to show an extra customizable field when banning.
300+
301+
This can be used to add additional information for the banned user, such as a ban appeal link.
302+
303+
**Arguments**
304+
305+
* ``[enabled]``: If an extra customizable embed field should appear when banning. |bool-input|
306+
307+
.. _mod-command-modset-banextrafieldtitle:
308+
309+
""""""""""""""""""""""""""""
310+
modset dm banextrafieldtitle
311+
""""""""""""""""""""""""""""
312+
313+
**Syntax**
314+
315+
.. code-block:: none
316+
317+
[p]modset dm banextrafieldtitle [title]
318+
319+
**Description**
320+
321+
Set the title for the optional extra embed on ban.
322+
323+
Cannot be over 252 characters long.
324+
325+
**Arguments**
326+
327+
* ``[title]``: The title of the embed field. Can by any string of text under 252 charcters long.
328+
329+
.. _mod-command-modset-banextrafieldcontents:
330+
331+
"""""""""""""""""""""""""""""""
332+
modset dm banextrafieldcontents
333+
"""""""""""""""""""""""""""""""
334+
335+
**Syntax**
336+
337+
.. code-block:: none
338+
339+
[p]modset dm banextrafieldcontents [contents]
340+
341+
**Description**
342+
343+
Set the contents for the optional extra embed on ban
344+
345+
Cannot be over 1024 characters long.
346+
347+
**Arguments**
348+
349+
* ``[contents]``: The contents of the embed field. Can by any string of text under 1024 charcters long.
350+
269351
.. _mod-command-modset-requirereason:
270352

271353
""""""""""""""""""""

redbot/cogs/mod/kickban.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ async def ban_user(
143143

144144
toggle = await self.config.guild(guild).dm_on_kickban()
145145
if toggle:
146+
extra_embed = await self.config.guild(guild).ban_show_extra()
147+
146148
with contextlib.suppress(discord.HTTPException):
147149
em = discord.Embed(
148150
title=bold(_("You have been banned from {guild}.").format(guild=guild)),
@@ -153,6 +155,17 @@ async def ban_user(
153155
value=reason if reason is not None else _("No reason was given."),
154156
inline=False,
155157
)
158+
if extra_embed:
159+
extra_embed_title = await self.config.guild(guild).ban_extra_embed_title()
160+
extra_embed_contents = await self.config.guild(
161+
guild
162+
).ban_extra_embed_contents()
163+
164+
em.add_field(
165+
name=bold(extra_embed_title, escape_formatting=False),
166+
value=extra_embed_contents,
167+
inline=False,
168+
)
156169
await user.send(embed=em)
157170

158171
ban_type = "ban"
@@ -658,16 +671,38 @@ async def tempban(
658671

659672
with contextlib.suppress(discord.HTTPException):
660673
# We don't want blocked DMs preventing us from banning
661-
msg = _("You have been temporarily banned from {server_name} until {date}.").format(
662-
server_name=guild.name, date=discord.utils.format_dt(unban_time)
674+
675+
extra_embed = await self.config.guild(guild).ban_show_extra()
676+
677+
em = discord.Embed(
678+
title=bold(
679+
_("You have been temporarily banned from {guild} until {date}.").format(
680+
guild=guild, date=discord.utils.format_dt(unban_time)
681+
)
682+
),
683+
color=await self.bot.get_embed_color(member),
684+
)
685+
em.add_field(
686+
name=_("**Reason**"),
687+
value=reason if reason is not None else _("No reason was given."),
688+
inline=False,
663689
)
664-
if guild_data["dm_on_kickban"] and reason:
665-
msg += _("\n\n**Reason:** {reason}").format(reason=reason)
666690
if invite:
667-
msg += _("\n\nHere is an invite for when your ban expires: {invite_link}").format(
668-
invite_link=invite
691+
em.add_field(
692+
name=bold(_("Here is an invite for when your ban expires")),
693+
value=invite,
694+
inline=False,
695+
)
696+
if extra_embed:
697+
extra_embed_title = await self.config.guild(guild).ban_extra_embed_title()
698+
extra_embed_contents = await self.config.guild(guild).ban_extra_embed_contents()
699+
700+
em.add_field(
701+
name=bold(extra_embed_title, escape_formatting=False),
702+
value=extra_embed_contents,
703+
inline=False,
669704
)
670-
await member.send(msg)
705+
await member.send(embed=em)
671706

672707
audit_reason = get_audit_reason(author, reason, shorten=True)
673708

redbot/cogs/mod/mod.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Mod(
6161
"default_days": 0,
6262
"default_tempban_duration": 60 * 60 * 24,
6363
"track_nicknames": True,
64+
"ban_show_extra": False,
65+
"ban_extra_embed_title": "Message from staff",
66+
"ban_extra_embed_contents": "Please set me",
6467
}
6568

6669
default_channel_settings = {"ignored": False}

redbot/cogs/mod/settings.py

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ async def modset_showsettings(self, ctx: commands.Context):
4848
dm_on_kickban = data["dm_on_kickban"]
4949
default_days = data["default_days"]
5050
default_tempban_duration = data["default_tempban_duration"]
51+
ban_show_extra = data["ban_show_extra"]
52+
ban_extra_embed_title = data["ban_extra_embed_title"]
53+
ban_extra_embed_contents = data["ban_extra_embed_contents"]
5154
if not track_all_names and track_nicknames:
5255
yes_or_no = _("Overridden by another setting")
5356
else:
@@ -98,9 +101,18 @@ async def modset_showsettings(self, ctx: commands.Context):
98101
)
99102
else:
100103
msg += _("Default message history delete on ban: Don't delete any\n")
101-
msg += _("Default tempban duration: {duration}").format(
104+
msg += _("Default tempban duration: {duration}\n").format(
102105
duration=humanize_timedelta(seconds=default_tempban_duration)
103106
)
107+
msg += _("Show optional information field in embed: {yes_or_no}\n").format(
108+
yes_or_no=_("Yes") if ban_show_extra else _("No")
109+
)
110+
msg += _("Title of the optional extra field: {ban_embed_title}\n").format(
111+
ban_embed_title=ban_extra_embed_title if ban_extra_embed_title else _("None")
112+
)
113+
msg += _("Contents of the optional extra field: {ban_embed_contents}").format(
114+
ban_embed_contents=ban_extra_embed_contents if ban_extra_embed_contents else _("None")
115+
)
104116
await ctx.send(box(msg))
105117

106118
@modset.command()
@@ -347,9 +359,15 @@ async def reinvite(self, ctx: commands.Context):
347359
)
348360
)
349361

350-
@modset.command()
362+
@modset.group()
351363
@commands.guild_only()
352-
async def dm(self, ctx: commands.Context, enabled: bool = None):
364+
async def dm(self, ctx: commands.Context):
365+
"""
366+
Settings for messaging the user when being kicked or banned.
367+
"""
368+
369+
@dm.command(name="sendmessage")
370+
async def dm_sendmessage(self, ctx: commands.Context, enabled: bool = None):
353371
"""Toggle whether a message should be sent to a user when they are kicked/banned.
354372
355373
If this option is enabled, the bot will attempt to DM the user with the guild name
@@ -370,6 +388,63 @@ async def dm(self, ctx: commands.Context, enabled: bool = None):
370388
_("Bot will no longer attempt to send a DM to user before kick and ban.")
371389
)
372390

391+
@dm.command(name="banshowextrafield")
392+
async def dm_banshowextrafield(self, ctx: commands.Context, enabled: bool = None):
393+
"""
394+
Toggle whether to show an extra customizable field when banning.
395+
396+
This can be used to add additional information for the banned user, such as a ban appeal link.
397+
"""
398+
guild = ctx.guild
399+
if enabled is None:
400+
setting = await self.config.guild(guild).ban_show_extra()
401+
await ctx.send(
402+
_("The extra embed field is currently set to: {setting}").format(setting=setting)
403+
)
404+
return
405+
await self.config.guild(guild).ban_show_extra.set(enabled)
406+
if enabled:
407+
await ctx.send(
408+
_(
409+
"An extra field will be shown when banning. Configure it with `{prefix}modset dm banextrafieldtitle` and `{prefix}modset dm banextrafieldcontents`"
410+
).format(prefix=ctx.prefix)
411+
)
412+
else:
413+
await ctx.send(_("An extra field will be no longer be shown when banning."))
414+
415+
@dm.command(name="banextrafieldtitle")
416+
async def dm_banextrafieldtitle(self, ctx: commands.Context, *, title: str) -> None:
417+
"""
418+
Set the title for the optional extra embed on ban.
419+
420+
Cannot be over 252 characters long.
421+
"""
422+
guild = ctx.guild
423+
# Bolding the text is 4 characters (**bolded**)
424+
# All the bold function used in the embeds does is add those star characters and some other convenience stuffs.
425+
# Such as escaping formatting.
426+
if len(title) > 252:
427+
await ctx.send(_("Embed title cannot be over 252 characters long."))
428+
else:
429+
await self.config.guild(guild).ban_extra_embed_title.set(title)
430+
await ctx.send(_("Embed Title has been set to `{title}`").format(title=title))
431+
432+
@dm.command(name="banextrafieldcontents")
433+
async def dm_banextrafieldcontents(self, ctx: commands.Context, *, contents: str) -> None:
434+
"""
435+
Set the contents for the optional extra embed on ban
436+
437+
Cannot be over 1024 characters long.
438+
"""
439+
guild = ctx.guild
440+
if len(contents) > 1024:
441+
await ctx.send(_("Embed contents cannot be over 1024 characters long."))
442+
else:
443+
await self.config.guild(guild).ban_extra_embed_contents.set(contents)
444+
await ctx.send(
445+
_("Embed Contents has been set to `{contents}`").format(contents=contents)
446+
)
447+
373448
@modset.command()
374449
@commands.guild_only()
375450
async def requirereason(self, ctx: commands.Context, enabled: bool = None):

0 commit comments

Comments
 (0)