Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Warnings] Add setting for warn channel and DMing warns toggle #2929

Merged
merged 30 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a44bd43
Initial Commit
Ianardo-DiCaprio Aug 12, 2019
c93ddb9
Add changelog
Ianardo-DiCaprio Aug 12, 2019
927cc7d
Merge branch 'V3/develop' into patch-1
Ianardo-DiCaprio Aug 13, 2019
00dca1c
Review changes
Ianardo-DiCaprio Aug 17, 2019
38598ba
Changed to use contextlib.suppress
Ianardo-DiCaprio Aug 20, 2019
0848b68
Update warnings.py
Ianardo-DiCaprio Aug 20, 2019
c16829c
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
2b03f60
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
d55aa27
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
2a62d25
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
14c5849
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
6b86ba0
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
5ec9a56
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
01b0838
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
e9a012b
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 23, 2020
2fc65c9
Rename 2932.bugfix.rst.txt to 2932.bugfix.rst
Ianardo-DiCaprio Jan 23, 2020
4b013d9
Rename 2929.enhance.rst.txt to 2929.enhance.rst
Ianardo-DiCaprio Jan 23, 2020
79b85c3
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 26, 2020
658c80c
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 26, 2020
7c9eccd
Update redbot/cogs/warnings/warnings.py
Ianardo-DiCaprio Jan 26, 2020
a841763
Rename 2929.enhance.rst to 2929.feature.rst
Ianardo-DiCaprio Jan 26, 2020
31c07f0
Update warnings.py
Ianardo-DiCaprio Jan 26, 2020
2a64090
Add files via upload
Ianardo-DiCaprio Jan 26, 2020
d4a9f74
Update warnings.py
Ianardo-DiCaprio Jan 26, 2020
17c7fd4
Black
Ianardo-DiCaprio Jan 26, 2020
6033cf4
Update warnings.py
Ianardo-DiCaprio Jan 27, 2020
dce5785
black
Ianardo-DiCaprio Jan 27, 2020
ae544fd
Update warnings.py
Jackenmen Mar 12, 2020
8447783
Update warnings.py
Jackenmen Mar 12, 2020
b3ca9a9
Delete 2932.bugfix.rst
Jackenmen Mar 12, 2020
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
File renamed without changes.
2 changes: 2 additions & 0 deletions changelog.d/warnings/2929.enhance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added features to mod to be able to toggle warns being sent to both DM's and channel.
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
Added a command to set the channel the warns get sent to. (defaults to the channel the warn was issued in).
91 changes: 80 additions & 11 deletions redbot/cogs/warnings/warnings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import namedtuple
from typing import Union, Optional

import contextlib
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
import discord

from redbot.cogs.warnings.helpers import (
Expand All @@ -24,7 +25,14 @@
class Warnings(commands.Cog):
"""Warn misbehaving users and take automated actions."""

default_guild = {"actions": [], "reasons": {}, "allow_custom_reasons": False}
default_guild = {
"actions": [],
"reasons": {},
"allow_custom_reasons": False,
"toggle_dm": True,
"warn_channel": None,
"toggle_channel": False,
}

default_member = {"total_points": 0, "status": "", "warnings": {}}

Expand Down Expand Up @@ -76,6 +84,49 @@ async def allowcustomreasons(self, ctx: commands.Context, allowed: bool):
else:
await ctx.send(_("Custom reasons have been disabled."))

@warningset.command()
@commands.guild_only()
async def toggledm(self, ctx: commands.Context):
"""Toggle whether warnings should be sent to users in DMs."""
guild = ctx.guild
toggle = not await self.config.guild(guild).toggle_dm()
await self.config.guild(guild).toggle_dm.set(toggle)
if toggle:
await ctx.send(_("Warnings will now be sent to users in DMs."))
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
else:
await ctx.send(_("Warnings will no longer be sent to users in DMs."))

@warningset.command()
@commands.guild_only()
async def warnchannel(self, ctx: commands.Context, channel: discord.TextChannel = None):
"""Set the channel where warnings should be sent to.

Leave empty to use the channel `[p]warn` command was called in.
"""
guild = ctx.guild
if channel:
await self.config.guild(guild).warn_channel.set(channel.id)
await ctx.send(
_("The warn channel has been set to {channel}").format(channel=channel.mention)
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
)
else:
await self.config.guild(guild).warn_channel.set(channel)
await ctx.send(_("Warnings will now be sent in the channel command was used in."))

@warningset.command()
@commands.guild_only()
async def togglechannel(self, ctx: commands.Context):
"""
Toggle if warnings should be sent to a channel set with `[p]warningset warnchannel`
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
"""
guild = ctx.guild
toggle = await self.config.guild(guild).toggle_channel()
await self.config.guild(guild).toggle_channel.set(not toggle)
if not toggle:
await ctx.send(_("Warnings will now be sent to set warn channel."))
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
else:
await ctx.send(_("Warns will no longer be sent in the channel."))
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved

@commands.group()
@commands.guild_only()
@checks.guildowner_or_permissions(administrator=True)
Expand Down Expand Up @@ -251,7 +302,7 @@ async def warn(
user: discord.Member,
points: Optional[int] = 1,
*,
reason: str
reason: str,
):
"""Warn the user for the specified reason.

Expand All @@ -260,6 +311,8 @@ async def warn(
`<reason>` can be a registered reason if it exists or a custom one
is created by default.
"""
channel = ctx.channel
guild = ctx.guild
if user == ctx.author:
await ctx.send(_("You cannot warn yourself."))
return
Expand Down Expand Up @@ -300,20 +353,37 @@ async def warn(
await member_settings.total_points.set(current_point_count)

await warning_points_add_check(self.config, ctx, user, current_point_count)
try:
dm = await self.config.guild(ctx.guild).toggle_dm()
if dm:
Jackenmen marked this conversation as resolved.
Show resolved Hide resolved
em = discord.Embed(
title=_("Warning from {user}").format(user=ctx.author),
description=reason_type["description"],
)
em.add_field(name=_("Points"), value=str(reason_type["points"]))
await user.send(
_("You have received a warning in {guild_name}.").format(
guild_name=ctx.guild.name
),
embed=em,
with contextlib.suppress(discord.HTTPException):
await user.send(
_("You have received a warning in {guild_name}.").format(
guild_name=ctx.guild.name
),
embed=em,
)

toggle_channel = await self.config.guild(guild).toggle_channel()
if toggle_channel:
em = discord.Embed(
title=_("Warning from {user}").format(user=ctx.author),
description=reason_type["description"],
)
except discord.HTTPException:
pass
em.add_field(name=_("Points"), value=str(reason_type["points"]))
warn_channel = self.bot.get_channel(await self.config.guild(guild).warn_channel())
if warn_channel:
channel = warn_channel
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
await ctx.tick()
else:
channel = ctx.channel
await channel.send(_("{user} has been warned.").format(user=user.mention), embed=em)
Ianardo-DiCaprio marked this conversation as resolved.
Show resolved Hide resolved
else:
await ctx.tick()
try:
reason_msg = _(
"{reason}\n\nUse `{prefix}unwarn {user} {message}` to remove this warning."
Expand All @@ -338,7 +408,6 @@ async def warn(
)
except RuntimeError:
pass
await ctx.send(_("User {user} has been warned.").format(user=user))

@commands.command()
@commands.guild_only()
Expand Down