| @@ -125,6 +125,7 @@ namespace Discord | |||||
| var userIds = !channel.IsPrivate ? Mention.GetUserIds(text).Distinct() : new string[0]; | var userIds = !channel.IsPrivate ? Mention.GetUserIds(text).Distinct() : new string[0]; | ||||
| if (Config.UseMessageQueue) | if (Config.UseMessageQueue) | ||||
| { | { | ||||
| var channelIds = !channel.IsPrivate ? Mention.GetChannelIds(text).Distinct() : new string[0]; | |||||
| var nonce = GenerateNonce(); | var nonce = GenerateNonce(); | ||||
| msg = _messages.GetOrAdd("nonce_" + nonce, channel.Id, _userId); | msg = _messages.GetOrAdd("nonce_" + nonce, channel.Id, _userId); | ||||
| var currentUser = msg.User; | var currentUser = msg.User; | ||||
| @@ -136,9 +137,19 @@ namespace Discord | |||||
| ChannelId = channel.Id, | ChannelId = channel.Id, | ||||
| IsTextToSpeech = isTextToSpeech | IsTextToSpeech = isTextToSpeech | ||||
| }); | }); | ||||
| msg.Mentions = userIds.Select(x => _users[x, channel.Server.Id]).Where(x => x != null).ToArray(); | |||||
| msg.IsQueued = true; | |||||
| msg.Nonce = nonce; | msg.Nonce = nonce; | ||||
| msg.IsQueued = true; | |||||
| //IsPrivate check is already done earlier | |||||
| msg.MentionedUsers = userIds | |||||
| .Select(x => _users[x, channel.Server.Id]) | |||||
| .Where(x => x != null) | |||||
| .ToArray(); | |||||
| msg.MentionedChannels = channelIds | |||||
| .Select(x => _channels[x]) | |||||
| .Where(x => x != null && x.Server == channel.Server) | |||||
| .ToArray(); | |||||
| _pendingMessages.Enqueue(msg); | _pendingMessages.Enqueue(msg); | ||||
| } | } | ||||
| else | else | ||||
| @@ -258,7 +269,7 @@ namespace Discord | |||||
| SendMessageResponse response = null; | SendMessageResponse response = null; | ||||
| try | try | ||||
| { | { | ||||
| response = await _api.SendMessage(msg.Channel.Id, msg.RawText, msg.Mentions.Select(x => x.Id), msg.Nonce, msg.IsTTS).ConfigureAwait(false); | |||||
| response = await _api.SendMessage(msg.Channel.Id, msg.RawText, msg.MentionedUsers.Select(x => x.Id), msg.Nonce, msg.IsTTS).ConfigureAwait(false); | |||||
| } | } | ||||
| catch (WebException) { break; } | catch (WebException) { break; } | ||||
| catch (HttpException) { hasFailed = true; } | catch (HttpException) { hasFailed = true; } | ||||
| @@ -52,5 +52,12 @@ namespace Discord | |||||
| .Select(x => x.Groups[1].Value) | .Select(x => x.Groups[1].Value) | ||||
| .Where(x => x != null); | .Where(x => x != null); | ||||
| } | } | ||||
| internal static IEnumerable<string> GetChannelIds(string text) | |||||
| { | |||||
| return _channelRegex.Matches(text) | |||||
| .OfType<Match>() | |||||
| .Select(x => x.Groups[1].Value) | |||||
| .Where(x => x != null); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -125,8 +125,12 @@ namespace Discord | |||||
| /// <summary> Returns a collection of all users mentioned in this message. </summary> | /// <summary> Returns a collection of all users mentioned in this message. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public IEnumerable<User> Mentions { get; internal set; } | |||||
| public IEnumerable<User> MentionedUsers { get; internal set; } | |||||
| /// <summary> Returns a collection of all channels mentioned in this message. </summary> | |||||
| [JsonIgnore] | |||||
| public IEnumerable<Channel> MentionedChannels { get; internal set; } | |||||
| /// <summary> Returns the server containing the channel this message was sent to. </summary> | /// <summary> Returns the server containing the channel this message was sent to. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public Server Server => _channel.Value.Server; | public Server Server => _channel.Value.Server; | ||||
| @@ -208,13 +212,26 @@ namespace Discord | |||||
| EditedTimestamp = model.EditedTimestamp; | EditedTimestamp = model.EditedTimestamp; | ||||
| if (model.Mentions != null) | if (model.Mentions != null) | ||||
| { | { | ||||
| Mentions = model.Mentions.Select(x => _client.Users[x.Id, Channel.Server?.Id]).ToArray(); | |||||
| IsMentioningMe = model.Mentions.Any(x => x.Id == _client.CurrentUserId); | |||||
| MentionedUsers = model.Mentions | |||||
| .Select(x => _client.Users[x.Id, Channel.Server?.Id]) | |||||
| .ToArray(); | |||||
| IsMentioningMe = model.Mentions | |||||
| .Any(x => x.Id == _client.CurrentUserId); | |||||
| } | } | ||||
| if (model.Content != null) | if (model.Content != null) | ||||
| { | { | ||||
| RawText = model.Content; | RawText = model.Content; | ||||
| _cleanText = null; | _cleanText = null; | ||||
| if (!Channel.IsPrivate) | |||||
| { | |||||
| MentionedChannels = Mention.GetChannelIds(model.Content) | |||||
| .Select(x => _client.Channels[x]) | |||||
| .Where(x => x.Server == Channel.Server) | |||||
| .ToArray(); | |||||
| } | |||||
| else | |||||
| MentionedChannels = new Channel[0]; | |||||
| } | } | ||||
| } | } | ||||