Merge pull request #27 from NoiTheCat/tweaks/unlimit-list

Remove top 20 distinct zone limit
This commit is contained in:
Noi 2024-05-09 22:53:47 -07:00 committed by GitHub
commit a84bf9ad7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 6 deletions

View file

@ -29,9 +29,7 @@ public class CommandsBase : InteractionModuleBase<ShardedInteractionContext> {
/// </summary>
protected static string TzPrint(string zone, bool use12hr) {
var tzdb = DateTimeZoneProviders.Tzdb;
DateTimeZone tz = tzdb.GetZoneOrNull(zone)!;
if (tz == null) throw new Exception("Encountered unknown time zone: " + zone);
DateTimeZone tz = tzdb.GetZoneOrNull(zone) ?? throw new Exception("Encountered unknown time zone: " + zone);
var now = SystemClock.Instance.GetCurrentInstant().InZone(tz);
var sortpfx = now.ToString("MMddHH", DateTimeFormatInfo.InvariantInfo);
string fullstr;

View file

@ -73,11 +73,10 @@ public class UserCommands : CommandsBase {
return;
}
// Order times by popularity to limit how many are shown, group by printed name
// Generate time and zone names to be displayed, group with associated user IDs
var sortedlist = new SortedDictionary<string, List<ulong>>();
var ampm = db.GuildSettings.Where(s => s.GuildId == Context.Guild.Id).SingleOrDefault()?.Use12HourTime ?? false;
foreach ((string area, List<ulong> users) in userlist.OrderByDescending(o => o.Value.Count).Take(20)) {
// Filter further to top 20 distinct timezones, even if they are not displayed in the final result
foreach ((string area, List<ulong> users) in userlist.OrderByDescending(o => o.Value.Count)) {
var areaprint = TzPrint(area, ampm);
if (!sortedlist.ContainsKey(areaprint)) sortedlist.Add(areaprint, new List<ulong>());
sortedlist[areaprint].AddRange(users);