Add per-server per-system proxy enable toggle

This commit is contained in:
Ske
2019-12-22 14:15:56 +01:00
parent 857b0488b9
commit 639c813ce7
5 changed files with 62 additions and 5 deletions

View File

@@ -64,11 +64,9 @@ namespace PluralKit {
public ISet<ulong> Blacklist { get; set; }
}
public struct ChannelConfig
public class SystemGuildSettings
{
public ulong Id { get; set; }
public bool OnList { get; set; }
public bool LogMessages { get; set; }
public bool ProxyEnabled { get; set; } = true;
}
public interface IDataStore
@@ -118,6 +116,9 @@ namespace PluralKit {
/// <param name="system">The system to check in.</param>
Task<IEnumerable<PKMember>> GetConflictingProxies(PKSystem system, ProxyTag tag);
Task<SystemGuildSettings> GetSystemGuildSettings(PKSystem system, ulong guild);
Task SetGuildSystemSettings(PKSystem system, ulong guild, SystemGuildSettings settings);
/// <summary>
/// Creates a system, auto-generating its corresponding IDs.
/// </summary>
@@ -384,6 +385,25 @@ namespace PluralKit {
});
}
public async Task<SystemGuildSettings> GetSystemGuildSettings(PKSystem system, ulong guild)
{
using (var conn = await _conn.Obtain())
return await conn.QuerySingleOrDefaultAsync<SystemGuildSettings>(
"select * from system_guild where system = @System and guild = @Guild",
new {System = system.Id, Guild = guild}) ?? new SystemGuildSettings();
}
public async Task SetGuildSystemSettings(PKSystem system, ulong guild, SystemGuildSettings settings)
{
using (var conn = await _conn.Obtain())
await conn.ExecuteAsync("insert into system_guild (system, guild, proxy_enabled) values (@System, @Guild, @ProxyEnabled) on conflict (system, guild) do update set proxy_enabled = @ProxyEnabled", new
{
System = system.Id,
Guild = guild,
ProxyEnabled = settings.ProxyEnabled
});
}
public async Task<PKSystem> CreateSystem(string systemName = null) {
string hid;
do

View File

@@ -20,6 +20,16 @@ create table if not exists systems
ui_tz text not null default 'UTC'
);
create table if not exists system_guild
(
system serial not null references systems (id) on delete cascade,
guild bigint not null,
proxy_enabled bool not null default true,
primary key (system, guild)
);
create table if not exists members
(
id serial primary key,