Disforget/Delete.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2023-02-22 22:03:01 +01:00
namespace Disforget;
public class Delete
{
public Delete(List<Message> messages)
{
_messages = messages;
_cli = Utils.CreateClient();
}
2023-02-23 10:27:59 +01:00
private readonly HttpClient _cli;
private readonly List<Message> _messages;
2023-02-22 22:03:01 +01:00
public async Task<int> StartDeletion()
{
int cnt = 1;
int repeats = 0;
foreach (var msg in _messages)
{
await Task.Delay(1500);
REQ:
var resp = await _cli.DeleteAsync($"https://discord.com/api/v9/channels/{msg.ChannelId}/messages/{msg.Id}");
Console.Write($"\x1b[2K\rRequest {cnt}/{_messages.Count} Status: {resp.StatusCode} [{(resp.IsSuccessStatusCode ? "OK" : "REPEATING")}] ... ({_messages.Count - cnt} left)");
if ((int)resp.StatusCode / 100 == 4)
{
cnt++;
continue;
}
2023-02-22 22:03:01 +01:00
if (!resp.IsSuccessStatusCode)
{
await Task.Delay(30000);
repeats++;
goto REQ;
}
cnt++;
}
return repeats;
}
}