2023-07-18 15:25:02 +03:00
|
|
|
using System.Text.Json.Nodes;
|
2023-07-09 16:32:14 +03:00
|
|
|
using Remora.Rest.Core;
|
2023-01-18 17:39:24 +03:00
|
|
|
|
2023-09-30 16:58:32 +03:00
|
|
|
namespace Octobot.Data;
|
2023-01-18 17:39:24 +03:00
|
|
|
|
2023-07-09 16:32:14 +03:00
|
|
|
/// <summary>
|
|
|
|
/// Stores information about a guild. This information is not accessible via the Discord API.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>This information is stored on disk as a JSON file.</remarks>
|
2023-08-02 23:51:16 +03:00
|
|
|
public sealed class GuildData
|
|
|
|
{
|
2023-01-18 17:39:24 +03:00
|
|
|
public readonly Dictionary<ulong, MemberData> MemberData;
|
2023-08-02 23:51:16 +03:00
|
|
|
public readonly string MemberDataPath;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
|
|
public readonly Dictionary<ulong, ScheduledEventData> ScheduledEvents;
|
2023-08-02 23:51:16 +03:00
|
|
|
public readonly string ScheduledEventsPath;
|
|
|
|
public readonly JsonNode Settings;
|
|
|
|
public readonly string SettingsPath;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
|
|
public GuildData(
|
2023-08-02 23:51:16 +03:00
|
|
|
JsonNode settings, string settingsPath,
|
2023-07-09 16:32:14 +03:00
|
|
|
Dictionary<ulong, ScheduledEventData> scheduledEvents, string scheduledEventsPath,
|
2023-08-02 23:51:16 +03:00
|
|
|
Dictionary<ulong, MemberData> memberData, string memberDataPath)
|
|
|
|
{
|
2023-07-18 15:25:02 +03:00
|
|
|
Settings = settings;
|
|
|
|
SettingsPath = settingsPath;
|
2023-07-09 16:32:14 +03:00
|
|
|
ScheduledEvents = scheduledEvents;
|
|
|
|
ScheduledEventsPath = scheduledEventsPath;
|
|
|
|
MemberData = memberData;
|
|
|
|
MemberDataPath = memberDataPath;
|
2023-01-18 17:39:24 +03:00
|
|
|
}
|
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
public MemberData GetOrCreateMemberData(Snowflake memberId)
|
2023-08-02 23:51:16 +03:00
|
|
|
{
|
2023-10-04 18:21:10 +03:00
|
|
|
if (MemberData.TryGetValue(memberId.Value, out var existing))
|
2023-08-02 23:51:16 +03:00
|
|
|
{
|
|
|
|
return existing;
|
|
|
|
}
|
2023-01-18 17:39:24 +03:00
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
var newData = new MemberData(memberId.Value);
|
|
|
|
MemberData.Add(memberId.Value, newData);
|
2023-01-18 17:39:24 +03:00
|
|
|
return newData;
|
|
|
|
}
|
|
|
|
}
|