class Pladdble: ''' Pladdble is class that helps pladder to interface with a mumble server. ''' def __init__(self, bot, network): self.connector = RetryProxy(bot.bus, f'se.raek.PladderConnector.{network}') def connected_users(self) -> str: users = self.connector.GetChannelUsers('Root', on_error=lambda e: e) if users is None: return 'Icke ansluten till servern' return f'Antalet anslutna nötter är: {len(users) - 1}' # Exclude the bot itself def list_users(self) -> str: config = self.connector.GetConfig(on_error=lambda e: None) if self is None: return 'Icke ansluten till servern' self_nick = config['user'] users = self.connector.GetChannelUsers('Root', on_error=lambda e: None) if users is None: return 'Icke ansluten till servern' users.remove(self_nick) # Remove the bot itself from the list return ", ".join(users) def get_info(self) -> str: config = self.connector.GetConfig(on_error=lambda e: None) if self is None: return 'Icke ansluten till servern' info_string = [ f'Bot name: {config["user"]}', f'Server address: {config["host"]}', f'Port: {config["port"]}', f'Network: {config["network"]}', ] return ' '.join(info_string)
def connector_config(self, context, network=None): if network is None: network = context.metadata["network"] connector = RetryProxy(self.bus, f"se.raek.PladderConnector.{network}") config = connector.GetConfig(on_error=lambda e: None) if config is None: return f"Not connected to network {network}." else: parts = [] for key, value in config.items(): parts.append(f"{key}={repr(value)}") return f"{network}: {', '.join(parts)}"