mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Mod] Make tempbans permanent when using [p]hackban (#4025)
* Remove users from tempban unban list when hackbanning them * black and missing bracket * make sure this actually gets processed * let the user know when a tempban was upgraded * say more things * reduce config calls * jack loves performance * adress review * review the 2nd
This commit is contained in:
parent
5b612b8ac7
commit
49b19450fd
@ -7,7 +7,7 @@ from typing import Optional, Union
|
||||
import discord
|
||||
from redbot.core import commands, i18n, checks, modlog
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils.chat_formatting import pagify, humanize_number, bold
|
||||
from redbot.core.utils.chat_formatting import pagify, humanize_number, bold, humanize_list
|
||||
from redbot.core.utils.mod import is_allowed_by_hierarchy, get_audit_reason
|
||||
from .abc import MixinMeta
|
||||
from .converters import RawUserIds
|
||||
@ -292,6 +292,7 @@ class KickBanMixin(MixinMeta):
|
||||
using this command"""
|
||||
banned = []
|
||||
errors = {}
|
||||
upgrades = []
|
||||
|
||||
async def show_results():
|
||||
text = _("Banned {num} users from the server.").format(
|
||||
@ -300,6 +301,11 @@ class KickBanMixin(MixinMeta):
|
||||
if errors:
|
||||
text += _("\nErrors:\n")
|
||||
text += "\n".join(errors.values())
|
||||
if upgrades:
|
||||
text += _(
|
||||
"\nFollowing user IDs have been upgraded from a temporary to a permanent ban:\n"
|
||||
)
|
||||
text += humanize_list(upgrades)
|
||||
|
||||
for p in pagify(text):
|
||||
await ctx.send(p)
|
||||
@ -326,10 +332,16 @@ class KickBanMixin(MixinMeta):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return await ctx.send(_("I lack the permissions to do this."))
|
||||
|
||||
tempbans = await self.config.guild(guild).current_tempbans()
|
||||
|
||||
ban_list = await guild.bans()
|
||||
for entry in ban_list:
|
||||
for user_id in user_ids:
|
||||
if entry.user.id == user_id:
|
||||
if user_id in tempbans:
|
||||
# We need to check if a user is tempbanned here because otherwise they won't be processed later on.
|
||||
continue
|
||||
else:
|
||||
errors[user_id] = _("User {user_id} is already banned.").format(
|
||||
user_id=user_id
|
||||
)
|
||||
@ -343,6 +355,10 @@ class KickBanMixin(MixinMeta):
|
||||
for user_id in user_ids:
|
||||
user = guild.get_member(user_id)
|
||||
if user is not None:
|
||||
if user_id in tempbans:
|
||||
# We need to check if a user is tempbanned here because otherwise they won't be processed later on.
|
||||
continue
|
||||
else:
|
||||
# Instead of replicating all that handling... gets attr from decorator
|
||||
try:
|
||||
result = await self.ban_user(
|
||||
@ -369,17 +385,30 @@ class KickBanMixin(MixinMeta):
|
||||
user = discord.Object(id=user_id)
|
||||
audit_reason = get_audit_reason(author, reason)
|
||||
queue_entry = (guild.id, user_id)
|
||||
async with self.config.guild(guild).current_tempbans() as tempbans:
|
||||
if user_id in tempbans:
|
||||
tempbans.remove(user_id)
|
||||
upgrades.append(str(user_id))
|
||||
log.info(
|
||||
"{}({}) upgraded the tempban for {} to a permaban.".format(
|
||||
author.name, author.id, user_id
|
||||
)
|
||||
)
|
||||
banned.append(user_id)
|
||||
else:
|
||||
try:
|
||||
await guild.ban(user, reason=audit_reason, delete_message_days=days)
|
||||
log.info("{}({}) hackbanned {}".format(author.name, author.id, user_id))
|
||||
except discord.NotFound:
|
||||
errors[user_id] = _("User {user_id} does not exist.").format(user_id=user_id)
|
||||
continue
|
||||
except discord.Forbidden:
|
||||
errors[user_id] = _("Could not ban {user_id}: missing permissions.").format(
|
||||
errors[user_id] = _("User {user_id} does not exist.").format(
|
||||
user_id=user_id
|
||||
)
|
||||
continue
|
||||
except discord.Forbidden:
|
||||
errors[user_id] = _(
|
||||
"Could not ban {user_id}: missing permissions."
|
||||
).format(user_id=user_id)
|
||||
continue
|
||||
else:
|
||||
banned.append(user_id)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user