Trying different way of executing modmail

Not massive if statements anymore
pull/8/head
sgoudham 4 years ago
parent 6347c48204
commit 454a7adb57

@ -630,100 +630,56 @@ class Guild(Cog):
if str(reaction.emoji) == "": if str(reaction.emoji) == "":
self.anon = True self.anon = True
# 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=send_instructions(member))
# 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:
await user_channel.send(embed=error_handling(member))
# Wait for the message from the author
msg = await self.bot.wait_for('message', check=check)
# As long as the message is above 50 characters and in the correct channel
if len(msg.content) > 50 and msg.channel == user_channel:
# Delete the previous embed
await instructions.delete()
# Store all text in the channel in a bytesio object
text = ""
async for message in user_channel.history(limit=300):
text += "".join(f"{message.created_at} : {message.content}\n")
text_bytes = str.encode(text)
file = io.BytesIO(text_bytes)
# Send the message to the modmail channel
await modmail_channel.send(embed=send_modmail(self, msg, member),
file=File(file, 'Anon.txt'))
# Make sure the user knows that their message has been sent
await user_channel.send(embed=message_sent_confirmation(member))
# Let the user read the message for 5 seconds
await asyncio.sleep(5)
# Delete the channel and then stop the function
await user_channel.delete()
# If the user types anywhere else, delete the channel
else:
await user_channel.delete()
return
if str(reaction.emoji) == "": if str(reaction.emoji) == "":
self.anon = False self.anon = False
# Delete the old embed # Delete the old embed
await Anon_or_Not.delete() await Anon_or_Not.delete()
# Tell the user to type their mail into the chat # Tell the user to type their mail into the chat
instructions = await user_channel.send(embed=send_instructions(member)) instructions = await user_channel.send(embed=send_instructions(member))
# Wait for the message from the author # Wait for the message from the author
msg = await self.bot.wait_for('message', check=check, timeout=300) 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:
await user_channel.send(embed=error_handling(member))
# Making sure that the message is below 50 characters and the message was sent in the channel # Wait for the message from the author
while len(msg.content) < 50 and msg.channel == user_channel: msg = await self.bot.wait_for('message', check=check)
await user_channel.send(embed=error_handling(member))
# Wait for the message from the author again # As long as the message is above 50 characters and in the correct channel
msg = await self.bot.wait_for('message', check=check, timeout=300) if len(msg.content) > 50 and msg.channel == user_channel:
# Delete the previous embed
await instructions.delete()
if len(msg.content) > 50 and msg.channel == user_channel: # Store all text in the channel in a bytesio object
# Delete the previous embed text = ""
await instructions.delete() async for message in user_channel.history(limit=300):
text += "".join(f"{message.created_at} : {message.content}\n")
text_bytes = str.encode(text)
# Store all text in the channel in a bytesio object file = io.BytesIO(text_bytes)
text = ""
async for message in user_channel.history(limit=300):
text = "".join(f"{message.created_at} : {message.content}\n")
text_bytes = str.encode(text)
file = io.BytesIO(text_bytes) file_name = "Anon.txt" if self.anon else f"{member.name}.txt"
# Send the message to the modmail channel # Send the message to the modmail channel
await modmail_channel.send(embed=send_modmail(self, msg, member), await modmail_channel.send(embed=send_modmail(self, msg, member),
file=File(file, f'{member.name}.txt')) file=File(file, file_name))
# Make sure the user knows that their message has been sent # Make sure the user knows that their message has been sent
await user_channel.send(embed=message_sent_confirmation(member)) await user_channel.send(embed=message_sent_confirmation(member))
# Let the user read the message for 5 seconds # Let the user read the message for 5 seconds
await asyncio.sleep(5) await asyncio.sleep(5)
# Delete the channel # Delete the channel and then stop the function
await user_channel.delete() await user_channel.delete()
# If the user types anywhere else, delete the channel # If the user types anywhere else, delete the channel
else: else:
await user_channel.delete() await user_channel.delete()
except Exception as ex: except Exception as ex:
print(ex) print(ex)

Loading…
Cancel
Save