From b53af56fff6179a4c9d32928b356f468628c2b92 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 17 May 2017 00:45:28 +0200 Subject: [PATCH] mention related stuff --- Maki/Discord.cs | 1 + Maki/DiscordChannel.cs | 2 ++ Maki/DiscordChannelType.cs | 9 +++++++++ Maki/DiscordMessage.cs | 14 ++++++++++++++ Maki/Maki.csproj | 5 +++-- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Maki/DiscordChannelType.cs diff --git a/Maki/Discord.cs b/Maki/Discord.cs index a92e0a7..66e2407 100644 --- a/Maki/Discord.cs +++ b/Maki/Discord.cs @@ -705,6 +705,7 @@ namespace Maki OnMessageUpdate?.Invoke(msg); } + // TODO: account for DMs private void ShardManager_OnTypingStart(GatewayShard shard, TypingStart typing) { DiscordChannel channel = channels.Find(x => x.Id == typing.Channel); diff --git a/Maki/DiscordChannel.cs b/Maki/DiscordChannel.cs index 2786c96..ef589cf 100644 --- a/Maki/DiscordChannel.cs +++ b/Maki/DiscordChannel.cs @@ -12,12 +12,14 @@ namespace Maki private readonly Discord client; public string Name { get; internal set; } + public DiscordChannelType Type { get; internal set; } internal DiscordChannel(Discord discord, Channel channel, DiscordServer server) { client = discord; Id = channel.Id; Name = channel.Name; + Type = (DiscordChannelType)channel.Type; Server = server; } diff --git a/Maki/DiscordChannelType.cs b/Maki/DiscordChannelType.cs new file mode 100644 index 0000000..71e8b5a --- /dev/null +++ b/Maki/DiscordChannelType.cs @@ -0,0 +1,9 @@ +namespace Maki +{ + public enum DiscordChannelType + { + Text = 0, + Private = 1, + Voice = 2, + } +} diff --git a/Maki/DiscordMessage.cs b/Maki/DiscordMessage.cs index e17730b..91f6bb5 100644 --- a/Maki/DiscordMessage.cs +++ b/Maki/DiscordMessage.cs @@ -1,5 +1,6 @@ using Maki.Structures.Messages; using System; +using System.Linq; namespace Maki { @@ -13,6 +14,16 @@ namespace Maki public string Text { get; internal set; } public DateTime Edited { get; internal set; } + public DiscordMember[] MentionsUsers { get; internal set; } + public DiscordRole[] MentionsRoles { get; internal set; } + public bool MentionsEveryone { get; internal set; } + + public bool MentionsMe(bool everyone = false, bool roles = true) => + (everyone && MentionsEveryone) + || (roles && client.members.Where(x => x.User == client.Me && x.Server == Channel.Server).First().Roles.Where(x => MentionsRoles.Contains(x)).Count() > 0) + || MentionsUsers.Select(x => x.User).Contains(client.Me); + + public bool IsMe => client.Me == Sender.User; internal DiscordMessage(Discord discord, Message msg, DiscordMember member, DiscordChannel channel) { @@ -22,6 +33,9 @@ namespace Maki Text = msg.Content; Sender = member; Channel = channel; + MentionsUsers = client.members.Where(x => x.Server == channel.Server && msg.Mentions.Select(y => y.Id).Contains(x.User.Id)).ToArray(); + MentionsRoles = client.roles.Where(x => x.Server == channel.Server && msg.MentionsRoles.Contains(x.Id)).ToArray(); + MentionsEveryone = msg.MentioningEveryone; } public DiscordMessage Edit(string text) diff --git a/Maki/Maki.csproj b/Maki/Maki.csproj index 853405c..f91521d 100644 --- a/Maki/Maki.csproj +++ b/Maki/Maki.csproj @@ -36,7 +36,7 @@ - ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll @@ -46,12 +46,13 @@ - ..\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll + ..\..\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll +