Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions docs/cog_guides/mutes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ activemutes

.. code-block:: none

[p]activemutes
[p]activemutes

**Description**

Expand Down Expand Up @@ -113,7 +113,7 @@ muteset

.. code-block:: none

[p]muteset
[p]muteset

**Description**

Expand Down Expand Up @@ -219,8 +219,8 @@ Sets the role to be applied when muting a user.
If no role is setup the bot will attempt to mute a user
by utilizing server timeouts.

.. Note::
.. Note::

If no role is setup a user may be able to leave the server
and rejoin no longer being muted.

Expand Down Expand Up @@ -262,7 +262,7 @@ muteset settings

.. code-block:: none

[p]muteset settings
[p]muteset settings

.. tip:: Alias: ``muteset showsettings``

Expand Down Expand Up @@ -292,6 +292,31 @@ Decide whether the name of the moderator muting a user should be included in the

* ``<true_or_false>``: Whether to enable or disable this setting, must provide ``true`` or ``false``.

.. _mutes-command-muteset-unmutesenddm:

""""""""""""""""""""
muteset unmutesenddm
""""""""""""""""""""

.. note:: |mod-lock|

**Syntax**

.. code-block:: none

[p]muteset unmutesenddm <true_or_false>

**Description**

Set whether unmute notifications should be sent to users in DMs.

This setting is independent of ``[p]muteset senddm``, which controls
DM notifications for mutes. Both can be toggled separately.

**Arguments**

* ``<true_or_false>``: Whether to enable or disable this setting, must provide ``true`` or ``false``.

.. _mutes-command-unmute:

^^^^^^
Expand Down Expand Up @@ -413,4 +438,4 @@ Unmute a user in their current voice channel.
**Arguments**

* ``<users...>``: A space separated list of usernames, ID's, or mentions.
* ``[reason]``: The reason for the unmute.
* ``[reason]``: The reason for the unmute.
61 changes: 53 additions & 8 deletions redbot/cogs/mutes/mutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self, bot: Red):
"muted_users": {},
"default_time": 0,
"dm": False,
"dm_on_unmute": False,
"show_mod": False,
}
self.config.register_global(schema_version=0)
Expand Down Expand Up @@ -188,6 +189,11 @@ async def _maybe_update_config(self):
schema_version += 1
await self.config.schema_version.set(schema_version)

if schema_version == 1:
await self._schema_1_to_2()
schema_version += 1
await self.config.schema_version.set(schema_version)

async def _schema_0_to_1(self):
"""This contains conversion that adds guild ID to channel mutes data."""
all_channels = await self.config.all_channels()
Expand All @@ -213,6 +219,14 @@ async def _schema_0_to_1(self):
datetime.now() - start,
)

async def _schema_1_to_2(self):
"""This migration sets dm_on_unmute to True for guilds that previously had dm enabled,
preserving the existing unmute DM behaviour for those guilds."""
all_guilds = await self.config.all_guilds()
for guild_id, guild_data in all_guilds.items():
if guild_data.get("dm", False):
await self.config.guild_from_id(guild_id).dm_on_unmute.set(True)

async def cog_before_invoke(self, ctx: commands.Context):
if not self._ready.is_set():
async with ctx.typing():
Expand Down Expand Up @@ -345,7 +359,7 @@ async def _auto_unmute_user(self, guild: discord.Guild, data: dict):
until=None,
)
await self._send_dm_notification(
member, author, guild, _("Server unmute"), _("Automatic unmute")
member, author, guild, _("Server unmute"), _("Automatic unmute"), is_unmute=True
)
else:
chan_id = await self.config.guild(guild).notification_channel()
Expand Down Expand Up @@ -453,7 +467,7 @@ async def _auto_channel_unmute_user_multi(
until=None,
)
await self._send_dm_notification(
member, author, guild, _("Server unmute"), _("Automatic unmute")
member, author, guild, _("Server unmute"), _("Automatic unmute"), is_unmute=True
)
self._channel_mute_events[guild.id].set()
if any(results):
Expand Down Expand Up @@ -532,7 +546,12 @@ async def _auto_channel_unmute_user(
channel=channel,
)
await self._send_dm_notification(
member, author, channel.guild, notification_title, _("Automatic unmute")
member,
author,
channel.guild,
notification_title,
_("Automatic unmute"),
is_unmute=True,
)
return None
else:
Expand Down Expand Up @@ -562,11 +581,16 @@ async def _send_dm_notification(
mute_type: str,
reason: Optional[str],
duration=None,
*,
is_unmute: bool = False,
):
if user.bot:
return

if not await self.config.guild(guild).dm():
if is_unmute:
if not await self.config.guild(guild).dm_on_unmute():
return
elif not await self.config.guild(guild).dm():
return

show_mod = await self.config.guild(guild).show_mod()
Expand Down Expand Up @@ -654,7 +678,12 @@ async def on_member_update(self, before: discord.Member, after: discord.Member):
del self._server_mutes[guild.id][after.id]
should_save = True
await self._send_dm_notification(
after, None, guild, _("Server unmute"), _("Manually removed mute role")
after,
None,
guild,
_("Server unmute"),
_("Manually removed mute role"),
is_unmute=True,
)
elif mute_role in roles_added:
# send modlog case for mute and add to cache
Expand Down Expand Up @@ -742,6 +771,7 @@ async def on_guild_channel_update(
after.guild,
notification_title,
_("Manually removed channel overwrites"),
is_unmute=True,
)
await modlog.create_case(
self.bot,
Expand Down Expand Up @@ -802,6 +832,19 @@ async def senddm(self, ctx: commands.Context, true_or_false: bool):
else:
await ctx.send(_("Mute notifications will no longer be sent to users DMs."))

@muteset.command(name="unmutesenddm")
@commands.guild_only()
@commands.mod_or_permissions(manage_channels=True)
async def unmutesenddm(self, ctx: commands.Context, true_or_false: bool):
"""Set whether unmute notifications should be sent to users in DMs.

This is independent of `[p]muteset senddm` which controls mute DMs."""
await self.config.guild(ctx.guild).dm_on_unmute.set(true_or_false)
if true_or_false:
await ctx.send(_("I will now try to send unmute notifications to users DMs."))
else:
await ctx.send(_("Unmute notifications will no longer be sent to users DMs."))

@muteset.command()
@commands.guild_only()
@commands.mod_or_permissions(manage_channels=True)
Expand Down Expand Up @@ -837,12 +880,14 @@ async def show_mutes_settings(self, ctx: commands.Context):
"Notification Channel: {channel}\n"
"Default Time: {time}\n"
"Send DM: {dm}\n"
"Send Unmute DM: {dm_on_unmute}\n"
"Show moderator: {show_mod}"
).format(
role=mute_role.mention if mute_role else _("None"),
channel=notification_channel.mention if notification_channel else _("None"),
time=humanize_timedelta(timedelta=default_time) if default_time else _("None"),
dm=data["dm"],
dm_on_unmute=data["dm_on_unmute"],
show_mod=data["show_mod"],
)
await ctx.maybe_send_embed(msg)
Expand Down Expand Up @@ -1507,7 +1552,7 @@ async def unmute(
until=None,
)
await self._send_dm_notification(
user, author, guild, _("Server unmute"), reason
user, author, guild, _("Server unmute"), reason, is_unmute=True
)
else:
issue_list.append(response)
Expand Down Expand Up @@ -1581,7 +1626,7 @@ async def forceunmute(
until=None,
)
await self._send_dm_notification(
user, author, guild, _("Server unmute"), reason
user, author, guild, _("Server unmute"), reason, is_unmute=True
)
await self.config.member(user).clear()

Expand Down Expand Up @@ -1650,7 +1695,7 @@ async def unmute_channel(
channel=channel,
)
await self._send_dm_notification(
user, author, guild, _("Channel unmute"), reason
user, author, guild, _("Channel unmute"), reason, is_unmute=True
)
else:
issue_list.append(response)
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/mutes/voicemutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async def unmute_voice(
channel=channel,
)
await self._send_dm_notification(
user, author, guild, _("Voice unmute"), reason
user, author, guild, _("Voice unmute"), reason, is_unmute=True
)
else:
issue_list.append((user, result.reason))
Expand Down
Loading