mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-25 06:27:03 +01:00
Realtime emoji and discord member sidebar fix
This commit is contained in:
parent
0539efb204
commit
d1225e5273
@ -229,8 +229,10 @@ class Titan(discord.Client):
|
|||||||
await self.wait_until_dbonline()
|
await self.wait_until_dbonline()
|
||||||
if len(after) == 0:
|
if len(after) == 0:
|
||||||
await self.database.update_guild(before[0].server)
|
await self.database.update_guild(before[0].server)
|
||||||
|
await self.socketio.on_guild_emojis_update(before)
|
||||||
else:
|
else:
|
||||||
await self.database.update_guild(after[0].server)
|
await self.database.update_guild(after[0].server)
|
||||||
|
await self.socketio.on_guild_emojis_update(after)
|
||||||
|
|
||||||
async def on_webhooks_update(self, server):
|
async def on_webhooks_update(self, server):
|
||||||
await self.wait_until_dbonline()
|
await self.wait_until_dbonline()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import socketio
|
import socketio
|
||||||
from titanembeds.utils import get_message_author, get_message_mentions
|
from titanembeds.utils import get_message_author, get_message_mentions, get_roles_list
|
||||||
import time
|
import time
|
||||||
from email import utils as emailutils
|
from email import utils as emailutils
|
||||||
|
|
||||||
@ -64,7 +64,10 @@ class SocketIOInterface:
|
|||||||
"id": user.id,
|
"id": user.id,
|
||||||
"status": str(user.status),
|
"status": str(user.status),
|
||||||
"username": user.name,
|
"username": user.name,
|
||||||
|
"nick": None,
|
||||||
}
|
}
|
||||||
|
if user.nick:
|
||||||
|
userobj["nick"] = user.nick
|
||||||
if user.game:
|
if user.game:
|
||||||
userobj["game"] = {
|
userobj["game"] = {
|
||||||
"name": user.game.name
|
"name": user.game.name
|
||||||
@ -91,3 +94,20 @@ class SocketIOInterface:
|
|||||||
async def on_guild_member_update(self, member):
|
async def on_guild_member_update(self, member):
|
||||||
user = self.get_formatted_user(member)
|
user = self.get_formatted_user(member)
|
||||||
await self.io.emit('GUILD_MEMBER_UPDATE', data=user, room=str("GUILD_"+member.server.id), namespace='/gateway')
|
await self.io.emit('GUILD_MEMBER_UPDATE', data=user, room=str("GUILD_"+member.server.id), namespace='/gateway')
|
||||||
|
|
||||||
|
def get_formatted_emojis(self, emojis):
|
||||||
|
emotes = []
|
||||||
|
for emo in emojis:
|
||||||
|
emotes.append({
|
||||||
|
"id": emo.id,
|
||||||
|
"managed": emo.managed,
|
||||||
|
"name": emo.name,
|
||||||
|
"require_colons": emo.require_colons,
|
||||||
|
"roles": get_roles_list(emo.roles),
|
||||||
|
"url": emo.url,
|
||||||
|
})
|
||||||
|
return emotes
|
||||||
|
|
||||||
|
async def on_guild_emojis_update(self, emojis):
|
||||||
|
emotes = self.get_formatted_emojis(emojis)
|
||||||
|
await self.io.emit('GUILD_EMOJIS_UPDATE', data=emotes, room=str("GUILD_"+emojis[0].server.id), namespace='/gateway')
|
@ -20,7 +20,7 @@
|
|||||||
var last_message_id; // last message tracked
|
var last_message_id; // last message tracked
|
||||||
var selected_channel = null; // user selected channel
|
var selected_channel = null; // user selected channel
|
||||||
var guild_channels = {}; // all server channels used to highlight channels in messages
|
var guild_channels = {}; // all server channels used to highlight channels in messages
|
||||||
var emoji_store = {}; // all server emojis
|
var emoji_store = []; // all server emojis
|
||||||
var current_username_discrim; // Current username/discrim pair, eg EndenDraogn#4151
|
var current_username_discrim; // Current username/discrim pair, eg EndenDraogn#4151
|
||||||
var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
|
var visitor_mode = false; // Keep track of if using the visitor mode or authenticate mode
|
||||||
var socket = null; // Socket.io object
|
var socket = null; // Socket.io object
|
||||||
@ -486,6 +486,21 @@
|
|||||||
var rendered_role = Mustache.render(template_role, {"name": roleobj["name"] + " - " + roleobj["members"].length});
|
var rendered_role = Mustache.render(template_role, {"name": roleobj["name"] + " - " + roleobj["members"].length});
|
||||||
discordmembercnt += roleobj["members"].length;
|
discordmembercnt += roleobj["members"].length;
|
||||||
$("#discord-members").append(rendered_role);
|
$("#discord-members").append(rendered_role);
|
||||||
|
roleobj.members.sort(function(a, b){
|
||||||
|
var name_a = a.username;
|
||||||
|
var name_b = b.username;
|
||||||
|
if (a.nick) {
|
||||||
|
name_a = a.nick;
|
||||||
|
}
|
||||||
|
if (b.nick) {
|
||||||
|
name_b = b.nick;
|
||||||
|
}
|
||||||
|
name_a = name_a.toUpperCase();
|
||||||
|
name_b = name_b.toUpperCase();
|
||||||
|
if(name_a < name_b) return -1;
|
||||||
|
if(name_a > name_b) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
for (var j = 0; j < roleobj.members.length; j++) {
|
for (var j = 0; j < roleobj.members.length; j++) {
|
||||||
var member = roleobj.members[j];
|
var member = roleobj.members[j];
|
||||||
var member_name = member.nick;
|
var member_name = member.nick;
|
||||||
@ -1032,13 +1047,12 @@
|
|||||||
socket.on("GUILD_MEMBER_UPDATE", function (usr) {
|
socket.on("GUILD_MEMBER_UPDATE", function (usr) {
|
||||||
for (var i = 0; i < discord_users_list.length; i++) {
|
for (var i = 0; i < discord_users_list.length; i++) {
|
||||||
if (usr.id == discord_users_list[i].id) {
|
if (usr.id == discord_users_list[i].id) {
|
||||||
if (usr.status == "offline") {
|
|
||||||
discord_users_list.splice(i, 1);
|
discord_users_list.splice(i, 1);
|
||||||
|
if (usr.status != "offline") {
|
||||||
|
discord_users_list.push(usr);
|
||||||
|
}
|
||||||
fill_discord_members(discord_users_list);
|
fill_discord_members(discord_users_list);
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
discord_users_list.push(usr);
|
discord_users_list.push(usr);
|
||||||
@ -1054,6 +1068,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on("GUILD_EMOJIS_UPDATE", function (emo) {
|
||||||
|
emoji_store = emo;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_socket_heartbeat() {
|
function send_socket_heartbeat() {
|
||||||
|
Loading…
Reference in New Issue
Block a user