Reducing amount of indents

pull/8/head
sgoudham 4 years ago
parent 0546469e81
commit f35ea75859

@ -22,14 +22,15 @@ def AnonOrNot(author):
AnonModMailEmbed.set_thumbnail(url=author.avatar_url) AnonModMailEmbed.set_thumbnail(url=author.avatar_url)
AnonModMailEmbed.set_footer(text=f"Sent by {author}") AnonModMailEmbed.set_footer(text=f"Sent by {author}")
fields = [(blank_space, "**We understand that for some things, you may want to remain Anonymous." fields = [(blank_space, "**We understand that for some things,"
"\nFeel free to use the reactions below to choose!**", False), "you may want to remain Anonymous."
"\nUse the reactions below to choose!**", False),
(blank_space, "**Use :white_check_mark: for** `Yes`", True), (blank_space, "**Use :white_check_mark: for** `Yes`", True),
(blank_space, "**Use :x: for** `No`", True), (blank_space, "**Use :x: for** `No`", True),
(blank_space, blank_space, True), (blank_space, blank_space, True),
(blank_space, (blank_space,
"This will make sure that Staff do not know who is sending the mail." "The Staff will not know who is sending this"
"\nAgain, purely negative feedback will not be considered.", True)] "\nPurely negative feedback will not be considered.", True)]
for name, value, inline in fields: for name, value, inline in fields:
AnonModMailEmbed.add_field(name=name, value=value, inline=inline) AnonModMailEmbed.add_field(name=name, value=value, inline=inline)
@ -179,178 +180,154 @@ class Modmail(commands.Cog):
message_id = int(result[2]) message_id = int(result[2])
modmail_channel_id = int(result[3]) modmail_channel_id = int(result[3])
if payload.guild_id == guild_id: # Bunch of checks to make sure it has the right guild, channel, message and reaction
if payload.channel_id == channel_id: if payload.guild_id == guild_id and payload.channel_id == channel_id and payload.message_id == message_id and payload.emoji.name == "":
if payload.message_id == message_id:
if payload.emoji.name == "": # Get the guild
guild = self.bot.get_guild(payload.guild_id)
# Get the guild # Get the member
guild = self.bot.get_guild(payload.guild_id) member = guild.get_member(payload.user_id)
# Get the member # Get the setup modmail channel
member = guild.get_member(payload.user_id) channel = guild.get_channel(payload.channel_id)
# Get the setup modmail channel # Get the modmail logging channel
channel = guild.get_channel(payload.channel_id) modmail_channel = guild.get_channel(modmail_channel_id)
# Get the modmail logging channel
modmail_channel = guild.get_channel(modmail_channel_id) # Fetch the message and remove the reaction
reaction = await channel.fetch_message(message_id)
# Fetch the message and remove the reaction await reaction.remove_reaction('', member)
reaction = await channel.fetch_message(message_id)
await reaction.remove_reaction('', member) # Setting up the channel permissions for the new channel that will be created
overwrites = {
# Setting up the channel permissions for the new channel that will be created guild.default_role: discord.PermissionOverwrite(read_messages=False),
overwrites = { guild.me: discord.PermissionOverwrite(read_messages=True),
guild.default_role: discord.PermissionOverwrite(read_messages=False), member: discord.PermissionOverwrite(read_messages=True, send_messages=True)
guild.me: discord.PermissionOverwrite(read_messages=True), }
member: discord.PermissionOverwrite(read_messages=True, send_messages=True)
} # Saving this for later within when discord.py 1.4 comes out
# cat = await guild.create_category_channel(member.name, overwrites=overwrites)
# Saving this for later within when discord.py 1.4 comes out
# cat = await guild.create_category_channel(member.name, overwrites=overwrites) # Create the text channel
user_channel = await guild.create_text_channel(member.name, overwrites=overwrites,
# Create the text channel position=0)
user_channel = await guild.create_text_channel(member.name, overwrites=overwrites,
position=0) # Mention the user to make sure that they get pinged
mention = await user_channel.send(member.mention)
# Mention the user to make sure that they get pinged await mention.delete()
mention = await user_channel.send(member.mention)
await mention.delete() try:
try: # Send the embed if they want to remain anonymous or not
Anon_or_Not = await user_channel.send(embed=AnonOrNot(member))
# Send the embed if they want to remain anonymous or not # Add reactions to the message
Anon_or_Not = await user_channel.send(embed=AnonOrNot(member)) await Anon_or_Not.add_reaction('')
# Add reactions to the message await Anon_or_Not.add_reaction('')
await Anon_or_Not.add_reaction('')
await Anon_or_Not.add_reaction('') # Checking if the user reacted with ✅ with response to sending staff a message
def emoji_check(reaction, user):
# Checking if the user reacted with ✅ with response to sending staff a message return user == member and str(reaction.emoji) in ['', '']
def emoji_check(reaction, user):
return user == member and str(reaction.emoji) in ['', ''] # Surround with try/except to catch any exceptions that may occur
try:
# Surround with try/except to catch any exceptions that may occur # Wait for the user to add a reaction
try: reaction, user = await self.bot.wait_for('reaction_add', check=emoji_check)
# Wait for the user to add a reaction except Exception as ex:
reaction, user = await self.bot.wait_for('reaction_add', check=emoji_check) print(ex)
except Exception as ex: return
print(ex) else:
return if str(reaction.emoji) == "":
else: self.anon = True
if str(reaction.emoji) == "":
self.anon = True # Delete the old embed
await Anon_or_Not.delete()
# Delete the old embed
await Anon_or_Not.delete() # Tell the user to type their mail into the chat
instructions = await user_channel.send(embed=SendInstructions(member))
# Tell the user to type their mail into the chat
instructions = await user_channel.send(embed=SendInstructions(member)) # Making sure that the reply is from the author
def check(m):
# Making sure that the reply is from the author return m.author == payload.member and user_channel.id == instructions.channel.id
def check(m):
return m.author == payload.member and user_channel.id == instructions.channel.id # Wait for the message from the author
msg = await self.bot.wait_for('message', check=check)
# Wait for the message from the author
msg = await self.bot.wait_for('message', check=check) # Making sure that the message is below 50 characters and the message was sent in the channel
while len(msg.content) < 50 and msg.channel == user_channel:
# Making sure that the message is below 50 characters and the message was sent in the channel await user_channel.send(embed=ErrorHandling(member))
while len(msg.content) < 50 and msg.channel == user_channel:
await user_channel.send(embed=ErrorHandling(member)) # Wait for the message from the author
msg = await self.bot.wait_for('message', check=check)
# Wait for the message from the author
msg = await self.bot.wait_for('message', check=check) if len(msg.content) > 50 and msg.channel == user_channel:
# Delete the previous embed
if len(msg.content) > 50 and msg.channel == user_channel: await instructions.delete()
# Delete the previous embed
await instructions.delete() # Determine a path for the message logs to be stored
path = "cogs/modmail/{}.txt".format(payload.member.name)
# Determine a path for the message logs to be stored with open(path, 'a+') as f:
path = "cogs/modmail/{}.txt".format(payload.member.name) # Store the date and content of every message in the text file
with open(path, 'a+') as f: async for message in user_channel.history(limit=300):
# Store the date and content of every message in the text file print(f"{message.created_at} : {message.content}", file=f)
async for message in user_channel.history(limit=300):
print(f"{message.created_at} : {message.content}", file=f) # Send the message to the modmail channel
await modmail_channel.send(embed=SendMsgToModMail(self, msg, member),
# Send the message to the modmail channel file=File(fp=path))
await modmail_channel.send(embed=SendMsgToModMail(self, msg, member),
file=File(fp=path))
# Removing file from the directory after it has been sent
if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Make sure the user knows that their message has been sent
await user_channel.send(embed=MessageSentConfirmation(member))
# Let the user read the message for 5 seconds
await asyncio.sleep(5)
await user_channel.delete()
return
# If the user types anywhere else, delete the channel
else:
await user_channel.delete()
if str(reaction.emoji) == "":
self.anon = False
# Delete the old embed # Removing file from the directory after it has been sent
await Anon_or_Not.delete() if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Tell the user to type their mail into the chat # Make sure the user knows that their message has been sent
instructions = await user_channel.send(embed=SendInstructions(member)) await user_channel.send(embed=MessageSentConfirmation(member))
# Making sure that the reply is from the author # Let the user read the message for 5 seconds
def check(m): await asyncio.sleep(5)
return m.author == payload.member and user_channel.id == instructions.channel.id
# Wait for the message from the author await user_channel.delete()
msg = await self.bot.wait_for('message', check=check, timeout=300) return
# Making sure that the message is below 50 characters and the message was sent in the channel # If the user types anywhere else, delete the channel
while len(msg.content) < 50 and msg.channel == user_channel: else:
await user_channel.send(embed=ErrorHandling(member)) await user_channel.delete()
# Wait for the message from the author again if str(reaction.emoji) == "":
msg = await self.bot.wait_for('message', check=check, timeout=300) self.anon = False
if len(msg.content) > 50 and msg.channel == user_channel: # Delete the old embed
# Delete the previous embed await Anon_or_Not.delete()
await instructions.delete()
# Determine a path for the message logs to be stored # Tell the user to type their mail into the chat
path = "cogs/modmail/{}.txt".format(payload.member.name) instructions = await user_channel.send(embed=SendInstructions(member))
with open(path, 'a+') as f:
# Store the date and content of every message in the text file
async for message in user_channel.history(limit=300):
print(f"{message.created_at} : {message.content}", file=f)
# Send the message to the modmail channel # Making sure that the reply is from the author
await modmail_channel.send(embed=SendMsgToModMail(self, msg, member), def check(m):
file=File(fp=path)) return m.author == payload.member and user_channel.id == instructions.channel.id
# Removing file from the directory after it has been sent # Wait for the message from the author
if os.path.exists(path): msg = await self.bot.wait_for('message', check=check, timeout=300)
os.remove(path)
else:
print("The file does not exist")
# Make sure the user knows that their message has been sent # Making sure that the message is below 50 characters and the message was sent in the channel
await user_channel.send(embed=MessageSentConfirmation(member)) while len(msg.content) < 50 and msg.channel == user_channel:
await user_channel.send(embed=ErrorHandling(member))
# Let the user read the message for 5 seconds # Wait for the message from the author again
await asyncio.sleep(5) msg = await self.bot.wait_for('message', check=check, timeout=300)
await user_channel.delete() if len(msg.content) > 50 and msg.channel == user_channel:
return # Delete the previous embed
await instructions.delete()
# If the user types anywhere else, delete the channel # Determine a path for the message logs to be stored
else: path = "cogs/modmail/{}.txt".format(payload.member.name)
await user_channel.delete() with open(path, 'a+') as f:
# Store the date and content of every message in the text file
async for message in user_channel.history(limit=300):
print(f"{message.created_at} : {message.content}", file=f)
except Exception as ex: # Send the message to the modmail channel
print(ex) await modmail_channel.send(embed=SendMsgToModMail(self, msg, member),
file=File(fp=path))
# Removing file from the directory after it has been sent # Removing file from the directory after it has been sent
if os.path.exists(path): if os.path.exists(path):
@ -358,14 +335,36 @@ class Modmail(commands.Cog):
else: else:
print("The file does not exist") print("The file does not exist")
# Send out an error message if the user waited too long # Make sure the user knows that their message has been sent
await user_channel.send( await user_channel.send(embed=MessageSentConfirmation(member))
"Sorry! Something seems to have gone wrong and the modmail will be aborting."
"\nRemember to make sure it's under **1024** characters!!")
# Let the user read the message for 5 seconds
await asyncio.sleep(5) await asyncio.sleep(5)
await user_channel.delete()
return
# If the user types anywhere else, delete the channel
else:
await user_channel.delete() await user_channel.delete()
except Exception as ex:
print(ex)
# Removing file from the directory after it has been sent
if os.path.exists(path):
os.remove(path)
else:
print("The file does not exist")
# Send out an error message if the user waited too long
await user_channel.send(
"Sorry! Something seems to have gone wrong and the modmail will be aborting."
"\nRemember to make sure it's under **1024** characters!!")
await asyncio.sleep(5)
await user_channel.delete()
def setup(bot): def setup(bot):
bot.add_cog(Modmail(bot)) bot.add_cog(Modmail(bot))

Loading…
Cancel
Save