Browse Source

Set the @everyone IRole for @everyone and @here tags

Adds support for setting the IRole corresponding to @everyone or @here in a the tags of a message. Previously this would only set the TagType, but leave the value as null.

This does not distinguish between @everyone and @here, as that's done using TagType. The values of both will be the same.

This issue was suggested by @TheCasino
pull/1313/head
Chris Johnston 6 years ago
parent
commit
ac6b263516
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs

+ 8
- 2
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -152,10 +152,13 @@ namespace Discord.Rest
{ {
index = text.IndexOf("@everyone", index); index = text.IndexOf("@everyone", index);
if (index == -1) break; if (index == -1) break;
IRole mentionedRole = null;
if (guild != null)
mentionedRole = guild.GetRole(guild.Id);


var tagIndex = FindIndex(tags, index); var tagIndex = FindIndex(tags, index);
if (tagIndex.HasValue) if (tagIndex.HasValue)
tags.Insert(tagIndex.Value, new Tag<object>(TagType.EveryoneMention, index, "@everyone".Length, 0, null));
tags.Insert(tagIndex.Value, new Tag<IRole>(TagType.EveryoneMention, index, "@everyone".Length, 0, mentionedRole));
index++; index++;
} }


@@ -164,10 +167,13 @@ namespace Discord.Rest
{ {
index = text.IndexOf("@here", index); index = text.IndexOf("@here", index);
if (index == -1) break; if (index == -1) break;
IRole mentionedRole = null;
if (guild != null)
mentionedRole = guild.GetRole(guild.Id);


var tagIndex = FindIndex(tags, index); var tagIndex = FindIndex(tags, index);
if (tagIndex.HasValue) if (tagIndex.HasValue)
tags.Insert(tagIndex.Value, new Tag<object>(TagType.HereMention, index, "@here".Length, 0, null));
tags.Insert(tagIndex.Value, new Tag<IRole>(TagType.HereMention, index, "@here".Length, 0, mentionedRole));
index++; index++;
} }




Loading…
Cancel
Save