Add embed builder, some more ported classes

This commit is contained in:
Ske
2020-12-23 02:19:02 +01:00
parent 05334f0d25
commit f6fb8204bb
13 changed files with 305 additions and 189 deletions

View File

@@ -0,0 +1,86 @@
using System.Collections.Generic;
using Myriad.Types;
namespace Myriad.Builders
{
public class EmbedBuilder
{
private Embed _embed = new();
private readonly List<Embed.Field> _fields = new();
public EmbedBuilder Title(string? title)
{
_embed = _embed with {Title = title};
return this;
}
public EmbedBuilder Description(string? description)
{
_embed = _embed with { Description = description};
return this;
}
public EmbedBuilder Url(string? url)
{
_embed = _embed with {Url = url};
return this;
}
public EmbedBuilder Color(uint? color)
{
_embed = _embed with {Color = color};
return this;
}
public EmbedBuilder Footer(Embed.EmbedFooter? footer)
{
_embed = _embed with {
Footer = footer
};
return this;
}
public EmbedBuilder Image(Embed.EmbedImage? image)
{
_embed = _embed with {
Image = image
};
return this;
}
public EmbedBuilder Thumbnail(Embed.EmbedThumbnail? thumbnail)
{
_embed = _embed with {
Thumbnail = thumbnail
};
return this;
}
public EmbedBuilder Author(Embed.EmbedAuthor? author)
{
_embed = _embed with {
Author = author
};
return this;
}
public EmbedBuilder Timestamp(string? timestamp)
{
_embed = _embed with {
Timestamp = timestamp
};
return this;
}
public EmbedBuilder Field(Embed.Field field)
{
_fields.Add(field);
return this;
}
public Embed Build() =>
_embed with { Fields = _fields.ToArray() };
}
}

View File

@@ -1,6 +1,14 @@
namespace Myriad.Extensions
using Myriad.Gateway;
using Myriad.Types;
namespace Myriad.Extensions
{
public static class MessageExtensions
{
public static string JumpLink(this Message msg) =>
$"https://discord.com/channels/{msg.GuildId}/{msg.ChannelId}/{msg.Id}";
public static string JumpLink(this MessageReactionAddEvent msg) =>
$"https://discord.com/channels/{msg.GuildId}/{msg.ChannelId}/{msg.MessageId}";
}
}

View File

@@ -39,6 +39,10 @@ namespace Myriad.Rest
public Task<User?> GetUser(ulong id) =>
_client.Get<User>($"/users/{id}", ("GetUser", default));
public Task<GuildMember?> GetGuildMember(ulong guildId, ulong userId) =>
_client.Get<GuildMember>($"/guilds/{guildId}/members/{userId}",
("GetGuildMember", guildId));
public Task<Message> CreateMessage(ulong channelId, MessageRequest request) =>
_client.Post<Message>($"/channels/{channelId}/messages", ("CreateMessage", channelId), request)!;
@@ -110,7 +114,7 @@ namespace Myriad.Rest
public Task<Message> ExecuteWebhook(ulong webhookId, string webhookToken, ExecuteWebhookRequest request,
MultipartFile[]? files = null) =>
_client.PostMultipart<Message>($"/webhooks/{webhookId}/{webhookToken}",
_client.PostMultipart<Message>($"/webhooks/{webhookId}/{webhookToken}?wait=true",
("ExecuteWebhook", webhookId), request, files)!;
private static string EncodeEmoji(Emoji emoji) =>

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
namespace Myriad.Types
namespace Myriad.Types
{
public record Embed
{