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

[p]warn ask to ban when user not in server #6481

Merged
merged 18 commits into from
Dec 8, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b4cfaa2
implemented warning by UserID
Ascensionn Nov 20, 2024
9524bb0
Merge branch 'Cog-Creators:V3/develop' into V3/develop
Ascensionn Nov 20, 2024
9a9976d
updated warn command to ban user by ID if they are warned when they a…
Ascensionn Nov 26, 2024
113dd06
Merge branch 'V3/develop' of https://github.com/Ascensionn/Red-Discor…
Ascensionn Nov 26, 2024
80bdf14
Updated the warn command to include an option for the mod/owner to ba…
Ascensionn Nov 28, 2024
a970ecd
update made to the warn command for better interface when handling us…
Ascensionn Nov 30, 2024
eef6a42
update made to the warn command for users who have left the server be…
Ascensionn Nov 30, 2024
a2d83f5
update made to the warn command for users who have left the server be…
Ascensionn Nov 30, 2024
7e7d624
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
c5a41a9
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
c12bf99
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
198d1e7
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
b931471
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
39afcde
Update redbot/cogs/warnings/warnings.py
Ascensionn Dec 2, 2024
7e8279c
updated the bot to have the ability to ban users through the [p]warn …
Ascensionn Dec 2, 2024
31a54cf
updated the warn command to also give the owner/mod a chance to ban u…
Ascensionn Dec 5, 2024
b8f303f
Apply suggestions from code review
Flame442 Dec 8, 2024
d48609e
Consistent formatting
Flame442 Dec 8, 2024
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)
Ascensionn marked this conversation as resolved.
Show resolved Hide resolved

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