Proxy edited messages if the message is the last one in the channel, and the edit introduces proxy tags where there were none previously
This commit is contained in:
25
PluralKit.Bot/Services/LastMessageCacheService.cs
Normal file
25
PluralKit.Bot/Services/LastMessageCacheService.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
// Doing things like this instead of enabling D.NET's message cache because the message cache is, let's face it,
|
||||
// not particularly efficient? It allocates a dictionary *and* a queue for every single channel (500k in prod!)
|
||||
// whereas this is, worst case, one dictionary *entry* of a single ulong per channel, and one dictionary instance
|
||||
// on the whole instance, total. Yeah, much more efficient.
|
||||
public class LastMessageCacheService
|
||||
{
|
||||
private IDictionary<ulong, ulong> _cache = new ConcurrentDictionary<ulong, ulong>();
|
||||
|
||||
public void AddMessage(ulong channel, ulong message)
|
||||
{
|
||||
_cache[channel] = message;
|
||||
}
|
||||
|
||||
public ulong? GetLastMessage(ulong channel)
|
||||
{
|
||||
if (_cache.TryGetValue(channel, out var message)) return message;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user