Skip to content

Commit

Permalink
fix files and embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
PizzaConsole committed Jun 7, 2023
1 parent 0653e33 commit b1b48a1
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions Commands/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace PoisnCopy;
| Permissions.CreatePublicThreads
| Permissions.ManageThreads
| Permissions.SendMessagesInThreads
| Permissions.ManageEmojis
| Permissions.UseExternalEmojis
)]
public class SlashCommands : ApplicationCommandModule
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -117,17 +119,25 @@ await ctx.EditResponseAsync(

var newChan = await ctx.Guild.CreateChannelAsync(
new_channel_name,
selectedChannel.Type
selectedChannel.Type,
nsfw: selectedChannel.IsNSFW
);

await ctx.EditResponseAsync(
new DiscordWebhookBuilder().WithContent(
$"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
Expand All @@ -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<string, Stream> { { att.FileName, attachStream } }
);

await newChan.SendMessageAsync(attachDiscord);
await Task.Delay(800);
}
}

Expand Down

0 comments on commit b1b48a1

Please sign in to comment.