Escape Markdown in clean_content calls

Fixes #74
This commit is contained in:
leo60228 2020-10-01 20:03:41 -04:00
parent 165ce2f442
commit 8d899cf9a7
6 changed files with 64 additions and 19 deletions

View file

@ -50,7 +50,9 @@ intents = discord.Intents.default()
intents.typing = False intents.typing = False
intents.members = True 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.help_command = commands.DefaultHelpCommand(dm_help=True)
bot.log = log bot.log = log

View file

@ -58,7 +58,9 @@ class Lockdown(Cog):
) )
await ctx.send(public_msg) 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 = ( msg = (
f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} " f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} "
f"| {safe_name}" f"| {safe_name}"
@ -86,7 +88,9 @@ class Lockdown(Cog):
for role in roles: for role in roles:
await self.set_sendmessage(channel, role, True, ctx.author) 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.") await ctx.send("🔓 Channel unlocked.")
msg = ( msg = (
f"🔓 **Unlock**: {ctx.channel.mention} by {ctx.author.mention} " 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." 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̕&̡.̷ 👍̡") await ctx.send(f"{safe_name} is ̶n͢ow b̕&̡.̷ 👍̡")
@commands.command(hidden=True) @commands.command(hidden=True)
@ -155,7 +157,16 @@ class Meme(Cog):
"""test""" """test"""
await ctx.send("https://www.youtube.com/watch?v=VmarNEsjpDI") 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): async def yearoflinux(self, ctx):
"""Shows the year of Linux on the desktop""" """Shows the year of Linux on the desktop"""
await ctx.send( await ctx.send(

View file

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

View file

@ -44,7 +44,9 @@ class ModTimed(Cog):
target.name, 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}." dm_message = f"You were banned from {ctx.guild.name}."
if reason: if reason:
@ -110,7 +112,9 @@ class ModTimed(Cog):
target.name, 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!" dm_message = f"You were muted!"
if reason: if reason:

View file

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