add guild_ids

This commit is contained in:
Joshix 2021-08-07 22:57:17 +02:00
parent d0638b02b6
commit b0d1c0873d
4 changed files with 44 additions and 4 deletions

View file

@ -336,7 +336,9 @@ class DiscordConnector:
return
elif j["cmd"] == "GET_GUILDS":
for guild in j["data"]["guilds"]:
self.req_channels(guild["id"])
if len(self.voice_settings.guild_ids) == 0 or guild["id"] in self.voice_settings.guild_ids:
print("Requesting channels for guild:", guild)
self.req_channels(guild["id"])
self.guilds[guild["id"]] = guild
return
elif j["cmd"] == "GET_CHANNELS":

View file

@ -39,8 +39,11 @@ class Discover:
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)

View file

@ -57,6 +57,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 +185,12 @@ class VoiceOverlayWindow(OverlayWindow):
self.horizontal = horizontal
self.redraw()
def set_guild_ids(self, guild_ids=tuple()):
for _id in guild_ids:
if _id not in self.guild_ids:
self.discover.connection.req_channels(_id)
self.guild_ids = guild_ids
def set_wind_col(self):
"""
Use window colour to draw

View file

@ -20,6 +20,15 @@ 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)
class VoiceSettingsWindow(SettingsWindow):
"""Voice setting tab on settings window"""
@ -53,6 +62,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 +129,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 +155,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 +163,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 +203,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" % (", ".join(self.guild_ids)))
with open(self.config_file, 'w') as file:
config.write(file)
@ -398,6 +410,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 to load (empty = all)")
guild_ids = Gtk.HBox.new()
guild_ids.set_active(self.horizontal)
guild_ids.connect("toggled", self.change_horizontal)
box.attach(autohide_label, 0, 0, 1, 1)
box.attach(autohide, 1, 0, 1, 1)
box.attach(font_label, 0, 1, 1, 1)
@ -636,6 +654,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_content())
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()