FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implemented new DiscordMessage properties (#472) · DSharpPlus/DSharpPlus@ec539a6 · GitHub

Commit ec539a6

Browse files
authored andcommitted
Implemented new DiscordMessage properties (#472)
1 parent dd3b8f0 commit ec539a6

7 files changed

Lines changed: 275 additions & 60 deletions

File tree

‎DSharpPlus/Entities/DiscordApplication.cs‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ namespace DSharpPlus.Entities
99
/// <summary>
1010
/// Represents an OAuth2 application.
1111
/// </summary>
12-
public sealed class DiscordApplication : SnowflakeObject, IEquatable<DiscordApplication>
12+
public sealed class DiscordApplication : DiscordMessageApplication, IEquatable<DiscordApplication>
1313
{
14-
/// <summary>
15-
/// Gets the application's description.
16-
/// </summary>
17-
public string Description { get; internal set; }
18-
1914
/// <summary>
2015
/// Gets the application's summary.
2116
/// </summary>
@@ -24,19 +19,14 @@ public sealed class DiscordApplication : SnowflakeObject, IEquatable<DiscordAppl
2419
/// <summary>
2520
/// Gets the application's icon.
2621
/// </summary>
27-
public string Icon
22+
public override string Icon
2823
=> !string.IsNullOrWhiteSpace(this.IconHash) ? $"https://cdn.discordapp.com/app-icons/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.IconHash}.png?size=1024" : null;
2924

3025
/// <summary>
3126
/// Gets the application's icon hash.
3227
/// </summary>
3328
public string IconHash { get; internal set; }
3429

35-
/// <summary>
36-
/// Gets the application's name.
37-
/// </summary>
38-
public string Name { get; internal set; }
39-
4030
/// <summary>
4131
/// Gets the application's allowed RPC origins.
4232
/// </summary>
@@ -70,7 +60,7 @@ public string Icon
7060
/// <summary>
7161
/// Gets this application's cover image URL.
7262
/// </summary>
73-
public string CoverImageUrl
63+
public override string CoverImageUrl
7464
=> $"https://cdn.discordapp.com/app-icons/{this.Id.ToString(CultureInfo.InvariantCulture)}/{this.CoverImageHash}.png?size=1024";
7565

7666
/// <summary>

‎DSharpPlus/Entities/DiscordMessage.cs‎

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Newtonsoft.Json;
88
using System.Globalization;
99
using System.Linq;
10+
using DSharpPlus.Enums;
1011

1112
namespace DSharpPlus.Entities
1213
{
@@ -17,6 +18,11 @@ public class DiscordMessage : SnowflakeObject, IEquatable<DiscordMessage>
1718
{
1819
internal DiscordMessage()
1920
{
21+
if (this.Application != null)
22+
this.Application.Discord = this.Discord as DiscordClient;
23+
if (this.Reference != null)
24+
this.Reference._client = this.Discord as DiscordClient;
25+
2026
this._attachmentsLazy = new Lazy<IReadOnlyList<DiscordAttachment>>(() => new ReadOnlyCollection<DiscordAttachment>(this._attachments));
2127
this._embedsLazy = new Lazy<IReadOnlyList<DiscordEmbed>>(() => new ReadOnlyCollection<DiscordEmbed>(this._embeds));
2228
this._mentionedChannelsLazy = new Lazy<IReadOnlyList<DiscordChannel>>(() => {
@@ -76,7 +82,7 @@ public DiscordChannel Channel
7682
=> (this.Discord as DiscordClient)?.InternalGetCachedChannel(this.ChannelId);
7783

7884
/// <summary>
79-
/// Gets ID of the channel in which the message was sent.
85+
/// Gets the ID of the channel in which the message was sent.
8086
/// </summary>
8187
[JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)]
8288
public ulong ChannelId { get; internal set; }
@@ -234,6 +240,24 @@ public IReadOnlyList<DiscordReaction> Reactions
234240
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
235241
public MessageType? MessageType { get; internal set; }
236242

243+
/// <summary>
244+
/// Gets the message activity in the Rich Presence embed.
245+
/// </summary>
246+
[JsonProperty("activity", NullValueHandling = NullValueHandling.Ignore)]
247+
public DiscordMessageActivity Activity { get; internal set; }
248+
249+
/// <summary>
250+
/// Gets the message application in the Rich Presence embed.
251+
/// </summary>
252+
[JsonProperty("application", NullValueHandling = NullValueHandling.Ignore)]
253+
public DiscordMessageApplication Application { get; internal set; }
254+
255+
/// <summary>
256+
/// Gets the original message reference from the crossposted message.
257+
/// </summary>
258+
[JsonProperty("message_reference", NullValueHandling = NullValueHandling.Ignore)]
259+
public DiscordMessageReference Reference { get; internal set; }
260+
237261
/// <summary>
238262
/// Gets whether the message originated from a webhook.
239263
/// </summary>
@@ -466,50 +490,4 @@ public override int GetHashCode()
466490
public static bool operator !=(DiscordMessage e1, DiscordMessage e2)
467491
=> !(e1 == e2);
468492
}
469-
470-
/// <summary>
471-
/// Indicates the type of the message.
472-
/// </summary>
473-
public enum MessageType : int
474-
{
475-
/// <summary>
476-
/// Indicates a regular message.
477-
/// </summary>
478-
Default = 0,
479-
480-
/// <summary>
481-
/// Message indicating a recipient was added to a group direct message.
482-
/// </summary>
483-
RecipientAdd = 1,
484-
485-
/// <summary>
486-
/// Message indicating a recipient was removed from a group direct message.
487-
/// </summary>
488-
RecipientRemove = 2,
489-
490-
/// <summary>
491-
/// Message indicating a call.
492-
/// </summary>
493-
Call = 3,
494-
495-
/// <summary>
496-
/// Message indicating a group direct message channel rename.
497-
/// </summary>
498-
ChannelNameChange = 4,
499-
500-
/// <summary>
501-
/// Message indicating a group direct message channel icon change.
502-
/// </summary>
503-
ChannelIconChange = 5,
504-
505-
/// <summary>
506-
/// USER pinned a message to this channel.
507-
/// </summary>
508-
ChannelPinnedMessage = 6,
509-
510-
/// <summary>
511-
/// Message when a guild member joins. Most frequently seen in newer, smaller guilds.
512-
/// </summary>
513-
GuildMemberJoin = 7
514-
}
515493
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Newtonsoft.Json;
2+
3+
namespace DSharpPlus.Entities
4+
{
5+
/// <summary>
6+
/// Represents a Rich Presence activity.
7+
/// </summary>
8+
public class DiscordMessageActivity
9+
{
10+
/// <summary>
11+
/// Gets the activity type.
12+
/// </summary>
13+
[JsonProperty("type")]
14+
public int Type { get; internal set; }
15+
16+
/// <summary>
17+
/// Gets the party id of the activity.
18+
/// </summary>
19+
[JsonProperty("party_id")]
20+
public string PartyId { get; internal set; }
21+
22+
internal DiscordMessageActivity() { }
23+
}
24+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Newtonsoft.Json;
2+
3+
namespace DSharpPlus.Entities
4+
{
5+
/// <summary>
6+
/// Represents a Rich Presence application.
7+
/// </summary>
8+
public class DiscordMessageApplication : SnowflakeObject
9+
{
10+
/// <summary>
11+
/// Gets the ID of this application's cover image.
12+
/// </summary>
13+
[JsonProperty("cover_image")]
14+
public virtual string CoverImageUrl { get; internal set; }
15+
16+
/// <summary>
17+
/// Gets the application's description.
18+
/// </summary>
19+
[JsonProperty("description")]
20+
public string Description { get; internal set; }
21+
22+
/// <summary>
23+
/// Gets the ID of the application's icon.
24+
/// </summary>
25+
[JsonProperty("icon")]
26+
public virtual string Icon { get; internal set; }
27+
28+
/// <summary>
29+
/// Gets the application's name.
30+
/// </summary>
31+
[JsonProperty("name")]
32+
public string Name { get; internal set; }
33+
34+
internal DiscordMessageApplication() { }
35+
36+
37+
}
38+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
4+
namespace DSharpPlus.Entities
5+
{
6+
/// <summary>
7+
/// Represents data from the original message.
8+
/// </summary>
9+
public class DiscordMessageReference
10+
{
11+
/// <summary>
12+
/// Gets the original message.
13+
/// </summary>
14+
[JsonIgnore]
15+
public DiscordMessage Message { get; internal set; }
16+
17+
/// <summary>
18+
/// Gets the channel of the original message.
19+
/// </summary>
20+
[JsonIgnore]
21+
public DiscordChannel Channel { get; internal set; }
22+
23+
/// <summary>
24+
/// Gets the guild of the original message.
25+
/// </summary>
26+
[JsonIgnore]
27+
public DiscordGuild Guild { get; internal set; }
28+
29+
[JsonProperty("message_id")]
30+
internal ulong? messageId { get; set; }
31+
32+
[JsonProperty("channel_id")]
33+
internal ulong channelId { get; set; }
34+
35+
[JsonProperty("guild_id")]
36+
internal ulong? guildId { get; set; }
37+
38+
[JsonIgnore]
39+
internal DiscordClient _client { get; set; }
40+
41+
internal DiscordMessageReference()
42+
{
43+
if (this.guildId.HasValue)
44+
if (this._client._guilds.TryGetValue(this.guildId.Value, out var g))
45+
this.Guild = g;
46+
47+
else this.Guild = new DiscordGuild
48+
{
49+
Id = this.guildId.Value,
50+
Discord = this._client,
51+
};
52+
53+
var channel = this._client.InternalGetCachedChannel(this.channelId);
54+
55+
if (channel == null)
56+
this.Channel = new DiscordChannel
57+
{
58+
Id = this.channelId,
59+
GuildId = this.guildId.Value,
60+
Discord = this._client
61+
};
62+
63+
else this.Channel = channel;
64+
65+
this.Message = new DiscordMessage
66+
{
67+
ChannelId = this.channelId,
68+
Discord = this._client
69+
};
70+
71+
if (messageId.HasValue)
72+
if (this._client.MessageCache.TryGet(m => m.Id == messageId.Value && m.ChannelId == channelId, out var msg))
73+
this.Message = msg;
74+
75+
else this.Message.Id = this.messageId.Value;
76+
}
77+
}
78+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace DSharpPlus.Enums
2+
{
3+
/// <summary>
4+
/// Indicates the type of MessageActivity for the Rich Presence.
5+
/// </summary>
6+
public enum MessageActivityType
7+
{
8+
/// <summary>
9+
/// Invites the user to join.
10+
/// </summary>
11+
Join = 1,
12+
13+
/// <summary>
14+
/// Invites the user to spectate.
15+
/// </summary>
16+
Spectate = 2,
17+
18+
/// <summary>
19+
/// Invites the user to listen.
20+
/// </summary>
21+
Listen = 3,
22+
23+
/// <summary>
24+
/// Allows user to request to join.
25+
/// </summary>
26+
JoinRequest = 4
27+
}
28+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL