private async void CheckReminders(object sender, ElapsedEventArgs e) { var now = DateTime.UtcNow; // Get all accounts that have at least one reminder that needs to be sent out var accounts = _globalUserAccounts.GetFilteredAccounts(acc => acc.Reminders.Any(rem => rem.DueDate < now)); foreach (var account in accounts) { var guildUser = Global.Client.GetUser(account.Id); var dmChannel = await guildUser?.GetOrCreateDMChannelAsync(); if (dmChannel == null) { return; } var toBeRemoved = new List <ReminderEntry>(); foreach (var reminder in account.Reminders) { if (reminder.DueDate >= now) { continue; } dmChannel.SendMessageAsync(reminder.Description); // Usage of a second list because trying to use // accountReminders.Remove(reminder) would break the foreach loop toBeRemoved.Add(reminder); } // Remove all elements that needs to be removed toBeRemoved.ForEach(remRem => account.Reminders.Remove(remRem)); _globalUserAccounts.SaveAccounts(account.Id); } }
public async Task ShowRichesPeople(int page = 1) { if (page < 1) { await ReplyAsync("Are you really trying that right now? **REALLY?**"); return; } var guildUserIds = Context.Guild.Users.Select(user => user.Id); // Get only accounts of this server var accounts = GlobalUserAccounts.GetFilteredAccounts(acc => guildUserIds.Contains(acc.Id)); const int usersPerPage = 9; // Calculate the highest accepted page number => amount of pages we need to be able to fit all users in them // (amount of users) / (how many to show per page + 1) results in +1 page more every time we exceed our usersPerPage var lastPageNumber = 1 + (accounts.Count / (usersPerPage + 1)); if (page > lastPageNumber) { await ReplyAsync($"There are not that many pages...\nPage {lastPageNumber} is the last one..."); return; } // Sort the accounts descending by Minuies var ordered = accounts.OrderByDescending(acc => acc.Miunies).ToList(); var embB = new EmbedBuilder() .WithTitle("These are the richest people:") .WithFooter($"Page {page}/{lastPageNumber}"); // Add fields to the embed with information of users according to the provided page we should show // Two conditions because: 1. Only get as many as we want // 2. The last page might not be completely filled so we have to interrupt early page--; for (var i = 1; i <= usersPerPage && i + usersPerPage * page <= ordered.Count; i++) { // -1 because we take the users non zero based input var account = ordered[i - 1 + usersPerPage * page]; var user = Client.GetUser(account.Id); embB.AddField($"#{i + usersPerPage * page} {user.Username}", $"{account.Miunies} Miunies", true); } await ReplyAsync("", false, embB.Build()); }
public async Task ShowRichesPeople(int page = 1) { if (page < 1) { await ReplyAsync("Are you really trying that right now? ***REALLY?***"); return; } var config = GlobalGuildAccounts.GetGuildAccount(Context.Guild.Id); var guildUserIds = Context.Guild.Users.Select(user => user.Id); var accounts = GlobalUserAccounts.GetFilteredAccounts(acc => guildUserIds.Contains(acc.Id)); const int usersPerPage = 9; // Calculate the highest accepted page number => amount of pages we need to be able to fit all users in them // (amount of users) / (how many to show per page + 1) results in +1 page more every time we exceed our usersPerPage var lastPageNumber = 1 + (accounts.Count / (usersPerPage + 1)); if (page > lastPageNumber) { await ReplyAsync($"There are not that many pages...\nPage {lastPageNumber} is the last one..."); return; } // Sort the accounts descending by currency var ordered = accounts.OrderByDescending(acc => acc.Taiyaki).ToList(); var embB = new EmbedBuilder() .WithTitle($"{config.Currency} Leaderboard:") .WithFooter($"Page {page}/{lastPageNumber}"); page--; for (var i = 1; i <= usersPerPage && i + usersPerPage * page <= ordered.Count; i++) { var account = ordered[i - 1 + usersPerPage * page]; var user = Global.Client.GetUser(account.Id); embB.WithColor(Global.NayuColor); embB.AddField($"#{i + usersPerPage * page} {user.Username}", $"{account.Taiyaki} {config.Currency}", true); } await ReplyAsync("", false, embB.Build()); }
public async Task ShowRichesPeople(int NumerStrony = 1) { if (NumerStrony < 1) { await ReplyAsync("Czy Ty naprawde próbujesz to zrobić? xD ***SRSLY?!***"); return; } var guildUserIds = Context.Guild.Users.Select(user => user.Id); // Pokaż tylko użytkowników tego serwera var accounts = GlobalUserAccounts.GetFilteredAccounts(acc => guildUserIds.Contains(acc.Id)); const int usersPerPage = 9; // Oblicz najwyższą akceptowany numer storny => amount of pages we need to be able to fit all users in them // (amount of users) / (how many to show per page + 1) results in +1 page more every time we exceed our usersPerPage var lastPageNumber = 1 + (accounts.Count / (usersPerPage + 1)); if (NumerStrony > lastPageNumber) { await ReplyAsync($"Nie ma aż tylu stron...\nStrona numer {lastPageNumber} jest ostatnia."); return; } // Sortuj użytkowników malejąco według punktów var ordered = accounts.OrderByDescending(acc => acc.Miunies).ToList(); var embB = new EmbedBuilder() .WithTitle("Najszczęśliwsi są:") .WithFooter($"Strona {NumerStrony}/{lastPageNumber}"); // Add fields to the embed with information of users according to the provided page we should show // Two conditions because: 1. Only get as many as we want // 2. The last page might not be completely filled so we have to interrupt early NumerStrony--; for (var i = 1; i <= usersPerPage && i + usersPerPage * NumerStrony <= ordered.Count; i++) { // -1 because we take the users non zero based input var account = ordered[i - 1 + usersPerPage * NumerStrony]; var user = Context.Client.GetUser(account.Id); //try to give it a medal in cases 1 - 3, if it is not possible just send it with out change var contentName = string.Empty; if (NumerStrony == 0) { switch (i) { case 1: contentName = $"🥇 #{i + usersPerPage * NumerStrony} {user.Username}"; break; case 2: contentName = $"🥈 #{i + usersPerPage * NumerStrony} {user.Username}"; break; case 3: contentName = $"🥉 #{i + usersPerPage * NumerStrony} {user.Username}"; break; default: contentName = $"#{i + usersPerPage * NumerStrony} {user.Username}"; break; } } else { contentName = $"#{i + usersPerPage * NumerStrony} {user.Username}"; } embB.AddField(contentName, $"{account.Miunies} Punktów Szczęścia", true); } await ReplyAsync("", false, embB.Build()); }