-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDeleteEcho.cs
41 lines (37 loc) · 1.5 KB
/
DeleteEcho.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Discord;
using System;
using System.Threading.Tasks;
using static AcegikmoDiscordBot.Program;
namespace AcegikmoDiscordBot;
internal class DeleteEcho
{
private readonly Log _log;
public DeleteEcho(Log log)
{
_log = log;
}
public async Task MessageDeletedAsync(Cacheable<IMessage, ulong> messageId,
Cacheable<IMessageChannel, ulong> socketCached)
{
var socket = await socketCached.GetOrDownloadAsync();
if (socket is IGuildChannel socketGuild && socketGuild.GuildId == ACEGIKMO_SERVER &&
socket.Id != ACEGIKMO_DELETED_MESSAGES)
{
var modchannel = await socketGuild.Guild.GetTextChannelAsync(ACEGIKMO_DELETED_MESSAGES);
if (_log.TryGetMessage(messageId.Id, out var message))
{
var after = _log.TryGetPreviousMessage(messageId.Id, socket.Id, out var previous)
? $" after <https://discordapp.com/channels/{socketGuild.GuildId}/{previous.ChannelId}/{previous.MessageId}>"
: "";
var toSend =
$"Message by {MentionUtils.MentionUser(message.AuthorId)} deleted in {MentionUtils.MentionChannel(message.ChannelId)}{after}:\n{message.Message}";
Console.WriteLine(toSend);
await modchannel.SendMessageAsync(toSend);
}
else
{
await modchannel.SendMessageAsync($"Message deleted, but not found in DB: {messageId.Id}");
}
}
}
}