mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MinecraftClient.Mcp;
|
|
|
|
public sealed class MccMcpChatHistoryEntry
|
|
{
|
|
public required DateTimeOffset TimestampUtc { get; init; }
|
|
public required string Kind { get; init; }
|
|
public required string Text { get; init; }
|
|
public string? Sender { get; init; }
|
|
public string? Message { get; init; }
|
|
public string? Json { get; init; }
|
|
}
|
|
|
|
public static class MccMcpChatHistoryStore
|
|
{
|
|
private static readonly object historyLock = new();
|
|
private static readonly List<MccMcpChatHistoryEntry> history = new();
|
|
private const int MaxEntries = 500;
|
|
|
|
public static void Add(MccMcpChatHistoryEntry entry)
|
|
{
|
|
lock (historyLock)
|
|
{
|
|
history.Add(entry);
|
|
if (history.Count > MaxEntries)
|
|
history.RemoveRange(0, history.Count - MaxEntries);
|
|
}
|
|
}
|
|
|
|
public static MccMcpChatHistoryEntry[] GetLatest(int maxCount)
|
|
{
|
|
int count = Math.Clamp(maxCount, 1, MaxEntries);
|
|
lock (historyLock)
|
|
{
|
|
return history.TakeLast(count).ToArray();
|
|
}
|
|
}
|
|
|
|
public static void Clear()
|
|
{
|
|
lock (historyLock)
|
|
{
|
|
history.Clear();
|
|
}
|
|
}
|
|
}
|