Michael H c7608aeb17 [V3 Mod] Use a composite class for mod (#2501)
* [V3 Mod] Use a composite class for mod

This turns mod.py into acomposite class

I've split things in this up based on purpose, including `movetocore`

`movetocore` is a set of things which likely belong in the core bot and
not relying on mod being loaded.

This is part of #2500

Per discussion in discord, this should be the first thing in #2500
merged

* Move this back,
mod was importable,
and this was intended as non-breaking

* Prevent fix from being lost if merged before this.

see Cog-Creators/Red-DiscordBot#2510

* Move case creation to before sending

see #2515

* fix failed merge done in web
2019-04-01 03:34:27 -08:00

169 lines
6.6 KiB
Python

from redbot.core import commands, i18n, checks
from redbot.core.utils.chat_formatting import box
from .abc import MixinMeta
_ = i18n.Translator("Mod", __file__)
class ModSettings(MixinMeta):
"""
This is a mixin for the mod cog containing all settings commands.
"""
@commands.group()
@commands.guild_only()
@checks.guildowner_or_permissions(administrator=True)
async def modset(self, ctx: commands.Context):
"""Manage server administration settings."""
if ctx.invoked_subcommand is None:
guild = ctx.guild
# Display current settings
delete_repeats = await self.settings.guild(guild).delete_repeats()
ban_mention_spam = await self.settings.guild(guild).ban_mention_spam()
respect_hierarchy = await self.settings.guild(guild).respect_hierarchy()
delete_delay = await self.settings.guild(guild).delete_delay()
reinvite_on_unban = await self.settings.guild(guild).reinvite_on_unban()
msg = ""
msg += _("Delete repeats: {yes_or_no}\n").format(
yes_or_no=_("Yes") if delete_repeats else _("No")
)
msg += _("Ban mention spam: {num_mentions}\n").format(
num_mentions=_("{num} mentions").format(num=ban_mention_spam)
if ban_mention_spam
else _("No")
)
msg += _("Respects hierarchy: {yes_or_no}\n").format(
yes_or_no=_("Yes") if respect_hierarchy else _("No")
)
msg += _("Delete delay: {num_seconds}\n").format(
num_seconds=_("{num} seconds").format(num=delete_delay)
if delete_delay != -1
else _("None")
)
msg += _("Reinvite on unban: {yes_or_no}\n").format(
yes_or_no=_("Yes") if reinvite_on_unban else _("No")
)
await ctx.send(box(msg))
@modset.command()
@commands.guild_only()
async def hierarchy(self, ctx: commands.Context):
"""Toggle role hierarchy check for mods and admins.
**WARNING**: Disabling this setting will allow mods to take
actions on users above them in the role hierarchy!
This is enabled by default.
"""
guild = ctx.guild
toggled = await self.settings.guild(guild).respect_hierarchy()
if not toggled:
await self.settings.guild(guild).respect_hierarchy.set(True)
await ctx.send(
_("Role hierarchy will be checked when moderation commands are issued.")
)
else:
await self.settings.guild(guild).respect_hierarchy.set(False)
await ctx.send(
_("Role hierarchy will be ignored when moderation commands are issued.")
)
@modset.command()
@commands.guild_only()
async def banmentionspam(self, ctx: commands.Context, max_mentions: int = 0):
"""Set the autoban conditions for mention spam.
Users will be banned if they send any message which contains more than
`<max_mentions>` mentions.
`<max_mentions>` must be at least 5. Set to 0 to disable.
"""
guild = ctx.guild
if max_mentions:
if max_mentions < 5:
max_mentions = 5
await self.settings.guild(guild).ban_mention_spam.set(max_mentions)
await ctx.send(
_(
"Autoban for mention spam enabled. "
"Anyone mentioning {max_mentions} or more different people "
"in a single message will be autobanned."
).format(max_mentions=max_mentions)
)
else:
cur_setting = await self.settings.guild(guild).ban_mention_spam()
if not cur_setting:
await ctx.send_help()
return
await self.settings.guild(guild).ban_mention_spam.set(False)
await ctx.send(_("Autoban for mention spam disabled."))
@modset.command()
@commands.guild_only()
async def deleterepeats(self, ctx: commands.Context):
"""Enable auto-deletion of repeated messages."""
guild = ctx.guild
cur_setting = await self.settings.guild(guild).delete_repeats()
if not cur_setting:
await self.settings.guild(guild).delete_repeats.set(True)
await ctx.send(_("Messages repeated up to 3 times will be deleted."))
else:
await self.settings.guild(guild).delete_repeats.set(False)
await ctx.send(_("Repeated messages will be ignored."))
@modset.command()
@commands.guild_only()
async def deletedelay(self, ctx: commands.Context, time: int = None):
"""Set the delay until the bot removes the command message.
Must be between -1 and 60.
Set to -1 to disable this feature.
"""
guild = ctx.guild
if time is not None:
time = min(max(time, -1), 60) # Enforces the time limits
await self.settings.guild(guild).delete_delay.set(time)
if time == -1:
await ctx.send(_("Command deleting disabled."))
else:
await ctx.send(_("Delete delay set to {num} seconds.").format(num=time))
else:
delay = await self.settings.guild(guild).delete_delay()
if delay != -1:
await ctx.send(
_(
"Bot will delete command messages after"
" {num} seconds. Set this value to -1 to"
" stop deleting messages"
).format(num=delay)
)
else:
await ctx.send(_("I will not delete command messages."))
@modset.command()
@commands.guild_only()
async def reinvite(self, ctx: commands.Context):
"""Toggle whether an invite will be sent to a user when unbanned.
If this is True, the bot will attempt to create and send a single-use invite
to the newly-unbanned user.
"""
guild = ctx.guild
cur_setting = await self.settings.guild(guild).reinvite_on_unban()
if not cur_setting:
await self.settings.guild(guild).reinvite_on_unban.set(True)
await ctx.send(
_("Users unbanned with {command} will be reinvited.").format(
command=f"{ctx.prefix}unban"
)
)
else:
await self.settings.guild(guild).reinvite_on_unban.set(False)
await ctx.send(
_("Users unbanned with {command} will not be reinvited.").format(
command=f"{ctx.prefix}unban"
)
)