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
l1ttleO 868b6bcaa7
time-out failsafes and new warnings
rewrote setting values in SettingsCommand.cs
fixed a bug with message edited notification on mobile
fixed an exploit with WrapInline where you could escape the code block by simply using `
moved a few things in MuteCommand.cs
cleaned up code
updated library to 3.3.2
2022-02-21 22:08:55 +05:00

55 lines
1.6 KiB
C#

using System.Globalization;
using Newtonsoft.Json;
// ReSharper disable MemberCanBePrivate.Global
namespace Boyfriend;
public class GuildConfig {
public GuildConfig(ulong id) {
Id = id;
Validate();
}
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; }
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>>();
}
public async Task Save() {
Validate();
RolesRemovedOnMute!.TrimExcess();
await File.WriteAllTextAsync("config_" + Id + ".json", JsonConvert.SerializeObject(this));
}
}