Merge pull request #75 from leo60228/sanitize

Escape Markdown in clean_content calls
This commit is contained in:
Ave 2020-10-02 03:28:56 +03:00 committed by GitHub
commit ff7ba6790a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 19 deletions

View file

@ -50,7 +50,9 @@ intents = discord.Intents.default()
intents.typing = False
intents.members = True
bot = commands.Bot(command_prefix=get_prefix, description=config.bot_description, intents=intents)
bot = commands.Bot(
command_prefix=get_prefix, description=config.bot_description, intents=intents
)
bot.help_command = commands.DefaultHelpCommand(dm_help=True)
bot.log = log

View file

@ -58,7 +58,9 @@ class Lockdown(Cog):
)
await ctx.send(public_msg)
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(ctx.author)
)
msg = (
f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} "
f"| {safe_name}"
@ -86,7 +88,9 @@ class Lockdown(Cog):
for role in roles:
await self.set_sendmessage(channel, role, True, ctx.author)
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(ctx.author)
)
await ctx.send("🔓 Channel unlocked.")
msg = (
f"🔓 **Unlock**: {ctx.channel.mention} by {ctx.author.mention} "

View file

@ -142,7 +142,9 @@ class Meme(Cog):
f"I'm sorry {ctx.author.mention}, I'm afraid I can't do that."
)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
await ctx.send(f"{safe_name} is ̶n͢ow b̕&̡.̷ 👍̡")
@commands.command(hidden=True)
@ -155,7 +157,16 @@ class Meme(Cog):
"""test"""
await ctx.send("https://www.youtube.com/watch?v=VmarNEsjpDI")
@commands.command(hidden=True, aliases=["yotld", "yold", "yoltd", "yearoflinuxondesktop", "yearoflinuxonthedesktop"])
@commands.command(
hidden=True,
aliases=[
"yotld",
"yold",
"yoltd",
"yearoflinuxondesktop",
"yearoflinuxonthedesktop",
],
)
async def yearoflinux(self, ctx):
"""Shows the year of Linux on the desktop"""
await ctx.send(

View file

@ -52,7 +52,9 @@ class Mod(Cog):
userlog(target.id, ctx.author, reason, "mutes", target.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
dm_message = f"You were muted!"
if reason:
@ -95,7 +97,9 @@ class Mod(Cog):
@commands.command()
async def unmute(self, ctx, target: discord.Member):
"""Unmutes a user, staff only."""
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
mute_role = ctx.guild.get_role(config.mute_role)
await target.remove_roles(mute_role, reason=str(ctx.author))
@ -133,7 +137,9 @@ class Mod(Cog):
userlog(target.id, ctx.author, reason, "kicks", target.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
dm_message = f"You were kicked from {ctx.guild.name}."
if reason:
@ -194,7 +200,9 @@ class Mod(Cog):
userlog(target.id, ctx.author, reason, "bans", target.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
dm_message = f"You were banned from {ctx.guild.name}."
if reason:
@ -251,7 +259,9 @@ class Mod(Cog):
userlog(target, ctx.author, reason, "bans", target_user.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
await ctx.guild.ban(
target_user, reason=f"{ctx.author}, reason: {reason}", delete_message_days=0
@ -284,7 +294,9 @@ class Mod(Cog):
"""Unbans a user with their ID, doesn't message them, staff only."""
target_user = await self.bot.fetch_user(target)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
await ctx.guild.unban(target_user, reason=f"{ctx.author}, reason: {reason}")
chan_message = (
@ -325,7 +337,9 @@ class Mod(Cog):
userlog(target.id, ctx.author, reason, "bans", target.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
await target.ban(
reason=f"{ctx.author}, reason: {reason}", delete_message_days=0
@ -436,7 +450,9 @@ class Mod(Cog):
log_channel = self.bot.get_channel(config.modlog_channel)
warn_count = userlog(target.id, ctx.author, reason, "warns", target.name)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
chan_msg = (
f"⚠️ **Warned**: {ctx.author.mention} warned "
f"{target.mention} (warn #{warn_count}) "

View file

@ -44,7 +44,9 @@ class ModTimed(Cog):
target.name,
)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
dm_message = f"You were banned from {ctx.guild.name}."
if reason:
@ -110,7 +112,9 @@ class ModTimed(Cog):
target.name,
)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
dm_message = f"You were muted!"
if reason:

View file

@ -137,7 +137,9 @@ class ModUserlog(Cog):
"""Clears all events of given type for a user, staff only."""
log_channel = self.bot.get_channel(config.modlog_channel)
msg = self.clear_event_from_id(str(target.id), event)
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
await ctx.send(msg)
msg = (
f"🗑 **Cleared {event}**: {ctx.author.mention} cleared"
@ -173,7 +175,9 @@ class ModUserlog(Cog):
# This is hell.
if isinstance(del_event, discord.Embed):
await ctx.send(f"{target.mention} has a {event_name} removed!")
safe_name = await commands.clean_content().convert(ctx, str(target))
safe_name = await commands.clean_content(escape_markdown=True).convert(
ctx, str(target)
)
msg = (
f"🗑 **Deleted {event_name}**: "
f"{ctx.author.mention} removed "
@ -219,8 +223,12 @@ class ModUserlog(Cog):
str(user.id), str(user), event=event_types
)
user_name = await commands.clean_content().convert(ctx, user.name)
display_name = await commands.clean_content().convert(ctx, user.display_name)
user_name = await commands.clean_content(escape_markdown=True).convert(
ctx, user.name
)
display_name = await commands.clean_content(escape_markdown=True).convert(
ctx, user.display_name
)
await ctx.send(
f"user = {user_name}\n"