Add sorting member list randomly
This commit is contained in:
parent
f6d2f4b620
commit
df7fdce144
@ -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-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-last-message", "blm", "blp")) p.SortProperty = SortProperty.LastMessage;
|
||||||
if (ctx.MatchFlag("by-birthday", "by-birthdate", "bbd")) p.SortProperty = SortProperty.Birthdate;
|
if (ctx.MatchFlag("by-birthday", "by-birthdate", "bbd")) p.SortProperty = SortProperty.Birthdate;
|
||||||
|
if (ctx.MatchFlag("random")) p.SortProperty = SortProperty.Random;
|
||||||
|
|
||||||
// Sort reverse?
|
// Sort reverse?
|
||||||
if (ctx.MatchFlag("r", "rev", "reverse"))
|
if (ctx.MatchFlag("r", "rev", "reverse"))
|
||||||
p.Reverse = true;
|
p.Reverse = true;
|
||||||
|
@ -75,6 +75,8 @@ namespace PluralKit.Bot
|
|||||||
IComparer<T> ReverseMaybe<T>(IComparer<T> c) =>
|
IComparer<T> ReverseMaybe<T>(IComparer<T> c) =>
|
||||||
opts.Reverse ? Comparer<T>.Create((a, b) => c.Compare(b, a)) : c;
|
opts.Reverse ? Comparer<T>.Create((a, b) => c.Compare(b, a)) : c;
|
||||||
|
|
||||||
|
var randGen = new global::System.Random();
|
||||||
|
|
||||||
var culture = StringComparer.InvariantCultureIgnoreCase;
|
var culture = StringComparer.InvariantCultureIgnoreCase;
|
||||||
return (opts.SortProperty switch
|
return (opts.SortProperty switch
|
||||||
{
|
{
|
||||||
@ -96,6 +98,8 @@ namespace PluralKit.Bot
|
|||||||
SortProperty.LastSwitch => input
|
SortProperty.LastSwitch => input
|
||||||
.OrderByDescending(m => m.LastSwitchTime.HasValue)
|
.OrderByDescending(m => m.LastSwitchTime.HasValue)
|
||||||
.ThenByDescending(m => m.LastSwitchTime, ReverseMaybe(Comparer<Instant?>.Default)),
|
.ThenByDescending(m => m.LastSwitchTime, ReverseMaybe(Comparer<Instant?>.Default)),
|
||||||
|
SortProperty.Random => input
|
||||||
|
.OrderBy(m => randGen.Next()),
|
||||||
_ => throw new ArgumentOutOfRangeException($"Unknown sort property {opts.SortProperty}")
|
_ => throw new ArgumentOutOfRangeException($"Unknown sort property {opts.SortProperty}")
|
||||||
})
|
})
|
||||||
// Lastly, add a by-name fallback order for collisions (generally hits w/ lots of null values)
|
// Lastly, add a by-name fallback order for collisions (generally hits w/ lots of null values)
|
||||||
@ -112,7 +116,8 @@ namespace PluralKit.Bot
|
|||||||
CreationDate,
|
CreationDate,
|
||||||
LastSwitch,
|
LastSwitch,
|
||||||
LastMessage,
|
LastMessage,
|
||||||
Birthdate
|
Birthdate,
|
||||||
|
Random
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ListType
|
public enum ListType
|
||||||
|
Loading…
Reference in New Issue
Block a user