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 17, 2024
1 parent 65a764a commit 4de89df
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Commands/Moderation/MoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,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 @@ -49,7 +55,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 @@ -106,7 +112,7 @@ 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 4de89df

Please sign in to comment.