- Use guild icon in channel title

This commit is contained in:
trigg 2022-07-09 21:58:43 +01:00
parent 8672f87613
commit 59f35eef90
2 changed files with 30 additions and 7 deletions

View file

@ -53,6 +53,7 @@ class DiscordConnector:
self.user = {}
self.userlist = {}
self.in_room = []
self.current_guild = "0"
self.current_voice = "0"
self.current_text = "0"
self.list_altered = False
@ -98,7 +99,7 @@ class DiscordConnector:
log.error(response.text)
self.on_close()
def set_channel(self, channel, need_req=True):
def set_channel(self, channel, guild, need_req=True):
"""
Set currently active voice channel
"""
@ -106,12 +107,14 @@ class DiscordConnector:
if self.current_voice:
self.unsub_voice_channel(self.current_voice)
self.current_voice = "0"
self.current_guild = "0"
return
if channel != self.current_voice:
if self.current_voice != "0":
self.unsub_voice_channel(self.current_voice)
self.sub_voice_channel(channel)
self.current_voice = channel
self.current_guild = guild
if need_req:
self.req_channel_details(channel)
@ -291,21 +294,20 @@ class DiscordConnector:
# User might have been forcibly moved room
elif j["evt"] == "SPEAKING_START":
self.list_altered = True
# It's only possible to get alerts for the room you're in
self.set_channel(j["data"]["channel_id"])
self.userlist[j["data"]["user_id"]]["speaking"] = True
self.userlist[j["data"]["user_id"]]["lastspoken"] = time.time()
self.list_altered = True
self.set_in_room(j["data"]["user_id"], True)
elif j["evt"] == "SPEAKING_STOP":
self.list_altered = True
# It's only possible to get alerts for the room you're in
self.set_channel(j["data"]["channel_id"])
if j["data"]["user_id"] in self.userlist:
self.userlist[j["data"]["user_id"]]["speaking"] = False
self.set_in_room(j["data"]["user_id"], True)
elif j["evt"] == "VOICE_CHANNEL_SELECT":
self.set_channel(j["data"]["channel_id"])
if j["data"]["channel_id"]:
self.set_channel(j["data"]["channel_id"], j["data"]["guild_id"])
else:
self.set_channel(None, None)
elif j["evt"] == "VOICE_CONNECTION_STATUS":
self.discover.voice_overlay.set_connection_status(j["data"])
elif j["evt"] == "MESSAGE_CREATE":
@ -373,8 +375,12 @@ class DiscordConnector:
return
elif j["cmd"] == "GET_SELECTED_VOICE_CHANNEL":
if 'data' in j and j['data'] and 'id' in j['data']:
self.set_channel(j['data']['id'])
self.set_channel(j['data']['id'],j['data']['guild_id'])
self.discover.voice_overlay.set_channel_title(j["data"]["name"])
if self.current_guild in self.guilds and 'icon_url' in self.guilds[self.current_guild]:
self.discover.voice_overlay.set_channel_icon(self.guilds[self.current_guild]['icon_url'])
else:
self.discover.voice_overlay.set_channel_icon(None)
self.list_altered = True
self.in_room = []
for u in j['data']['voice_states']:

View file

@ -74,6 +74,7 @@ class VoiceOverlayWindow(OverlayWindow):
self.highlight_self = None
self.order = None
self.def_avatar = None
self.channel_icon = None
self.overflow = None
self.use_dummy = False
self.dummy_count = 10
@ -307,6 +308,17 @@ class VoiceOverlayWindow(OverlayWindow):
"""
self.channel_title = channel_title
def set_channel_icon(self, url):
"""
Change the icon for channel
"""
print("set_channel_icon : %s" % (url))
if not url:
self.channel_icon = None
else:
get_surface(self.recv_avatar, url, "channel",
self.avatar_size)
def set_user_list(self, userlist, alt):
"""
Set the users in list to draw
@ -525,8 +537,11 @@ class VoiceOverlayWindow(OverlayWindow):
"""
Called when image_getter has downloaded an image
"""
print(identifier)
if identifier == 'def':
self.def_avatar = pix
elif identifier == 'channel':
self.channel_icon = pix
else:
self.avatars[identifier] = pix
self.needsredraw = True
@ -554,6 +569,8 @@ class VoiceOverlayWindow(OverlayWindow):
avatar_size,
self.title_font
)
if self.channel_icon:
self.draw_avatar_pix(context, self.channel_icon,pos_x,pos_y,None, avatar_size)
return tw
def unused_fn_needed_translations(self):