mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 16:50:10 +00:00
feat: alternate proxy switch mode "add"
This commit is contained in:
parent
2555f7922c
commit
82b57de3e3
9 changed files with 65 additions and 17 deletions
|
|
@ -30,7 +30,7 @@ public partial class CommandTree
|
||||||
public static Command ConfigShowPrivate = new Command("config show private", "config show private [on|off]", "Sets whether private information is shown to linked accounts by default");
|
public static Command ConfigShowPrivate = new Command("config show private", "config show private [on|off]", "Sets whether private information is shown to linked accounts by default");
|
||||||
public static Command ConfigMemberDefaultPrivacy = new("config private member", "config private member [on|off]", "Sets whether member privacy is automatically set to private when creating a new member");
|
public static Command ConfigMemberDefaultPrivacy = new("config private member", "config private member [on|off]", "Sets whether member privacy is automatically set to private when creating a new member");
|
||||||
public static Command ConfigGroupDefaultPrivacy = new("config private group", "config private group [on|off]", "Sets whether group privacy is automatically set to private when creating a new group");
|
public static Command ConfigGroupDefaultPrivacy = new("config private group", "config private group [on|off]", "Sets whether group privacy is automatically set to private when creating a new group");
|
||||||
public static Command ConfigProxySwitch = new Command("config proxyswitch", "config proxyswitch [on|off]", "Sets whether to log a switch every time a proxy tag is used");
|
public static Command ConfigProxySwitch = new Command("config proxyswitch", "config proxyswitch [on|add|off]", "Sets whether to log a switch every time a proxy tag is used");
|
||||||
public static Command ConfigNameFormat = new Command("config nameformat", "config nameformat [format]", "Changes your system's username formatting");
|
public static Command ConfigNameFormat = new Command("config nameformat", "config nameformat [format]", "Changes your system's username formatting");
|
||||||
public static Command AutoproxySet = new Command("autoproxy", "autoproxy [off|front|latch|member]", "Sets your system's autoproxy mode for the current server");
|
public static Command AutoproxySet = new Command("autoproxy", "autoproxy [off|front|latch|member]", "Sets your system's autoproxy mode for the current server");
|
||||||
public static Command AutoproxyOff = new Command("autoproxy off", "autoproxy off", "Disables autoproxying for your system in the current server");
|
public static Command AutoproxyOff = new Command("autoproxy off", "autoproxy off", "Disables autoproxying for your system in the current server");
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,8 @@ public class Config
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
"Proxy Switch",
|
"Proxy Switch",
|
||||||
"Whether using a proxy tag logs a switch",
|
"Whether using a proxy tag logs a switch",
|
||||||
EnabledDisabled(ctx.Config.ProxySwitch),
|
ctx.Config.ProxySwitch.ToUserString(),
|
||||||
"disabled"
|
"off"
|
||||||
));
|
));
|
||||||
|
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
|
|
@ -555,14 +555,29 @@ public class Config
|
||||||
{
|
{
|
||||||
if (!ctx.HasNext())
|
if (!ctx.HasNext())
|
||||||
{
|
{
|
||||||
var msg = $"Logging a switch every time a proxy tag is used is currently **{EnabledDisabled(ctx.Config.ProxySwitch)}**.";
|
string msg = ctx.Config.ProxySwitch switch
|
||||||
|
{
|
||||||
|
SystemConfig.ProxySwitchAction.Off => "Currently, when you proxy as a member, no switches are logged or changed.",
|
||||||
|
SystemConfig.ProxySwitchAction.New => "When you proxy as a member, currently it makes a new switch.",
|
||||||
|
SystemConfig.ProxySwitchAction.Add => "When you proxy as a member, currently it adds them to the current switch.",
|
||||||
|
_ => throw new Exception("unreachable"),
|
||||||
|
};
|
||||||
await ctx.Reply(msg);
|
await ctx.Reply(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newVal = ctx.MatchToggle(false);
|
// toggle = false means off, toggle = true means on, otherwise if they said add that means add. If none of those, error
|
||||||
|
var toggle = ctx.MatchToggleOrNull(false);
|
||||||
|
var newVal = toggle == false ? SystemConfig.ProxySwitchAction.Off : toggle == true ? SystemConfig.ProxySwitchAction.New : ctx.Match("add", "a") ? SystemConfig.ProxySwitchAction.Add : throw new PKError("You must pass either \"on\" or \"off\" to this command.");
|
||||||
|
|
||||||
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { ProxySwitch = newVal });
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { ProxySwitch = newVal });
|
||||||
await ctx.Reply($"Logging a switch every time a proxy tag is used is now {EnabledDisabled(newVal)}.");
|
switch (newVal)
|
||||||
|
{
|
||||||
|
case SystemConfig.ProxySwitchAction.Off: await ctx.Reply("Now when you proxy as a member, no switches are logged or changed."); break;
|
||||||
|
case SystemConfig.ProxySwitchAction.New: await ctx.Reply("When you proxy as a member, it now makes a new switch."); break;
|
||||||
|
case SystemConfig.ProxySwitchAction.Add: await ctx.Reply("When you proxy as a member, it now adds them to the current switch."); break;
|
||||||
|
default: throw new Exception("unreachable");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NameFormat(Context ctx)
|
public async Task NameFormat(Context ctx)
|
||||||
|
|
|
||||||
|
|
@ -521,9 +521,22 @@ public class ProxyService
|
||||||
|
|
||||||
Task DispatchWebhook() => _dispatch.Dispatch(ctx.SystemId.Value, sentMessage);
|
Task DispatchWebhook() => _dispatch.Dispatch(ctx.SystemId.Value, sentMessage);
|
||||||
|
|
||||||
Task MaybeLogSwitch() => (ctx.ProxySwitch && !Array.Exists(ctx.LastSwitchMembers, element => element == match.Member.Id))
|
async Task MaybeLogSwitch()
|
||||||
? _db.Execute(conn => _repo.AddSwitch(conn, (SystemId)ctx.SystemId, new[] { match.Member.Id }))
|
{
|
||||||
: Task.CompletedTask;
|
if (ctx.ProxySwitch == SystemConfig.ProxySwitchAction.New && !Array.Exists(ctx.LastSwitchMembers, element => element == match.Member.Id))
|
||||||
|
await _db.Execute(conn => _repo.AddSwitch(conn, (SystemId)ctx.SystemId, new[] { match.Member.Id }));
|
||||||
|
else if (ctx.ProxySwitch == SystemConfig.ProxySwitchAction.Add)
|
||||||
|
{
|
||||||
|
if (ctx.LastSwitchMembers.Length == 0)
|
||||||
|
{
|
||||||
|
await _db.Execute(conn => _repo.AddSwitch(conn, (SystemId)ctx.SystemId, new[] { match.Member.Id }));
|
||||||
|
}
|
||||||
|
else if (!Array.Exists(ctx.LastSwitchMembers, element => element == match.Member.Id))
|
||||||
|
{
|
||||||
|
await _db.Execute(conn => _repo.EditSwitch(conn, (SwitchId)ctx.LastSwitch, ctx.LastSwitchMembers.Append(match.Member.Id).ToList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async Task DeleteProxyTriggerMessage()
|
async Task DeleteProxyTriggerMessage()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,6 @@ public class MessageContext
|
||||||
public int? LatchTimeout { get; }
|
public int? LatchTimeout { get; }
|
||||||
public bool CaseSensitiveProxyTags { get; }
|
public bool CaseSensitiveProxyTags { get; }
|
||||||
public bool ProxyErrorMessageEnabled { get; }
|
public bool ProxyErrorMessageEnabled { get; }
|
||||||
public bool ProxySwitch { get; }
|
public SystemConfig.ProxySwitchAction ProxySwitch { get; }
|
||||||
public bool DenyBotUsage { get; }
|
public bool DenyBotUsage { get; }
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ create function message_context(account_id bigint, guild_id bigint, channel_id b
|
||||||
latch_timeout integer,
|
latch_timeout integer,
|
||||||
case_sensitive_proxy_tags bool,
|
case_sensitive_proxy_tags bool,
|
||||||
proxy_error_message_enabled bool,
|
proxy_error_message_enabled bool,
|
||||||
proxy_switch bool,
|
proxy_switch int,
|
||||||
name_format text,
|
name_format text,
|
||||||
|
|
||||||
tag_enabled bool,
|
tag_enabled bool,
|
||||||
|
|
|
||||||
11
PluralKit.Core/Database/Migrations/49.sql
Normal file
11
PluralKit.Core/Database/Migrations/49.sql
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
-- database version 49
|
||||||
|
-- change proxy switch config to an enum
|
||||||
|
|
||||||
|
alter table system_config
|
||||||
|
alter column proxy_switch drop default,
|
||||||
|
alter column proxy_switch type int
|
||||||
|
using case when proxy_switch then 1 else 0 end,
|
||||||
|
alter column proxy_switch set default 0,
|
||||||
|
add constraint proxy_switch_check check (proxy_switch = ANY (ARRAY[0,1,2]));
|
||||||
|
|
||||||
|
update info set schema_version = 49;
|
||||||
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
||||||
internal class DatabaseMigrator
|
internal class DatabaseMigrator
|
||||||
{
|
{
|
||||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||||
private const int TargetSchemaVersion = 48;
|
private const int TargetSchemaVersion = 49;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public DatabaseMigrator(ILogger logger)
|
public DatabaseMigrator(ILogger logger)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
public Partial<bool> HidDisplayCaps { get; set; }
|
public Partial<bool> HidDisplayCaps { get; set; }
|
||||||
public Partial<string?> NameFormat { get; set; }
|
public Partial<string?> NameFormat { get; set; }
|
||||||
public Partial<SystemConfig.HidPadFormat> HidListPadding { get; set; }
|
public Partial<SystemConfig.HidPadFormat> HidListPadding { get; set; }
|
||||||
public Partial<bool> ProxySwitch { get; set; }
|
public Partial<SystemConfig.ProxySwitchAction> ProxySwitch { get; set; }
|
||||||
|
|
||||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||||
.With("ui_tz", UiTz)
|
.With("ui_tz", UiTz)
|
||||||
|
|
@ -107,7 +107,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
o.Add("hid_list_padding", HidListPadding.Value.ToUserString());
|
o.Add("hid_list_padding", HidListPadding.Value.ToUserString());
|
||||||
|
|
||||||
if (ProxySwitch.IsPresent)
|
if (ProxySwitch.IsPresent)
|
||||||
o.Add("proxy_switch", ProxySwitch.Value);
|
o.Add("proxy_switch", ProxySwitch.Value.ToUserString());
|
||||||
|
|
||||||
if (NameFormat.IsPresent)
|
if (NameFormat.IsPresent)
|
||||||
o.Add("name_format", NameFormat.Value);
|
o.Add("name_format", NameFormat.Value);
|
||||||
|
|
@ -150,7 +150,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
patch.HidDisplayCaps = o.Value<bool>("hid_display_caps");
|
patch.HidDisplayCaps = o.Value<bool>("hid_display_caps");
|
||||||
|
|
||||||
if (o.ContainsKey("proxy_switch"))
|
if (o.ContainsKey("proxy_switch"))
|
||||||
patch.ProxySwitch = o.Value<bool>("proxy_switch");
|
patch.ProxySwitch = o.Value<SystemConfig.ProxySwitchAction>("proxy_switch");
|
||||||
|
|
||||||
if (o.ContainsKey("name_format"))
|
if (o.ContainsKey("name_format"))
|
||||||
patch.NameFormat = o.Value<string>("name_format");
|
patch.NameFormat = o.Value<string>("name_format");
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class SystemConfig
|
||||||
public bool HidDisplaySplit { get; }
|
public bool HidDisplaySplit { get; }
|
||||||
public bool HidDisplayCaps { get; }
|
public bool HidDisplayCaps { get; }
|
||||||
public HidPadFormat HidListPadding { get; }
|
public HidPadFormat HidListPadding { get; }
|
||||||
public bool ProxySwitch { get; }
|
public ProxySwitchAction ProxySwitch { get; }
|
||||||
public string NameFormat { get; }
|
public string NameFormat { get; }
|
||||||
|
|
||||||
public enum HidPadFormat
|
public enum HidPadFormat
|
||||||
|
|
@ -33,6 +33,12 @@ public class SystemConfig
|
||||||
Left = 1,
|
Left = 1,
|
||||||
Right = 2,
|
Right = 2,
|
||||||
}
|
}
|
||||||
|
public enum ProxySwitchAction
|
||||||
|
{
|
||||||
|
Off = 0,
|
||||||
|
New = 1,
|
||||||
|
Add = 2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SystemConfigExt
|
public static class SystemConfigExt
|
||||||
|
|
@ -54,7 +60,7 @@ public static class SystemConfigExt
|
||||||
o.Add("hid_display_split", cfg.HidDisplaySplit);
|
o.Add("hid_display_split", cfg.HidDisplaySplit);
|
||||||
o.Add("hid_display_caps", cfg.HidDisplayCaps);
|
o.Add("hid_display_caps", cfg.HidDisplayCaps);
|
||||||
o.Add("hid_list_padding", cfg.HidListPadding.ToUserString());
|
o.Add("hid_list_padding", cfg.HidListPadding.ToUserString());
|
||||||
o.Add("proxy_switch", cfg.ProxySwitch);
|
o.Add("proxy_switch", cfg.ProxySwitch.ToUserString());
|
||||||
o.Add("name_format", cfg.NameFormat);
|
o.Add("name_format", cfg.NameFormat);
|
||||||
|
|
||||||
o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));
|
o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));
|
||||||
|
|
@ -67,4 +73,7 @@ public static class SystemConfigExt
|
||||||
if (val == SystemConfig.HidPadFormat.None) return "off";
|
if (val == SystemConfig.HidPadFormat.None) return "off";
|
||||||
return val.ToString().ToLower();
|
return val.ToString().ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToUserString(this SystemConfig.ProxySwitchAction val) => val.ToString().ToLower();
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue