Clean up mention with mustache

This commit is contained in:
Jeremy Zhang 2017-11-06 03:12:18 +00:00
parent 6a2a3d1f34
commit 07bd0b5f5b
2 changed files with 9 additions and 4 deletions

View File

@ -682,16 +682,17 @@
function replace_message_mentions(message) {
var mentions = message.mentions;
var template = $('#mustache_discordmention').html();
Mustache.parse(template);
for (var i = 0; i < mentions.length; i++) {
var mention = mentions[i];
var username = mention.username;
if (mention.nickname) {
username = mention.nickname;
}
console.log(message.content)
var templ = "<span class=\"mention\">@<span class=\"username\">" + username + "</span><span class=\"discriminator\">#" + mention.discriminator + "</span></span>";
message.content = message.content.replace(new RegExp("&lt;@" + mention.id + "&gt;", 'g'), templ);
message.content = message.content.replace(new RegExp("&lt;@!" + mention.id + "&gt;", 'g'), templ);
var rendered = Mustache.render(template, {"username": username, "discriminator": mention.discriminator}).trim();
message.content = message.content.replace(new RegExp("&lt;@" + mention.id + "&gt;", 'g'), rendered);
message.content = message.content.replace(new RegExp("&lt;@!" + mention.id + "&gt;", 'g'), rendered);
message.content = message.content.replace("&lt;@&" + guild_id + "&gt;", "@everyone");
}
return message;

View File

@ -233,6 +233,10 @@
<img class="message_emoji tooltipped" src='https://cdn.discordapp.com/emojis/{{id}}.png' data-position="top" data-delay="200" data-tooltip=":{{name}}:" alt=":{{name}}:" />
</script>
<script id="mustache_discordmention" type="text/template">
<span class="discordmention"><span class="atsign">@</span><span class="username">{{username}}</span><span class="hash">#</span><span class="discriminator">{{discriminator}}</span></span>
</script>
<script id="mustache_richembed" type="text/template">
<div class="richembed">
{{#color}}