diff --git a/Commands/SlashCommands.cs b/Commands/SlashCommands.cs index 96e4d9c..82b8de1 100644 --- a/Commands/SlashCommands.cs +++ b/Commands/SlashCommands.cs @@ -20,6 +20,8 @@ namespace PoisnCopy; | Permissions.CreatePublicThreads | Permissions.ManageThreads | Permissions.SendMessagesInThreads + | Permissions.ManageEmojis + | Permissions.UseExternalEmojis )] public class SlashCommands : ApplicationCommandModule { @@ -96,7 +98,7 @@ string new_channel_name var messag = await selectedChannel.GetMessagesAsync(); var messCopy = messag.ToList(); - var more = await selectedChannel.GetMessagesAsync(100); + var more = await selectedChannel.GetMessagesBeforeAsync(messCopy.LastOrDefault().Id); while (more.Count > 0) { @@ -117,7 +119,8 @@ await ctx.EditResponseAsync( var newChan = await ctx.Guild.CreateChannelAsync( new_channel_name, - selectedChannel.Type + selectedChannel.Type, + nsfw: selectedChannel.IsNSFW ); await ctx.EditResponseAsync( @@ -125,9 +128,16 @@ await ctx.EditResponseAsync( $"Posting {messCopy.Count} messages... (this could take awhile)" ) ); - + using var httpClient = new HttpClient(); foreach (var mes in messCopy) { + if (mes.Embeds.Count > 0) + { + var embeds = new DiscordMessageBuilder().AddEmbeds(mes.Embeds); + await newChan.SendMessageAsync(embeds); + await Task.Delay(800); + } + if (!string.IsNullOrEmpty(mes.Content)) { var whAu = new EmbedAuthor @@ -141,30 +151,35 @@ await ctx.EditResponseAsync( Author = whAu, Timestamp = mes.Timestamp }; - await newChan.SendMessageAsync(what); await Task.Delay(800); } - if (mes.Attachments.Count > 0) + foreach (var att in mes.Attachments) { - foreach (var att in mes.Attachments) + var whAu = new EmbedAuthor { - var whAu = new EmbedAuthor - { - Name = mes.Author.Username, - IconUrl = mes.Author.AvatarUrl - }; - var what = new DiscordEmbedBuilder - { - ImageUrl = att.Url, - Author = whAu, - Timestamp = mes.Timestamp - }; + Name = mes.Author.Username, + IconUrl = mes.Author.AvatarUrl + }; + var what = new DiscordEmbedBuilder + { + Description = att.FileName, + Author = whAu, + Timestamp = mes.Timestamp, + }; - await newChan.SendMessageAsync(what); - await Task.Delay(800); - } + await newChan.SendMessageAsync(what); + await Task.Delay(800); + var attachStream = await httpClient.GetStreamAsync(att.Url); + + // upload attachment to discord + var attachDiscord = new DiscordMessageBuilder().AddFiles( + new Dictionary { { att.FileName, attachStream } } + ); + + await newChan.SendMessageAsync(attachDiscord); + await Task.Delay(800); } }