Initial commit, basic proxying working

This commit is contained in:
Ske
2020-12-22 13:15:26 +01:00
parent c3f6becea4
commit a6fbd869be
109 changed files with 3539 additions and 359 deletions

View File

@@ -3,14 +3,15 @@ using System.Threading.Tasks;
using App.Metrics;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Myriad.Gateway;
using PluralKit.Core;
namespace PluralKit.Bot
{
public class MessageEdited: IEventHandler<MessageUpdateEventArgs>
public class MessageEdited: IEventHandler<MessageUpdateEvent>
{
private readonly LastMessageCacheService _lastMessageCache;
private readonly ProxyService _proxy;
@@ -29,22 +30,23 @@ namespace PluralKit.Bot
_client = client;
}
public async Task Handle(DiscordClient shard, MessageUpdateEventArgs evt)
public async Task Handle(Shard shard, MessageUpdateEvent evt)
{
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);
// 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);
}
}
}