feat(webhooks): add message create event
This commit is contained in:
parent
e48e39eeb1
commit
1822788e4d
@ -30,17 +30,19 @@ namespace PluralKit.Bot
|
|||||||
private readonly ModelRepository _repo;
|
private readonly ModelRepository _repo;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly WebhookExecutorService _webhookExecutor;
|
private readonly WebhookExecutorService _webhookExecutor;
|
||||||
|
private readonly DispatchService _dispatch;
|
||||||
private readonly ProxyMatcher _matcher;
|
private readonly ProxyMatcher _matcher;
|
||||||
private readonly IMetrics _metrics;
|
private readonly IMetrics _metrics;
|
||||||
private readonly IDiscordCache _cache;
|
private readonly IDiscordCache _cache;
|
||||||
private readonly LastMessageCacheService _lastMessage;
|
private readonly LastMessageCacheService _lastMessage;
|
||||||
private readonly DiscordApiClient _rest;
|
private readonly DiscordApiClient _rest;
|
||||||
|
|
||||||
public ProxyService(LogChannelService logChannel, ILogger logger, WebhookExecutorService webhookExecutor, IDatabase db,
|
public ProxyService(LogChannelService logChannel, ILogger logger, WebhookExecutorService webhookExecutor, DispatchService dispatch, IDatabase db,
|
||||||
ProxyMatcher matcher, IMetrics metrics, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest, LastMessageCacheService lastMessage)
|
ProxyMatcher matcher, IMetrics metrics, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest, LastMessageCacheService lastMessage)
|
||||||
{
|
{
|
||||||
_logChannel = logChannel;
|
_logChannel = logChannel;
|
||||||
_webhookExecutor = webhookExecutor;
|
_webhookExecutor = webhookExecutor;
|
||||||
|
_dispatch = dispatch;
|
||||||
_db = db;
|
_db = db;
|
||||||
_matcher = matcher;
|
_matcher = matcher;
|
||||||
_metrics = metrics;
|
_metrics = metrics;
|
||||||
@ -295,6 +297,8 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
Task LogMessageToChannel() => _logChannel.LogMessage(ctx, sentMessage, triggerMessage, proxyMessage).AsTask();
|
Task LogMessageToChannel() => _logChannel.LogMessage(ctx, sentMessage, triggerMessage, proxyMessage).AsTask();
|
||||||
|
|
||||||
|
Task DispatchWebhook() => _dispatch.Dispatch(ctx.SystemId.Value, sentMessage);
|
||||||
|
|
||||||
async Task DeleteProxyTriggerMessage()
|
async Task DeleteProxyTriggerMessage()
|
||||||
{
|
{
|
||||||
// Wait a second or so before deleting the original message
|
// Wait a second or so before deleting the original message
|
||||||
@ -313,11 +317,11 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run post-proxy actions (simultaneously; order doesn't matter)
|
// Run post-proxy actions (simultaneously; order doesn't matter)
|
||||||
// Note that only AddMessage is using our passed-in connection, careful not to pass it elsewhere and run into conflicts
|
|
||||||
await Task.WhenAll(
|
await Task.WhenAll(
|
||||||
DeleteProxyTriggerMessage(),
|
DeleteProxyTriggerMessage(),
|
||||||
SaveMessageInDatabase(),
|
SaveMessageInDatabase(),
|
||||||
LogMessageToChannel()
|
LogMessageToChannel(),
|
||||||
|
DispatchWebhook()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user