1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00
Octobot/Boyfriend/GuildConfig.cs

49 lines
1.6 KiB
C#
Raw Normal View History

2022-01-30 11:43:15 +03:00
using System.Globalization;
using Newtonsoft.Json;
2021-12-15 09:19:14 +03:00
namespace Boyfriend;
public class GuildConfig {
2022-01-30 11:43:15 +03:00
public ulong? Id { get; }
public string? Lang { get; set; }
public string? Prefix { get; set; }
public bool? RemoveRolesOnMute { get; set; }
public bool? UseSystemChannel { get; set; }
public bool? SendWelcomeMessages { get; set; }
public bool? ReceiveStartupMessages { get; set; }
public string? WelcomeMessage { get; set; }
public ulong? DefaultRole { get; set; }
public ulong? MuteRole { get; set; }
public ulong? AdminLogChannel { get; set; }
public ulong? BotLogChannel { get; set; }
public Dictionary<ulong, List<ulong>>? RolesRemovedOnMute { get; private set; }
2021-12-15 09:19:14 +03:00
2022-01-30 11:43:15 +03:00
public GuildConfig(ulong id) {
2021-12-15 09:19:14 +03:00
Id = id;
2022-01-30 11:43:15 +03:00
Validate();
}
public void Validate() {
if (Id == null) throw new Exception("Something went horribly, horribly wrong");
Lang ??= "ru";
Messages.Culture = new CultureInfo(Lang);
Prefix ??= "!";
RemoveRolesOnMute ??= false;
UseSystemChannel ??= true;
SendWelcomeMessages ??= true;
ReceiveStartupMessages ??= true;
WelcomeMessage ??= Messages.DefaultWelcomeMessage;
DefaultRole ??= 0;
MuteRole ??= 0;
AdminLogChannel ??= 0;
BotLogChannel ??= 0;
RolesRemovedOnMute ??= new Dictionary<ulong, List<ulong>>();
2021-12-15 09:19:14 +03:00
}
public async Task Save() {
2022-01-30 11:43:15 +03:00
Validate();
RolesRemovedOnMute!.TrimExcess();
await File.WriteAllTextAsync("config_" + Id + ".json", JsonConvert.SerializeObject(this));
2021-12-15 09:19:14 +03:00
}
2022-01-30 11:43:15 +03:00
}