mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-25 06:27:03 +01:00
Parse formatting within rich embeds
This commit is contained in:
parent
07e4e4113c
commit
6578526ef6
@ -1343,6 +1343,12 @@
|
||||
message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), rendered);
|
||||
}
|
||||
|
||||
message.content = parse_role_mention(message.content);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
function parse_role_mention(content) {
|
||||
var template = $("#mustache_rolemention").html();
|
||||
Mustache.parse(template);
|
||||
for (var i = 0; i < guild_roles_list.length; i++) {
|
||||
@ -1352,9 +1358,9 @@
|
||||
roleobj.color = "#" + role.color.toString(16);
|
||||
}
|
||||
var rendered = Mustache.render(template, roleobj).trim();
|
||||
message.content = message.content.replace("<@&" + role.id + ">", rendered);
|
||||
content = content.replace("<@&" + role.id + ">", rendered);
|
||||
}
|
||||
return message;
|
||||
return content;
|
||||
}
|
||||
|
||||
function getPosition(string, subString, index) {
|
||||
@ -1450,7 +1456,7 @@
|
||||
for (var i = 0; i < channelids.length; i++) {
|
||||
var pattern = "<#" + channelids[i] + ">";
|
||||
var elem = "<span class=\"channellink\" channelid=\"" + channelids[i] + "\">#" + guild_channels[channelids[i]].channel.name + "</span>";
|
||||
message.content = message.content.replace(new RegExp(pattern, "g"), elem);
|
||||
message = message.replace(new RegExp(pattern, "g"), elem);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
@ -1467,13 +1473,13 @@
|
||||
emoji_format = "<:" + emoji.name + ":" + emoji.id + ">";
|
||||
}
|
||||
var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name, "animated": emoji.animated}).trim();
|
||||
message.content = message.content.replaceAll(emoji_format, rendered);
|
||||
message = message.replaceAll(emoji_format, rendered);
|
||||
}
|
||||
var rendered = Mustache.render(template, {"id": "$2", "name": "$1"}).trim();
|
||||
message.content = message.content.replace(/<:(.*?):(.*?)>/g, rendered);
|
||||
message = message.replace(/<:(.*?):(.*?)>/g, rendered);
|
||||
rendered = Mustache.render(template, {"id": "$2", "name": "$1", "animated": true}).trim();
|
||||
message.content = message.content.replace(/<a:(.*?):(.*?)>/g, rendered);
|
||||
message.content = twemoji.parse(message.content, {
|
||||
message = message.replace(/<a:(.*?):(.*?)>/g, rendered);
|
||||
message = twemoji.parse(message, {
|
||||
className: "message_emoji",
|
||||
callback: function(icon, options, variant) { // exclude special characters
|
||||
switch (icon) {
|
||||
@ -1592,12 +1598,41 @@
|
||||
if (disembed.color) {
|
||||
disembed.hexColor = "#" + disembed.color.toString(16);
|
||||
}
|
||||
if (disembed.title) {
|
||||
disembed.title = render_embed_text_formatting(disembed.title);
|
||||
}
|
||||
if (disembed.description) {
|
||||
disembed.description = render_embed_text_formatting(disembed.description);
|
||||
}
|
||||
if (disembed.fields) {
|
||||
for (var i = 0; i < disembed.fields.length; i++) {
|
||||
disembed.fields[i].name = render_embed_text_formatting(disembed.fields[i].name);
|
||||
disembed.fields[i].value = render_embed_text_formatting(disembed.fields[i].value);
|
||||
}
|
||||
}
|
||||
var template = $('#mustache_richembed').html();
|
||||
Mustache.parse(template);
|
||||
var rendered = Mustache.render(template, disembed);
|
||||
return rendered;
|
||||
}
|
||||
|
||||
function render_embed_text_formatting(content) {
|
||||
content = content.replaceAll("\\<", "<");
|
||||
content = content.replaceAll("\\>", ">");
|
||||
content = escapeHtml(content);
|
||||
content = parse_role_mention(content);
|
||||
content = parse_message_markdown(content);
|
||||
content = parse_channels_in_message(content);
|
||||
content = parse_emoji_in_message(content);
|
||||
content = content.replace(/<https:\/\/(.*?)>/g, "https://$1");
|
||||
content = content.replace(/<http:\/\/(.*?)>/g, "http://$1");
|
||||
var el = $("<div></div>").html(content);
|
||||
el.linkify({
|
||||
target: "_blank"
|
||||
});
|
||||
return el.html();
|
||||
}
|
||||
|
||||
function parse_message_reactions(reactions) {
|
||||
var reacts = []
|
||||
var template = $("#mustache_reactionchip").html();
|
||||
@ -1700,8 +1735,8 @@
|
||||
message = replace_message_mentions(message);
|
||||
message = parse_message_attachments(message);
|
||||
message.content = parse_message_markdown(message.content);
|
||||
message = parse_channels_in_message(message);
|
||||
message = parse_emoji_in_message(message);
|
||||
message.content = parse_channels_in_message(message.content);
|
||||
message.content = parse_emoji_in_message(message.content);
|
||||
message.content = message.content.replace(/<https:\/\/(.*?)>/g, "https://$1");
|
||||
message.content = message.content.replace(/<http:\/\/(.*?)>/g, "http://$1");
|
||||
if (message.type == 7) {
|
||||
|
@ -530,12 +530,12 @@
|
||||
<a href="
|
||||
{{#url}}{{url}}{{/url}}
|
||||
{{^url}}#{{/url}}
|
||||
" target="_blank">{{title}}</a>
|
||||
" target="_blank">{{{title}}}</a>
|
||||
</div>
|
||||
{{/title}}
|
||||
{{^isVideo}}
|
||||
{{#description}}
|
||||
<div class="description">{{description}}</div>
|
||||
<div class="description">{{{description}}}</div>
|
||||
{{/description}}
|
||||
{{/isVideo}}
|
||||
{{#isVideo}}
|
||||
@ -552,8 +552,8 @@
|
||||
<div class="fields">
|
||||
{{#fields}}
|
||||
<div class="field {{#inline}}inline{{/inline}}">
|
||||
<div class="field-name">{{name}}</div>
|
||||
<div class="field-content">{{value}}</div>
|
||||
<div class="field-name">{{{name}}}</div>
|
||||
<div class="field-content">{{{value}}}</div>
|
||||
</div>
|
||||
{{/fields}}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user