Provide more information for api.channels

This commit is contained in:
jesopo 2018-10-04 17:37:34 +01:00
parent d7f4050ae8
commit 52b7beb407

View file

@ -60,6 +60,11 @@ class Module(ModuleManager.BaseModule):
}
return servers
def _channel_stats(self, channel):
return {
"users": len(channel.users),
"topic": channel.topic
}
@utils.hook("api.channels")
def channels_api(self, event):
print(event["path"])
@ -74,12 +79,13 @@ class Module(ModuleManager.BaseModule):
return None
channels = {}
for channel in server.channels.values():
channels[channel.name] = len(channel.users)
channels[channel.name] = self._channel_stats(channel)
return channels
else:
channels = {}
for server in self.bot.servers.values():
channels[server.id] = {}
for channel in server.channels.values():
channels[server.id][str(channel)] = len(channel.users)
channels[server.id][str(channel)] = self._channel_stats(
channel)
return channels