From 1bd27b25068ebb0be87984f0cc312314637441fc Mon Sep 17 00:00:00 2001 From: trigg Date: Sat, 17 Oct 2020 17:06:34 +0000 Subject: [PATCH] - Subscribe less greedily. We'll need to ensure we subscribe when we need them now! --- discover_overlay/discord_connector.py | 13 +++++++++++-- discover_overlay/discover_overlay.py | 1 + discover_overlay/settings_window.py | 1 + discover_overlay/text_overlay.py | 1 + discover_overlay/text_settings.py | 7 +++++++ discover_overlay/voice_overlay.py | 7 ++++--- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index 09ee2a5..56e2dae 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -35,6 +35,7 @@ class DiscordConnector: self.last_connection = "" self.text = [] self.authed = False + self.last_text_channel = None def get_access_token_stage1(self): self.ws.send("{\"cmd\":\"AUTHORIZE\",\"args\":{\"client_id\":\"%s\",\"scopes\":[\"rpc\",\"messages.read\"],\"prompt\":\"none\"},\"nonce\":\"deadbeef\"}" % ( @@ -262,8 +263,8 @@ class DiscordConnector: if channel["type"] == 2: self.req_channel_details(channel["id"]) self.check_guilds() - self.sub_all_voice_guild(j["nonce"]) - self.sub_all_text_guild(j["nonce"]) + #self.sub_all_voice_guild(j["nonce"]) + #self.sub_all_text_guild(j["nonce"]) return elif j["cmd"] == "SUBSCRIBE": return @@ -308,6 +309,8 @@ class DiscordConnector: u"%s: %s" % (guild["name"], channels)) self.sub_server() self.find_user() + if self.last_text_channel: + self.sub_text_channel(self.last_text_channel) def on_error(self, error): logging.error("ERROR : %s" % (error)) @@ -430,6 +433,12 @@ class DiscordConnector: return True return True + def start_listening_text(self, ch): + if self.ws: + self.sub_text_channel(ch) + else: + self.last_text_channel = ch + def connect(self): if self.ws: return diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index 4558aff..54916ab 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -35,6 +35,7 @@ class Discover: self.connection = DiscordConnector( self.settings.text_settings, self.settings.voice_settings, self.text_overlay, self.voice_overlay) + self.settings.text_settings.add_connector(self.connection) self.connection.connect() GLib.timeout_add((1000 / 60), self.connection.do_read) self.rpc_file = rpc_file diff --git a/discover_overlay/settings_window.py b/discover_overlay/settings_window.py index c088581..d0952f1 100644 --- a/discover_overlay/settings_window.py +++ b/discover_overlay/settings_window.py @@ -19,6 +19,7 @@ class MainSettingsWindow(Gtk.Window): self.text_overlay = text_overlay self.voice_overlay = voice_overlay + self.set_title("Discover Overlay Configuration") # Create nb = Gtk.Notebook() diff --git a/discover_overlay/text_overlay.py b/discover_overlay/text_overlay.py index 29d2b82..37460a1 100644 --- a/discover_overlay/text_overlay.py +++ b/discover_overlay/text_overlay.py @@ -31,6 +31,7 @@ class TextOverlayWindow(OverlayWindow): self.imgList = [] self.imgFinder = re.compile(r"`") + self.set_title("Discover Text") def set_text_time(self, t): self.text_time = t diff --git a/discover_overlay/text_settings.py b/discover_overlay/text_settings.py index 2e40128..1091f99 100644 --- a/discover_overlay/text_settings.py +++ b/discover_overlay/text_settings.py @@ -22,6 +22,11 @@ class TextSettingsWindow(SettingsWindow): self.ignore_channel_change = False self.create_gui() + def add_connector(self, conn): + self.connector = conn + if self.channel: + self.connector.start_listening_text(self.channel) + def present(self): self.show_all() if not self.floating: @@ -307,7 +312,9 @@ class TextSettingsWindow(SettingsWindow): def change_channel(self, button): if self.ignore_channel_change: return + c = self.channel_lookup[button.get_active()] + self.connector.start_listening_text(c) self.channel = c self.save_config() diff --git a/discover_overlay/voice_overlay.py b/discover_overlay/voice_overlay.py index 9503c19..edb7b18 100644 --- a/discover_overlay/voice_overlay.py +++ b/discover_overlay/voice_overlay.py @@ -36,9 +36,10 @@ class VoiceOverlayWindow(OverlayWindow): self.users_to_draw = [] self.connected = False self.force_location() - self.def_avatar = get_surface(self.recv_avatar, - "https://cdn.discordapp.com/embed/avatars/3.png", - 'def', self.avatar_size) + get_surface(self.recv_avatar, + "https://cdn.discordapp.com/embed/avatars/3.png", + 'def', self.avatar_size) + self.set_title("Discover Voice") def set_bg(self, bg): self.norm_col = bg