Add api.server endpoint for individual server information

This commit is contained in:
jesopo 2018-10-05 09:51:17 +01:00
parent 808694c113
commit bc3c9b742e

View file

@ -48,20 +48,34 @@ class Module(ModuleManager.BaseModule):
networks, channels, users = self._stats() networks, channels, users = self._stats()
return {"networks": networks, "channels": channels, "users": users} return {"networks": networks, "channels": channels, "users": users}
def _server_stats(self, server):
return {
"hostname": server.target_hostname,
"port": server.port,
"tls": server.tls,
"alias": server.alias,
"hostmask": "%s!%s@%s" % (
server.nickname, server.username, server.hostname),
"users": len(server.users)
}
@utils.hook("api.servers") @utils.hook("api.servers")
def servers_api(self, event): def servers_api(self, event):
servers = {} if event["path"]:
for server in self.bot.servers.values(): server_id = event["path"][0]
servers[server.id] = { if not server_id.isdigit():
"hostname": server.target_hostname, return None
"port": server.port, server_id = int(server_id)
"tls": server.tls,
"alias": server.alias, server = self.bot.get_server(server_id)
"hostmask": "%s!%s@%s" % ( if not server:
server.nickname, server.username, server.hostname), return None
"users": len(server.users) return self._server_stats(server)
} else:
return servers servers = {}
for server in self.bot.servers.values():
servers[server.id] = self._server_stats(server)
return servers
def _channel_stats(self, channel): def _channel_stats(self, channel):
return { return {