Send mentions from embed

This commit is contained in:
Jeremy Zhang 2017-04-09 16:40:11 -07:00
parent 674c98b100
commit ceb19cd1af
2 changed files with 24 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import random
import requests import requests
import json import json
import datetime import datetime
import re
from config import config from config import config
api = Blueprint("api", __name__) api = Blueprint("api", __name__)
@ -99,7 +100,13 @@ def check_user_in_guild(guild_id):
def format_post_content(message): def format_post_content(message):
message = message.replace("<", "\<") message = message.replace("<", "\<")
message = message.replace(">", "\>") #escape mentions for now message = message.replace(">", "\>")
pattern = re.compile(r'\[@[0-9]+\]')
for match in re.findall(pattern, message):
mention = "<@" + match[2: len(match) - 1] + ">"
message = message.replace(match, mention, 1)
if (session['unauthenticated']): if (session['unauthenticated']):
message = "**[{}#{}]** {}".format(session['username'], session['user_id'], message) message = "**[{}#{}]** {}".format(session['username'], session['user_id'], message)
else: else:

View File

@ -155,14 +155,25 @@ function fill_channels(channels) {
$("#channel-"+selected_channel).parent().addClass("active"); $("#channel-"+selected_channel).parent().addClass("active");
} }
function mention_member(member_id) {
if (!$('#messagebox').prop('disabled')) {
$('#messagebox').val( $('#messagebox').val() + "[@" + member_id + "] " );
$('.button-collapse').sideNav('hide');
$("#messagebox").focus();
}
}
function fill_discord_members(discordmembers) { function fill_discord_members(discordmembers) {
var template = $('#mustache_authedusers').html(); var template = $('#mustache_authedusers').html();
Mustache.parse(template); Mustache.parse(template);
$("#discord-members").empty(); $("#discord-members").empty();
for (var i = 0; i < discordmembers.length; i++) { for (var i = 0; i < discordmembers.length; i++) {
var member = discordmembers[i]; var member = discordmembers[i];
var rendered = Mustache.render(template, {"id": member.id, "username": member.username, "avatar": member.avatar_url}); var rendered = Mustache.render(template, {"id": member.id.toString() + "d", "username": member.username, "avatar": member.avatar_url});
$("#discord-members").append(rendered); $("#discord-members").append(rendered);
$( "#discorduser-" + member.id.toString() + "d").click(function() {
mention_member(member.id.toString());
});
} }
} }
@ -172,8 +183,11 @@ function fill_authenticated_users(users) {
$("#embed-discord-members").empty(); $("#embed-discord-members").empty();
for (var i = 0; i < users.length; i++) { for (var i = 0; i < users.length; i++) {
var member = users[i]; var member = users[i];
var rendered = Mustache.render(template, {"id": member.id, "username": member.username, "avatar": member.avatar_url}); var rendered = Mustache.render(template, {"id": member.id.toString() + "a", "username": member.username, "avatar": member.avatar_url});
$("#embed-discord-members").append(rendered); $("#embed-discord-members").append(rendered);
$( "#discorduser-" + member.id.toString() + "a").click(function() {
mention_member(member.id.toString());
});
} }
} }