|
|
@ -52,15 +52,26 @@ async def send_to_modlogs(self, ctx, target, reason, action):
|
|
|
|
if modlog := self.bot.get_modlog_for_guild(ctx.guild.id):
|
|
|
|
if modlog := self.bot.get_modlog_for_guild(ctx.guild.id):
|
|
|
|
channel = ctx.guild.get_channel(modlog)
|
|
|
|
channel = ctx.guild.get_channel(modlog)
|
|
|
|
|
|
|
|
|
|
|
|
desc = f"**Member -->{target.mention} | {target}\nID -->** {target.id}" \
|
|
|
|
if isinstance(target, User):
|
|
|
|
f"\n\n**Auctioned By --> {ctx.author.mention} | {ctx.author}\nID -->** {ctx.author.id}"
|
|
|
|
desc = f"**User -->** {target}\n**ID -->** {target.id}" \
|
|
|
|
embed = Embed(title=f"Member {action}",
|
|
|
|
f"\n\n**Auctioned By --> {ctx.author.mention} | {ctx.author}\nID -->** {ctx.author.id}"
|
|
|
|
description=desc,
|
|
|
|
embed = Embed(title=f"User {action}",
|
|
|
|
colour=self.bot.admin_colour,
|
|
|
|
description=desc,
|
|
|
|
timestamp=datetime.datetime.utcnow())
|
|
|
|
colour=self.bot.admin_colour,
|
|
|
|
embed.set_thumbnail(url=target.avatar_url)
|
|
|
|
timestamp=datetime.datetime.utcnow())
|
|
|
|
embed.add_field(name="Reason", value=reason, inline=False)
|
|
|
|
embed.set_thumbnail(url=target.avatar_url)
|
|
|
|
embed.set_footer(text=f"Member {action}")
|
|
|
|
embed.add_field(name="Reason", value=reason, inline=False)
|
|
|
|
|
|
|
|
embed.set_footer(text=f"User {action}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
desc = f"**Member --> {target.mention} |** {target}\n**ID -->** {target.id}" \
|
|
|
|
|
|
|
|
f"\n\n**Auctioned By --> {ctx.author.mention} | {ctx.author}\nID -->** {ctx.author.id}"
|
|
|
|
|
|
|
|
embed = Embed(title=f"Member {action}",
|
|
|
|
|
|
|
|
description=desc,
|
|
|
|
|
|
|
|
colour=self.bot.admin_colour,
|
|
|
|
|
|
|
|
timestamp=datetime.datetime.utcnow())
|
|
|
|
|
|
|
|
embed.set_thumbnail(url=target.avatar_url)
|
|
|
|
|
|
|
|
embed.add_field(name="Reason", value=reason, inline=False)
|
|
|
|
|
|
|
|
embed.set_footer(text=f"Member {action}")
|
|
|
|
|
|
|
|
|
|
|
|
await channel.send(embed=embed)
|
|
|
|
await channel.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
@ -172,7 +183,7 @@ async def mute_members(self, ctx, targets, reason, muted):
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"**{target.mention} Could Not Be Muted!**")
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"**{target.mention} Could Not Be Muted!**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def ban_members(self, ctx, targets, reason):
|
|
|
|
async def ban_members(self, ctx, users, reason):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
Method to allow members to be banned
|
|
|
|
Method to allow members to be banned
|
|
|
@ -182,22 +193,41 @@ async def ban_members(self, ctx, targets, reason):
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
for target in targets:
|
|
|
|
# Get the list of banned users from the server
|
|
|
|
if (ctx.guild.me.top_role.position > target.top_role.position
|
|
|
|
bans = await ctx.guild.bans()
|
|
|
|
and not target.guild_permissions.administrator):
|
|
|
|
banned_members = list(map(lambda m: m.user, bans))
|
|
|
|
|
|
|
|
|
|
|
|
await target.ban(reason=reason)
|
|
|
|
for user in users:
|
|
|
|
|
|
|
|
# Make sure that the user not banned already
|
|
|
|
|
|
|
|
if user in banned_members:
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.cross} **Member Is Already Banned!** {ctx.bot.cross}")
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.tick} **{target}** Was Banned! {ctx.bot.tick}")
|
|
|
|
# Ban
|
|
|
|
|
|
|
|
if user in ctx.guild.members:
|
|
|
|
|
|
|
|
member = ctx.guild.get_member(user.id)
|
|
|
|
|
|
|
|
if (ctx.guild.me.top_role.position > member.top_role.position
|
|
|
|
|
|
|
|
and not member.guild_permissions.administrator):
|
|
|
|
|
|
|
|
|
|
|
|
await send_to_modlogs(self, ctx, target, reason, action="Banned")
|
|
|
|
await member.ban(reason=reason)
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.tick} **{member}** Was Banned! {ctx.bot.tick}")
|
|
|
|
|
|
|
|
|
|
|
|
# Send error message if the User could not be banned
|
|
|
|
await send_to_modlogs(self, ctx, member, reason, action="Banned")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send error message if the User could not be banned
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"**{member} Could Not Be Banned!**")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"**{target.mention} Could Not Be Banned!**")
|
|
|
|
await ctx.guild.ban(discord.Object(id=user.id), reason=reason)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send confirmation to the channel that the user is in
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx,
|
|
|
|
|
|
|
|
desc=f"{self.bot.tick} **{user}** Was Power Banned! {self.bot.tick}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await send_to_modlogs(self, ctx, user, reason, action="Power Banned")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def unban_members(self, ctx, targets, reason):
|
|
|
|
async def unban_members(self, ctx, users, reason):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
Method to allow members to be unbanned
|
|
|
|
Method to allow members to be unbanned
|
|
|
@ -211,18 +241,17 @@ async def unban_members(self, ctx, targets, reason):
|
|
|
|
bans = await ctx.guild.bans()
|
|
|
|
bans = await ctx.guild.bans()
|
|
|
|
ban_users = list(map(lambda m: m.user, bans))
|
|
|
|
ban_users = list(map(lambda m: m.user, bans))
|
|
|
|
|
|
|
|
|
|
|
|
for target in targets:
|
|
|
|
for user in users:
|
|
|
|
if target not in ban_users:
|
|
|
|
if user not in ban_users:
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.cross} **Member Is Not In Ban's List!** {ctx.bot.cross}")
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.cross} **Member Is Not Banned!** {ctx.bot.cross}")
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Get the member and unban them
|
|
|
|
await ctx.guild.unban(discord.Object(id=user.id), reason=reason)
|
|
|
|
await ctx.guild.unban(target, reason=reason)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Send confirmation to the channel that the user is in
|
|
|
|
# Send confirmation to the channel that the user is in
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.tick} **{target}** Was Unbanned! {ctx.bot.tick}")
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"{ctx.bot.tick} **{user}** Was Unbanned! {ctx.bot.tick}")
|
|
|
|
|
|
|
|
|
|
|
|
await send_to_modlogs(self, ctx, target, reason, action="Unbanned")
|
|
|
|
await send_to_modlogs(self, ctx, user, reason, action="Unbanned")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def kick_members(self, ctx, targets, reason):
|
|
|
|
async def kick_members(self, ctx, targets, reason):
|
|
|
@ -279,6 +308,7 @@ class Moderation(Cog):
|
|
|
|
@command(name="mute", usage="`<member>...` `[reason]`")
|
|
|
|
@command(name="mute", usage="`<member>...` `[reason]`")
|
|
|
|
@has_guild_permissions(manage_roles=True)
|
|
|
|
@has_guild_permissions(manage_roles=True)
|
|
|
|
@bot_has_guild_permissions(manage_roles=True)
|
|
|
|
@bot_has_guild_permissions(manage_roles=True)
|
|
|
|
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
async def mute(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
async def mute(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Mute Member(s) from Server
|
|
|
|
Mute Member(s) from Server
|
|
|
@ -292,7 +322,7 @@ class Moderation(Cog):
|
|
|
|
role = discord.utils.get(ctx.guild.roles, name="Muted")
|
|
|
|
role = discord.utils.get(ctx.guild.roles, name="Muted")
|
|
|
|
|
|
|
|
|
|
|
|
# Create muted role when no muted role exists and mute member(s)
|
|
|
|
# Create muted role when no muted role exists and mute member(s)
|
|
|
|
if role is None:
|
|
|
|
if not role:
|
|
|
|
muted = await ctx.guild.create_role(name="Muted")
|
|
|
|
muted = await ctx.guild.create_role(name="Muted")
|
|
|
|
for channel in ctx.guild.channels:
|
|
|
|
for channel in ctx.guild.channels:
|
|
|
|
await channel.set_permissions(muted, send_messages=False)
|
|
|
|
await channel.set_permissions(muted, send_messages=False)
|
|
|
@ -305,6 +335,7 @@ class Moderation(Cog):
|
|
|
|
@command(name="unmute", usage="`<member>...` `[reason]`")
|
|
|
|
@command(name="unmute", usage="`<member>...` `[reason]`")
|
|
|
|
@has_guild_permissions(manage_roles=True)
|
|
|
|
@has_guild_permissions(manage_roles=True)
|
|
|
|
@bot_has_guild_permissions(manage_roles=True)
|
|
|
|
@bot_has_guild_permissions(manage_roles=True)
|
|
|
|
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
async def unmute(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
async def unmute(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Unmute Member(s) from Server
|
|
|
|
Unmute Member(s) from Server
|
|
|
@ -315,30 +346,25 @@ class Moderation(Cog):
|
|
|
|
if not await check(ctx, members):
|
|
|
|
if not await check(ctx, members):
|
|
|
|
with ctx.typing():
|
|
|
|
with ctx.typing():
|
|
|
|
role = discord.utils.get(ctx.guild.roles, name="Muted")
|
|
|
|
role = discord.utils.get(ctx.guild.roles, name="Muted")
|
|
|
|
|
|
|
|
if not role:
|
|
|
|
if role is None:
|
|
|
|
desc = f"**{self.bot.cross} No Muted Role Was Found! {self.bot.cross}**"
|
|
|
|
embed = Embed(description="**❌ No Muted Role Was Found! ❌**",
|
|
|
|
await self.bot.generate_embed(ctx, desc=desc)
|
|
|
|
colour=self.bot.admin_colour)
|
|
|
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
for member in members:
|
|
|
|
for member in members:
|
|
|
|
if role in member.roles:
|
|
|
|
if role in member.roles:
|
|
|
|
await ummute_members(self, ctx, members, reason)
|
|
|
|
await ummute_members(self, ctx, members, reason)
|
|
|
|
unmute = True
|
|
|
|
unmute = True
|
|
|
|
|
|
|
|
|
|
|
|
if role not in member.roles and unmute is False:
|
|
|
|
if role not in member.roles and unmute is False:
|
|
|
|
embed = Embed(description=f"**❌ {member.mention} Is Not Muted! ❌**",
|
|
|
|
desc = f"**{self.bot.cross} {member.mention} Is Not Muted! {self.bot.cross}**"
|
|
|
|
colour=self.bot.admin_colour)
|
|
|
|
await self.bot.generate_embed(ctx, desc=desc)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="ban", usage="`<member>...` `[reason]`")
|
|
|
|
@command(name="ban", usage="`<member>...` `[reason]`")
|
|
|
|
@guild_only()
|
|
|
|
@guild_only()
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
async def ban(self, ctx, members: Greedy[Member], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
async def ban(self, ctx, members: Greedy[User], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Ban Member(s) from Server
|
|
|
|
Ban Member(s) from Server
|
|
|
|
Multiple Members can be banned at once
|
|
|
|
Multiple Members can be banned at once
|
|
|
@ -348,33 +374,6 @@ class Moderation(Cog):
|
|
|
|
with ctx.typing():
|
|
|
|
with ctx.typing():
|
|
|
|
await ban_members(self, ctx, members, reason)
|
|
|
|
await ban_members(self, ctx, members, reason)
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="forceban", aliases=["powerban", "ultraban"], usage="`<member>...` `[reason]`")
|
|
|
|
|
|
|
|
@guild_only()
|
|
|
|
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
|
|
|
|
@bot_has_guild_permissions(ban_members=True)
|
|
|
|
|
|
|
|
@cooldown(1, 1, BucketType.user)
|
|
|
|
|
|
|
|
async def force_ban(self, ctx, users: Greedy[int], *, reason: Optional[str] = "No Reason Given"):
|
|
|
|
|
|
|
|
"""Ban User(s) from Server (MUST PROVIDE ID)"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not await check(ctx, users):
|
|
|
|
|
|
|
|
# Get the list of banned users from the server
|
|
|
|
|
|
|
|
bans = await ctx.guild.bans()
|
|
|
|
|
|
|
|
ban_ids = list(map(lambda m: m.user.id, bans))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Power ban users from guilds without them being in there
|
|
|
|
|
|
|
|
for user in users:
|
|
|
|
|
|
|
|
if user in ban_ids:
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx,
|
|
|
|
|
|
|
|
desc=f"{self.bot.cross} **Member Is Already Banned!** {self.bot.cross}")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
await ctx.guild.ban(discord.Object(id=user))
|
|
|
|
|
|
|
|
target = await self.bot.fetch_user(user)
|
|
|
|
|
|
|
|
# Send confirmation to the channel that the user is in
|
|
|
|
|
|
|
|
await self.bot.generate_embed(ctx,
|
|
|
|
|
|
|
|
desc=f"{self.bot.tick} **{target}** Was Power Banned! {self.bot.tick}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await send_to_modlogs(self, ctx, target, reason, action="Power Banned")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@command(name="unban", usage="`<member>...` `[reason]`")
|
|
|
|
@command(name="unban", usage="`<member>...` `[reason]`")
|
|
|
|
@guild_only()
|
|
|
|
@guild_only()
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
|
@has_guild_permissions(ban_members=True)
|
|
|
@ -431,14 +430,13 @@ class Moderation(Cog):
|
|
|
|
|
|
|
|
|
|
|
|
@ban.error
|
|
|
|
@ban.error
|
|
|
|
@unban.error
|
|
|
|
@unban.error
|
|
|
|
@force_ban.error
|
|
|
|
|
|
|
|
async def ban_command_error(self, ctx, exc):
|
|
|
|
async def ban_command_error(self, ctx, exc):
|
|
|
|
"""Catching error if channel is not recognised"""
|
|
|
|
"""Catching error if channel is not recognised"""
|
|
|
|
|
|
|
|
|
|
|
|
error = getattr(exc, "original", exc)
|
|
|
|
error = getattr(exc, "original", exc)
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(error, NotFound):
|
|
|
|
if isinstance(error, NotFound):
|
|
|
|
text = "**❌ User Not Detected... Aborting Process** ❌"
|
|
|
|
text = f"**{self.bot.cross} User Not Detected... Aborting Process** {self.bot.cross}"
|
|
|
|
await self.bot.generate_embed(ctx, desc=text)
|
|
|
|
await self.bot.generate_embed(ctx, desc=text)
|
|
|
|
|
|
|
|
|
|
|
|
@Cog.listener()
|
|
|
|
@Cog.listener()
|
|
|
|