mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-09 02:42:30 -05:00
Merge branch 'V3/develop' into V3/feature/mutes
This commit is contained in:
@@ -101,7 +101,7 @@ class Events(MixinMeta):
|
||||
while None in name_list: # clean out null entries from a bug
|
||||
name_list.remove(None)
|
||||
if after.name in name_list:
|
||||
# Ensure order is maintained without duplicates occuring
|
||||
# Ensure order is maintained without duplicates occurring
|
||||
name_list.remove(after.name)
|
||||
name_list.append(after.name)
|
||||
while len(name_list) > 20:
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import cast, Optional, Union
|
||||
|
||||
import discord
|
||||
from redbot.core import commands, i18n, checks, modlog
|
||||
from redbot.core.utils.chat_formatting import pagify, humanize_number, format_perms_list
|
||||
from redbot.core.utils.chat_formatting import pagify, humanize_number, bold, format_perms_list
|
||||
from redbot.core.utils.mod import is_allowed_by_hierarchy, get_audit_reason
|
||||
from .abc import MixinMeta
|
||||
from .converters import RawUserIds
|
||||
@@ -124,6 +124,19 @@ class KickBanMixin(MixinMeta):
|
||||
elif not (0 <= days <= 7):
|
||||
return _("Invalid days. Must be between 0 and 7.")
|
||||
|
||||
toggle = await self.settings.guild(guild).dm_on_kickban()
|
||||
if toggle:
|
||||
with contextlib.suppress(discord.HTTPException):
|
||||
em = discord.Embed(
|
||||
title=bold(_("You have been banned from {guild}.").format(guild=guild))
|
||||
)
|
||||
em.add_field(
|
||||
name=_("**Reason**"),
|
||||
value=reason if reason is not None else _("No reason was given."),
|
||||
inline=False,
|
||||
)
|
||||
await user.send(embed=em)
|
||||
|
||||
audit_reason = get_audit_reason(author, reason)
|
||||
|
||||
queue_entry = (guild.id, user.id)
|
||||
@@ -137,7 +150,7 @@ class KickBanMixin(MixinMeta):
|
||||
except discord.Forbidden:
|
||||
return _("I'm not allowed to do that.")
|
||||
except Exception as e:
|
||||
return e # TODO: impproper return type? Is this intended to be re-raised?
|
||||
return e # TODO: improper return type? Is this intended to be re-raised?
|
||||
|
||||
if create_modlog_case:
|
||||
try:
|
||||
@@ -228,6 +241,18 @@ class KickBanMixin(MixinMeta):
|
||||
await ctx.send(_("I cannot do that due to discord hierarchy rules"))
|
||||
return
|
||||
audit_reason = get_audit_reason(author, reason)
|
||||
toggle = await self.settings.guild(guild).dm_on_kickban()
|
||||
if toggle:
|
||||
with contextlib.suppress(discord.HTTPException):
|
||||
em = discord.Embed(
|
||||
title=bold(_("You have been kicked from {guild}.").format(guild=guild))
|
||||
)
|
||||
em.add_field(
|
||||
name=_("**Reason**"),
|
||||
value=reason if reason is not None else _("No reason was given."),
|
||||
inline=False,
|
||||
)
|
||||
await user.send(embed=em)
|
||||
try:
|
||||
await guild.kick(user, reason=audit_reason)
|
||||
log.info("{}({}) kicked {}({})".format(author.name, author.id, user.name, user.id))
|
||||
@@ -260,14 +285,19 @@ class KickBanMixin(MixinMeta):
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
user: discord.Member,
|
||||
days: Optional[int] = 0,
|
||||
days: Optional[int] = None,
|
||||
*,
|
||||
reason: str = None,
|
||||
):
|
||||
"""Ban a user from this server and optionally delete days of messages.
|
||||
|
||||
If days is not a number, it's treated as the first word of the reason.
|
||||
Minimum 0 days, maximum 7. Defaults to 0."""
|
||||
|
||||
Minimum 0 days, maximum 7. If not specified, defaultdays setting will be used instead."""
|
||||
author = ctx.author
|
||||
guild = ctx.guild
|
||||
if days is None:
|
||||
days = await self.settings.guild(guild).default_days()
|
||||
|
||||
result = await self.ban_user(
|
||||
user=user, ctx=ctx, days=days, reason=reason, create_modlog_case=True
|
||||
@@ -286,7 +316,7 @@ class KickBanMixin(MixinMeta):
|
||||
self,
|
||||
ctx: commands.Context,
|
||||
user_ids: commands.Greedy[RawUserIds],
|
||||
days: Optional[int] = 0,
|
||||
days: Optional[int] = None,
|
||||
*,
|
||||
reason: str = None,
|
||||
):
|
||||
@@ -294,7 +324,6 @@ class KickBanMixin(MixinMeta):
|
||||
|
||||
User IDs need to be provided in order to ban
|
||||
using this command"""
|
||||
days = cast(int, days)
|
||||
banned = []
|
||||
errors = {}
|
||||
|
||||
@@ -321,6 +350,9 @@ class KickBanMixin(MixinMeta):
|
||||
await ctx.send_help()
|
||||
return
|
||||
|
||||
if days is None:
|
||||
days = await self.settings.guild(guild).default_days()
|
||||
|
||||
if not (0 <= days <= 7):
|
||||
await ctx.send(_("Invalid days. Must be between 0 and 7."))
|
||||
return
|
||||
|
||||
@@ -51,6 +51,8 @@ class Mod(
|
||||
"delete_delay": -1,
|
||||
"reinvite_on_unban": False,
|
||||
"current_tempbans": [],
|
||||
"dm_on_kickban": False,
|
||||
"default_days": 0,
|
||||
}
|
||||
|
||||
default_channel_settings = {"ignored": False}
|
||||
|
||||
@@ -21,11 +21,14 @@ class ModSettings(MixinMeta):
|
||||
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()
|
||||
data = await self.settings.guild(guild).all()
|
||||
delete_repeats = data["delete_repeats"]
|
||||
ban_mention_spam = data["ban_mention_spam"]
|
||||
respect_hierarchy = data["respect_hierarchy"]
|
||||
delete_delay = data["delete_delay"]
|
||||
reinvite_on_unban = data["reinvite_on_unban"]
|
||||
dm_on_kickban = data["dm_on_kickban"]
|
||||
default_days = data["default_days"]
|
||||
msg = ""
|
||||
msg += _("Delete repeats: {num_repeats}\n").format(
|
||||
num_repeats=_("after {num} repeats").format(num=delete_repeats)
|
||||
@@ -48,6 +51,15 @@ class ModSettings(MixinMeta):
|
||||
msg += _("Reinvite on unban: {yes_or_no}\n").format(
|
||||
yes_or_no=_("Yes") if reinvite_on_unban else _("No")
|
||||
)
|
||||
msg += _("Send message to users on kick/ban: {yes_or_no}\n").format(
|
||||
yes_or_no=_("Yes") if dm_on_kickban else _("No")
|
||||
)
|
||||
if default_days:
|
||||
msg += _(
|
||||
"Default message history delete on ban: Previous {num_days} days\n"
|
||||
).format(num_days=default_days)
|
||||
else:
|
||||
msg += _("Default message history delete on ban: Don't delete any\n")
|
||||
await ctx.send(box(msg))
|
||||
|
||||
@modset.command()
|
||||
@@ -199,3 +211,43 @@ class ModSettings(MixinMeta):
|
||||
command=f"{ctx.prefix}unban"
|
||||
)
|
||||
)
|
||||
|
||||
@modset.command()
|
||||
@commands.guild_only()
|
||||
async def dm(self, ctx: commands.Context, enabled: bool = None):
|
||||
"""Toggle whether a message should be sent to a user when they are kicked/banned.
|
||||
|
||||
If this option is enabled, the bot will attempt to DM the user with the guild name
|
||||
and reason as to why they were kicked/banned.
|
||||
"""
|
||||
guild = ctx.guild
|
||||
if enabled is None:
|
||||
setting = await self.settings.guild(guild).dm_on_kickban()
|
||||
await ctx.send(
|
||||
_("DM when kicked/banned is currently set to: {setting}").format(setting=setting)
|
||||
)
|
||||
return
|
||||
await self.settings.guild(guild).dm_on_kickban.set(enabled)
|
||||
if enabled:
|
||||
await ctx.send(_("Bot will now attempt to send a DM to user before kick and ban."))
|
||||
else:
|
||||
await ctx.send(
|
||||
_("Bot will no longer attempt to send a DM to user before kick and ban.")
|
||||
)
|
||||
|
||||
@modset.command()
|
||||
@commands.guild_only()
|
||||
async def defaultdays(self, ctx: commands.Context, days: int = 0):
|
||||
"""Set the default number of days worth of messages to be deleted when a user is banned.
|
||||
|
||||
The number of days must be between 0 and 7.
|
||||
"""
|
||||
guild = ctx.guild
|
||||
if not (0 <= days <= 7):
|
||||
return await ctx.send(_("Invalid number of days. Must be between 0 and 7."))
|
||||
await self.settings.guild(guild).default_days.set(days)
|
||||
await ctx.send(
|
||||
_("{days} days worth of messages will be deleted when a user is banned.").format(
|
||||
days=days
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user