async Task ShowException(ulong exceptionId, [CallFlag('f', "full", Flags.EXCEPTION_F)] bool full = false) { var exception = await Database.FindById <Error>(exceptionId); if (exception == null) { await ReplyAsync(ExceptionText.NOTFOUND, ReplyType.Error, exceptionId); return; } var user = Client.GetUser(exception.User ?? 0); var channel = Client.GetChannel(exception.Channel ?? 0) as IMessageChannel; var message = channel?.GetMessageAsync(exception.Message ?? 0)?.Result as IUserMessage; if (full) { var text = TextResource.GetResource(ExceptionText.USER) + $":\n{(user?.Username ?? TBLocalisation.UNKNOWNUSER)}#{user?.Discriminator ?? "0000"} ({user?.Id})\n" + TextResource.GetResource(ExceptionText.CHANNEL) + $":\n{channel.Name} ({channel.Id})\n"; if (channel is IGuildChannel guildChannel) { text += $"{TextResource.GetResource(ExceptionText.GUILD)}:\n{guildChannel.Guild.Name} ({guildChannel.Guild.Id})\n"; } text += $"{TextResource.GetResource(ExceptionText.MESSAGE)}:\n{message.Content}\n\n"; text += exception.Content; await Reply().WithAttachment(() => text.ToStream(), $"Exception{exceptionId}.txt") .WithMessage(new LocalisedString(ExceptionText.FULLMESSAGE, ReplyType.Success, exceptionId)) .SendAsync(); } else { var builder = new LocalisedEmbedBuilder { Timestamp = exception.Time, Color = Color.Red }.WithRawDescription(exception.Description) .AddField(f => f.WithName(ExceptionText.MESSAGE).WithRawValue(message.Content)) .AddInlineField(f => f.WithName(ExceptionText.CHANNEL).WithRawValue($"{channel.Name} ({channel.Id})")); if (user == null) { builder.WithAuthor(a => a.WithName(TBLocalisation.UNKNOWNUSER)); } else { builder.WithAuthor(a => a.WithIconUrl(user.GetAvatarUrl()).WithRawName($"{user.Username}#{user.Discriminator}")); } if (channel is IGuildChannel guildChannel) { builder.AddInlineField(f => f.WithName(ExceptionText.GUILD).WithRawValue($"{guildChannel.Guild.Name} ({guildChannel.Guild.Id})")); } await ReplyAsync(builder); } }
private static ILocalisable <EmbedBuilder> GetBuilder(Embed embed) { if (embed == null) { return(null); } var builder = new LocalisedEmbedBuilder() { Fields = embed.Fields.Select(f => (LocalisedFieldBuilder)(new EmbedFieldBuilder().WithIsInline(f.Inline).WithName(f.Name).WithValue(f.Value))) .ToList() }; if (embed.Author != null) { builder.WithAuthor(new EmbedAuthorBuilder { IconUrl = embed.Author?.IconUrl, Name = embed.Author?.Name, Url = embed.Author?.Url }); } if (embed.Color != null) { builder.WithColor(embed.Color.Value); } builder.WithRawDescription(embed.Description); if (embed.Footer != null) { builder.WithFooter(new EmbedFooterBuilder { IconUrl = embed.Footer?.IconUrl, Text = embed.Footer?.Text }); } if (embed.Image != null) { builder.WithRawImageUrl(embed.Image?.Url); } if (embed.Thumbnail != null) { builder.WithRawThumbnailUrl(embed.Thumbnail?.Url); } if (embed.Timestamp != null) { builder.WithTimestamp(embed.Timestamp.Value); } builder.WithRawTitle(embed.Title); builder.WithRawUrl(embed.Url); return(builder); }