From f6d2f4b6209b5d5ddeb56f3438cad4c6bf869a75 Mon Sep 17 00:00:00 2001 From: acw0 Date: Tue, 4 Aug 2020 18:43:17 -0400 Subject: [PATCH 1/3] Add -all flag in random command --- PluralKit.Bot/Commands/Member.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/Member.cs b/PluralKit.Bot/Commands/Member.cs index f9285f2b..92fb5dcb 100644 --- a/PluralKit.Bot/Commands/Member.cs +++ b/PluralKit.Bot/Commands/Member.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using System.Collections.Generic; using PluralKit.Core; @@ -61,7 +62,11 @@ namespace PluralKit.Bot //Maybe move this somewhere else in the file structure since it doesn't need to get created at every command // TODO: don't buffer these, find something else to do ig - var members = await _data.GetSystemMembers(ctx.System).Where(m => m.MemberVisibility == PrivacyLevel.Public).ToListAsync(); + + List members; + if (ctx.MatchFlag("all", "a")) members = await _data.GetSystemMembers(ctx.System).ToListAsync(); + else members = await _data.GetSystemMembers(ctx.System).Where(m => m.MemberVisibility == PrivacyLevel.Public).ToListAsync(); + if (members == null || !members.Any()) throw Errors.NoMembersError; var randInt = randGen.Next(members.Count); From df7fdce14498ef73494cae20582a6a14be2a5699 Mon Sep 17 00:00:00 2001 From: acw0 Date: Tue, 4 Aug 2020 19:28:29 -0400 Subject: [PATCH 2/3] Add sorting member list randomly --- PluralKit.Bot/Commands/Lists/ContextListExt.cs | 3 ++- PluralKit.Bot/Commands/Lists/MemberListOptions.cs | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Commands/Lists/ContextListExt.cs b/PluralKit.Bot/Commands/Lists/ContextListExt.cs index f1efadb0..8bee0927 100644 --- a/PluralKit.Bot/Commands/Lists/ContextListExt.cs +++ b/PluralKit.Bot/Commands/Lists/ContextListExt.cs @@ -40,7 +40,8 @@ namespace PluralKit.Bot if (ctx.MatchFlag("by-last-fronted", "by-last-front", "by-last-switch", "blf", "bls")) p.SortProperty = SortProperty.LastSwitch; if (ctx.MatchFlag("by-last-message", "blm", "blp")) p.SortProperty = SortProperty.LastMessage; if (ctx.MatchFlag("by-birthday", "by-birthdate", "bbd")) p.SortProperty = SortProperty.Birthdate; - + if (ctx.MatchFlag("random")) p.SortProperty = SortProperty.Random; + // Sort reverse? if (ctx.MatchFlag("r", "rev", "reverse")) p.Reverse = true; diff --git a/PluralKit.Bot/Commands/Lists/MemberListOptions.cs b/PluralKit.Bot/Commands/Lists/MemberListOptions.cs index 9e00b226..2f6a7aad 100644 --- a/PluralKit.Bot/Commands/Lists/MemberListOptions.cs +++ b/PluralKit.Bot/Commands/Lists/MemberListOptions.cs @@ -75,6 +75,8 @@ namespace PluralKit.Bot IComparer ReverseMaybe(IComparer c) => opts.Reverse ? Comparer.Create((a, b) => c.Compare(b, a)) : c; + var randGen = new global::System.Random(); + var culture = StringComparer.InvariantCultureIgnoreCase; return (opts.SortProperty switch { @@ -96,6 +98,8 @@ namespace PluralKit.Bot SortProperty.LastSwitch => input .OrderByDescending(m => m.LastSwitchTime.HasValue) .ThenByDescending(m => m.LastSwitchTime, ReverseMaybe(Comparer.Default)), + SortProperty.Random => input + .OrderBy(m => randGen.Next()), _ => throw new ArgumentOutOfRangeException($"Unknown sort property {opts.SortProperty}") }) // Lastly, add a by-name fallback order for collisions (generally hits w/ lots of null values) @@ -112,7 +116,8 @@ namespace PluralKit.Bot CreationDate, LastSwitch, LastMessage, - Birthdate + Birthdate, + Random } public enum ListType From 5bc31cbf3e34de787901da04f0d19023fb8da8c0 Mon Sep 17 00:00:00 2001 From: acw0 Date: Wed, 5 Aug 2020 19:56:40 -0400 Subject: [PATCH 3/3] Fix error message --- PluralKit.Bot/Commands/Lists/MemberListOptions.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/Lists/MemberListOptions.cs b/PluralKit.Bot/Commands/Lists/MemberListOptions.cs index 2f6a7aad..6e760aed 100644 --- a/PluralKit.Bot/Commands/Lists/MemberListOptions.cs +++ b/PluralKit.Bot/Commands/Lists/MemberListOptions.cs @@ -28,7 +28,8 @@ namespace PluralKit.Bot public string CreateFilterString() { var str = new StringBuilder(); - str.Append("Sorting by "); + str.Append("Sorting "); + if (SortProperty != SortProperty.Random) str.Append("by "); str.Append(SortProperty switch { SortProperty.Name => "member name", @@ -39,6 +40,7 @@ namespace PluralKit.Bot SortProperty.LastSwitch => "last switch", SortProperty.MessageCount => "message count", SortProperty.Birthdate => "birthday", + SortProperty.Random => "randomly", _ => new ArgumentOutOfRangeException($"Couldn't find readable string for sort property {SortProperty}") });