Add helper classes to simplify embed creation for interactions
This commit is contained in:
parent
c15a66255f
commit
ea17ce2866
2 changed files with 41 additions and 10 deletions
|
@ -1,11 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Geekbot.Core.Interactions.Embed
|
namespace Geekbot.Core.Interactions.Embed
|
||||||
{
|
{
|
||||||
/// <see href="https://discord.com/developers/docs/resources/channel#embed-object" />
|
/// <see href="https://discord.com/developers/docs/resources/channel#embed-object" />
|
||||||
public record Embed
|
public class Embed
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// title of embed
|
/// title of embed
|
||||||
|
@ -17,7 +18,7 @@ namespace Geekbot.Core.Interactions.Embed
|
||||||
/// type of embed (always "rich" for webhook embeds)
|
/// type of embed (always "rich" for webhook embeds)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("type")]
|
[JsonPropertyName("type")]
|
||||||
public EmbedTypes Type { get; set; }
|
public EmbedTypes Type { get; set; } = EmbedTypes.Rich;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// description of embed
|
/// description of embed
|
||||||
|
@ -41,7 +42,7 @@ namespace Geekbot.Core.Interactions.Embed
|
||||||
/// color code of the embed
|
/// color code of the embed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("color")]
|
[JsonPropertyName("color")]
|
||||||
public int Color { get; set; }
|
public uint Color { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// footer information
|
/// footer information
|
||||||
|
@ -83,6 +84,26 @@ namespace Geekbot.Core.Interactions.Embed
|
||||||
/// fields information
|
/// fields information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("fields")]
|
[JsonPropertyName("fields")]
|
||||||
public List<EmbedField> Fields { get; set; }
|
public List<EmbedField> Fields { get; set; } = new List<EmbedField>();
|
||||||
|
|
||||||
|
public void AddField(string name, string value, bool inline = false)
|
||||||
|
{
|
||||||
|
Fields.Add(new EmbedField()
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Value = value,
|
||||||
|
Inline = inline
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddInlineField(string name, string value)
|
||||||
|
{
|
||||||
|
AddField(name, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetColor(Color c)
|
||||||
|
{
|
||||||
|
Color = (uint)(c.R << 16 | c.G << 8 | c.B);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -30,9 +30,7 @@ namespace Geekbot.Core.Interactions
|
||||||
return SimpleResponse(Localization.Internal.SomethingWentWrong);
|
return SimpleResponse(Localization.Internal.SomethingWentWrong);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InteractionResponse SimpleResponse(string message)
|
protected InteractionResponse SimpleResponse(string message) => new InteractionResponse()
|
||||||
{
|
|
||||||
return new InteractionResponse()
|
|
||||||
{
|
{
|
||||||
Type = InteractionResponseType.ChannelMessageWithSource,
|
Type = InteractionResponseType.ChannelMessageWithSource,
|
||||||
Data = new()
|
Data = new()
|
||||||
|
@ -40,7 +38,19 @@ namespace Geekbot.Core.Interactions
|
||||||
Content = message
|
Content = message
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
protected InteractionResponse SimpleResponse(Embed.Embed embed) => new InteractionResponse()
|
||||||
|
{
|
||||||
|
Type = InteractionResponseType.ChannelMessageWithSource,
|
||||||
|
Data = new ()
|
||||||
|
{
|
||||||
|
Content = string.Empty,
|
||||||
|
Embeds = new ()
|
||||||
|
{
|
||||||
|
embed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public abstract Command GetCommandInfo();
|
public abstract Command GetCommandInfo();
|
||||||
public abstract Task<InteractionResponse> Exec(Interaction interaction);
|
public abstract Task<InteractionResponse> Exec(Interaction interaction);
|
||||||
|
|
Loading…
Reference in a new issue