/// <inheritdoc/> ITransformationMap <T> ITransformationMap <T> .Embed <TMember>( string relation, Expression <Func <T, TMember> > memberSelector, Func <T, ILinkData> linkSelector) { if (memberSelector is null) { throw new ArgumentNullException(nameof(memberSelector)); } if (relation is null) { throw new ArgumentNullException(nameof(relation)); } if (linkSelector is null) { throw new ArgumentNullException(nameof(linkSelector)); } switch (memberSelector.Body) { case MemberExpression me: var valueSelector = memberSelector.Compile(); Links[relation] = new LinkInstruction <T>(linkSelector); Embeds.Add(new MemberEmbedInstruction <T, TMember>(relation, me.Member.Name, valueSelector)); return(this); default: throw new ArgumentException(MalformedValueSelector); } }
/// <inheritdoc/> ITransformationMap <T> ITransformationMap <T> .Embed <TMember>( string relation, Expression <Func <T, TMember> > memberSelector, Func <T, TMember, ILinkData> linkSelector) { if (memberSelector is null) { throw new ArgumentNullException(nameof(memberSelector)); } if (relation is null) { throw new ArgumentNullException(nameof(relation)); } if (linkSelector is null) { throw new ArgumentNullException(nameof(linkSelector)); } switch (memberSelector.Body) { // todo(cosborn) Allow indexing, in the case of collections and dictionaries? case MemberExpression me: var valueSelector = memberSelector.Compile(); Links[relation] = new LinkInstruction <T>(t => linkSelector(t, valueSelector(t))); Embeds.Add(new MemberEmbedInstruction <T, TMember>(relation, me.Member.Name, valueSelector)); return(this); default: throw new ArgumentException(MalformedValueSelector); } }
/// <summary> /// The GetWarnings method returns an array of embeds detailing the user's warnings, time of warning, and moderator (if enabled). /// </summary> /// <param name="User">The user whose warnings you wish to receive.</param> /// <param name="RunBy">The user who has run the given warnings command.</param> /// <param name="Mention">The stringified mention for the target user.</param> /// <param name="Username">The target user's username in the given context.</param> /// <param name="ShowIssuer">Whether or not the moderators should be shown in the log. Enabled for moderators, disabled for DMed records.</param> /// <returns>An array of embeds containing the given user's warnings.</returns> public EmbedBuilder[] GetWarnings(ulong User, ulong RunBy, string Mention, string Username, bool ShowIssuer) { Infraction[] Infractions = InfractionsDB.GetInfractions(User); if (Infractions.Length <= 0) { return new EmbedBuilder[1] { BuildEmbed(EmojiEnum.Love) .WithTitle("No issued infractions!") .WithDescription($"{Mention} has a clean slate!\n" + $"Go give {(User == RunBy ? "yourself" : "them")} a pat on the back. <3") } } ; List <EmbedBuilder> Embeds = new (); DexterProfile DexterProfile = InfractionsDB.GetOrCreateProfile(User); EmbedBuilder CurrentBuilder = BuildEmbed(EmojiEnum.Love) .WithTitle($"{Username}'s Infractions - {Infractions.Length} {(Infractions.Length == 1 ? "Entry" : "Entries")} and {DexterProfile.InfractionAmount} {(DexterProfile.InfractionAmount == 1 ? "Point" : "Points")}.") .WithDescription($"All times are displayed in {TimeZoneInfo.Local.DisplayName}"); for (int Index = 0; Index < Infractions.Length; Index++) { Infraction Infraction = Infractions[Index]; IUser Issuer = Client.GetUser(Infraction.Issuer); long TimeOfIssue = Infraction.TimeOfIssue; DateTimeOffset Time = DateTimeOffset.FromUnixTimeSeconds(TimeOfIssue > 253402300799 ? TimeOfIssue / 1000 : TimeOfIssue); EmbedFieldBuilder Field = new EmbedFieldBuilder() .WithName($"{(Infraction.InfractionTime == 0 ? "Warning" : $"{TimeSpan.FromSeconds(Infraction.InfractionTime).Humanize().Titleize()} Mute")} {Index + 1} (ID {Infraction.InfractionID}), {(Infraction.PointCost > 0 ? "-" : "")}{Infraction.PointCost} {(Infraction.PointCost == 1 ? "Point" : "Points")}.") .WithValue($"{(ShowIssuer ? $":cop: {(Issuer != null ? Issuer.GetUserInformation() : $"Unknown ({Infraction.Issuer})")}\n" : "")}" + $":calendar: {Time:M/d/yyyy h:mm:ss}\n" + $":notepad_spiral: {Infraction.Reason}" ); if (Index % 5 == 0 && Index != 0) { Embeds.Add(CurrentBuilder); CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green); } else { try { CurrentBuilder.AddField(Field); } catch (Exception) { Embeds.Add(CurrentBuilder); CurrentBuilder = new EmbedBuilder().AddField(Field).WithColor(Color.Green); } } } Embeds.Add(CurrentBuilder); return(Embeds.ToArray()); }
/// <inheritdoc/> ITransformationMap <TCollection, TElement> IElementTransformationMap <TCollection, TElement> .EmbedElements( string relation, Func <TElement, ILinkData?> selector) { Links[relation] = new ManyLinkInstruction <TCollection>(c => c.Select(selector)); Embeds.Add(new ManyEmbedInstruction <TCollection, TElement>(relation, "[*]", _ => _)); return(this); }
/// <summary> /// Adds a new embed to the list of embed to send /// </summary> /// <param name="embed">Embed to add</param> /// <returns>This</returns> /// <exception cref="IndexOutOfRangeException">Thrown if more than 10 embeds are added in a send as that is the discord limit</exception> public WebhookEditMessage AddEmbed(DiscordEmbed embed) { if (Embeds.Count >= 10) { throw new IndexOutOfRangeException("Only 10 embed are allowed per message"); } Embeds.Add(embed); return(this); }
/// <inheritdoc/> ITransformationMap <TCollection, TElement> ITransformationMap <TCollection, TElement> .Embed <TMember>( string relation, Expression <Func <TCollection, TMember> > memberSelector, Func <TCollection, ILinkData?> linkSelector) { switch (memberSelector.Body) { case MemberExpression me: var valueSelector = memberSelector.Compile(); Links[relation] = new LinkInstruction <TCollection>(linkSelector); Embeds.Add(new MemberEmbedInstruction <TCollection, TMember>(relation, me.Member.Name, valueSelector)); return(this); default: throw new ArgumentException(MalformedValueSelector); } }
/// <inheritdoc/> ITransformationMap <TCollection, TElement> IElementTransformationMap <TCollection, TElement> .EmbedElements( string relation, Func <TElement, ILinkData> selector) { if (relation is null) { throw new ArgumentNullException(nameof(relation)); } if (selector is null) { throw new ArgumentNullException(nameof(selector)); } Links[relation] = new ManyLinkInstruction <TCollection>(c => c.Select(selector)); Embeds.Add(new ItemsEmbedInstruction <TCollection, TElement>(relation)); return(this); }
private Task OnMessageUpdated(MessageUpdateEventArgs e) { if (e.Message.Id != Message.Id) { return(Task.CompletedTask); } if (Embeds.SequenceEqual(e.Message.Embeds)) { return(Task.CompletedTask); } _context.Post((o) => { Embeds.Clear(); foreach (var embed in e.Message.Embeds) { Embeds.Add(embed); } }, null); return(Task.CompletedTask); }
public DefaultMessage(IDictionary <string, string> queryParameters, string title, string description) { queryParameters.TryGetValue("username", out string queryUsername); Username = string.IsNullOrWhiteSpace(queryUsername) ? "VSTS" : queryUsername; queryParameters.TryGetValue("tts", out string queryTTS); if (!string.IsNullOrWhiteSpace(queryTTS)) { bool.TryParse(queryTTS, out var queryTTSBool); TTS = queryTTSBool; } Embeds.Add(new Embed { Title = title, Description = description, Footer = new EmbedFooter { Text = "VSTS Discord Integration", //IconUrl = "https://cdn.discordapp.com/embed/avatars/0.png" } }); }
public WebHookData(Embed embed) { Embeds.Add(embed); }
public void AddEmbed(IMessage message, PaginatedEmbed embed) { Embeds.Add(message.Id, embed); }