- Request channel details when selecting guild in text settings
- Store channels until all replies are in and then repopulate gui - Fix a bug in non-image attachment loading
This commit is contained in:
parent
00ebe352ac
commit
2fcf3c1c31
3 changed files with 69 additions and 35 deletions
|
|
@ -63,6 +63,10 @@ class DiscordConnector:
|
|||
self.authed = False
|
||||
self.last_text_channel = None
|
||||
|
||||
self.request_text_rooms = None
|
||||
self.request_text_rooms_response = None
|
||||
self.request_text_rooms_awaiting = 0
|
||||
|
||||
def get_access_token_stage1(self):
|
||||
"""
|
||||
First stage of getting an access token. Request authorization from Discord client
|
||||
|
|
@ -342,26 +346,39 @@ class DiscordConnector:
|
|||
elif j["cmd"] == "SUBSCRIBE":
|
||||
return
|
||||
elif j["cmd"] == "GET_CHANNEL":
|
||||
self.request_text_rooms_awaiting -= 1
|
||||
if j["evt"] == "ERROR":
|
||||
logging.info(
|
||||
"Could not get room")
|
||||
return
|
||||
for voice in j["data"]["voice_states"]:
|
||||
if voice["user"]["id"] == self.user["id"]:
|
||||
self.set_channel(j["data"]["id"], False)
|
||||
if j["data"]["id"] == self.current_voice:
|
||||
self.list_altered = True
|
||||
self.in_room = []
|
||||
if j["data"]["type"] == 2:
|
||||
for voice in j["data"]["voice_states"]:
|
||||
thisuser = voice["user"]
|
||||
if "nick" in j["data"]:
|
||||
thisuser["nick"] = j["data"]["nick"]
|
||||
self.update_user(thisuser)
|
||||
self.set_in_room(thisuser["id"], True)
|
||||
if self.current_text == j["data"]["id"]:
|
||||
self.text = []
|
||||
for message in j["data"]["messages"]:
|
||||
self.add_text(message)
|
||||
if voice["user"]["id"] == self.user["id"]:
|
||||
self.set_channel(j["data"]["id"], False)
|
||||
if j["data"]["id"] == self.current_voice:
|
||||
self.list_altered = True
|
||||
self.in_room = []
|
||||
for voice in j["data"]["voice_states"]:
|
||||
thisuser = voice["user"]
|
||||
if "nick" in j["data"]:
|
||||
thisuser["nick"] = j["data"]["nick"]
|
||||
self.update_user(thisuser)
|
||||
self.set_in_room(thisuser["id"], True)
|
||||
elif j["data"]["type"] == 0:
|
||||
if self.request_text_rooms_response is not None:
|
||||
self.request_text_rooms_response[j['data']
|
||||
['position']] = j['data']
|
||||
if self.current_text == j["data"]["id"]:
|
||||
self.text = []
|
||||
for message in j["data"]["messages"]:
|
||||
self.add_text(message)
|
||||
if (self.request_text_rooms_awaiting == 0 and
|
||||
self.request_text_rooms is not None):
|
||||
# Update text channels
|
||||
self.text_settings.set_channels(
|
||||
self.request_text_rooms_response)
|
||||
self.request_text_rooms = None
|
||||
|
||||
return
|
||||
logging.info(j)
|
||||
|
||||
|
|
@ -441,7 +458,7 @@ class DiscordConnector:
|
|||
self.websocket.send(json.dumps(cmd))
|
||||
|
||||
def req_channel_details(self, channel):
|
||||
"""
|
||||
"""message
|
||||
Request information about a specific channel
|
||||
"""
|
||||
cmd = {
|
||||
|
|
@ -453,6 +470,14 @@ class DiscordConnector:
|
|||
}
|
||||
self.websocket.send(json.dumps(cmd))
|
||||
|
||||
def req_all_channel_details(self, guild):
|
||||
"""
|
||||
Ask for information on all channels in a guild
|
||||
"""
|
||||
for channel in self.guilds[guild]["channels"]:
|
||||
self.request_text_rooms_awaiting += 1
|
||||
self.req_channel_details(channel["id"])
|
||||
|
||||
def find_user(self):
|
||||
"""
|
||||
***Potential overload issue***
|
||||
|
|
@ -550,8 +575,6 @@ class DiscordConnector:
|
|||
if self.text_altered:
|
||||
self.text_overlay.set_text_list(self.text, self.text_altered)
|
||||
self.text_altered = False
|
||||
# Update text channels
|
||||
self.text_settings.set_channels(self.channels)
|
||||
# Update guilds
|
||||
self.text_settings.set_guilds(self.guilds)
|
||||
# Check for changed channel
|
||||
|
|
@ -582,6 +605,18 @@ class DiscordConnector:
|
|||
else:
|
||||
self.last_text_channel = channel
|
||||
|
||||
def request_text_rooms_for_guild(self, guild_id):
|
||||
"""
|
||||
Request a correctly ordered list of text channels.
|
||||
|
||||
This will be mixed in with 'None' in the list where a voice channel is
|
||||
"""
|
||||
self.request_text_rooms_awaiting = 0
|
||||
self.request_text_rooms = guild_id
|
||||
self.request_text_rooms_response = [
|
||||
None] * len(self.guilds[guild_id]["channels"])
|
||||
self.req_all_channel_details(guild_id)
|
||||
|
||||
def connect(self):
|
||||
"""
|
||||
Attempt to connect to websocket
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import logging
|
|||
import gi
|
||||
import requests
|
||||
import cairo
|
||||
import PIL
|
||||
import PIL.Image as Image
|
||||
gi.require_version('GdkPixbuf', '2.0')
|
||||
# pylint: disable=wrong-import-position
|
||||
|
|
@ -91,6 +92,8 @@ class SurfaceGetter():
|
|||
logging.error("Unable to read %s", self.url)
|
||||
except TypeError:
|
||||
logging.error("Unable to read %s", self.url)
|
||||
except PIL.UnidentifiedImageError:
|
||||
logging.error("Unknown image type")
|
||||
|
||||
def from_pil(self, image, alpha=1.0):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -71,28 +71,19 @@ class TextSettingsWindow(SettingsWindow):
|
|||
"""
|
||||
Update the Channel selector.
|
||||
|
||||
Populate with all channels from guild if a guild is chosen or all channels generall if not
|
||||
Populate with all channels from guild.
|
||||
Leave empty if guild is unselected
|
||||
"""
|
||||
# potentially organize channels by their group/parent_id
|
||||
# https://discord.com/developers/docs/resources/channel#channel-object-channel-structure
|
||||
c_model = Gtk.ListStore(str, bool)
|
||||
self.channel_lookup = []
|
||||
|
||||
for guild in self.guild_list():
|
||||
guild_id, guild_name = guild
|
||||
# if no guild is specified, populate channel list with every channel from each guild
|
||||
if self.guild == GUILD_DEFAULT_VALUE:
|
||||
c_model.append([guild_name, False])
|
||||
for channel_key in self.list_channels_keys:
|
||||
chan = self.list_channels[channel_key]
|
||||
if chan['guild_id'] == guild_id:
|
||||
c_model.append([chan["name"], True])
|
||||
self.channel_lookup.append(channel_key)
|
||||
|
||||
# if a guild is specified, poulate channel list with every channel from *just that guild*
|
||||
if self.guild != GUILD_DEFAULT_VALUE:
|
||||
for channel_key in self.list_channels_keys:
|
||||
chan = self.list_channels[channel_key]
|
||||
for position in self.list_channels_keys:
|
||||
chan = self.list_channels[position]
|
||||
channel_key = chan["id"]
|
||||
if chan['guild_id'] == self.guild:
|
||||
c_model.append([chan["name"], True])
|
||||
self.channel_lookup.append(channel_key)
|
||||
|
|
@ -163,6 +154,9 @@ class TextSettingsWindow(SettingsWindow):
|
|||
break
|
||||
idxg += 1
|
||||
|
||||
if self.guild is not None:
|
||||
self.connector.request_text_rooms_for_guild(self.guild)
|
||||
|
||||
def guild_list(self):
|
||||
"""
|
||||
Return a list of all guilds
|
||||
|
|
@ -181,12 +175,13 @@ class TextSettingsWindow(SettingsWindow):
|
|||
"""
|
||||
self.list_channels = in_list
|
||||
self.list_channels_keys = []
|
||||
for key in in_list.keys():
|
||||
for (key, _value) in enumerate(in_list):
|
||||
# filter for only text channels
|
||||
# https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
||||
if in_list[key]["type"] == 0:
|
||||
if in_list[key] is not None and in_list[key]["type"] == 0:
|
||||
self.list_channels_keys.append(key)
|
||||
self.list_channels_keys.sort()
|
||||
self.update_channel_model()
|
||||
|
||||
def set_guilds(self, in_list):
|
||||
"""
|
||||
|
|
@ -467,7 +462,8 @@ class TextSettingsWindow(SettingsWindow):
|
|||
guild_id = self.guild_lookup[button.get_active()]
|
||||
self.guild = guild_id
|
||||
self.save_config()
|
||||
self.update_channel_model()
|
||||
# self.update_channel_model()
|
||||
self.connector.request_text_rooms_for_guild(self.guild)
|
||||
|
||||
def change_popup_style(self, button):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue