27 lines
856 B
C#
27 lines
856 B
C#
using System;
|
|
using System.Linq;
|
|
using ChaosBot.Models;
|
|
using System.Text.Json;
|
|
|
|
namespace ChaosBot.Repositories
|
|
{
|
|
public static class ConfigurationRepository
|
|
{
|
|
public static T GetValue<T>(string key, ulong guildId)
|
|
{
|
|
return GetValue<T>(key, guildId, default);
|
|
}
|
|
|
|
public static T GetValue<T>(string key, ulong guildId, T defaultValue)
|
|
{
|
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
|
{
|
|
Configuration config = dbContext.Configuration
|
|
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
|
if (String.IsNullOrEmpty(config.SerializedValue))
|
|
return defaultValue;
|
|
return JsonSerializer.Deserialize<T>(config.SerializedValue);
|
|
}
|
|
}
|
|
}
|
|
} |