diff --git a/.gitignore b/.gitignore index 3a1424b..adf4a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ build env .vscode/launch.json .vscode/settings.json -__pycache__ \ No newline at end of file +__pycache__ +venv +.idea \ No newline at end of file diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index 5b14599..e214d43 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -336,8 +336,9 @@ class DiscordConnector: return elif j["cmd"] == "GET_GUILDS": for guild in j["data"]["guilds"]: - self.req_channels(guild["id"]) self.guilds[guild["id"]] = guild + if len(self.voice_settings.guild_ids) == 0 or guild["id"] in self.voice_settings.guild_ids: + self.req_channels(guild["id"]) return elif j["cmd"] == "GET_CHANNELS": self.guilds[j['nonce']]["channels"] = j["data"]["channels"] @@ -459,7 +460,13 @@ class DiscordConnector: Request all channels information for given guild. Don't perform now but pass off to rate-limiter """ - self.rate_limited_channels.append(guild) + + if guild in self.guilds: + self.rate_limited_channels.append(guild) + print("Requesting channels for guild:", + self.guilds.get(guild)) + else: + print("Didn't find guild with id", guild) #cmd = { # "cmd": "GET_CHANNELS", # "args": { @@ -635,11 +642,10 @@ class DiscordConnector: This will be mixed in with 'None' in the list where a voice channel is """ - if guild_id in self.guilds: + if guild_id in self.guilds and "channels" in self.guilds[guild_id]: 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.request_text_rooms_response = [None] * len(self.guilds[guild_id]["channels"]) self.req_all_channel_details(guild_id) def connect(self): diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index 896638b..a92dce5 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -38,9 +38,14 @@ class Discover: self.tray = None self.create_gui() + self.connection = DiscordConnector( - self.settings.text_settings, self.settings.voice_settings, - self.text_overlay, self.voice_overlay) + 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) diff --git a/discover_overlay/overlay.py b/discover_overlay/overlay.py index d726b1d..8f479fa 100644 --- a/discover_overlay/overlay.py +++ b/discover_overlay/overlay.py @@ -47,8 +47,9 @@ class OverlayWindow(Gtk.Window): return Gtk.WindowType.TOPLEVEL return Gtk.WindowType.POPUP - def __init__(self): + def __init__(self, discover): Gtk.Window.__init__(self, type=self.detect_type()) + self.discover = discover screen = self.get_screen() self.compositing = False self.text_font = None diff --git a/discover_overlay/text_overlay.py b/discover_overlay/text_overlay.py index b0634d1..7e6a41d 100644 --- a/discover_overlay/text_overlay.py +++ b/discover_overlay/text_overlay.py @@ -28,8 +28,7 @@ class TextOverlayWindow(OverlayWindow): """Overlay window for voice""" def __init__(self, discover): - OverlayWindow.__init__(self) - self.discover = discover + OverlayWindow.__init__(self, discover) self.text_spacing = 4 self.content = [] self.text_font = None diff --git a/discover_overlay/voice_overlay.py b/discover_overlay/voice_overlay.py index f4882e4..d25cad2 100644 --- a/discover_overlay/voice_overlay.py +++ b/discover_overlay/voice_overlay.py @@ -27,9 +27,8 @@ class VoiceOverlayWindow(OverlayWindow): """Overlay window for voice""" def __init__(self, discover): - OverlayWindow.__init__(self) + OverlayWindow.__init__(self, discover) - self.discover = discover self.avatars = {} self.avatar_size = 48 @@ -57,6 +56,8 @@ class VoiceOverlayWindow(OverlayWindow): self.userlist = [] self.users_to_draw = [] self.connected = False + self.horizontal = False + self.guild_ids = tuple() self.force_location() get_surface(self.recv_avatar, "https://cdn.discordapp.com/embed/avatars/3.png", @@ -183,6 +184,17 @@ class VoiceOverlayWindow(OverlayWindow): self.horizontal = horizontal self.redraw() + def set_guild_ids(self, guild_ids=tuple()): + try: + for _id in guild_ids: + if _id not in self.guild_ids: + self.discover.connection.req_channels(_id) + except AttributeError as _e: + print(_e) + # it some times says: AttributeError: 'Discover' object has no attribute 'connection' + pass + self.guild_ids = guild_ids + def set_wind_col(self): """ Use window colour to draw diff --git a/discover_overlay/voice_settings.py b/discover_overlay/voice_settings.py index e721898..ddad003 100644 --- a/discover_overlay/voice_settings.py +++ b/discover_overlay/voice_settings.py @@ -20,6 +20,20 @@ gi.require_version("Gtk", "3.0") from gi.repository import Gtk, Gdk +def parse_guild_ids(guild_ids_str): + """Parse the guild_ids from a str and return them in a tuple""" + guild_ids = set() + for guild_id in guild_ids_str.split(","): + guild_id = guild_id.strip() + if guild_id != "": + guild_ids.add(guild_id) + return tuple(guild_ids) + + +def guild_ids_to_string(guild_ids): + """Put the guild ids into a comma seperated string.""" + return ", ".join(str(_id) for _id in guild_ids) + class VoiceSettingsWindow(SettingsWindow): """Voice setting tab on settings window""" @@ -53,6 +67,7 @@ class VoiceSettingsWindow(SettingsWindow): self.floating = None self.order = None self.horizontal = None + self.guild_ids = None self.init_config() self.create_gui() @@ -119,6 +134,7 @@ class VoiceSettingsWindow(SettingsWindow): self.order = config.getint("main", "order", fallback=0) self.autohide = config.getboolean("text", "autohide", fallback=False) self.horizontal = config.getboolean("main", "horizontal", fallback=False) + self.guild_ids = parse_guild_ids(config.get("main", "guild_ids", fallback="")) # Pass all of our config over to the overlay self.overlay.set_align_x(self.align_x) @@ -144,6 +160,7 @@ class VoiceSettingsWindow(SettingsWindow): self.overlay.set_order(self.order) self.overlay.set_hide_on_mouseover(self.autohide) self.overlay.set_horizontal(self.horizontal) + self.overlay.set_guild_ids(self.guild_ids) self.overlay.set_floating( self.floating, self.floating_x, self.floating_y, self.floating_w, self.floating_h) @@ -151,7 +168,6 @@ class VoiceSettingsWindow(SettingsWindow): if self.font: self.overlay.set_font(self.font) - def save_config(self): """ Write settings out to the 'main' section of the config file @@ -192,6 +208,7 @@ class VoiceSettingsWindow(SettingsWindow): config.set("main", "floating_h", "%s" % (self.floating_h)) config.set("main", "order", "%s" % (self.order)) config.set("main", "horizontal", "%s" % (self.horizontal)) + config.set("main", "guild_ids", "%s" % guild_ids_to_string(self.guild_ids)) with open(self.config_file, 'w') as file: config.write(file) @@ -398,6 +415,12 @@ class VoiceSettingsWindow(SettingsWindow): horizontal.set_active(self.horizontal) horizontal.connect("toggled", self.change_horizontal) + # Guild ids to load: + guild_ids_label = Gtk.Label.new("Guild Ids") + guild_ids = Gtk.Entry.new() + guild_ids.set_text(guild_ids_to_string(self.guild_ids)) + guild_ids.connect("changed", self.change_guild_ids) + box.attach(autohide_label, 0, 0, 1, 1) box.attach(autohide, 1, 0, 1, 1) box.attach(font_label, 0, 1, 1, 1) @@ -444,6 +467,8 @@ class VoiceSettingsWindow(SettingsWindow): box.attach(order, 1, 23, 1, 1) box.attach(horizontal_label, 0, 24, 1, 1) box.attach(horizontal, 1, 24, 1, 1) + box.attach(guild_ids_label, 0, 25, 1, 1) + box.attach(guild_ids, 1, 25, 1, 1) self.add(box) @@ -636,6 +661,15 @@ class VoiceSettingsWindow(SettingsWindow): self.save_config() self.set_orientated_names() + def change_guild_ids(self, button): + """ + Horizontal layout setting changed + """ + self.guild_ids = parse_guild_ids(button.get_text()) + self.overlay.set_guild_ids(self.guild_ids) + self.save_config() + self.set_orientated_names() + def set_orientated_names(self): i= self.align_x_store.get_iter_first() i2=self.align_y_store.get_iter_first()