2020-05-01 23:52:52 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2020-06-14 20:19:12 +00:00
|
|
|
using App.Metrics;
|
|
|
|
|
2020-09-20 19:49:52 +00:00
|
|
|
using DSharpPlus;
|
2020-12-22 12:15:26 +00:00
|
|
|
|
|
|
|
using Myriad.Gateway;
|
2020-05-01 23:52:52 +00:00
|
|
|
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
{
|
2020-12-22 12:15:26 +00:00
|
|
|
public class MessageEdited: IEventHandler<MessageUpdateEvent>
|
2020-05-01 23:52:52 +00:00
|
|
|
{
|
|
|
|
private readonly LastMessageCacheService _lastMessageCache;
|
|
|
|
private readonly ProxyService _proxy;
|
2020-06-13 17:36:43 +00:00
|
|
|
private readonly IDatabase _db;
|
2020-08-29 11:46:27 +00:00
|
|
|
private readonly ModelRepository _repo;
|
2020-06-14 20:19:12 +00:00
|
|
|
private readonly IMetrics _metrics;
|
2020-09-20 19:49:52 +00:00
|
|
|
private readonly DiscordShardedClient _client;
|
2020-05-01 23:52:52 +00:00
|
|
|
|
2020-09-20 19:49:52 +00:00
|
|
|
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo, DiscordShardedClient client)
|
2020-05-01 23:52:52 +00:00
|
|
|
{
|
|
|
|
_lastMessageCache = lastMessageCache;
|
|
|
|
_proxy = proxy;
|
2020-06-12 21:13:21 +00:00
|
|
|
_db = db;
|
2020-06-14 20:19:12 +00:00
|
|
|
_metrics = metrics;
|
2020-08-29 11:46:27 +00:00
|
|
|
_repo = repo;
|
2020-09-20 19:49:52 +00:00
|
|
|
_client = client;
|
2020-05-01 23:52:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 12:15:26 +00:00
|
|
|
public async Task Handle(Shard shard, MessageUpdateEvent evt)
|
2020-05-01 23:52:52 +00:00
|
|
|
{
|
2020-12-22 12:15:26 +00:00
|
|
|
// TODO: fix
|
|
|
|
// if (evt.Author?.Id == _client.CurrentUser?.Id) return;
|
|
|
|
//
|
|
|
|
// // Edit message events sometimes arrive with missing data; double-check it's all there
|
|
|
|
// if (evt.Message.Content == null || evt.Author == null || evt.Channel.Guild == null) return;
|
|
|
|
//
|
|
|
|
// // Only react to the last message in the channel
|
|
|
|
// if (_lastMessageCache.GetLastMessage(evt.Channel.Id) != evt.Message.Id) return;
|
|
|
|
//
|
|
|
|
// // Just run the normal message handling code, with a flag to disable autoproxying
|
|
|
|
// MessageContext ctx;
|
|
|
|
// await using (var conn = await _db.Obtain())
|
|
|
|
// using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
|
|
|
|
// ctx = await _repo.GetMessageContext(conn, evt.Author.Id, evt.Channel.GuildId, evt.Channel.Id);
|
|
|
|
// await _proxy.HandleIncomingMessage(shard, evt.Message, ctx, allowAutoproxy: false);
|
2020-05-01 23:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|