Made API models internal. Removed Discord.Net.API.
This commit is contained in:
24
src/Discord.Net.Rest/API/Common/Application.cs
Normal file
24
src/Discord.Net.Rest/API/Common/Application.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Application
|
||||
{
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
[JsonProperty("rpc_origins")]
|
||||
public string[] RPCOrigins { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
[JsonProperty("flags"), Int53]
|
||||
public Optional<ulong> Flags { get; set; }
|
||||
[JsonProperty("owner")]
|
||||
public Optional<User> Owner { get; set; }
|
||||
}
|
||||
}
|
||||
23
src/Discord.Net.Rest/API/Common/Attachment.cs
Normal file
23
src/Discord.Net.Rest/API/Common/Attachment.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Attachment
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("filename")]
|
||||
public string Filename { get; set; }
|
||||
[JsonProperty("size")]
|
||||
public int Size { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("proxy_url")]
|
||||
public string ProxyUrl { get; set; }
|
||||
[JsonProperty("height")]
|
||||
public Optional<int> Height { get; set; }
|
||||
[JsonProperty("width")]
|
||||
public Optional<int> Width { get; set; }
|
||||
}
|
||||
}
|
||||
13
src/Discord.Net.Rest/API/Common/Ban.cs
Normal file
13
src/Discord.Net.Rest/API/Common/Ban.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Ban
|
||||
{
|
||||
[JsonProperty("user")]
|
||||
public User User { get; set; }
|
||||
[JsonProperty("reason")]
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
}
|
||||
47
src/Discord.Net.Rest/API/Common/Channel.cs
Normal file
47
src/Discord.Net.Rest/API/Common/Channel.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Channel
|
||||
{
|
||||
//Shared
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public ChannelType Type { get; set; }
|
||||
[JsonProperty("last_message_id")]
|
||||
public ulong? LastMessageId { get; set; }
|
||||
|
||||
//GuildChannel
|
||||
[JsonProperty("guild_id")]
|
||||
public Optional<ulong> GuildId { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public Optional<string> Name { get; set; }
|
||||
[JsonProperty("position")]
|
||||
public Optional<int> Position { get; set; }
|
||||
[JsonProperty("permission_overwrites")]
|
||||
public Optional<Overwrite[]> PermissionOverwrites { get; set; }
|
||||
|
||||
//TextChannel
|
||||
[JsonProperty("topic")]
|
||||
public Optional<string> Topic { get; set; }
|
||||
[JsonProperty("last_pin_timestamp")]
|
||||
public Optional<DateTimeOffset?> LastPinTimestamp { get; set; }
|
||||
|
||||
//VoiceChannel
|
||||
[JsonProperty("bitrate")]
|
||||
public Optional<int> Bitrate { get; set; }
|
||||
[JsonProperty("user_limit")]
|
||||
public Optional<int> UserLimit { get; set; }
|
||||
|
||||
//PrivateChannel
|
||||
[JsonProperty("recipients")]
|
||||
public Optional<User[]> Recipients { get; set; }
|
||||
|
||||
//GroupChannel
|
||||
[JsonProperty("icon")]
|
||||
public Optional<string> Icon { get; set; }
|
||||
}
|
||||
}
|
||||
21
src/Discord.Net.Rest/API/Common/Connection.cs
Normal file
21
src/Discord.Net.Rest/API/Common/Connection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Connection
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("revoked")]
|
||||
public bool Revoked { get; set; }
|
||||
|
||||
[JsonProperty("integrations")]
|
||||
public IReadOnlyCollection<ulong> Integrations { get; set; }
|
||||
}
|
||||
}
|
||||
36
src/Discord.Net.Rest/API/Common/Embed.cs
Normal file
36
src/Discord.Net.Rest/API/Common/Embed.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma warning disable CS1591
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Embed
|
||||
{
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("color")]
|
||||
public uint? Color { get; set; }
|
||||
[JsonProperty("timestamp")]
|
||||
public DateTimeOffset? Timestamp { get; set; }
|
||||
[JsonProperty("author")]
|
||||
public Optional<EmbedAuthor> Author { get; set; }
|
||||
[JsonProperty("footer")]
|
||||
public Optional<EmbedFooter> Footer { get; set; }
|
||||
[JsonProperty("video")]
|
||||
public Optional<EmbedVideo> Video { get; set; }
|
||||
[JsonProperty("thumbnail")]
|
||||
public Optional<EmbedThumbnail> Thumbnail { get; set; }
|
||||
[JsonProperty("image")]
|
||||
public Optional<EmbedImage> Image { get; set; }
|
||||
[JsonProperty("provider")]
|
||||
public Optional<EmbedProvider> Provider { get; set; }
|
||||
[JsonProperty("fields")]
|
||||
public Optional<EmbedField[]> Fields { get; set; }
|
||||
}
|
||||
}
|
||||
16
src/Discord.Net.Rest/API/Common/EmbedAuthor.cs
Normal file
16
src/Discord.Net.Rest/API/Common/EmbedAuthor.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedAuthor
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("icon_url")]
|
||||
public string IconUrl { get; set; }
|
||||
[JsonProperty("proxy_icon_url")]
|
||||
public string ProxyIconUrl { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Common/EmbedField.cs
Normal file
14
src/Discord.Net.Rest/API/Common/EmbedField.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedField
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("value")]
|
||||
public string Value { get; set; }
|
||||
[JsonProperty("inline")]
|
||||
public bool Inline { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Common/EmbedFooter.cs
Normal file
14
src/Discord.Net.Rest/API/Common/EmbedFooter.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedFooter
|
||||
{
|
||||
[JsonProperty("text")]
|
||||
public string Text { get; set; }
|
||||
[JsonProperty("icon_url")]
|
||||
public string IconUrl { get; set; }
|
||||
[JsonProperty("proxy_icon_url")]
|
||||
public string ProxyIconUrl { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Common/EmbedImage.cs
Normal file
17
src/Discord.Net.Rest/API/Common/EmbedImage.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedImage
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("proxy_url")]
|
||||
public string ProxyUrl { get; set; }
|
||||
[JsonProperty("height")]
|
||||
public Optional<int> Height { get; set; }
|
||||
[JsonProperty("width")]
|
||||
public Optional<int> Width { get; set; }
|
||||
}
|
||||
}
|
||||
13
src/Discord.Net.Rest/API/Common/EmbedProvider.cs
Normal file
13
src/Discord.Net.Rest/API/Common/EmbedProvider.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedProvider
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs
Normal file
17
src/Discord.Net.Rest/API/Common/EmbedThumbnail.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedThumbnail
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("proxy_url")]
|
||||
public string ProxyUrl { get; set; }
|
||||
[JsonProperty("height")]
|
||||
public Optional<int> Height { get; set; }
|
||||
[JsonProperty("width")]
|
||||
public Optional<int> Width { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/EmbedVideo.cs
Normal file
15
src/Discord.Net.Rest/API/Common/EmbedVideo.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class EmbedVideo
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("height")]
|
||||
public Optional<int> Height { get; set; }
|
||||
[JsonProperty("width")]
|
||||
public Optional<int> Width { get; set; }
|
||||
}
|
||||
}
|
||||
19
src/Discord.Net.Rest/API/Common/Emoji.cs
Normal file
19
src/Discord.Net.Rest/API/Common/Emoji.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Emoji
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong? Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("roles")]
|
||||
public ulong[] Roles { get; set; }
|
||||
[JsonProperty("require_colons")]
|
||||
public bool RequireColons { get; set; }
|
||||
[JsonProperty("managed")]
|
||||
public bool Managed { get; set; }
|
||||
}
|
||||
}
|
||||
23
src/Discord.Net.Rest/API/Common/Game.cs
Normal file
23
src/Discord.Net.Rest/API/Common/Game.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Game
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public Optional<string> StreamUrl { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public Optional<StreamType?> StreamType { get; set; }
|
||||
|
||||
[OnError]
|
||||
internal void OnError(StreamingContext context, ErrorContext errorContext)
|
||||
{
|
||||
errorContext.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/Discord.Net.Rest/API/Common/Guild.cs
Normal file
43
src/Discord.Net.Rest/API/Common/Guild.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Guild
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("icon")]
|
||||
public string Icon { get; set; }
|
||||
[JsonProperty("splash")]
|
||||
public string Splash { get; set; }
|
||||
[JsonProperty("owner_id")]
|
||||
public ulong OwnerId { get; set; }
|
||||
[JsonProperty("region")]
|
||||
public string Region { get; set; }
|
||||
[JsonProperty("afk_channel_id")]
|
||||
public ulong? AFKChannelId { get; set; }
|
||||
[JsonProperty("afk_timeout")]
|
||||
public int AFKTimeout { get; set; }
|
||||
[JsonProperty("embed_enabled")]
|
||||
public bool EmbedEnabled { get; set; }
|
||||
[JsonProperty("embed_channel_id")]
|
||||
public ulong? EmbedChannelId { get; set; }
|
||||
[JsonProperty("verification_level")]
|
||||
public VerificationLevel VerificationLevel { get; set; }
|
||||
[JsonProperty("voice_states")]
|
||||
public VoiceState[] VoiceStates { get; set; }
|
||||
[JsonProperty("roles")]
|
||||
public Role[] Roles { get; set; }
|
||||
[JsonProperty("emojis")]
|
||||
public Emoji[] Emojis { get; set; }
|
||||
[JsonProperty("features")]
|
||||
public string[] Features { get; set; }
|
||||
[JsonProperty("mfa_level")]
|
||||
public MfaLevel MfaLevel { get; set; }
|
||||
[JsonProperty("default_message_notifications")]
|
||||
public DefaultMessageNotifications DefaultMessageNotifications { get; set; }
|
||||
}
|
||||
}
|
||||
13
src/Discord.Net.Rest/API/Common/GuildEmbed.cs
Normal file
13
src/Discord.Net.Rest/API/Common/GuildEmbed.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class GuildEmbed
|
||||
{
|
||||
[JsonProperty("enabled")]
|
||||
public bool Enabled { get; set; }
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
}
|
||||
}
|
||||
22
src/Discord.Net.Rest/API/Common/GuildMember.cs
Normal file
22
src/Discord.Net.Rest/API/Common/GuildMember.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class GuildMember
|
||||
{
|
||||
[JsonProperty("user")]
|
||||
public User User { get; set; }
|
||||
[JsonProperty("nick")]
|
||||
public Optional<string> Nick { get; set; }
|
||||
[JsonProperty("roles")]
|
||||
public ulong[] Roles { get; set; }
|
||||
[JsonProperty("joined_at")]
|
||||
public DateTimeOffset JoinedAt { get; set; }
|
||||
[JsonProperty("deaf")]
|
||||
public bool Deaf { get; set; }
|
||||
[JsonProperty("mute")]
|
||||
public bool Mute { get; set; }
|
||||
}
|
||||
}
|
||||
32
src/Discord.Net.Rest/API/Common/Integration.cs
Normal file
32
src/Discord.Net.Rest/API/Common/Integration.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Integration
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty("enabled")]
|
||||
public bool Enabled { get; set; }
|
||||
[JsonProperty("syncing")]
|
||||
public bool Syncing { get; set; }
|
||||
[JsonProperty("role_id")]
|
||||
public ulong RoleId { get; set; }
|
||||
[JsonProperty("expire_behavior")]
|
||||
public ulong ExpireBehavior { get; set; }
|
||||
[JsonProperty("expire_grace_period")]
|
||||
public ulong ExpireGracePeriod { get; set; }
|
||||
[JsonProperty("user")]
|
||||
public User User { get; set; }
|
||||
[JsonProperty("account")]
|
||||
public IntegrationAccount Account { get; set; }
|
||||
[JsonProperty("synced_at")]
|
||||
public DateTimeOffset SyncedAt { get; set; }
|
||||
}
|
||||
}
|
||||
13
src/Discord.Net.Rest/API/Common/IntegrationAccount.cs
Normal file
13
src/Discord.Net.Rest/API/Common/IntegrationAccount.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class IntegrationAccount
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/Invite.cs
Normal file
15
src/Discord.Net.Rest/API/Common/Invite.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Invite
|
||||
{
|
||||
[JsonProperty("code")]
|
||||
public string Code { get; set; }
|
||||
[JsonProperty("guild")]
|
||||
public InviteGuild Guild { get; set; }
|
||||
[JsonProperty("channel")]
|
||||
public InviteChannel Channel { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/InviteChannel.cs
Normal file
15
src/Discord.Net.Rest/API/Common/InviteChannel.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class InviteChannel
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/InviteGuild.cs
Normal file
15
src/Discord.Net.Rest/API/Common/InviteGuild.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class InviteGuild
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("splash_hash")]
|
||||
public string SplashHash { get; set; }
|
||||
}
|
||||
}
|
||||
24
src/Discord.Net.Rest/API/Common/InviteMetadata.cs
Normal file
24
src/Discord.Net.Rest/API/Common/InviteMetadata.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class InviteMetadata : Invite
|
||||
{
|
||||
[JsonProperty("inviter")]
|
||||
public User Inviter { get; set; }
|
||||
[JsonProperty("uses")]
|
||||
public int Uses { get; set; }
|
||||
[JsonProperty("max_uses")]
|
||||
public int MaxUses { get; set; }
|
||||
[JsonProperty("max_age")]
|
||||
public int MaxAge { get; set; }
|
||||
[JsonProperty("temporary")]
|
||||
public bool Temporary { get; set; }
|
||||
[JsonProperty("created_at")]
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
[JsonProperty("revoked")]
|
||||
public bool Revoked { get; set; }
|
||||
}
|
||||
}
|
||||
42
src/Discord.Net.Rest/API/Common/Message.cs
Normal file
42
src/Discord.Net.Rest/API/Common/Message.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Message
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public MessageType Type { get; set; }
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
[JsonProperty("webhook_id")]
|
||||
public Optional<ulong> WebhookId { get; set; }
|
||||
[JsonProperty("author")]
|
||||
public Optional<User> Author { get; set; }
|
||||
[JsonProperty("content")]
|
||||
public Optional<string> Content { get; set; }
|
||||
[JsonProperty("timestamp")]
|
||||
public Optional<DateTimeOffset> Timestamp { get; set; }
|
||||
[JsonProperty("edited_timestamp")]
|
||||
public Optional<DateTimeOffset?> EditedTimestamp { get; set; }
|
||||
[JsonProperty("tts")]
|
||||
public Optional<bool> IsTextToSpeech { get; set; }
|
||||
[JsonProperty("mention_everyone")]
|
||||
public Optional<bool> MentionEveryone { get; set; }
|
||||
[JsonProperty("mentions")]
|
||||
public Optional<EntityOrId<User>[]> UserMentions { get; set; }
|
||||
[JsonProperty("mention_roles")]
|
||||
public Optional<ulong[]> RoleMentions { get; set; }
|
||||
[JsonProperty("attachments")]
|
||||
public Optional<Attachment[]> Attachments { get; set; }
|
||||
[JsonProperty("embeds")]
|
||||
public Optional<Embed[]> Embeds { get; set; }
|
||||
[JsonProperty("pinned")]
|
||||
public Optional<bool> Pinned { get; set; }
|
||||
[JsonProperty("reactions")]
|
||||
public Optional<Reaction[]> Reactions { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Common/Overwrite.cs
Normal file
17
src/Discord.Net.Rest/API/Common/Overwrite.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Overwrite
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong TargetId { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public PermissionTarget TargetType { get; set; }
|
||||
[JsonProperty("deny"), Int53]
|
||||
public ulong Deny { get; set; }
|
||||
[JsonProperty("allow"), Int53]
|
||||
public ulong Allow { get; set; }
|
||||
}
|
||||
}
|
||||
22
src/Discord.Net.Rest/API/Common/Presence.cs
Normal file
22
src/Discord.Net.Rest/API/Common/Presence.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Presence
|
||||
{
|
||||
[JsonProperty("user")]
|
||||
public User User { get; set; }
|
||||
[JsonProperty("guild_id")]
|
||||
public Optional<ulong> GuildId { get; set; }
|
||||
[JsonProperty("status")]
|
||||
public UserStatus Status { get; set; }
|
||||
[JsonProperty("game")]
|
||||
public Game Game { get; set; }
|
||||
|
||||
[JsonProperty("roles")]
|
||||
public Optional<ulong[]> Roles { get; set; }
|
||||
[JsonProperty("nick")]
|
||||
public Optional<string> Nick { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Common/Reaction.cs
Normal file
14
src/Discord.Net.Rest/API/Common/Reaction.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Reaction
|
||||
{
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
[JsonProperty("me")]
|
||||
public bool Me { get; set; }
|
||||
[JsonProperty("emoji")]
|
||||
public Emoji Emoji { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/ReadState.cs
Normal file
15
src/Discord.Net.Rest/API/Common/ReadState.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class ReadState
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("mention_count")]
|
||||
public int MentionCount { get; set; }
|
||||
[JsonProperty("last_message_id")]
|
||||
public Optional<ulong> LastMessageId { get; set; }
|
||||
}
|
||||
}
|
||||
15
src/Discord.Net.Rest/API/Common/Relationship.cs
Normal file
15
src/Discord.Net.Rest/API/Common/Relationship.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Relationship
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("user")]
|
||||
public User User { get; set; }
|
||||
[JsonProperty("type")]
|
||||
public RelationshipType Type { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/Discord.Net.Rest/API/Common/RelationshipType.cs
Normal file
11
src/Discord.Net.Rest/API/Common/RelationshipType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma warning disable CS1591
|
||||
namespace Discord.API
|
||||
{
|
||||
internal enum RelationshipType
|
||||
{
|
||||
Friend = 1,
|
||||
Blocked = 2,
|
||||
IncomingPending = 3,
|
||||
OutgoingPending = 4
|
||||
}
|
||||
}
|
||||
25
src/Discord.Net.Rest/API/Common/Role.cs
Normal file
25
src/Discord.Net.Rest/API/Common/Role.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class Role
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("color")]
|
||||
public uint Color { get; set; }
|
||||
[JsonProperty("hoist")]
|
||||
public bool Hoist { get; set; }
|
||||
[JsonProperty("mentionable")]
|
||||
public bool Mentionable { get; set; }
|
||||
[JsonProperty("position")]
|
||||
public int Position { get; set; }
|
||||
[JsonProperty("permissions"), Int53]
|
||||
public ulong Permissions { get; set; }
|
||||
[JsonProperty("managed")]
|
||||
public bool Managed { get; set; }
|
||||
}
|
||||
}
|
||||
27
src/Discord.Net.Rest/API/Common/User.cs
Normal file
27
src/Discord.Net.Rest/API/Common/User.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class User
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("username")]
|
||||
public Optional<string> Username { get; set; }
|
||||
[JsonProperty("discriminator")]
|
||||
public Optional<string> Discriminator { get; set; }
|
||||
[JsonProperty("bot")]
|
||||
public Optional<bool> Bot { get; set; }
|
||||
[JsonProperty("avatar")]
|
||||
public Optional<string> Avatar { get; set; }
|
||||
|
||||
//CurrentUser
|
||||
[JsonProperty("verified")]
|
||||
public Optional<bool> Verified { get; set; }
|
||||
[JsonProperty("email")]
|
||||
public Optional<string> Email { get; set; }
|
||||
[JsonProperty("mfa_enabled")]
|
||||
public Optional<bool> MfaEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
19
src/Discord.Net.Rest/API/Common/UserGuild.cs
Normal file
19
src/Discord.Net.Rest/API/Common/UserGuild.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class UserGuild
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("icon")]
|
||||
public string Icon { get; set; }
|
||||
[JsonProperty("owner")]
|
||||
public bool Owner { get; set; }
|
||||
[JsonProperty("permissions"), Int53]
|
||||
public ulong Permissions { get; set; }
|
||||
}
|
||||
}
|
||||
21
src/Discord.Net.Rest/API/Common/VoiceRegion.cs
Normal file
21
src/Discord.Net.Rest/API/Common/VoiceRegion.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class VoiceRegion
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("vip")]
|
||||
public bool IsVip { get; set; }
|
||||
[JsonProperty("optimal")]
|
||||
public bool IsOptimal { get; set; }
|
||||
[JsonProperty("sample_hostname")]
|
||||
public string SampleHostname { get; set; }
|
||||
[JsonProperty("sample_port")]
|
||||
public int SamplePort { get; set; }
|
||||
}
|
||||
}
|
||||
27
src/Discord.Net.Rest/API/Common/VoiceState.cs
Normal file
27
src/Discord.Net.Rest/API/Common/VoiceState.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class VoiceState
|
||||
{
|
||||
[JsonProperty("guild_id")]
|
||||
public ulong? GuildId { get; set; }
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong? ChannelId { get; set; }
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
[JsonProperty("session_id")]
|
||||
public string SessionId { get; set; }
|
||||
[JsonProperty("deaf")]
|
||||
public bool Deaf { get; set; }
|
||||
[JsonProperty("mute")]
|
||||
public bool Mute { get; set; }
|
||||
[JsonProperty("self_deaf")]
|
||||
public bool SelfDeaf { get; set; }
|
||||
[JsonProperty("self_mute")]
|
||||
public bool SelfMute { get; set; }
|
||||
[JsonProperty("suppress")]
|
||||
public bool Suppress { get; set; }
|
||||
}
|
||||
}
|
||||
19
src/Discord.Net.Rest/API/EntityOrId.cs
Normal file
19
src/Discord.Net.Rest/API/EntityOrId.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Discord.API
|
||||
{
|
||||
internal struct EntityOrId<T>
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public T Object { get; }
|
||||
|
||||
public EntityOrId(ulong id)
|
||||
{
|
||||
Id = id;
|
||||
Object = default(T);
|
||||
}
|
||||
public EntityOrId(T obj)
|
||||
{
|
||||
Id = 0;
|
||||
Object = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Discord.Net.Rest/API/Image.cs
Normal file
21
src/Discord.Net.Rest/API/Image.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal struct Image
|
||||
{
|
||||
public Stream Stream { get; }
|
||||
public string Hash { get; }
|
||||
|
||||
public Image(Stream stream)
|
||||
{
|
||||
Stream = stream;
|
||||
Hash = null;
|
||||
}
|
||||
public Image(string hash)
|
||||
{
|
||||
Stream = null;
|
||||
Hash = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Discord.Net.Rest/API/Int53Attribute.cs
Normal file
8
src/Discord.Net.Rest/API/Int53Attribute.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma warning disable CS1591
|
||||
using System;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
internal class Int53Attribute : Attribute { }
|
||||
}
|
||||
16
src/Discord.Net.Rest/API/Net/MultipartFile.cs
Normal file
16
src/Discord.Net.Rest/API/Net/MultipartFile.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Discord.Net.Rest
|
||||
{
|
||||
internal struct MultipartFile
|
||||
{
|
||||
public Stream Stream { get; }
|
||||
public string Filename { get; }
|
||||
|
||||
public MultipartFile(Stream stream, string filename)
|
||||
{
|
||||
Stream = stream;
|
||||
Filename = filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs
Normal file
16
src/Discord.Net.Rest/API/Rest/CreateChannelInviteParams.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateChannelInviteParams
|
||||
{
|
||||
[JsonProperty("max_age")]
|
||||
public Optional<int> MaxAge { get; set; }
|
||||
[JsonProperty("max_uses")]
|
||||
public Optional<int> MaxUses { get; set; }
|
||||
[JsonProperty("temporary")]
|
||||
public Optional<bool> IsTemporary { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs
Normal file
17
src/Discord.Net.Rest/API/Rest/CreateDMChannelParams.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateDMChannelParams
|
||||
{
|
||||
[JsonProperty("recipient_id")]
|
||||
public ulong RecipientId { get; }
|
||||
|
||||
public CreateDMChannelParams(ulong recipientId)
|
||||
{
|
||||
RecipientId = recipientId;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs
Normal file
8
src/Discord.Net.Rest/API/Rest/CreateGuildBanParams.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma warning disable CS1591
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class CreateGuildBanParams
|
||||
{
|
||||
public Optional<int> DeleteMessageDays { get; set; }
|
||||
}
|
||||
}
|
||||
23
src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs
Normal file
23
src/Discord.Net.Rest/API/Rest/CreateGuildChannelParams.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateGuildChannelParams
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; }
|
||||
[JsonProperty("type")]
|
||||
public ChannelType Type { get; }
|
||||
|
||||
[JsonProperty("bitrate")]
|
||||
public Optional<int> Bitrate { get; set; }
|
||||
|
||||
public CreateGuildChannelParams(string name, ChannelType type)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateGuildIntegrationParams
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; }
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; }
|
||||
|
||||
public CreateGuildIntegrationParams(ulong id, string type)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs
Normal file
23
src/Discord.Net.Rest/API/Rest/CreateGuildParams.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateGuildParams
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; }
|
||||
[JsonProperty("region")]
|
||||
public string RegionId { get; }
|
||||
|
||||
[JsonProperty("icon")]
|
||||
public Optional<Image?> Icon { get; set; }
|
||||
|
||||
public CreateGuildParams(string name, string regionId)
|
||||
{
|
||||
Name = name;
|
||||
RegionId = regionId;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs
Normal file
24
src/Discord.Net.Rest/API/Rest/CreateMessageParams.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class CreateMessageParams
|
||||
{
|
||||
[JsonProperty("content")]
|
||||
public string Content { get; }
|
||||
|
||||
[JsonProperty("nonce")]
|
||||
public Optional<string> Nonce { get; set; }
|
||||
[JsonProperty("tts")]
|
||||
public Optional<bool> IsTTS { get; set; }
|
||||
[JsonProperty("embed")]
|
||||
public Optional<Embed> Embed { get; set; }
|
||||
|
||||
public CreateMessageParams(string content)
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs
Normal file
17
src/Discord.Net.Rest/API/Rest/DeleteMessagesParams.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class DeleteMessagesParams
|
||||
{
|
||||
[JsonProperty("messages")]
|
||||
public ulong[] MessageIds { get; }
|
||||
|
||||
public DeleteMessagesParams(ulong[] messageIds)
|
||||
{
|
||||
MessageIds = messageIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs
Normal file
13
src/Discord.Net.Rest/API/Rest/GetBotGatewayResponse.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetBotGatewayResponse
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("shards")]
|
||||
public int Shards { get; set; }
|
||||
}
|
||||
}
|
||||
10
src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs
Normal file
10
src/Discord.Net.Rest/API/Rest/GetChannelMessagesParams.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma warning disable CS1591
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetChannelMessagesParams
|
||||
{
|
||||
public Optional<int> Limit { get; set; }
|
||||
public Optional<Direction> RelativeDirection { get; set; }
|
||||
public Optional<ulong> RelativeMessageId { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs
Normal file
11
src/Discord.Net.Rest/API/Rest/GetGatewayResponse.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetGatewayResponse
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
||||
9
src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs
Normal file
9
src/Discord.Net.Rest/API/Rest/GetGuildMembersParams.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma warning disable CS1591
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetGuildMembersParams
|
||||
{
|
||||
public Optional<int> Limit { get; set; }
|
||||
public Optional<ulong> AfterUserId { get; set; }
|
||||
}
|
||||
}
|
||||
11
src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs
Normal file
11
src/Discord.Net.Rest/API/Rest/GetGuildPruneCountResponse.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetGuildPruneCountResponse
|
||||
{
|
||||
[JsonProperty("pruned")]
|
||||
public int Pruned { get; set; }
|
||||
}
|
||||
}
|
||||
8
src/Discord.Net.Rest/API/Rest/GetReactionUsersParams.cs
Normal file
8
src/Discord.Net.Rest/API/Rest/GetReactionUsersParams.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class GetReactionUsersParams
|
||||
{
|
||||
public Optional<int> Limit { get; set; }
|
||||
public Optional<ulong> AfterUserId { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs
Normal file
17
src/Discord.Net.Rest/API/Rest/GuildPruneParams.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class GuildPruneParams
|
||||
{
|
||||
[JsonProperty("days")]
|
||||
public int Days { get; }
|
||||
|
||||
public GuildPruneParams(int days)
|
||||
{
|
||||
Days = days;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyChannelPermissionsParams
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; }
|
||||
[JsonProperty("allow")]
|
||||
public ulong Allow { get; }
|
||||
[JsonProperty("deny")]
|
||||
public ulong Deny { get; }
|
||||
|
||||
public ModifyChannelPermissionsParams(string type, ulong allow, ulong deny)
|
||||
{
|
||||
Type = type;
|
||||
Allow = allow;
|
||||
Deny = deny;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs
Normal file
17
src/Discord.Net.Rest/API/Rest/ModifyCurrentUserNickParams.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyCurrentUserNickParams
|
||||
{
|
||||
[JsonProperty("nick")]
|
||||
public string Nickname { get; }
|
||||
|
||||
public ModifyCurrentUserNickParams(string nickname)
|
||||
{
|
||||
Nickname = nickname;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs
Normal file
14
src/Discord.Net.Rest/API/Rest/ModifyCurrentUserParams.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyCurrentUserParams
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
public Optional<string> Username { get; set; }
|
||||
[JsonProperty("avatar")]
|
||||
public Optional<Image?> Avatar { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs
Normal file
14
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelParams.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildChannelParams
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public Optional<string> Name { get; set; }
|
||||
[JsonProperty("position")]
|
||||
public Optional<int> Position { get; set; }
|
||||
}
|
||||
}
|
||||
20
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs
Normal file
20
src/Discord.Net.Rest/API/Rest/ModifyGuildChannelsParams.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildChannelsParams
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("position")]
|
||||
public int Position { get; set; }
|
||||
|
||||
public ModifyGuildChannelsParams(ulong id, int position)
|
||||
{
|
||||
Id = id;
|
||||
Position = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs
Normal file
14
src/Discord.Net.Rest/API/Rest/ModifyGuildEmbedParams.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildEmbedParams
|
||||
{
|
||||
[JsonProperty("enabled")]
|
||||
public Optional<bool> Enabled { get; set; }
|
||||
[JsonProperty("channel")]
|
||||
public Optional<ulong?> ChannelId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildIntegrationParams
|
||||
{
|
||||
[JsonProperty("expire_behavior")]
|
||||
public Optional<int> ExpireBehavior { get; set; }
|
||||
[JsonProperty("expire_grace_period")]
|
||||
public Optional<int> ExpireGracePeriod { get; set; }
|
||||
[JsonProperty("enable_emoticons")]
|
||||
public Optional<bool> EnableEmoticons { get; set; }
|
||||
}
|
||||
}
|
||||
20
src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs
Normal file
20
src/Discord.Net.Rest/API/Rest/ModifyGuildMemberParams.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildMemberParams
|
||||
{
|
||||
[JsonProperty("mute")]
|
||||
public Optional<bool> Mute { get; set; }
|
||||
[JsonProperty("deaf")]
|
||||
public Optional<bool> Deaf { get; set; }
|
||||
[JsonProperty("nick")]
|
||||
public Optional<string> Nickname { get; set; }
|
||||
[JsonProperty("roles")]
|
||||
public Optional<ulong[]> RoleIds { get; set; }
|
||||
[JsonProperty("channel_id")]
|
||||
public Optional<ulong> ChannelId { get; set; }
|
||||
}
|
||||
}
|
||||
30
src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs
Normal file
30
src/Discord.Net.Rest/API/Rest/ModifyGuildParams.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildParams
|
||||
{
|
||||
[JsonProperty("username")]
|
||||
public Optional<string> Username { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public Optional<string> Name { get; set; }
|
||||
[JsonProperty("region")]
|
||||
public Optional<string> RegionId { get; set; }
|
||||
[JsonProperty("verification_level")]
|
||||
public Optional<VerificationLevel> VerificationLevel { get; set; }
|
||||
[JsonProperty("default_message_notifications")]
|
||||
public Optional<DefaultMessageNotifications> DefaultMessageNotifications { get; set; }
|
||||
[JsonProperty("afk_timeout")]
|
||||
public Optional<int> AfkTimeout { get; set; }
|
||||
[JsonProperty("icon")]
|
||||
public Optional<Image?> Icon { get; set; }
|
||||
[JsonProperty("splash")]
|
||||
public Optional<Image?> Splash { get; set; }
|
||||
[JsonProperty("afk_channel_id")]
|
||||
public Optional<ulong?> AfkChannelId { get; set; }
|
||||
[JsonProperty("owner_id")]
|
||||
public Optional<ulong> OwnerId { get; set; }
|
||||
}
|
||||
}
|
||||
22
src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs
Normal file
22
src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildRoleParams
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public Optional<string> Name { get; set; }
|
||||
[JsonProperty("permissions")]
|
||||
public Optional<ulong> Permissions { get; set; }
|
||||
[JsonProperty("position")]
|
||||
public Optional<int> Position { get; set; }
|
||||
[JsonProperty("color")]
|
||||
public Optional<uint> Color { get; set; }
|
||||
[JsonProperty("hoist")]
|
||||
public Optional<bool> Hoist { get; set; }
|
||||
[JsonProperty("mentionable")]
|
||||
public Optional<bool> Mentionable { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs
Normal file
17
src/Discord.Net.Rest/API/Rest/ModifyGuildRolesParams.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyGuildRolesParams : ModifyGuildRoleParams
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; }
|
||||
|
||||
public ModifyGuildRolesParams(ulong id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs
Normal file
14
src/Discord.Net.Rest/API/Rest/ModifyMessageParams.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyMessageParams
|
||||
{
|
||||
[JsonProperty("content")]
|
||||
public Optional<string> Content { get; set; }
|
||||
[JsonProperty("embed")]
|
||||
public Optional<Embed> Embed { get; set; }
|
||||
}
|
||||
}
|
||||
12
src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
Normal file
12
src/Discord.Net.Rest/API/Rest/ModifyTextChannelParams.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyTextChannelParams : ModifyGuildChannelParams
|
||||
{
|
||||
[JsonProperty("topic")]
|
||||
public Optional<string> Topic { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs
Normal file
14
src/Discord.Net.Rest/API/Rest/ModifyVoiceChannelParams.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
internal class ModifyVoiceChannelParams : ModifyGuildChannelParams
|
||||
{
|
||||
[JsonProperty("bitrate")]
|
||||
public Optional<int> Bitrate { get; set; }
|
||||
[JsonProperty("user_limit")]
|
||||
public Optional<int> UserLimit { get; set; }
|
||||
}
|
||||
}
|
||||
35
src/Discord.Net.Rest/API/Rest/UploadFileParams.cs
Normal file
35
src/Discord.Net.Rest/API/Rest/UploadFileParams.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma warning disable CS1591
|
||||
using Discord.Net.Rest;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class UploadFileParams
|
||||
{
|
||||
public Stream File { get; }
|
||||
|
||||
public Optional<string> Filename { get; set; }
|
||||
public Optional<string> Content { get; set; }
|
||||
public Optional<string> Nonce { get; set; }
|
||||
public Optional<bool> IsTTS { get; set; }
|
||||
|
||||
public UploadFileParams(Stream file)
|
||||
{
|
||||
File = file;
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, object> ToDictionary()
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
d["file"] = new MultipartFile(File, Filename.GetValueOrDefault("unknown.dat"));
|
||||
if (Content.IsSpecified)
|
||||
d["content"] = Content.Value;
|
||||
if (IsTTS.IsSpecified)
|
||||
d["tts"] = IsTTS.Value.ToString();
|
||||
if (Nonce.IsSpecified)
|
||||
d["nonce"] = Nonce.Value;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/Discord.Net.Rest/API/RpcFrame.cs
Normal file
20
src/Discord.Net.Rest/API/RpcFrame.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.API.Rpc
|
||||
{
|
||||
internal class RpcFrame
|
||||
{
|
||||
[JsonProperty("cmd")]
|
||||
public string Cmd { get; set; }
|
||||
[JsonProperty("nonce")]
|
||||
public Optional<Guid?> Nonce { get; set; }
|
||||
[JsonProperty("evt")]
|
||||
public Optional<string> Event { get; set; }
|
||||
[JsonProperty("data")]
|
||||
public Optional<object> Data { get; set; }
|
||||
[JsonProperty("args")]
|
||||
public object Args { get; set; }
|
||||
}
|
||||
}
|
||||
17
src/Discord.Net.Rest/API/SocketFrame.cs
Normal file
17
src/Discord.Net.Rest/API/SocketFrame.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS1591
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
internal class SocketFrame
|
||||
{
|
||||
[JsonProperty("op")]
|
||||
public int Operation { get; set; }
|
||||
[JsonProperty("t", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty("s", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public int? Sequence { get; set; }
|
||||
[JsonProperty("d")]
|
||||
public object Payload { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace Discord.Rest
|
||||
private bool _isFirstLogin;
|
||||
private bool _isDisposed;
|
||||
|
||||
public API.DiscordRestApiClient ApiClient { get; }
|
||||
internal API.DiscordRestApiClient ApiClient { get; }
|
||||
internal LogManager LogManager { get; }
|
||||
public LoginState LoginState { get; private set; }
|
||||
public ISelfUser CurrentUser { get; protected set; }
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<EmbeddedResource Include="**\*.resx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Discord.Net.API\Discord.Net.API.csproj" />
|
||||
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||
|
||||
@@ -22,7 +22,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.API
|
||||
{
|
||||
public class DiscordRestApiClient : IDisposable
|
||||
internal class DiscordRestApiClient : IDisposable
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, Func<BucketIds, string>> _bucketIdGenerators = new ConcurrentDictionary<string, Func<BucketIds, string>>();
|
||||
|
||||
@@ -45,7 +45,9 @@ namespace Discord.API
|
||||
|
||||
public LoginState LoginState { get; private set; }
|
||||
public TokenType AuthTokenType { get; private set; }
|
||||
public User CurrentUser { get; private set; }
|
||||
internal User CurrentUser { get; private set; }
|
||||
|
||||
public ulong? CurrentUserId => CurrentUser?.Id;
|
||||
|
||||
public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry,
|
||||
JsonSerializer serializer = null, bool fetchCurrentUser = true)
|
||||
|
||||
@@ -150,9 +150,9 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
public static async Task<RestUserMessage> SendMessageAsync(IMessageChannel channel, BaseDiscordClient client,
|
||||
string text, bool isTTS, EmbedBuilder embed, RequestOptions options)
|
||||
string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
{
|
||||
var args = new CreateMessageParams(text) { IsTTS = isTTS, Embed = embed?.Build() };
|
||||
var args = new CreateMessageParams(text) { IsTTS = isTTS, Embed = embed.ToModel() };
|
||||
var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
return RestUserMessage.Create(client, channel, client.CurrentUser, model);
|
||||
}
|
||||
|
||||
10
src/Discord.Net.Rest/Entities/Channels/ChannelType.cs
Normal file
10
src/Discord.Net.Rest/Entities/Channels/ChannelType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Discord
|
||||
{
|
||||
public enum ChannelType
|
||||
{
|
||||
Text = 0,
|
||||
DM = 1,
|
||||
Voice = 2,
|
||||
Group = 3
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Discord.Rest
|
||||
public interface IRestMessageChannel : IMessageChannel
|
||||
{
|
||||
/// <summary> Sends a message to this message channel. </summary>
|
||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, EmbedBuilder embed = null, RequestOptions options = null);
|
||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null);
|
||||
#if NETSTANDARD1_3
|
||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
|
||||
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Discord.Rest
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, EmbedBuilder embed = null, RequestOptions options = null)
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if NETSTANDARD1_3
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
@@ -130,7 +130,7 @@ namespace Discord.Rest
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, EmbedBuilder embed, RequestOptions options)
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Discord.Rest
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, EmbedBuilder embed = null, RequestOptions options = null)
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if NETSTANDARD1_3
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
@@ -140,7 +140,7 @@ namespace Discord.Rest
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, EmbedBuilder embed, RequestOptions options)
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Discord.Rest
|
||||
var overwrites = model.PermissionOverwrites.Value;
|
||||
var newOverwrites = ImmutableArray.CreateBuilder<Overwrite>(overwrites.Length);
|
||||
for (int i = 0; i < overwrites.Length; i++)
|
||||
newOverwrites.Add(new Overwrite(overwrites[i]));
|
||||
newOverwrites.Add(overwrites[i].ToEntity());
|
||||
_overwrites = newOverwrites.ToImmutable();
|
||||
}
|
||||
|
||||
@@ -83,12 +83,12 @@ namespace Discord.Rest
|
||||
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false);
|
||||
_overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }));
|
||||
_overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(perms.AllowValue, perms.DenyValue)));
|
||||
}
|
||||
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false);
|
||||
_overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }));
|
||||
_overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(perms.AllowValue, perms.DenyValue)));
|
||||
}
|
||||
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Discord.API.Rest;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -55,7 +54,7 @@ namespace Discord.Rest
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, EmbedBuilder embed = null, RequestOptions options = null)
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if NETSTANDARD1_3
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null)
|
||||
@@ -112,7 +111,7 @@ namespace Discord.Rest
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, EmbedBuilder embed, RequestOptions options)
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Discord.Rest
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, EmbedBuilder embed = null, RequestOptions options = null)
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, Embed embed = null, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
|
||||
#if NETSTANDARD1_3
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
|
||||
@@ -90,7 +90,7 @@ namespace Discord.Rest
|
||||
#endif
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, EmbedBuilder embed, RequestOptions options)
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, Embed embed, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, embed, options);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Discord.Rest
|
||||
{
|
||||
var emojis = ImmutableArray.CreateBuilder<GuildEmoji>(model.Emojis.Length);
|
||||
for (int i = 0; i < model.Emojis.Length; i++)
|
||||
emojis.Add(GuildEmoji.Create(model.Emojis[i]));
|
||||
emojis.Add(model.Emojis[i].ToEntity());
|
||||
_emojis = emojis.ToImmutableArray();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Discord.API.Rest;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Integration;
|
||||
@@ -37,7 +36,7 @@ namespace Discord.Rest
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void Update(Model model)
|
||||
internal void Update(Model model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Type = model.Type;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Discord.Rest
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void Update(Model model)
|
||||
internal void Update(Model model)
|
||||
{
|
||||
_iconId = model.Icon;
|
||||
IsOwner = model.Owner;
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.Embed;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class Embed : IEmbed
|
||||
{
|
||||
public string Description { get; }
|
||||
public string Url { get; }
|
||||
public string Title { get; }
|
||||
public string Type { get; }
|
||||
public DateTimeOffset? Timestamp { get; }
|
||||
public Color? Color { get; }
|
||||
public EmbedImage? Image { get; }
|
||||
public EmbedVideo? Video { get; }
|
||||
public EmbedAuthor? Author { get; }
|
||||
public EmbedFooter? Footer { get; }
|
||||
public EmbedProvider? Provider { get; }
|
||||
public EmbedThumbnail? Thumbnail { get; }
|
||||
public ImmutableArray<EmbedField> Fields { get; }
|
||||
|
||||
internal Embed(string type,
|
||||
string title,
|
||||
string description,
|
||||
string url,
|
||||
DateTimeOffset? timestamp,
|
||||
Color? color,
|
||||
EmbedImage? image,
|
||||
EmbedVideo? video,
|
||||
EmbedAuthor? author,
|
||||
EmbedFooter? footer,
|
||||
EmbedProvider? provider,
|
||||
EmbedThumbnail? thumbnail,
|
||||
ImmutableArray<EmbedField> fields)
|
||||
{
|
||||
Type = type;
|
||||
Title = title;
|
||||
Description = description;
|
||||
Url = url;
|
||||
Color = color;
|
||||
Timestamp = timestamp;
|
||||
Image = image;
|
||||
Video = video;
|
||||
Author = author;
|
||||
Footer = footer;
|
||||
Provider = provider;
|
||||
Thumbnail = thumbnail;
|
||||
Fields = fields;
|
||||
}
|
||||
internal static Embed Create(Model model)
|
||||
{
|
||||
return new Embed(model.Type, model.Title, model.Description, model.Url,model.Timestamp,
|
||||
model.Color.HasValue ? new Color(model.Color.Value) : (Color?)null,
|
||||
model.Image.IsSpecified ? EmbedImage.Create(model.Image.Value) : (EmbedImage?)null,
|
||||
model.Video.IsSpecified ? EmbedVideo.Create(model.Video.Value) : (EmbedVideo?)null,
|
||||
model.Author.IsSpecified ? EmbedAuthor.Create(model.Author.Value) : (EmbedAuthor?)null,
|
||||
model.Footer.IsSpecified ? EmbedFooter.Create(model.Footer.Value) : (EmbedFooter?)null,
|
||||
model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null,
|
||||
model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null,
|
||||
model.Fields.IsSpecified ? model.Fields.Value.Select(EmbedField.Create).ToImmutableArray() : ImmutableArray.Create<EmbedField>());
|
||||
}
|
||||
|
||||
public override string ToString() => Title;
|
||||
private string DebuggerDisplay => $"{Title} ({Type})";
|
||||
}
|
||||
}
|
||||
208
src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs
Normal file
208
src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public class EmbedBuilder
|
||||
{
|
||||
private readonly Embed _embed;
|
||||
private readonly List<EmbedFieldBuilder> _fields;
|
||||
|
||||
public EmbedBuilder()
|
||||
{
|
||||
_embed = new Embed("rich");
|
||||
_fields = new List<EmbedFieldBuilder>();
|
||||
}
|
||||
|
||||
public string Title { get { return _embed.Title; } set { _embed.Title = value; } }
|
||||
public string Description { get { return _embed.Description; } set { _embed.Description = value; } }
|
||||
public string Url { get { return _embed.Url; } set { _embed.Url = value; } }
|
||||
public string ThumbnailUrl { get { return _embed.Thumbnail?.Url; } set { _embed.Thumbnail = new EmbedThumbnail(value, null, null, null); } }
|
||||
public string ImageUrl { get { return _embed.Image?.Url; } set { _embed.Image = new EmbedImage(value, null, null, null); } }
|
||||
public DateTimeOffset? Timestamp { get { return _embed.Timestamp; } set { _embed.Timestamp = value; } }
|
||||
public Color? Color { get { return _embed.Color; } set { _embed.Color = value; } }
|
||||
|
||||
public EmbedAuthorBuilder Author { get; set; }
|
||||
public EmbedFooterBuilder Footer { get; set; }
|
||||
|
||||
public EmbedBuilder WithTitle(string title)
|
||||
{
|
||||
Title = title;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithDescription(string description)
|
||||
{
|
||||
Description = description;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithUrl(string url)
|
||||
{
|
||||
Url = url;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithThumbnailUrl(string thumbnailUrl)
|
||||
{
|
||||
ThumbnailUrl = thumbnailUrl;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithImageUrl(string imageUrl)
|
||||
{
|
||||
ImageUrl = imageUrl;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithCurrentTimestamp()
|
||||
{
|
||||
Timestamp = DateTimeOffset.UtcNow;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset)
|
||||
{
|
||||
Timestamp = dateTimeOffset;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithColor(Color color)
|
||||
{
|
||||
Color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder WithAuthor(EmbedAuthorBuilder author)
|
||||
{
|
||||
Author = author;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithAuthor(Action<EmbedAuthorBuilder> action)
|
||||
{
|
||||
var author = new EmbedAuthorBuilder();
|
||||
action(author);
|
||||
Author = author;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithFooter(EmbedFooterBuilder footer)
|
||||
{
|
||||
Footer = footer;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithFooter(Action<EmbedFooterBuilder> action)
|
||||
{
|
||||
var footer = new EmbedFooterBuilder();
|
||||
action(footer);
|
||||
Footer = footer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
|
||||
{
|
||||
var field = new EmbedFieldBuilder();
|
||||
action(field);
|
||||
_fields.Add(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Embed Build()
|
||||
{
|
||||
_embed.Footer = Footer?.Build();
|
||||
_embed.Author = Author?.Build();
|
||||
var fields = ImmutableArray.CreateBuilder<EmbedField>(_fields.Count);
|
||||
for (int i = 0; i < _fields.Count; i++)
|
||||
fields.Add(_fields[i].Build());
|
||||
_embed.Fields = fields.ToImmutable();
|
||||
return _embed;
|
||||
}
|
||||
public static implicit operator Embed(EmbedBuilder builder) => builder?.Build();
|
||||
}
|
||||
|
||||
public class EmbedFieldBuilder
|
||||
{
|
||||
private EmbedField _field;
|
||||
|
||||
public string Name { get { return _field.Name; } set { _field.Name = value; } }
|
||||
public string Value { get { return _field.Value; } set { _field.Value = value; } }
|
||||
public bool IsInline { get { return _field.Inline; } set { _field.Inline = value; } }
|
||||
|
||||
public EmbedFieldBuilder()
|
||||
{
|
||||
_field = new EmbedField();
|
||||
}
|
||||
|
||||
public EmbedFieldBuilder WithName(string name)
|
||||
{
|
||||
Name = name;
|
||||
return this;
|
||||
}
|
||||
public EmbedFieldBuilder WithValue(string value)
|
||||
{
|
||||
Value = value;
|
||||
return this;
|
||||
}
|
||||
public EmbedFieldBuilder WithIsInline(bool isInline)
|
||||
{
|
||||
IsInline = isInline;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedField Build()
|
||||
=> _field;
|
||||
}
|
||||
|
||||
public class EmbedAuthorBuilder
|
||||
{
|
||||
private EmbedAuthor _author;
|
||||
|
||||
public string Name { get { return _author.Name; } set { _author.Name = value; } }
|
||||
public string Url { get { return _author.Url; } set { _author.Url = value; } }
|
||||
public string IconUrl { get { return _author.IconUrl; } set { _author.IconUrl = value; } }
|
||||
|
||||
public EmbedAuthorBuilder()
|
||||
{
|
||||
_author = new EmbedAuthor();
|
||||
}
|
||||
|
||||
public EmbedAuthorBuilder WithName(string name)
|
||||
{
|
||||
Name = name;
|
||||
return this;
|
||||
}
|
||||
public EmbedAuthorBuilder WithUrl(string url)
|
||||
{
|
||||
Url = url;
|
||||
return this;
|
||||
}
|
||||
public EmbedAuthorBuilder WithIconUrl(string iconUrl)
|
||||
{
|
||||
IconUrl = iconUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedAuthor Build()
|
||||
=> _author;
|
||||
}
|
||||
|
||||
public class EmbedFooterBuilder
|
||||
{
|
||||
private EmbedFooter _footer;
|
||||
|
||||
public string Text { get { return _footer.Text; } set { _footer.Text = value; } }
|
||||
public string IconUrl { get { return _footer.IconUrl; } set { _footer.IconUrl = value; } }
|
||||
|
||||
public EmbedFooterBuilder()
|
||||
{
|
||||
_footer = new EmbedFooter();
|
||||
}
|
||||
|
||||
public EmbedFooterBuilder WithText(string text)
|
||||
{
|
||||
Text = text;
|
||||
return this;
|
||||
}
|
||||
public EmbedFooterBuilder WithIconUrl(string iconUrl)
|
||||
{
|
||||
IconUrl = iconUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedFooter Build()
|
||||
=> _footer;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace Discord.Rest
|
||||
var apiArgs = new API.Rest.ModifyMessageParams
|
||||
{
|
||||
Content = args.Content,
|
||||
Embed = args.Embed.IsSpecified ? args.Embed.Value.Build() : Optional.Create<API.Embed>()
|
||||
Embed = args.Embed.IsSpecified ? args.Embed.Value.ToModel() : Optional.Create<API.Embed>()
|
||||
};
|
||||
return await client.ApiClient.ModifyMessageAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Model = Discord.API.Reaction;
|
||||
|
||||
namespace Discord
|
||||
namespace Discord.Rest
|
||||
{
|
||||
public class RestReaction : IReaction
|
||||
{
|
||||
@@ -16,7 +16,7 @@ namespace Discord
|
||||
}
|
||||
internal static RestReaction Create(Model model)
|
||||
{
|
||||
return new RestReaction(Emoji.Create(model.Emoji), model.Count, model.Me);
|
||||
return new RestReaction(new Emoji(model.Emoji.Id, model.Emoji.Name), model.Count, model.Me);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Discord.Rest
|
||||
{
|
||||
var embeds = ImmutableArray.CreateBuilder<Embed>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
embeds.Add(Embed.Create(value[i]));
|
||||
embeds.Add(value[i].ToEntity());
|
||||
_embeds = embeds.ToImmutable();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Discord.Rest
|
||||
=> UserHelper.CreateDMChannelAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
|
||||
//IUser
|
||||
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
|
||||
|
||||
124
src/Discord.Net.Rest/Extensions/EntityExtensions.cs
Normal file
124
src/Discord.Net.Rest/Extensions/EntityExtensions.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
internal static class EntityExtensions
|
||||
{
|
||||
public static GuildEmoji ToEntity(this API.Emoji model)
|
||||
{
|
||||
return new GuildEmoji(model.Id.Value, model.Name, model.Managed, model.RequireColons, ImmutableArray.Create(model.Roles));
|
||||
}
|
||||
|
||||
public static Embed ToEntity(this API.Embed model)
|
||||
{
|
||||
return new Embed(model.Type, model.Title, model.Description, model.Url, model.Timestamp,
|
||||
model.Color.HasValue ? new Color(model.Color.Value) : (Color?)null,
|
||||
model.Image.IsSpecified ? model.Image.Value.ToEntity() : (EmbedImage?)null,
|
||||
model.Video.IsSpecified ? model.Video.Value.ToEntity() : (EmbedVideo?)null,
|
||||
model.Author.IsSpecified ? model.Author.Value.ToEntity() : (EmbedAuthor?)null,
|
||||
model.Footer.IsSpecified ? model.Footer.Value.ToEntity() : (EmbedFooter?)null,
|
||||
model.Provider.IsSpecified ? model.Provider.Value.ToEntity() : (EmbedProvider?)null,
|
||||
model.Thumbnail.IsSpecified ? model.Thumbnail.Value.ToEntity() : (EmbedThumbnail?)null,
|
||||
model.Fields.IsSpecified ? model.Fields.Value.Select(x => x.ToEntity()).ToImmutableArray() : ImmutableArray.Create<EmbedField>());
|
||||
}
|
||||
public static API.Embed ToModel(this Embed entity)
|
||||
{
|
||||
var model = new API.Embed
|
||||
{
|
||||
Type = entity.Type,
|
||||
Title = entity.Title,
|
||||
Description = entity.Description,
|
||||
Url = entity.Url,
|
||||
Timestamp = entity.Timestamp,
|
||||
Color = entity.Color?.RawValue
|
||||
};
|
||||
if (entity.Author != null)
|
||||
model.Author = entity.Author.Value.ToModel();
|
||||
model.Fields = entity.Fields.Select(x => x.ToModel()).ToArray();
|
||||
if (entity.Footer != null)
|
||||
model.Footer = entity.Footer.Value.ToModel();
|
||||
if (entity.Image != null)
|
||||
model.Image = entity.Image.Value.ToModel();
|
||||
if (entity.Provider != null)
|
||||
model.Provider = entity.Provider.Value.ToModel();
|
||||
if (entity.Thumbnail != null)
|
||||
model.Thumbnail = entity.Thumbnail.Value.ToModel();
|
||||
if (entity.Video != null)
|
||||
model.Video = entity.Video.Value.ToModel();
|
||||
return model;
|
||||
}
|
||||
public static EmbedAuthor ToEntity(this API.EmbedAuthor model)
|
||||
{
|
||||
return new EmbedAuthor(model.Name, model.Url, model.IconUrl, model.ProxyIconUrl);
|
||||
}
|
||||
public static API.EmbedAuthor ToModel(this EmbedAuthor entity)
|
||||
{
|
||||
return new API.EmbedAuthor { Name = entity.Name, Url = entity.Url, IconUrl = entity.IconUrl };
|
||||
}
|
||||
public static EmbedField ToEntity(this API.EmbedField model)
|
||||
{
|
||||
return new EmbedField(model.Name, model.Value, model.Inline);
|
||||
}
|
||||
public static API.EmbedField ToModel(this EmbedField entity)
|
||||
{
|
||||
return new API.EmbedField { Name = entity.Name, Value = entity.Value, Inline = entity.Inline };
|
||||
}
|
||||
public static EmbedFooter ToEntity(this API.EmbedFooter model)
|
||||
{
|
||||
return new EmbedFooter(model.Text, model.IconUrl, model.ProxyIconUrl);
|
||||
}
|
||||
public static API.EmbedFooter ToModel(this EmbedFooter entity)
|
||||
{
|
||||
return new API.EmbedFooter { Text = entity.Text, IconUrl = entity.IconUrl };
|
||||
}
|
||||
public static EmbedImage ToEntity(this API.EmbedImage model)
|
||||
{
|
||||
return new EmbedImage(model.Url, model.ProxyUrl,
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null);
|
||||
}
|
||||
public static API.EmbedImage ToModel(this EmbedImage entity)
|
||||
{
|
||||
return new API.EmbedImage { Url = entity.Url };
|
||||
}
|
||||
public static EmbedProvider ToEntity(this API.EmbedProvider model)
|
||||
{
|
||||
return new EmbedProvider(model.Name, model.Url);
|
||||
}
|
||||
public static API.EmbedProvider ToModel(this EmbedProvider entity)
|
||||
{
|
||||
return new API.EmbedProvider { Name = entity.Name, Url = entity.Url };
|
||||
}
|
||||
public static EmbedThumbnail ToEntity(this API.EmbedThumbnail model)
|
||||
{
|
||||
return new EmbedThumbnail(model.Url, model.ProxyUrl,
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null);
|
||||
}
|
||||
public static API.EmbedThumbnail ToModel(this EmbedThumbnail entity)
|
||||
{
|
||||
return new API.EmbedThumbnail { Url = entity.Url };
|
||||
}
|
||||
public static EmbedVideo ToEntity(this API.EmbedVideo model)
|
||||
{
|
||||
return new EmbedVideo(model.Url,
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null);
|
||||
}
|
||||
public static API.EmbedVideo ToModel(this EmbedVideo entity)
|
||||
{
|
||||
return new API.EmbedVideo { Url = entity.Url };
|
||||
}
|
||||
|
||||
public static API.Image ToModel(this Image entity)
|
||||
{
|
||||
return new API.Image(entity.Stream);
|
||||
}
|
||||
|
||||
public static Overwrite ToEntity(this API.Overwrite model)
|
||||
{
|
||||
return new Overwrite(model.TargetId, model.TargetType, new OverwritePermissions(model.Allow, model.Deny));
|
||||
}
|
||||
}
|
||||
}
|
||||
59
src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs
Normal file
59
src/Discord.Net.Rest/Net/Converters/ArrayConverter.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class ArrayConverter<T> : JsonConverter
|
||||
{
|
||||
private readonly JsonConverter _innerConverter;
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public ArrayConverter(JsonConverter innerConverter)
|
||||
{
|
||||
_innerConverter = innerConverter;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var result = new List<T>();
|
||||
if (reader.TokenType == JsonToken.StartArray)
|
||||
{
|
||||
reader.Read();
|
||||
while (reader.TokenType != JsonToken.EndArray)
|
||||
{
|
||||
T obj;
|
||||
if (_innerConverter != null)
|
||||
obj = (T)_innerConverter.ReadJson(reader, typeof(T), null, serializer);
|
||||
else
|
||||
obj = serializer.Deserialize<T>(reader);
|
||||
result.Add(obj);
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
var a = (T[])value;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
if (_innerConverter != null)
|
||||
_innerConverter.WriteJson(writer, a[i], serializer);
|
||||
else
|
||||
serializer.Serialize(writer, a[i], typeof(T));
|
||||
}
|
||||
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
else
|
||||
writer.WriteNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
103
src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs
Normal file
103
src/Discord.Net.Rest/Net/Converters/DiscordContractResolver.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Discord.API;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class DiscordContractResolver : DefaultContractResolver
|
||||
{
|
||||
private static readonly TypeInfo _ienumerable = typeof(IEnumerable<ulong[]>).GetTypeInfo();
|
||||
private static readonly MethodInfo _shouldSerialize = typeof(DiscordContractResolver).GetTypeInfo().GetDeclaredMethod("ShouldSerialize");
|
||||
|
||||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||
{
|
||||
var property = base.CreateProperty(member, memberSerialization);
|
||||
if (property.Ignored)
|
||||
return property;
|
||||
|
||||
var propInfo = member as PropertyInfo;
|
||||
if (propInfo != null)
|
||||
{
|
||||
var converter = GetConverter(property, propInfo, propInfo.PropertyType, 0);
|
||||
if (converter != null)
|
||||
{
|
||||
property.Converter = converter;
|
||||
property.MemberConverter = converter;
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new InvalidOperationException($"{member.DeclaringType.FullName}.{member.Name} is not a property.");
|
||||
return property;
|
||||
}
|
||||
|
||||
private static JsonConverter GetConverter(JsonProperty property, PropertyInfo propInfo, Type type, int depth)
|
||||
{
|
||||
if (type.IsArray)
|
||||
return MakeGenericConverter(property, propInfo, typeof(ArrayConverter<>), type.GetElementType(), depth);
|
||||
if (type.IsConstructedGenericType)
|
||||
{
|
||||
Type genericType = type.GetGenericTypeDefinition();
|
||||
if (depth == 0 && genericType == typeof(Optional<>))
|
||||
{
|
||||
var typeInput = propInfo.DeclaringType;
|
||||
var innerTypeOutput = type.GenericTypeArguments[0];
|
||||
|
||||
var getter = typeof(Func<,>).MakeGenericType(typeInput, type);
|
||||
var getterDelegate = propInfo.GetMethod.CreateDelegate(getter);
|
||||
var shouldSerialize = _shouldSerialize.MakeGenericMethod(typeInput, innerTypeOutput);
|
||||
var shouldSerializeDelegate = (Func<object, Delegate, bool>)shouldSerialize.CreateDelegate(typeof(Func<object, Delegate, bool>));
|
||||
property.ShouldSerialize = x => shouldSerializeDelegate(x, getterDelegate);
|
||||
|
||||
return MakeGenericConverter(property, propInfo, typeof(OptionalConverter<>), innerTypeOutput, depth);
|
||||
}
|
||||
else if (genericType == typeof(Nullable<>))
|
||||
return MakeGenericConverter(property, propInfo, typeof(NullableConverter<>), type.GenericTypeArguments[0], depth);
|
||||
else if (genericType == typeof(EntityOrId<>))
|
||||
return MakeGenericConverter(property, propInfo, typeof(UInt64EntityOrIdConverter<>), type.GenericTypeArguments[0], depth);
|
||||
}
|
||||
|
||||
//Primitives
|
||||
bool hasInt53 = propInfo.GetCustomAttribute<Int53Attribute>() != null;
|
||||
if (!hasInt53)
|
||||
{
|
||||
if (type == typeof(ulong))
|
||||
return UInt64Converter.Instance;
|
||||
}
|
||||
|
||||
//Enums
|
||||
if (type == typeof(PermissionTarget))
|
||||
return PermissionTargetConverter.Instance;
|
||||
if (type == typeof(UserStatus))
|
||||
return UserStatusConverter.Instance;
|
||||
|
||||
//Special
|
||||
if (type == typeof(API.Image))
|
||||
return ImageConverter.Instance;
|
||||
|
||||
//Entities
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
if (typeInfo.ImplementedInterfaces.Any(x => x == typeof(IEntity<ulong>)))
|
||||
return UInt64EntityConverter.Instance;
|
||||
if (typeInfo.ImplementedInterfaces.Any(x => x == typeof(IEntity<string>)))
|
||||
return StringEntityConverter.Instance;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ShouldSerialize<TOwner, TValue>(object owner, Delegate getter)
|
||||
{
|
||||
return (getter as Func<TOwner, Optional<TValue>>)((TOwner)owner).IsSpecified;
|
||||
}
|
||||
|
||||
private static JsonConverter MakeGenericConverter(JsonProperty property, PropertyInfo propInfo, Type converterType, Type innerType, int depth)
|
||||
{
|
||||
var genericType = converterType.MakeGenericType(innerType).GetTypeInfo();
|
||||
var innerConverter = GetConverter(property, propInfo, innerType, depth + 1);
|
||||
return genericType.DeclaredConstructors.First().Invoke(new object[] { innerConverter }) as JsonConverter;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Discord.Net.Rest/Net/Converters/ImageConverter.cs
Normal file
37
src/Discord.Net.Rest/Net/Converters/ImageConverter.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Discord.API;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Model = Discord.API.Image;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class ImageConverter : JsonConverter
|
||||
{
|
||||
public static readonly ImageConverter Instance = new ImageConverter();
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var image = (Model)value;
|
||||
|
||||
if (image.Stream != null)
|
||||
{
|
||||
byte[] bytes = new byte[image.Stream.Length - image.Stream.Position];
|
||||
image.Stream.Read(bytes, 0, bytes.Length);
|
||||
|
||||
string base64 = Convert.ToBase64String(bytes);
|
||||
writer.WriteValue($"data:image/jpeg;base64,{base64}");
|
||||
}
|
||||
else if (image.Hash != null)
|
||||
writer.WriteValue(image.Hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
src/Discord.Net.Rest/Net/Converters/NullableConverter.cs
Normal file
50
src/Discord.Net.Rest/Net/Converters/NullableConverter.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class NullableConverter<T> : JsonConverter
|
||||
where T : struct
|
||||
{
|
||||
private readonly JsonConverter _innerConverter;
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public NullableConverter(JsonConverter innerConverter)
|
||||
{
|
||||
_innerConverter = innerConverter;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
object value = reader.Value;
|
||||
if (value == null)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
T obj;
|
||||
if (_innerConverter != null)
|
||||
obj = (T)_innerConverter.ReadJson(reader, typeof(T), null, serializer);
|
||||
else
|
||||
obj = serializer.Deserialize<T>(reader);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
writer.WriteNull();
|
||||
else
|
||||
{
|
||||
var nullable = (T?)value;
|
||||
if (_innerConverter != null)
|
||||
_innerConverter.WriteJson(writer, nullable.Value, serializer);
|
||||
else
|
||||
serializer.Serialize(writer, nullable.Value, typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/Discord.Net.Rest/Net/Converters/OptionalConverter.cs
Normal file
38
src/Discord.Net.Rest/Net/Converters/OptionalConverter.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class OptionalConverter<T> : JsonConverter
|
||||
{
|
||||
private readonly JsonConverter _innerConverter;
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public OptionalConverter(JsonConverter innerConverter)
|
||||
{
|
||||
_innerConverter = innerConverter;
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
T obj;
|
||||
if (_innerConverter != null)
|
||||
obj = (T)_innerConverter.ReadJson(reader, typeof(T), null, serializer);
|
||||
else
|
||||
obj = serializer.Deserialize<T>(reader);
|
||||
return new Optional<T>(obj);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
value = ((Optional<T>)value).Value;
|
||||
if (_innerConverter != null)
|
||||
_innerConverter.WriteJson(writer, value, serializer);
|
||||
else
|
||||
serializer.Serialize(writer, value, typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class PermissionTargetConverter : JsonConverter
|
||||
{
|
||||
public static readonly PermissionTargetConverter Instance = new PermissionTargetConverter();
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
switch ((string)reader.Value)
|
||||
{
|
||||
case "member":
|
||||
return PermissionTarget.User;
|
||||
case "role":
|
||||
return PermissionTarget.Role;
|
||||
default:
|
||||
throw new JsonSerializationException("Unknown permission target");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
switch ((PermissionTarget)value)
|
||||
{
|
||||
case PermissionTarget.User:
|
||||
writer.WriteValue("member");
|
||||
break;
|
||||
case PermissionTarget.Role:
|
||||
writer.WriteValue("role");
|
||||
break;
|
||||
default:
|
||||
throw new JsonSerializationException("Invalid permission target");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/Discord.Net.Rest/Net/Converters/StringEntityConverter.cs
Normal file
27
src/Discord.Net.Rest/Net/Converters/StringEntityConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
{
|
||||
internal class StringEntityConverter : JsonConverter
|
||||
{
|
||||
public static readonly StringEntityConverter Instance = new StringEntityConverter();
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => false;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
writer.WriteValue((value as IEntity<string>).Id);
|
||||
else
|
||||
writer.WriteNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user