2021-05-03 08:29:22 +00:00
|
|
|
|
#nullable enable
|
|
|
|
|
using System.Collections.Concurrent;
|
2020-02-12 13:21:48 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2021-03-22 07:07:33 +00:00
|
|
|
|
using Myriad.Types;
|
|
|
|
|
|
2020-02-12 13:21:48 +00:00
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
|
{
|
2021-03-25 18:02:44 +00:00
|
|
|
|
// TODO: Should this be moved to Myriad.Cache?
|
2020-02-12 13:21:48 +00:00
|
|
|
|
public class LastMessageCacheService
|
|
|
|
|
{
|
2021-03-22 07:07:33 +00:00
|
|
|
|
private readonly IDictionary<ulong, CachedMessage> _cache = new ConcurrentDictionary<ulong, CachedMessage>();
|
2020-02-12 13:21:48 +00:00
|
|
|
|
|
2021-03-22 07:07:33 +00:00
|
|
|
|
public void AddMessage(Message msg)
|
2020-02-12 13:21:48 +00:00
|
|
|
|
{
|
2021-05-03 08:29:22 +00:00
|
|
|
|
_cache[msg.ChannelId] = new CachedMessage(msg.Id, msg.ReferencedMessage.Value?.Id);
|
2020-02-12 13:21:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 08:29:22 +00:00
|
|
|
|
public CachedMessage? GetLastMessage(ulong channel)
|
2020-02-12 13:21:48 +00:00
|
|
|
|
{
|
2021-05-03 08:29:22 +00:00
|
|
|
|
return _cache.TryGetValue(channel, out var message) ? message : null;
|
2020-02-12 13:21:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-22 07:07:33 +00:00
|
|
|
|
|
2021-05-03 08:29:22 +00:00
|
|
|
|
public record CachedMessage(ulong Id, ulong? ReferencedMessage);
|
2021-03-25 18:02:44 +00:00
|
|
|
|
}
|