private Embed ParseEmbed(JToken json) { // Get basic data string title = json["title"]?.Value <string>(); string description = json["description"]?.Value <string>(); string url = json["url"]?.Value <string>(); DateTimeOffset?timestamp = json["timestamp"]?.Value <DateTime>().ToDateTimeOffset(); // Get color Color color = json["color"] != null ? Color.FromArgb(json["color"].Value <int>()).ResetAlpha() : Color.FromArgb(79, 84, 92); // default color // Get author EmbedAuthor author = json["author"] != null?ParseEmbedAuthor(json["author"]) : null; // Get fields EmbedField[] fields = json["fields"].EmptyIfNull().Select(ParseEmbedField).ToArray(); // Get thumbnail EmbedImage thumbnail = json["thumbnail"] != null?ParseEmbedImage(json["thumbnail"]) : null; // Get image EmbedImage image = json["image"] != null?ParseEmbedImage(json["image"]) : null; // Get footer EmbedFooter footer = json["footer"] != null?ParseEmbedFooter(json["footer"]) : null; return(new Embed(title, url, timestamp, color, author, description, fields, thumbnail, image, footer)); }
/// <summary> /// Adds meta information about the quote to the embed. /// </summary> /// <param name="message">The quoted message.</param> /// <param name="quotingUser">The quoting user.</param> /// <param name="embed">The embed to add the information to.</param> private static Embed AddMeta ( IMessage message, Snowflake quotingUser, Embed embed ) { var getUserAvatar = CDN.GetUserAvatarUrl(message.Author); var author = new EmbedAuthor($"{message.Author.Username}#{message.Author.Discriminator}") { IconUrl = getUserAvatar.IsSuccess ? getUserAvatar.Entity.ToString() : default(Optional <string>) }; return(embed with { Author = author, Footer = new EmbedFooter(GetPostedTimeInfo(message)), Colour = Color.FromArgb(95, 186, 125), Fields = new[] { CreateQuoteMarkerField(message, quotingUser) } }); }
private void WriteEmbedFooter(EmbedFooter embedFooter) { _writer.WriteStartObject("footer"); _writer.WriteString("text", embedFooter.Text); _writer.WriteString("iconUrl", embedFooter.IconUrl); _writer.WriteEndObject(); }
private static JSONContainer getFooterJSON(IEmbed embed) { EmbedFooter footer = embed.Footer.Value; JSONContainer footerJSON = JSONContainer.NewObject(); checkAddStringField(footer.Text, footerJSON, TEXT); checkAddStringField(footer.IconUrl, footerJSON, ICON_URL); return(footerJSON); }
public DiscordEmbed AddFooter(string text, string icon_url = null, string proxy_icon_url = null) { var footer = new EmbedFooter() { Text = text, IconUrl = icon_url, ProxyIconUrl = proxy_icon_url }; this.Footer = footer; return(this); }
/// <summary> /// Constructs a new embed builder using another embed as prototype. /// </summary> /// <param name="original">Embed to use as prototype.</param> public DiscordEmbedBuilder(DiscordEmbed original) : this() { Title = original.Title; Description = original.Description; Url = original.Url?.ToString(); Color = original.Color; Timestamp = original.Timestamp; if (original.Thumbnail != null) { Thumbnail = new EmbedThumbnail { Url = original.Thumbnail.Url?.ToString(), Height = original.Thumbnail.Height, Width = original.Thumbnail.Width } } ; if (original.Author != null) { Author = new EmbedAuthor { IconUrl = original.Author.IconUrl?.ToString(), Name = original.Author.Name, Url = original.Author.Url?.ToString() } } ; if (original.Footer != null) { Footer = new EmbedFooter { IconUrl = original.Footer.IconUrl?.ToString(), Text = original.Footer.Text } } ; if (original.Fields?.Any() == true) { _fields.AddRange(original.Fields); } while (_fields.Count > 25) { _fields.RemoveAt(_fields.Count - 1); } }
private async ValueTask WriteEmbedFooterAsync(EmbedFooter embedFooter) { _writer.WriteStartObject("footer"); _writer.WriteString("text", embedFooter.Text); if (!string.IsNullOrWhiteSpace(embedFooter.IconUrl)) { _writer.WriteString("iconUrl", await Context.ResolveMediaUrlAsync(embedFooter.IconUrl)); } _writer.WriteEndObject(); await _writer.FlushAsync(); }
private async ValueTask WriteEmbedFooterAsync( EmbedFooter embedFooter, CancellationToken cancellationToken = default) { _writer.WriteStartObject("footer"); _writer.WriteString("text", embedFooter.Text); if (!string.IsNullOrWhiteSpace(embedFooter.IconUrl)) { _writer.WriteString("iconUrl", await Context.ResolveMediaUrlAsync(embedFooter.IconProxyUrl ?? embedFooter.IconUrl, cancellationToken)); } _writer.WriteEndObject(); await _writer.FlushAsync(cancellationToken); }
public async Task start(CommandContext ctx) { Game.Game.setupGame(ctx.Guild); Game.Game.playing.Add(ctx.Guild, true); Game.Game.wrongGuessCounter.Add(ctx.Guild, 0); Game.Game.guessedChars.Add(ctx.Guild, new List <String>()); DiscordEmbed embed = new DiscordEmbedBuilder(); EmbedFooter footer = new EmbedFooter(); footer.Text = "Developed by Julian#5916"; var builder = new DiscordEmbedBuilder() { Title = "New Game!", Color = DiscordColor.CornflowerBlue, Description = "use .guess <char> to guess a char!", Footer = footer, }; string txt = ""; string word1; if (Game.Game.word.TryGetValue(ctx.Guild, out word1)) { word1 = word1; } for (int i = 0; i < word1.Length; i++) { txt = txt + "_ "; } int value; if (Game.Game.wrongGuessCounter.TryGetValue(ctx.Guild, out value)) { value = value; } builder.AddField("Tries Left", $"{7 - value}", false); builder.AddField("Guessed Chars", $"```{txt}```", false); await ctx.Channel.SendMessageAsync(builder); }
public Embed(Model model) { Url = model.Url; Type = model.Type; Title = model.Title; Description = model.Description; Color = model.Color.Value; Timestamp = model.Timestamp.Value; if (model.Provider.IsSpecified) { Provider = new EmbedProvider(model.Provider.Value); } if (model.Provider.IsSpecified) { Provider = new EmbedProvider(model.Provider.Value); } if (model.Thumbnail.IsSpecified) { Thumbnail = new EmbedThumbnail(model.Thumbnail.Value); } if (model.Author.IsSpecified) { Author = new EmbedAuthor(model.Author.Value); } if (model.Image.IsSpecified) { Image = EmbedImage.Create(model.Image.Value); } if (model.Video.IsSpecified) { Video = EmbedVideo.Create(model.Video.Value); } if (model.Footer.IsSpecified) { Footer = new EmbedFooter(model.Footer.Value); } if (model.Fields.IsSpecified) { Fields = model.Fields.Value.Select(EmbedField.Create).ToImmutableArray(); } else { Fields = ImmutableArray.Create <EmbedField>(); } }
public static API.EmbedFooter ToModel(this EmbedFooter entity) { return(new API.EmbedFooter { Text = entity.Text, IconUrl = entity.IconUrl }); }
public static EmbedFooterModel ToModel(this EmbedFooter footer) => footer == null ? null : new EmbedFooterModel { Text = footer.Text, IconUrl = footer.IconUrl };
public DiscordEmbed AddFooter(EmbedFooter footer) { this.Footer = footer; return(this); }
public async Task guessWord(CommandContext ctx, string word) { string word1; if (Game.Game.word.TryGetValue(ctx.Guild, out word1)) { word1 = word1; } int value; if (Game.Game.wrongGuessCounter.TryGetValue(ctx.Guild, out value)) { value = value; } Boolean value1; if (Game.Game.playing.TryGetValue(ctx.Guild, out value1)) { value1 = value1; } if (value1) { if (!(value >= 6)) { if (word1 == word) { //win EmbedFooter footer = new EmbedFooter(); footer.Text = "Developed by Julian#5916"; var builder1 = new DiscordEmbedBuilder() { Title = "You won!", Color = DiscordColor.CornflowerBlue, Description = "Goodjob, " + ctx.User.Username, Footer = footer }; Game.Game.resetGame(ctx.Guild); await ctx.Channel.SendMessageAsync(builder1).ConfigureAwait(false); } else { //lose var builder = new DiscordEmbedBuilder() { Title = "Game Over!", Color = DiscordColor.CornflowerBlue, Description = "U lost the game, the word was: " + Game.Game.word, }; Game.Game.resetGame(ctx.Guild); await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); } } else { var builder = new DiscordEmbedBuilder() { Title = "Game Over!", Color = DiscordColor.CornflowerBlue, Description = "U lost the game, the word was: " + Game.Game.word, }; Game.Game.resetGame(ctx.Guild); await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); } } else { var builder = new DiscordEmbedBuilder() { Title = "Start a game first with .start", Color = DiscordColor.CornflowerBlue, Description = ":)" }; await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); } }
public static void GetJSONFromMessageContentAndEmbed(string messageContent, IEmbed embed, out JSONContainer json) { json = JSONContainer.NewObject(); if (messageContent != null) { json.TryAddField(MESSAGECONTENT, messageContent); } if (embed != null) { JSONContainer embedJSON = JSONContainer.NewObject(); // Insert TITLE, DESCRIPTION, TITLE_URL, TIMESTAMP if (!string.IsNullOrEmpty(embed.Title)) { embedJSON.TryAddField(TITLE, embed.Title); } if (!string.IsNullOrEmpty(embed.Description)) { embedJSON.TryAddField(DESCRIPTION, embed.Description); } if (!string.IsNullOrEmpty(embed.Url)) { embedJSON.TryAddField(URL, embed.Url); } if (embed.Timestamp != null) { embedJSON.TryAddField(TIMESTAMP, embed.Timestamp?.ToString("u")); } // Insert AUTHOR if (embed.Author != null) { EmbedAuthor author = embed.Author.Value; JSONContainer authorJSON = JSONContainer.NewObject(); if (!string.IsNullOrEmpty(author.Name)) { authorJSON.TryAddField(NAME, author.Name); } if (!string.IsNullOrEmpty(author.IconUrl)) { authorJSON.TryAddField(ICON_URL, author.IconUrl); } if (!string.IsNullOrEmpty(author.Url)) { authorJSON.TryAddField(URL, author.Url); } embedJSON.TryAddField(AUTHOR, authorJSON); } // Insert THUMBNAIL, IMAGE if (embed.Thumbnail != null) { if (!string.IsNullOrEmpty(embed.Thumbnail.Value.Url)) { JSONContainer thumbnailJSON = JSONContainer.NewObject(); thumbnailJSON.TryAddField(URL, embed.Thumbnail.Value.Url); embedJSON.TryAddField(THUMBNAIL, thumbnailJSON); } } if (embed.Image != null) { if (!string.IsNullOrEmpty(embed.Image.Value.Url)) { JSONContainer imagJSON = JSONContainer.NewObject(); imagJSON.TryAddField(URL, embed.Image.Value.Url); embedJSON.TryAddField(IMAGE, imagJSON); } } // Insert Color if (embed.Color != null) { if (embed.Color.Value.RawValue != 0) { embedJSON.TryAddField(COLOR, embed.Color.Value.RawValue); } } // Insert Footer if (embed.Footer != null) { EmbedFooter footer = embed.Footer.Value; JSONContainer footerJSON = JSONContainer.NewObject(); if (!string.IsNullOrEmpty(footer.Text)) { footerJSON.TryAddField(TEXT, footer.Text); } if (!string.IsNullOrEmpty(footer.IconUrl)) { footerJSON.TryAddField(ICON_URL, footer.IconUrl); } embedJSON.TryAddField(FOOTER, footerJSON); } // Insert Fields if ((embed.Fields != null) && embed.Fields.Length > 0) { JSONContainer fieldsJSON = JSONContainer.NewArray(); foreach (Discord.EmbedField embedField in embed.Fields) { JSONContainer fieldJSON = JSONContainer.NewObject(); fieldJSON.TryAddField(NAME, embedField.Name); fieldJSON.TryAddField(VALUE, embedField.Value); fieldJSON.TryAddField(INLINE, embedField.Inline); fieldsJSON.Add(fieldJSON); } embedJSON.TryAddField(FIELDS, fieldsJSON); } json.TryAddField(EMBED, embedJSON); } }
public async Task Guess(CommandContext ctx, string guess) { Console.WriteLine("Command ran!"); string word1; if (Game.Game.word.TryGetValue(ctx.Guild, out word1)) { word1 = word1; } List <String> guessedChars; if (Game.Game.guessedChars.TryGetValue(ctx.Guild, out guessedChars)) { guessedChars = guessedChars; } Boolean value; if (Game.Game.playing.TryGetValue(ctx.Guild, out value)) { value = value; } if (value) { int value1; if (Game.Game.wrongGuessCounter.TryGetValue(ctx.Guild, out value1)) { value1 = value1; } if (!(value1 >= 7)) { Console.WriteLine(word1); Game.Game.GuessChar(ctx.Guild, guess); Console.Write("test1"); EmbedFooter footer = new EmbedFooter(); footer.Text = "Developed by Julian#5916"; var builder = new DiscordEmbedBuilder() { Title = "Hangman Game", Color = DiscordColor.CornflowerBlue, Description = "use .guess <char> to guess a char!", Footer = footer }; string txt = ""; char[] charWords = word1.ToCharArray(); for (int i = 0; i < word1.Length; i++) { if (guessedChars.Contains(charWords[i].ToString())) { txt = txt + charWords[i].ToString() + " "; } else { txt = txt + "_ "; } } Console.WriteLine("test123"); int wrongCount; if (Game.Game.wrongGuessCounter.TryGetValue(ctx.Guild, out wrongCount)) { wrongCount = wrongCount; } builder.AddField("Tries Left", $"{7 - wrongCount}", false); builder.AddField("Guessed Chars", $"```{txt}```", true); await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); if (word1.Length == guessedChars.Count) { var builder1 = new DiscordEmbedBuilder() { Title = "You won!", Color = DiscordColor.CornflowerBlue, Description = "Goodjob, " + ctx.User.Username, }; Game.Game.resetGame(ctx.Guild); await ctx.Channel.SendMessageAsync(builder1).ConfigureAwait(false); } } else { var builder = new DiscordEmbedBuilder() { Title = "Game Over!", Color = DiscordColor.CornflowerBlue, Description = "U lost the game, the word was: " + word1, }; Game.Game.resetGame(ctx.Guild); await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); } } else { var builder = new DiscordEmbedBuilder() { Title = "Start a game first with .start", Color = DiscordColor.CornflowerBlue, Description = ":)" }; await ctx.Channel.SendMessageAsync(builder).ConfigureAwait(false); } }
public static EmbedFooterBuilder ToBuilder(this EmbedFooter footer) => new EmbedFooterBuilder() { Text = footer.Text, IconUrl = footer.IconUrl, };
public RichEmbed SetFooter(EmbedFooter footer) { this.embed.Footer = footer; return(this); }
public async Task <Result> ListAvailableRolesAsync() { var baseEmbed = new Embed { Colour = _feedback.Theme.Secondary, Title = "Available character roles", Description = "These are the roles you can apply to your characters to automatically switch you " + "to that role when you assume the character.\n" + "\n" + "In order to avoid mentioning everyone that has the role, use the numerical ID or " + "role name instead of the actual mention. The ID is listed below along with the " + "role name." }; var getCharacterRoles = await _characterRoles.GetCharacterRolesAsync(_context.GuildID.Value); if (!getCharacterRoles.IsSuccess) { return(Result.FromError(getCharacterRoles)); } var characterRoles = getCharacterRoles.Entity; if (!characterRoles.Any()) { baseEmbed = baseEmbed with { Footer = new EmbedFooter("There aren't any character roles available in this server.") }; return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, new[] { baseEmbed }, ct : this.CancellationToken )); } var getGuildRoles = await _guildAPI.GetGuildRolesAsync(_context.GuildID.Value, this.CancellationToken); if (!getGuildRoles.IsSuccess) { return(Result.FromError(getGuildRoles)); } var guildRoles = getGuildRoles.Entity; var fields = characterRoles.Select ( r => { var guildRole = guildRoles.FirstOrDefault(gr => gr.ID == r.DiscordID); var roleStatus = r.Access == RoleAccess.Open ? "open to everyone" : "restricted"; var name = guildRole is null ? $"??? ({r.DiscordID} - this role appears to be deleted.)" : $"{guildRole.Name} ({r.DiscordID})"; var value = $"*This role is {roleStatus}.*"; return(new EmbedField(name, value)); } ); var pages = PageFactory.FromFields(fields, pageBase: baseEmbed); return((Result)await _feedback.SendContextualPaginatedMessageAsync ( _context.User.ID, pages, ct : this.CancellationToken )); }
/// <summary> /// Sets the footer of the embed. /// </summary> /// <param name="iconUrl"> /// The URL of the icon to display in the footer. /// <para>To use attachments uploaded alongside the embed, use the format: attachment://FILENAME_WITH_EXT</para> /// </param> public EmbedOptions SetFooter(string text, string iconUrl = null) { Footer = new EmbedFooter(text, iconUrl); return(this); }
private async Task Update() { if (this.Message == null) { return; } string display = this.DisplayCallback?.Invoke(this.Data[this.CurrentIndex]); await this.Message.ModifyAsync(prop => { if (this.Embed != null) { Embed oldEmbed = this.Embed; EmbedBuilder builder = new EmbedBuilder(); builder .WithLimitedTitle(oldEmbed.Title) .WithLimitedDescription(display); if (oldEmbed.Color.HasValue) { builder.WithColor(oldEmbed.Color.Value); } if (oldEmbed.Timestamp.HasValue) { builder.WithTimestamp(oldEmbed.Timestamp.Value); } if (oldEmbed.Author.HasValue) { EmbedAuthor oldAuthor = oldEmbed.Author.Value; EmbedAuthorBuilder authorBuilder = new EmbedAuthorBuilder(); authorBuilder .WithIconUrl(oldAuthor.IconUrl) .WithName(oldAuthor.Name) .WithUrl(oldAuthor.Url); builder.WithAuthor(authorBuilder); } if (oldEmbed.Footer.HasValue) { EmbedFooter oldFooter = oldEmbed.Footer.Value; EmbedFooterBuilder footerBuilder = new EmbedFooterBuilder(); footerBuilder .WithText(oldFooter.Text) .WithIconUrl(oldFooter.IconUrl); builder.WithFooter(footerBuilder); } this.DisplayEmbedCallback?.Invoke(this.Data[this.CurrentIndex], builder); this.Embed = builder.Build(); prop.Embed = this.Embed; } else { prop.Content = display; } }); this.Refresh(); }