Skip to content

Commit

Permalink
Fix the move command
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Oct 1, 2024
1 parent acbc387 commit 35d1ef0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Commands/Moderation/MoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ public sealed class MoveCommand
[Command("move"), Description("Moves a chunk of messages (inclusive) to a different channel."), RequirePermissions(DiscordPermissions.ManageMessages | DiscordPermissions.ReadMessageHistory)]
public async ValueTask MoveAsync(CommandContext context, DiscordChannel channel, DiscordMessage firstMessage, DiscordMessage? lastMessage = null)
{
await context.DeleteResponseAsync();
await context.DeferResponseAsync();

List<DiscordUser> users = [];
List<DiscordMessage> messages = [];
await foreach (DiscordMessage message in firstMessage.Channel!.GetMessagesAfterAsync(firstMessage.Id))
{
if (!users.Contains(message.Author!))
{
users.Add(message.Author!);
}

messages.Add(message);
if (message.Id == lastMessage?.Id)
{
Expand All @@ -50,7 +56,7 @@ public async ValueTask MoveAsync(CommandContext context, DiscordChannel channel,
{
Username = $"{context.Guild!.CurrentMember.Username} (Message Mover)",
AvatarUrl = context.Guild.CurrentMember.AvatarUrl,
Content = $"Started moving messages. This may take awhile.\nFirst message: {firstMessage.JumpLink}\nLast message: {(lastMessage is null ? "Latest message." : lastMessage.JumpLink)}"
Content = $"I've started moving messages. This may take a moment.\nFirst message: {firstMessage.JumpLink}\nLast message: {(lastMessage is null ? "Latest message." : lastMessage.JumpLink)}"
};

DiscordWebhook webhook;
Expand Down Expand Up @@ -107,7 +113,8 @@ public async ValueTask MoveAsync(CommandContext context, DiscordChannel channel,

await webhook.ExecuteAsync(webhookBuilder);
}
await webhook.ExecuteAsync(new DiscordWebhookBuilder().WithUsername(context.Guild.CurrentMember.Username + " (Message Mover)").WithAvatarUrl(context.Guild.CurrentMember.AvatarUrl).WithContent($"Messages have been moved."));

await webhook.ExecuteAsync(new DiscordWebhookBuilder().WithUsername(context.Guild.CurrentMember.Username + " (Message Mover)").WithAvatarUrl(context.Guild.CurrentMember.AvatarUrl).WithContent($"I've finished moving messages. {messages.Count:N0} messages have been moved.\n-# Cc {string.Join(", ", users.OrderBy(user => user.Id).Select(x => x.Mention))}"));
await webhook.DeleteAsync();
await context.RespondAsync($"{messages.Count:N0} messages have been moved.");
}
Expand Down

0 comments on commit 35d1ef0

Please sign in to comment.