private async static Task <IEnumerable <Page> > GetGuildMovieNightsPages(DiscordGuild guild, List <GuildMovieNight> movieNights, InteractivityExtension interactivity, bool hasManageServer) { StringBuilder guildMovieNightStringBuilder = new(); int count = 1; HashSet <string> movieNightIds = movieNights.Select(mn => mn.MovieNightStartHangfireId).ToHashSet(); Dictionary <string, RecurringJobDto> rJobDict = JobStorage .Current.GetConnection() .GetRecurringJobs() .Where(job => movieNightIds.Contains(job.Id)) .ToDictionary(rjobDto => rjobDto.Id); if (movieNights.Count == rJobDict.Count) { foreach (GuildMovieNight movieNight in movieNights) { string cron = rJobDict[movieNight.MovieNightStartHangfireId].Cron; cron = CronExpressionDescriptor.ExpressionDescriptor.GetDescription(cron); guildMovieNightStringBuilder.AppendLine($"{count}. {(hasManageServer ? $"{(await guild.GetMemberAsync(movieNight.HostId)).DisplayName}: " : "")}{cron}"); count += 1; } } if (!movieNights.Any() || !rJobDict.Any()) { guildMovieNightStringBuilder.AppendLine("This guild does not have any movie nights currently running"); } DiscordEmbedBuilder embedBase = new DiscordEmbedBuilder().WithTitle("Select a movie night by typing: <number>"); return(interactivity.GeneratePagesInEmbed(guildMovieNightStringBuilder.ToString(), DSharpPlus.Interactivity.Enums.SplitType.Line, embedBase)); }
private static IEnumerable <Page> GetGuildPrefixPages(List <GuildPrefix> guildPrefixes, InteractivityExtension interactivity, DiscordEmbedBuilder pageEmbedBase = null) { StringBuilder guildPrefixesStringBuilder = new StringBuilder(); int count = 1; foreach (GuildPrefix prefix in guildPrefixes) { guildPrefixesStringBuilder.AppendLine($"{count}. {prefix.Prefix}"); count++; } return(interactivity.GeneratePagesInEmbed(guildPrefixesStringBuilder.ToString(), SplitType.Line, pageEmbedBase)); }
private static IEnumerable <Page> GetGuildMovieSuggestionsPages(List <GuildMovieSuggestion> suggestions, InteractivityExtension interactivity) { StringBuilder builder = new StringBuilder(); int count = 1; foreach (GuildMovieSuggestion suggestion in suggestions) { builder.AppendLine($"{count}. {suggestion.Title}"); count += 1; } DiscordEmbedBuilder embedBase = new DiscordEmbedBuilder().WithTitle("Select a movie night by typing: <number>"); return(interactivity.GeneratePagesInEmbed(builder.ToString(), DSharpPlus.Interactivity.Enums.SplitType.Line, embedBase)); }
public async Task TagList(CommandContext ctx) { InteractivityExtension intex = ctx.Client.GetInteractivity(); List <DiscordUrieTag> tags = await discordUrie.Config.GetTags(ctx.Guild); if (tags.Count <= 0) { return; } IEnumerable <string> TagKeys = tags.Select(xr => xr.Tag); string EditedTags = String.Join("\n", TagKeys); await intex.SendPaginatedMessageAsync(ctx.Channel, ctx.User, intex.GeneratePagesInEmbed(EditedTags, DSharpPlus.Interactivity.Enums.SplitType.Line)); }
private static IEnumerable <Page> GetScheduledEventsPages(IEnumerable <GuildBackgroundJob> guildEventJobs, InteractivityExtension interactivity, DiscordEmbedBuilder pageEmbedBase = null) { StringBuilder guildEventsStringBuilder = new StringBuilder(); int count = 1; foreach (GuildBackgroundJob job in guildEventJobs) { guildEventsStringBuilder.AppendLine($"{count}. {job.JobName} - {job.ScheduledTimeInTimeZone.LocalDateTime:f}"); count++; } if (!guildEventJobs.Any()) { guildEventsStringBuilder.AppendLine("This guild doesn't have any scheduled events."); } return(interactivity.GeneratePagesInEmbed(guildEventsStringBuilder.ToString(), SplitType.Line, embedbase: pageEmbedBase)); }
private static IEnumerable <Page> GetGuildEventsPages(IEnumerable <GuildEvent> guildEvents, InteractivityExtension interactivity, DiscordEmbedBuilder pageEmbedBase = null) { StringBuilder guildEventsStringBuilder = new StringBuilder(); int count = 1; foreach (GuildEvent guildEvent in guildEvents) { guildEventsStringBuilder.AppendLine($"{count}. {guildEvent.EventName}"); count++; } if (!guildEvents.Any()) { guildEventsStringBuilder.AppendLine("This guild doesn't have any defined events."); } return(interactivity.GeneratePagesInEmbed(guildEventsStringBuilder.ToString(), SplitType.Line, embedbase: pageEmbedBase)); }
public async Task UnregisterRoyalRoadFictionAsync(CommandContext context) { DbResult <IEnumerable <GuildNovelRegistration> > getNovelRegistrationsResult = await this.mediator.Send(new GuildNovelRegistrations.GetMemberNovelRegistrations(context.Member)); if (!getNovelRegistrationsResult.TryGetValue(out var novelRegistrations)) { await context.RespondAsync("There was an error getting your Novel Registrations. An error report has been sent to the developer. DM any extra details to the developer that you might find relevant."); throw new Exception("error using GetGuildNovelRegistration"); } GuildNovelRegistration[] allRegisteredFictions = novelRegistrations.ToArray(); StringBuilder pageString = new(); for (int i = 0; i < allRegisteredFictions.Length; i++) { pageString.AppendLine($"{i + 1}. {allRegisteredFictions[i].NovelInfo.Name}"); } DiscordEmbedBuilder builder = new DiscordEmbedBuilder().WithTitle("Select the fiction to deregister by typing the number of the fiction"); InteractivityExtension interactivity = context.Client.GetInteractivity(); IEnumerable <Page> pages = interactivity.GeneratePagesInEmbed(pageString.ToString(), DSharpPlus.Interactivity.Enums.SplitType.Line, embedbase: builder); _ = interactivity.SendPaginatedMessageAsync(context.Channel, context.User, pages); InteractivityResult <DiscordMessage> result = await interactivity.WaitForMessageAsync(message => int.TryParse(message.Content, out _)); if (!result.TimedOut) { int index = int.Parse(result.Result.Content) - 1; NovelInfo delete = allRegisteredFictions[index].NovelInfo; await this.mediator.Send(new GuildNovelRegistrations.Delete(allRegisteredFictions[index])); await context.RespondAsync($"Unregistered {delete.Name}"); } }