mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
WIP: port fronters embed to CV2
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled
Build and push Rust service Docker images / rust docker build (push) Has been cancelled
rust checks / cargo fmt (push) Has been cancelled
Some checks failed
Build and push Docker image / .net docker build (push) Has been cancelled
.net checks / run .net tests (push) Has been cancelled
.net checks / dotnet-format (push) Has been cancelled
Build and push Rust service Docker images / rust docker build (push) Has been cancelled
rust checks / cargo fmt (push) Has been cancelled
This commit is contained in:
parent
83f866384a
commit
981546647a
7 changed files with 244 additions and 2 deletions
|
|
@ -596,6 +596,8 @@ public partial class CommandTree
|
||||||
return ctx.Execute<Config>(null, m => m.HidListPadding(ctx));
|
return ctx.Execute<Config>(null, m => m.HidListPadding(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "show" }, new[] { "color", "colour", "colors", "colours" }) || ctx.Match("showcolor", "showcolour", "showcolors", "showcolours", "colorcode", "colorhex"))
|
if (ctx.MatchMultiple(new[] { "show" }, new[] { "color", "colour", "colors", "colours" }) || ctx.Match("showcolor", "showcolour", "showcolors", "showcolours", "colorcode", "colorhex"))
|
||||||
return ctx.Execute<Config>(null, m => m.CardShowColorHex(ctx));
|
return ctx.Execute<Config>(null, m => m.CardShowColorHex(ctx));
|
||||||
|
if (ctx.MatchMultiple(new[] { "fronter", "front" }, new[] { "list" }, new[] { "format" }) || ctx.Match("fronterlistformat", "frontlistformat", "flf"))
|
||||||
|
return ctx.Execute<Config>(null, m => m.FronterListFormat(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "name" }, new[] { "format" }) || ctx.Match("nameformat", "nf"))
|
if (ctx.MatchMultiple(new[] { "name" }, new[] { "format" }) || ctx.Match("nameformat", "nf"))
|
||||||
return ctx.Execute<Config>(null, m => m.NameFormat(ctx));
|
return ctx.Execute<Config>(null, m => m.NameFormat(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "member", "group" }, new[] { "limit" }) || ctx.Match("limit"))
|
if (ctx.MatchMultiple(new[] { "member", "group" }, new[] { "limit" }) || ctx.Match("limit"))
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using NodaTime.TimeZones;
|
||||||
using PluralKit.Core;
|
using PluralKit.Core;
|
||||||
|
|
||||||
namespace PluralKit.Bot;
|
namespace PluralKit.Bot;
|
||||||
|
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
private record PaginatedConfigItem(string Key, string Description, string? CurrentValue, string DefaultValue);
|
private record PaginatedConfigItem(string Key, string Description, string? CurrentValue, string DefaultValue);
|
||||||
|
|
@ -130,6 +131,13 @@ public class Config
|
||||||
"disabled"
|
"disabled"
|
||||||
));
|
));
|
||||||
|
|
||||||
|
items.Add(new(
|
||||||
|
"fronter list format",
|
||||||
|
"Whether to show the fronter list as full or short.",
|
||||||
|
ctx.Config.FronterListFormat.ToUserString(),
|
||||||
|
"short"
|
||||||
|
));
|
||||||
|
|
||||||
items.Add(new(
|
items.Add(new(
|
||||||
"Proxy Switch",
|
"Proxy Switch",
|
||||||
"Switching behavior when proxy tags are used",
|
"Switching behavior when proxy tags are used",
|
||||||
|
|
@ -591,6 +599,29 @@ public class Config
|
||||||
await ctx.Reply($"Showing color codes on system/member/group cards is now {EnabledDisabled(newVal)}.");
|
await ctx.Reply($"Showing color codes on system/member/group cards is now {EnabledDisabled(newVal)}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task FronterListFormat(Context ctx)
|
||||||
|
{
|
||||||
|
if (!ctx.HasNext())
|
||||||
|
{
|
||||||
|
var msg = $"Format of the fronter list is currently **{ctx.Config.FronterListFormat}**.";
|
||||||
|
await ctx.Reply(msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var badInputError = "Valid list format settings are `short` or `full`.";
|
||||||
|
if (ctx.Match("full", "f"))
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { FronterListFormat = SystemConfig.ListFormat.Full });
|
||||||
|
await ctx.Reply($"Fronter lists are now formatted as `full`");
|
||||||
|
}
|
||||||
|
else if (ctx.Match("short", "s"))
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { FronterListFormat = SystemConfig.ListFormat.Short });
|
||||||
|
await ctx.Reply($"Fronter lists are now formatted as `short`");
|
||||||
|
}
|
||||||
|
else throw new PKError(badInputError);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task ProxySwitch(Context ctx)
|
public async Task ProxySwitch(Context ctx)
|
||||||
{
|
{
|
||||||
if (!ctx.HasNext())
|
if (!ctx.HasNext())
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,12 @@ public class SystemFront
|
||||||
var sw = await ctx.Repository.GetLatestSwitch(system.Id);
|
var sw = await ctx.Repository.GetLatestSwitch(system.Id);
|
||||||
if (sw == null) throw Errors.NoRegisteredSwitches;
|
if (sw == null) throw Errors.NoRegisteredSwitches;
|
||||||
|
|
||||||
await ctx.Reply(embed: await _embeds.CreateFronterEmbed(sw, ctx.Zone, ctx.LookupContextFor(system.Id)));
|
if (ctx.MatchFlag("show-embed", "se"))
|
||||||
|
{
|
||||||
|
await ctx.Reply(text: EmbedService.LEGACY_EMBED_WARNING, embed: await _embeds.CreateFronterEmbed(sw, ctx.Zone, ctx.LookupContextFor(system.Id)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await ctx.Reply(components: await _embeds.CreateFronterMessageComponents(ctx, system, sw, ctx.LookupContextFor(system.Id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SystemFrontHistory(Context ctx, PKSystem system)
|
public async Task SystemFrontHistory(Context ctx, PKSystem system)
|
||||||
|
|
|
||||||
|
|
@ -766,6 +766,185 @@ public class EmbedService
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<MessageComponent[]> CreateFronterMessageComponents(Context cctx, PKSystem system, PKSwitch sw, LookupContext ctx)
|
||||||
|
{
|
||||||
|
var formatType = cctx.Config.FronterListFormat;
|
||||||
|
if (cctx.MatchFlag("short")) formatType = SystemConfig.ListFormat.Short;
|
||||||
|
if (cctx.MatchFlag("full")) formatType = SystemConfig.ListFormat.Full;
|
||||||
|
|
||||||
|
if (formatType == SystemConfig.ListFormat.Full)
|
||||||
|
{
|
||||||
|
return await CreateFronterList(cctx, system, sw, ctx);
|
||||||
|
}
|
||||||
|
return await CreateFronterListShort(cctx, system, sw, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MessageComponent[]> CreateFronterListShort(Context cctx, PKSystem system, PKSwitch sw, LookupContext ctx)
|
||||||
|
{
|
||||||
|
var systemGuildSettings = await _repo.GetSystemGuild(cctx.Guild.Id, system.Id);
|
||||||
|
var members = await _db.Execute(c => _repo.GetSwitchMembers(c, sw.Id).ToListAsync().AsTask());
|
||||||
|
var memberStr = "*(no fronter)*";
|
||||||
|
|
||||||
|
if (members.Count > 0)
|
||||||
|
{
|
||||||
|
memberStr = "";
|
||||||
|
foreach (var item in members.Select((value, i) => new { i, value }))
|
||||||
|
{
|
||||||
|
memberStr += item.i == 0 ? "" : ", ";
|
||||||
|
if (memberStr.Length < 900)
|
||||||
|
memberStr += item.value.NameFor(ctx);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberStr += $"*({members.Count - item.i} not shown)*";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"## Current fronter(s) in {systemGuildSettings.DisplayName ?? system.NameFor(ctx) ?? $"`{system.Hid}`"}"
|
||||||
|
},
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Container,
|
||||||
|
AccentColor = members.FirstOrDefault()?.Color?.ToDiscordColor(),
|
||||||
|
Components = [
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"**Current fronters:** \n{memberStr}"
|
||||||
|
},
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Separator,
|
||||||
|
},
|
||||||
|
new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"**Since:** {DiscordUtils.InstantToTimestampString(sw.Timestamp)} (<t:{sw.Timestamp.ToUnixTimeSeconds()}:R>)"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MessageComponent[]> CreateFronterList(Context cctx, PKSystem system, PKSwitch sw, LookupContext ctx)
|
||||||
|
{
|
||||||
|
var systemGuildSettings = await _repo.GetSystemGuild(cctx.Guild.Id, system.Id);
|
||||||
|
var members = await _db.Execute(c => _repo.GetSwitchMembers(c, sw.Id).ToListAsync().AsTask());
|
||||||
|
var memberStr = "*(no fronter)*";
|
||||||
|
var memberList = new List<MessageComponent>();
|
||||||
|
|
||||||
|
if (members.Count > 0)
|
||||||
|
{
|
||||||
|
memberStr = "";
|
||||||
|
foreach (var item in members.Select((value, i) => new { i, value }))
|
||||||
|
{
|
||||||
|
if (item.i < 5)
|
||||||
|
{
|
||||||
|
var guildSettings = cctx.Guild != null ? await _repo.GetMemberGuild(cctx.Guild.Id, item.value.Id) : null;
|
||||||
|
var avatar = guildSettings?.AvatarUrl ?? item.value.AvatarFor(ctx) ?? systemGuildSettings.AvatarUrl ?? system.AvatarFor(ctx);
|
||||||
|
var pronouns = item.value.PronounsFor(ctx);
|
||||||
|
var displayName = (guildSettings?.DisplayName) ?? item.value.DisplayName;
|
||||||
|
|
||||||
|
var headerText = "";
|
||||||
|
if (!displayName.EmptyOrNull() && item.value.NamePrivacy.CanAccess(ctx))
|
||||||
|
{
|
||||||
|
headerText += $"**Display name:** {displayName}\n";
|
||||||
|
}
|
||||||
|
if (!pronouns.EmptyOrNull())
|
||||||
|
{
|
||||||
|
headerText += $"**Pronouns:** {item.value.PronounsFor(ctx)}\n";
|
||||||
|
}
|
||||||
|
headerText += $"[View on dashboard]({_coreConfig.DashboardBaseUrl}/profile/m/{item.value.Hid})";
|
||||||
|
var nameItem = new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"### {item.value.NameFor(ctx)}\n{headerText}"
|
||||||
|
};
|
||||||
|
if (!avatar.EmptyOrNull())
|
||||||
|
{
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Section,
|
||||||
|
Components = [nameItem],
|
||||||
|
Accessory = new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Thumbnail,
|
||||||
|
Media = new ComponentMedia()
|
||||||
|
{
|
||||||
|
Url = avatar.TryGetCleanCdnUrl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberList.Add(nameItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Separator,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberStr += item.i == 5 ? "+ " : ", ";
|
||||||
|
if (memberStr.Length < 900)
|
||||||
|
memberStr += item.value.NameFor(ctx);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberStr += $"*({members.Count - item.i} not shown)*";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (memberStr.Length > 0)
|
||||||
|
{
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"{memberStr}"
|
||||||
|
});
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Separator,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = "*(no fronter)*"
|
||||||
|
});
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Separator
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
memberList.Add(new MessageComponent()
|
||||||
|
{
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"**Since:** {DiscordUtils.InstantToTimestampString(sw.Timestamp)} (<t:{sw.Timestamp.ToUnixTimeSeconds()}:R>)"
|
||||||
|
});
|
||||||
|
return [
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Text,
|
||||||
|
Content = $"## Current fronter(s) in {systemGuildSettings.DisplayName ?? system.NameFor(ctx) ?? $"`{system.Hid}`"}"
|
||||||
|
},
|
||||||
|
new MessageComponent(){
|
||||||
|
Type = ComponentType.Container,
|
||||||
|
AccentColor = members.FirstOrDefault()?.Color?.ToDiscordColor(),
|
||||||
|
Components = [
|
||||||
|
.. memberList.ToArray()
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<MessageComponent[]> CreateMessageInfoMessageComponents(FullMessage msg, bool showContent, SystemConfig? ccfg = null)
|
public async Task<MessageComponent[]> CreateMessageInfoMessageComponents(FullMessage msg, bool showContent, SystemConfig? ccfg = null)
|
||||||
{
|
{
|
||||||
var channel = await _cache.GetOrFetchChannel(_rest, msg.Message.Guild ?? 0, msg.Message.Channel);
|
var channel = await _cache.GetOrFetchChannel(_rest, msg.Message.Guild ?? 0, msg.Message.Channel);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
public Partial<bool> CardShowColorHex { get; set; }
|
public Partial<bool> CardShowColorHex { 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<SystemConfig.ListFormat> FronterListFormat { get; set; }
|
||||||
public Partial<SystemConfig.ProxySwitchAction> 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
|
||||||
|
|
@ -43,6 +44,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
.With("hid_display_caps", HidDisplayCaps)
|
.With("hid_display_caps", HidDisplayCaps)
|
||||||
.With("hid_list_padding", HidListPadding)
|
.With("hid_list_padding", HidListPadding)
|
||||||
.With("card_show_color_hex", CardShowColorHex)
|
.With("card_show_color_hex", CardShowColorHex)
|
||||||
|
.With("fronter_list_format", FronterListFormat)
|
||||||
.With("proxy_switch", ProxySwitch)
|
.With("proxy_switch", ProxySwitch)
|
||||||
.With("name_format", NameFormat)
|
.With("name_format", NameFormat)
|
||||||
);
|
);
|
||||||
|
|
@ -112,6 +114,9 @@ public class SystemConfigPatch: PatchObject
|
||||||
if (CardShowColorHex.IsPresent)
|
if (CardShowColorHex.IsPresent)
|
||||||
o.Add("card_show_color_hex", CardShowColorHex.Value);
|
o.Add("card_show_color_hex", CardShowColorHex.Value);
|
||||||
|
|
||||||
|
if (FronterListFormat.IsPresent)
|
||||||
|
o.Add("fronter_list_format", FronterListFormat.Value.ToUserString());
|
||||||
|
|
||||||
if (ProxySwitch.IsPresent)
|
if (ProxySwitch.IsPresent)
|
||||||
o.Add("proxy_switch", ProxySwitch.Value.ToUserString());
|
o.Add("proxy_switch", ProxySwitch.Value.ToUserString());
|
||||||
|
|
||||||
|
|
@ -158,6 +163,13 @@ public class SystemConfigPatch: PatchObject
|
||||||
if (o.ContainsKey("card_show_color_hex"))
|
if (o.ContainsKey("card_show_color_hex"))
|
||||||
patch.CardShowColorHex = o.Value<bool>("card_show_color_hex");
|
patch.CardShowColorHex = o.Value<bool>("card_show_color_hex");
|
||||||
|
|
||||||
|
if (o.ContainsKey("fronter_list_format"))
|
||||||
|
patch.FronterListFormat = o.Value<string>("fronter_list_format") switch
|
||||||
|
{
|
||||||
|
"full" => SystemConfig.ListFormat.Full,
|
||||||
|
_ => SystemConfig.ListFormat.Short,
|
||||||
|
};
|
||||||
|
|
||||||
if (o.ContainsKey("proxy_switch"))
|
if (o.ContainsKey("proxy_switch"))
|
||||||
patch.ProxySwitch = o.Value<string>("proxy_switch") switch
|
patch.ProxySwitch = o.Value<string>("proxy_switch") switch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ public class SystemConfig
|
||||||
public bool CardShowColorHex { get; }
|
public bool CardShowColorHex { get; }
|
||||||
public HidPadFormat HidListPadding { get; }
|
public HidPadFormat HidListPadding { get; }
|
||||||
public ProxySwitchAction ProxySwitch { get; }
|
public ProxySwitchAction ProxySwitch { get; }
|
||||||
|
public ListFormat FronterListFormat { get; }
|
||||||
public string NameFormat { get; }
|
public string NameFormat { get; }
|
||||||
|
|
||||||
public enum HidPadFormat
|
public enum HidPadFormat
|
||||||
|
|
@ -40,6 +41,11 @@ public class SystemConfig
|
||||||
New = 1,
|
New = 1,
|
||||||
Add = 2,
|
Add = 2,
|
||||||
}
|
}
|
||||||
|
public enum ListFormat
|
||||||
|
{
|
||||||
|
Short = 0,
|
||||||
|
Full = 1,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SystemConfigExt
|
public static class SystemConfigExt
|
||||||
|
|
@ -62,6 +68,7 @@ public static class SystemConfigExt
|
||||||
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("card_show_color_hex", cfg.CardShowColorHex);
|
o.Add("card_show_color_hex", cfg.CardShowColorHex);
|
||||||
|
o.Add("fronter_list_format", cfg.FronterListFormat.ToUserString());
|
||||||
o.Add("proxy_switch", cfg.ProxySwitch.ToUserString());
|
o.Add("proxy_switch", cfg.ProxySwitch.ToUserString());
|
||||||
o.Add("name_format", cfg.NameFormat);
|
o.Add("name_format", cfg.NameFormat);
|
||||||
|
|
||||||
|
|
@ -77,5 +84,5 @@ public static class SystemConfigExt
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToUserString(this SystemConfig.ProxySwitchAction val) => val.ToString().ToLower();
|
public static string ToUserString(this SystemConfig.ProxySwitchAction val) => val.ToString().ToLower();
|
||||||
|
public static string ToUserString(this SystemConfig.ListFormat val) => val.ToString().ToLower();
|
||||||
}
|
}
|
||||||
6
crates/migrate/data/migrations/54.sql
Normal file
6
crates/migrate/data/migrations/54.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- database version 54
|
||||||
|
-- add short/full option for fronter list
|
||||||
|
|
||||||
|
alter table system_config add column fronter_list_format int default 0;
|
||||||
|
|
||||||
|
update info set schema_version = 54;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue