Parse role mentions

This commit is contained in:
Jeremy Zhang 2018-03-04 06:29:16 +00:00
parent d438b6d34f
commit 487f5756f5
5 changed files with 51 additions and 6 deletions

View File

@ -159,6 +159,11 @@ class SocketIOInterface:
rol = {
"id": role.id,
"guild_id": role.server.id,
"name": role.name,
"color": role.color.value,
"hoist": role.hoist,
"position": role.position,
"permissions": role.permissions.value,
}
return rol

View File

@ -149,6 +149,10 @@ def get_guild_emojis(guild_id):
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
return json.loads(dbguild.emojis)
def get_guild_roles(guild_id):
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
return json.loads(dbguild.roles)
# Returns webhook url if exists and can post w/webhooks, otherwise None
def get_channel_webhook_url(guild_id, channel_id):
if not guild_webhooks_enabled(guild_id):
@ -387,11 +391,12 @@ def process_query_guild(guild_id, visitor=False):
discordmembers = [{"id": 0, "color": "FFD6D6", "status": "dnd", "username": "Discord Server Widget is Currently Disabled"}]
embedmembers = get_online_embed_users(guild_id)
emojis = get_guild_emojis(guild_id)
roles = get_guild_roles(guild_id)
guest_icon = get_guild_guest_icon(guild_id)
if visitor:
for channel in channels:
channel["write"] = False
return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, guest_icon=guest_icon, instant_invite=widget.get("instant_invite", None))
return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, roles=roles, guest_icon=guest_icon, instant_invite=widget.get("instant_invite", None))
@api.route("/query_guild", methods=["GET"])
@valid_session_required(api=True)

View File

@ -654,14 +654,14 @@ p.mentioned span.chatmessage {
margin-bottom: 3px;
}
.chatmessage .channellink, .chatmessage .discordmention {
.chatmessage .channellink, .chatmessage .discordmention, .rolemention {
border-radius: 5px;
background-color: rgba(0, 0, 0, 0.2);
color: #82b1ff;
cursor: pointer;
}
.chatmessage .channellink:hover, .chatmessage .discordmention:hover {
.chatmessage .channellink:hover, .chatmessage .discordmention:hover, .rolemention:hover {
background-color: rgba(0, 0, 0, 0.5);
color: white;
}

View File

@ -44,6 +44,7 @@
var notification_sound = null; // Sound Manager 2 demonstrative.mp3 object https://notificationsounds.com/message-tones/demonstrative-516
var notification_sound_setting; // nothing, mentions, newmsgs - to control what new sound it makes
var display_richembeds; // true/false - if rich embeds should be displayed
var guild_roles_list = []; // List of all guild roles
function element_in_view(element, fullyInView) {
var pageTop = $(window).scrollTop();
@ -519,6 +520,7 @@
function prepare_guild(guildobj) {
global_guest_icon = guildobj.guest_icon;
emoji_store = guildobj.emojis;
guild_roles_list = guildobj.roles;
fill_channels(guildobj.channels);
fill_discord_members(guildobj.discordmembers);
fill_authenticated_users(guildobj.embedmembers.authenticated);
@ -889,7 +891,18 @@
var rendered = Mustache.render(template, {"username": username, "discriminator": zeroPad(mention.discriminator)}).trim();
message.content = message.content.replace(new RegExp("<@" + mention.id + ">", 'g'), rendered);
message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), rendered);
message.content = message.content.replace("<@&" + guild_id + ">", "@everyone");
}
var template = $("#mustache_rolemention").html();
Mustache.parse(template);
for (var i = 0; i < guild_roles_list.length; i++) {
var role = guild_roles_list[i];
var roleobj = {"rolename": role.name};
if (role.color) {
roleobj.color = "#" + role.color.toString(16);
}
var rendered = Mustache.render(template, roleobj).trim();
message.content = message.content.replace("&lt;@&amp;" + role.id + "&gt;", rendered);
}
return message;
}
@ -1665,12 +1678,30 @@
update_socket_channels();
});
socket.on("GUILD_ROLE_UPDATE", function (chan) {
socket.on("GUILD_ROLE_CREATE", function (role) {
update_socket_channels();
guild_roles_list.push(role);
});
socket.on("GUILD_ROLE_DELETE", function (chan) {
socket.on("GUILD_ROLE_UPDATE", function (role) {
update_socket_channels();
for (var i = 0; i < guild_roles_list.length; i++) {
if (guild_roles_list[i].id == role.id) {
guild_roles_list.splice(i, 1);
guild_roles_list.push(role);
return;
}
}
});
socket.on("GUILD_ROLE_DELETE", function (role) {
update_socket_channels();
for (var i = 0; i < guild_roles_list.length; i++) {
if (guild_roles_list[i].id == role.id) {
guild_roles_list.splice(i, 1);
return;
}
}
});
socket.on("channel_list", function (chans) {

View File

@ -329,6 +329,10 @@
<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_rolemention" type="text/template">
<span class="rolemention" {{#color}}style="color: {{color}}"{{/color}}><span class="atsign">@</span><span class="rolename">{{rolename}}</span></span>
</script>
<script id="mustache_richembed" type="text/template">
<div class="richembed">
{{#color}}