public async Task GetTodayBirthdayAsync() { using var service = GetService <BirthdayService>(); var birthdayUsers = await service.Service.GetUsersWithTodayBirthdayAsync(Context.Guild); if (birthdayUsers.Count == 0) { await ReplyAsync("Dnes nemá nikdo narozeniny."); return; } var pages = new List <PaginatedEmbedPage>(); foreach (var user in birthdayUsers) { var page = new PaginatedEmbedPage($"**{user.User.GetFullName()}**", thumbnail: user.User.GetUserAvatarUrl()); if (user.Birthday.Value.Year > 1) { page.AddField(new EmbedFieldBuilder().WithName("Věk").WithValue(user.Birthday.Value.ComputeDateAge())); } pages.Add(page); } var embed = new PaginatedEmbed() { Pages = pages, ResponseFor = Context.User, Title = "Dnes má narozeniny" }; await SendPaginatedEmbedAsync(embed); }
private async Task <PaginatedEmbed> CreatePaginatedEmbedAsync(List <Reminder> reminders, bool full = false) { var embed = new PaginatedEmbed() { Pages = new List <PaginatedEmbedPage>(), ResponseFor = Context.User, Title = full ? "Upozornění" : "Moje upozornění" }; var chunks = reminders.SplitInParts(EmbedBuilder.MaxFieldCount); foreach (var chunk in chunks) { var page = new PaginatedEmbedPage(null); foreach (var reminder in chunk) { var title = await CreateFieldTitleAsync(reminder, full); if (string.IsNullOrEmpty(title)) { continue; } page.AddField(title, $"ID: {reminder.RemindID}\nZpráva: {reminder.Message}\nZa: {(reminder.At - DateTime.Now).ToFullCzechTimeString()}"); } if (page.AnyField()) { embed.Pages.Add(page); } } return(embed); }
public async Task GetCompleteEmoteInfoListAsync() { var fields = EmoteStats.GetAllValues(true, Context.Guild.Id, true) .Where(o => Context.Guild.Emotes.Any(x => x.ToString() == o.EmoteID)) .Select(o => new EmbedFieldBuilder().WithName(o.GetRealId()).WithValue(o.GetFormatedInfo())) .ToList(); var pages = new List <PaginatedEmbedPage>(); const int maxFieldsCount = EmbedBuilder.MaxFieldCount - 1; var pagesCount = Math.Ceiling((float)fields.Count / maxFieldsCount); for (int i = 0; i < pagesCount; i++) { var page = new PaginatedEmbedPage(null); page.AddFields(fields.Skip(i * maxFieldsCount).Take(maxFieldsCount)); pages.Add(page); } var embed = new PaginatedEmbed() { Title = "Kompletní statistika emotů", Pages = pages, ResponseFor = Context.User }; await SendPaginatedEmbedAsync(embed); }
private static PaginatedEmbedPage RenderPage(IEnumerable<MathSession> sessions, bool booster) { var page = new PaginatedEmbedPage(booster ? "Server booster" : "Ostatní sessions"); foreach (var session in sessions) { page.AddField( $"#{session.ID} {(session.IsUsed ? "(Používá se)" : "")}".Trim(), $"Čas: **{TimeSpan.FromMilliseconds(session.ComputingTime)}**\nPočet použití: **{session.UsedCount.FormatWithSpaces()}**", true ); } return page; }
private async Task <PaginatedEmbedPage> CreatePageAsync(ModuleInfo module, SocketCommandContext context) { var page = new PaginatedEmbedPage($"**{module.Name}**"); foreach (var command in module.Commands) { var result = await command.CheckPreconditionsAsync(context, ServiceProvider); if (result.IsSuccess) { AddCommandToPage(page, module, command); } } return(page); }
public async Task GetModulesAsync() { var moduleIdAttribute = typeof(ModuleIDAttribute); var unloadedModules = GetUnloadedModules(); var modulesChunk = CommandService.Modules .SplitInParts(EmbedBuilder.MaxFieldCount); var pages = new List <PaginatedEmbedPage>(); foreach (var chunk in modulesChunk) { var page = new PaginatedEmbedPage(null); foreach (var item in chunk) { var attribute = item.Attributes.FirstOrDefault(o => o.GetType() == moduleIdAttribute) as ModuleIDAttribute; var info = item.Name + (string.IsNullOrEmpty(item.Group) ? "" : $" ({item.Group})"); page.AddField(attribute.ID, info + (unloadedModules.Contains(attribute.ID) ? " - **Deaktivován**" : ""), false); } if (page.AnyField()) { pages.Add(page); } } if (pages.Count == 0) { await ReplyAsync("Nebyl nalezen žádný modul."); return; } var embed = new PaginatedEmbed() { Title = "Seznam modulů", Pages = pages, ResponseFor = Context.User, Thumbnail = Context.Client.CurrentUser.GetUserAvatarUrl() }; await SendPaginatedEmbedAsync(embed); }
private void AddCommandToPage(PaginatedEmbedPage page, ModuleInfo module, CommandInfo command) { var builder = new StringBuilder() .Append(CommandPrefix); if (!string.IsNullOrEmpty(module.Group)) { builder.Append(module.Group).Append(' '); } builder .Append(command.Name).Append(' ') .Append(string.Join(" ", command.Parameters.Select(o => "{" + o.Name + "}"))); var field = new EmbedFieldBuilder() .WithName(builder.ToString()) .WithValue(ProcessSummary(command)); page.AddField(field); }
public async Task ListItemsAsync() { using var service = GetService <AutoReplyService>(); var data = service.Service.GetList(Context.Guild); if (data.Count == 0) { await ReplyAsync("Ještě nejsou uloženy žádné odpovědi."); return; } var pages = new List <PaginatedEmbedPage>(); foreach (var item in data) { var page = new PaginatedEmbedPage($"**{item.ID} - {item.MustContains}**"); var builder = new EmbedFieldBuilder() .WithName($"Odpověď: {item.Reply}") .WithValue(string.Join("\n", new[] { $"Status: {(item.IsActive ? "Aktivní" : "Neaktivní")}", $"Metoda: {item.CompareType}", $"Počet použití: {item.CallsCount.FormatWithSpaces()}", $"Case sensitive: {(item.CaseSensitive ? "Ano" : "Ne")}", $"Kanál: {item.Channel}" })); page.AddField(builder); pages.Add(page); } var embed = new PaginatedEmbed() { Title = "Automatické odpovědi", ResponseFor = Context.User, Pages = pages }; await SendPaginatedEmbedAsync(embed); }
private PaginatedEmbed GetPaginatedResult(List <EmbedFieldBuilder> fields, string title) { var pages = new List <PaginatedEmbedPage>(); const int maxFieldsCount = EmbedBuilder.MaxFieldCount - 1; var pagesCount = Math.Ceiling((float)fields.Count / maxFieldsCount); for (int i = 0; i < pagesCount; i++) { var page = new PaginatedEmbedPage(null); page.AddFields(fields.Skip(i * maxFieldsCount).Take(maxFieldsCount)); pages.Add(page); } return(new PaginatedEmbed() { Title = title, Pages = pages, ResponseFor = Context.User }); }
public async Task ListMethodsAsync() { var embed = new PaginatedEmbed() { Pages = new List <PaginatedEmbedPage>(), ResponseFor = Context.User, Thumbnail = Context.Client.CurrentUser.GetUserAvatarUrl(), Title = "Konfigurace metod" }; using var service = GetService <IGrillBotRepository>(); var methods = await service.Service.ConfigRepository.GetAllMethods(Context.Guild.Id, true).ToListAsync(); foreach (var group in methods.GroupBy(o => o.Group)) { var page = new PaginatedEmbedPage(null); foreach (var method in group) { var value = string.Join("\n", new[] { $"ID: **{method.ID}**", $"Počet oprávnění: **{method.Permissions.Count.FormatWithSpaces()}**", $"Počet použití: **{method.UsedCount.FormatWithSpaces()}**" }); page.AddField($"{method.Group}/{method.Command}", value); } if (page.AnyField()) { embed.Pages.Add(page); } } await SendPaginatedEmbedAsync(embed); }
public async Task ListUnverifyAsync() { var users = await UnverifyService.ListPersonsAsync(Context.Guild); if (users.Count == 0) { await ReplyAsync("Nikdo zatím nemá odebraný přístup."); return; } var pages = new List <PaginatedEmbedPage>(); foreach (var user in users) { var page = new PaginatedEmbedPage($"**{user.Username}**"); page.AddField(new EmbedFieldBuilder().WithName("ID").WithValue(user.ID)); page.AddField(new EmbedFieldBuilder().WithName("Do kdy").WithValue(user.EndDateTime.ToLocaleDatetime())); page.AddField(new EmbedFieldBuilder().WithName("Role").WithValue(string.Join(", ", user.Roles))); page.AddField(new EmbedFieldBuilder().WithName("Extra kanály").WithValue(user.ChannelOverrideList)); page.AddField(new EmbedFieldBuilder().WithName("Důvod").WithValue(user.Reason)); pages.Add(page); } var embed = new PaginatedEmbed() { Title = "Seznam osob s odebraným přístupem", Pages = pages, ResponseFor = Context.User, Thumbnail = Context.Client.CurrentUser.GetUserAvatarUrl() }; await SendPaginatedEmbedAsync(embed); }
public async Task ListUnverifyAsync() { using var service = GetService <UnverifyService>(); var profiles = await service.Service.GetCurrentUnverifies(Context.Guild); if (profiles.Count == 0) { await ReplyAsync("Nikdo zatím nemá odebraný přístup."); return; } var pages = new List <PaginatedEmbedPage>(); foreach (var profile in profiles.Select(o => o.Profile)) { var page = new PaginatedEmbedPage($"**{profile.DestinationUser.GetFullName()}**", thumbnail: profile.DestinationUser.GetUserAvatarUrl()); page.AddField("ID", profile.DestinationUser.Id.ToString()); page.AddField("Začátek", profile.StartDateTime.ToLocaleDatetime(), true); page.AddField("Konec", profile.EndDateTime.ToLocaleDatetime(), true); page.AddField("Končí za", (profile.EndDateTime - DateTime.Now).ToFullCzechTimeString(), true); if (profile.RolesToKeep.Count > 0) { foreach (var chunk in profile.RolesToKeep.Select(o => o.Mention).SplitInParts(40)) { page.AddField("Ponechané role", string.Join(", ", chunk)); } } if (profile.RolesToRemove.Count > 0) { foreach (var chunk in profile.RolesToRemove.Select(o => o.Mention).SplitInParts(40)) { page.AddField("Odebrané role", string.Join(", ", chunk)); } } if (profile.ChannelsToKeep.Count > 0) { foreach (var chunk in profile.ChannelsToKeep.Select(o => $"<#{o.Channel.Id}>").SplitInParts(40)) { page.AddField("Ponechané kanály", string.Join(", ", chunk)); } } if (profile.ChannelsToRemove.Count > 0) { foreach (var chunk in profile.ChannelsToRemove.Select(o => $"<#{o.Channel.Id}>").SplitInParts(40)) { page.AddField("Odebrané kanály", string.Join(", ", chunk)); } } page.AddField("Důvod", profile.Reason); pages.Add(page); } var embed = new PaginatedEmbed() { Title = "Seznam osob s odebraným přístupem", Pages = pages, ResponseFor = Context.User, Thumbnail = Context.Client.CurrentUser.GetUserAvatarUrl() }; await SendPaginatedEmbedAsync(embed); }