From 5ee601bda55f7cec0ec1d288f9425091d9018bfc Mon Sep 17 00:00:00 2001 From: "Ayato (Shahil)" <67567036+Shahil-Ayato@users.noreply.github.com> Date: Tue, 12 Apr 2022 09:31:35 -0700 Subject: [PATCH] Update mod.py (#18) --- robocop_ng/cogs/mod.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/robocop_ng/cogs/mod.py b/robocop_ng/cogs/mod.py index 22406c0..8dc2622 100644 --- a/robocop_ng/cogs/mod.py +++ b/robocop_ng/cogs/mod.py @@ -690,6 +690,57 @@ class Mod(Cog): await ctx.send("Successfully set bot nickname.") + @commands.guild_only() + @commands.check(check_if_staff) + @commands.command() + async def move(context): + + # get the content of the message + content = context.message.content.split(' ') + # if the length is not three the command was used incorrectly + if len(content) != 3 or not content[2].isnumeric(): + await context.message.channel.send("Incorrect usage of !move. Example: !move {channel to move to} {number of messages}.") + return + # channel that it is going to be posted to + channelTo = content[1] + # get the number of messages to be moved (including the command message) + numberOfMessages = int(content[2]) + 1 + # get a list of the messages + fetchedMessages = await context.channel.history(limit=numberOfMessages).flatten() + + # delete all of those messages from the channel + for i in fetchedMessages: + await i.delete() + + # invert the list and remove the last message (gets rid of the command message) + fetchedMessages = fetchedMessages[::-1] + fetchedMessages = fetchedMessages[:-1] + + # Loop over the messages fetched + for messages in fetchedMessages: + # get the channel object for the server to send to + channelTo = discord.utils.get(messages.guild.channels, name=channelTo) + + # if the message is embeded already + if messages.embeds: + # set the embed message to the old embed object + embedMessage = messages.embeds[0] + # else + else: + # Create embed message object and set content to original + embedMessage = discord.Embed( + description = messages.content + ) + # set the embed message author to original author + embedMessage.set_author(name=messages.author, icon_url=messages.author.avatar_url) + # if message has attachments add them + if messages.attachments: + for i in messages.attachments: + embedMessage.set_image(url = i.proxy_url) + + # Send to the desired channel + await channelTo.send(embed=embedMessage) + async def setup(bot): await bot.add_cog(Mod(bot))