mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
Fix user card for offline members to work
This commit is contained in:
parent
cb05b44100
commit
1785cb81c9
@ -1,6 +1,6 @@
|
||||
from titanembeds.database import db, Guilds, UnauthenticatedUsers, UnauthenticatedBans, AuthenticatedUsers, KeyValueProperties, GuildMembers, Messages, get_channel_messages, list_all_guild_members, get_guild_member, get_administrators_list, get_badges
|
||||
from titanembeds.decorators import valid_session_required, discord_users_only
|
||||
from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key, user_unauthenticated, checkUserRevoke, checkUserBanned, update_user_status, check_user_in_guild, get_guild_channels, guild_webhooks_enabled, guild_unauthcaptcha_enabled
|
||||
from titanembeds.utils import check_guild_existance, guild_accepts_visitors, guild_query_unauth_users_bool, get_client_ipaddr, discord_api, rate_limiter, channel_ratelimit_key, guild_ratelimit_key, user_unauthenticated, checkUserRevoke, checkUserBanned, update_user_status, check_user_in_guild, get_guild_channels, guild_webhooks_enabled, guild_unauthcaptcha_enabled, get_member_roles
|
||||
from titanembeds.oauth import user_has_permission, generate_avatar_url, check_user_can_administrate_guild
|
||||
from flask import Blueprint, abort, jsonify, session, request, url_for
|
||||
from flask import current_app as app
|
||||
@ -429,9 +429,35 @@ def create_authenticated_user():
|
||||
response.status_code = 403
|
||||
return response
|
||||
|
||||
@api.route("/badges/<user_id>")
|
||||
def badges(user_id):
|
||||
return jsonify(get_badges(user_id))
|
||||
@api.route("/user/<guild_id>/<user_id>")
|
||||
def user_info(guild_id, user_id):
|
||||
usr = {
|
||||
"id": None,
|
||||
"username": None,
|
||||
"nickname": None,
|
||||
"discriminator": None,
|
||||
"avatar": None,
|
||||
"avatar_url": None,
|
||||
"roles": [],
|
||||
"badges": [],
|
||||
}
|
||||
member = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.user_id == user_id).first()
|
||||
if member:
|
||||
usr["id"] = member.user_id
|
||||
usr["username"] = member.username
|
||||
usr["nickname"] = member.nickname
|
||||
usr["discriminator"] = member.discriminator
|
||||
usr["avatar"] = member.avatar
|
||||
usr["avatar_url"] = generate_avatar_url(usr["id"], usr["avatar"], usr["discriminator"])
|
||||
roles = get_member_roles(guild_id, user_id)
|
||||
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
guild_roles = json.loads(dbguild.roles)
|
||||
for r in roles:
|
||||
for gr in guild_roles:
|
||||
if gr["id"] == r:
|
||||
usr["roles"].append(gr)
|
||||
usr["badges"] = get_badges(user_id)
|
||||
return jsonify(usr)
|
||||
|
||||
def canCleanupDB():
|
||||
canclean = False
|
||||
|
@ -135,10 +135,10 @@
|
||||
return funct.promise();
|
||||
}
|
||||
|
||||
function api_badges(user_id) {
|
||||
function api_user(user_id) {
|
||||
var funct = $.ajax({
|
||||
dataType: "json",
|
||||
url: "/api/badges/" + user_id,
|
||||
url: "/api/user/" + guild_id + "/" + user_id,
|
||||
});
|
||||
return funct.promise();
|
||||
}
|
||||
@ -692,54 +692,59 @@
|
||||
}
|
||||
|
||||
function openUserCard(user_id) {
|
||||
var bgs = api_badges(user_id);
|
||||
bgs.done(function (data) {
|
||||
var usr = api_user(user_id);
|
||||
usr.done(function (data) {
|
||||
for (var i = 0; i < badges_options.length; i++) {
|
||||
var badge = badges_options[i];
|
||||
if (data.indexOf(badge) != -1) {
|
||||
if (data.badges.indexOf(badge) != -1) {
|
||||
$(`#usercard .badges .${badge}`).show();
|
||||
} else {
|
||||
$(`#usercard .badges .${badge}`).hide();
|
||||
}
|
||||
}
|
||||
$("#usercard .avatar").attr("src", data.avatar_url);
|
||||
$("#usercard .identity .username").text(data.username);
|
||||
$("#usercard .identity .discriminator").text(data.discriminator);
|
||||
$("#usercard .identity .discriminator").text(data.discriminator);
|
||||
|
||||
var template = $('#mustache_rolebubble').html();
|
||||
Mustache.parse(template);
|
||||
data.roles.sort(function(a, b) {
|
||||
return parseFloat(b.position) - parseFloat(a.position);
|
||||
});
|
||||
$("#usercard .role .roles").empty();
|
||||
for (var j = 0; j < data.roles.length; j++) {
|
||||
var role = data.roles[j];
|
||||
var color = null;
|
||||
if (role.color) {
|
||||
color = "#" + role.color.toString(16);
|
||||
}
|
||||
var rol = Mustache.render(template, {name: role.name, color: color});
|
||||
$("#usercard .role .roles").append(rol);
|
||||
}
|
||||
|
||||
$("#usercard-mention-btn").off("click");
|
||||
$("#usercard-mention-btn").click(function () {
|
||||
mention_member(data.id);
|
||||
$("#usercard").modal('close');
|
||||
});
|
||||
});
|
||||
|
||||
$("#usercard .offline-text").show();
|
||||
$("#usercard .game").hide();
|
||||
$("#usercard .bottag").hide();
|
||||
for (var i = 0; i < discord_users_list.length; i++) {
|
||||
var usr = discord_users_list[i];
|
||||
if (usr.id == user_id) {
|
||||
$("#usercard .avatar").attr("src", usr.avatar_url);
|
||||
$("#usercard .identity .username").text(usr.username);
|
||||
$("#usercard .identity .discriminator").text(usr.discriminator);
|
||||
$("#usercard .offline-text").hide();
|
||||
if (usr.bot) {
|
||||
$("#usercard .bottag").show();
|
||||
} else {
|
||||
$("#usercard .bottag").hide();
|
||||
}
|
||||
if (usr.status == "offline") {
|
||||
$("#usercard .offline-text").show();
|
||||
} else {
|
||||
$("#usercard .offline-text").hide();
|
||||
}
|
||||
if (usr["hoist-role"]) {
|
||||
$("#usercard .role").show();
|
||||
$("#usercard .role .text").text(usr["hoist-role"].name);
|
||||
if (usr.color) {
|
||||
$("#usercard .role .bubble").css("color", "#" + usr.color);
|
||||
$("#usercard .role .color").css("background-color", "#" + usr.color);
|
||||
}
|
||||
} else {
|
||||
$("#usercard .role").hide();
|
||||
}
|
||||
if (usr.game) {
|
||||
$("#usercard .game").show();
|
||||
$("#usercard .game .text").text(usr.game.name);
|
||||
} else {
|
||||
$("#usercard .game").hide();
|
||||
}
|
||||
$("#usercard-mention-btn").off("click");
|
||||
$("#usercard-mention-btn").click(function () {
|
||||
mention_member(user_id);
|
||||
$("#usercard").modal('close');
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
$("#usercard").modal('open');
|
||||
|
@ -191,9 +191,9 @@
|
||||
<a class="supporter tooltipped" data-tooltip="TitanEmbeds Supporter" data-position="top" href="https://titanembeds.com/user/donate" target="_blank"><i class="material-icons">attach_money</i></a>
|
||||
<a class="star tooltipped" data-tooltip="GitHub Stargazer" data-position="top" href="https://github.com/TitanEmbeds/Titan" target="_blank"><i class="material-icons">star</i></a>
|
||||
</div>
|
||||
<p class="offline-text">User is Offline.</p>
|
||||
<p class="offline-text">User is OFFLINE in Discord.</p>
|
||||
<p class="game">Playing <span class="text"></span></p>
|
||||
<p class="role">Highest Role: <span class="bubble"><span class="color"></span> <span class="text"></span></span></p>
|
||||
<p class="role">Roles: <span class="roles"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -345,6 +345,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script id="mustache_rolebubble" type="text/template">
|
||||
<span class="bubble" {{#color}}style="color: {{color}};"{{/color}}><span class="color" {{#color}}style="background-color: {{color}};"{{/color}}></span> <span class="text">{{name}}</span></span>
|
||||
</script>
|
||||
{% endraw %}
|
||||
|
||||
<script>
|
||||
|
Loading…
Reference in New Issue
Block a user