This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
OctobotStealth/Boyfriend/GuildConfig.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2022-01-30 11:43:15 +03:00
using System.Globalization;
using Newtonsoft.Json;
// ReSharper disable MemberCanBePrivate.Global
2021-12-15 09:19:14 +03:00
namespace Boyfriend;
public class GuildConfig {
public GuildConfig(ulong id) {
Id = id;
Validate();
}
2022-01-30 11:43:15 +03:00
public ulong? Id { get; }
public string? Lang { get; set; }
public string? Prefix { get; set; }
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
public bool? RemoveRolesOnMute { get; set; }
public bool? UseSystemChannel { get; set; }
public bool? SendWelcomeMessages { get; set; }
public bool? ReceiveStartupMessages { get; set; }
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
public string? WelcomeMessage { get; set; }
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
public ulong? DefaultRole { get; set; }
public ulong? MuteRole { get; set; }
public ulong? AdminLogChannel { get; set; }
public ulong? BotLogChannel { get; set; }
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
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 void Validate() {
if (Id == null) throw new Exception("Something went horribly, horribly wrong");
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
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();
2022-02-02 16:14:26 +03:00
2022-01-30 11:43:15 +03:00
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
}