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

[pull] V3/develop from Cog-Creators:V3/develop #126

Merged
merged 1 commit into from
Dec 8, 2024
Merged
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
48 changes: 46 additions & 2 deletions redbot/cogs/warnings/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
)
from redbot.core import Config, commands, modlog
from redbot.core.bot import Red
from redbot.core.commands import UserInputOptional
from redbot.core.commands import UserInputOptional, RawUserIdConverter
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils import AsyncIter
from redbot.core.utils.views import ConfirmView
from redbot.core.utils.chat_formatting import warning, pagify
from redbot.core.utils.menus import menu

Expand Down Expand Up @@ -373,7 +374,7 @@ async def actionlist(self, ctx: commands.Context):
async def warn(
self,
ctx: commands.Context,
member: discord.Member,
user: Union[discord.Member, RawUserIdConverter],
points: UserInputOptional[int] = 1,
*,
reason: str,
Expand All @@ -386,6 +387,49 @@ async def warn(
or a custom reason if ``[p]warningset allowcustomreasons`` is set.
"""
guild = ctx.guild
member = None
if isinstance(user, discord.Member):
member = user
elif isinstance(user, int):
if not ctx.channel.permissions_for(ctx.guild.me).ban_members:
await ctx.send(_("User `{user}` is not in the server.").format(user=user))
return
user_obj = self.bot.get_user(user) or discord.Object(id=user)

confirm = ConfirmView(ctx.author, timeout=30)
confirm.message = await ctx.send(
_(
"User `{user}` is not in the server. Would you like to ban them instead?"
).format(user=user),
view=confirm,
)
await confirm.wait()
if confirm.result:
try:
await ctx.guild.ban(user_obj, reason=reason)
await modlog.create_case(
self.bot,
guild,
ctx.message.created_at,
"hackban",
user,
ctx.author,
reason,
until=None,
channel=None,
)
except discord.HTTPException as error:
await ctx.send(
_("An error occurred while trying to ban the user. Error: {error}").format(
error=error
)
)
else:
confirm.message = await ctx.send(_("No action taken."))

await ctx.tick()
return

if member == ctx.author:
return await ctx.send(_("You cannot warn yourself."))
if member.bot:
Expand Down
Loading