Add sorting member list randomly
This commit is contained in:
parent
f6d2f4b620
commit
df7fdce144
@ -40,6 +40,7 @@ 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"))
|
||||
|
@ -75,6 +75,8 @@ namespace PluralKit.Bot
|
||||
IComparer<T> ReverseMaybe<T>(IComparer<T> c) =>
|
||||
opts.Reverse ? Comparer<T>.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<Instant?>.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
|
||||
|
Loading…
Reference in New Issue
Block a user