I've started teaching myself Python about three weeks ago and i've been working on an RCON cog for my Ark server for Red discord bot. I have a config i am trying to format so that i can use a command to easily view all the settings for the servers.
here is the config i've created so far for the servers
{
"clusters": {
"pvp": {
"joinchannel": 739270285450018927,
"leavechannel": 851819367439400960,
"adminlogchannel": 848933429164507156,
"globalchatchannel": 841118994399494164,
"servers": {
"rag": {
"ip": "192.168.1.201",
"port": 27020,
"password": "passwd",
"chatchannel": 770891102601084928
},
"val": {
"ip": "192.168.1.203",
"port": 27024,
"password": "passwd",
"chatchannel": 770891102601084928
},
"island": {
"ip": "192.168.1.205",
"port": 27021,
"password": "passwd",
"chatchannel": 770891102601084928
}
}
},
"pve": {
"joinchannel": 739270285450018927,
"leavechannel": 851819367439400960,
"adminlogchannel": 848933429164507156,
"globalchatchannel": 841118994399494164,
"servers": {
"rag": {
"ip": "192.168.1.202",
"port": 27022,
"password": "passwd",
"chatchannel": 770891102601084928
},
"val": {
"ip": "192.168.1.204",
"port": 27023,
"password": "passwd",
"chatchannel": 770891102601084928
},
"island": {
"ip": "192.168.1.206",
"port": 27025,
"password": "passwd",
"chatchannel": 770891102601084928
}
}
}
}
}
Here is what i would like it to look like if i were to print the "server settings"
PvP Cluster
map: rag
ip: 192.168.1.201
port: 27020
password: psswrd
chatchannel: 770891102601084928
map: val
ip: 192.168.1.203
port: 27024
password: psswrd
chatchannel: 770891102601084928
map: island
ip: 192.168.1.205
port: 27021
password: psswrd
chatchannel: 770891102601084928
PvE Cluster
map: rag
ip: 192.168.1.202
port: 27022
password: psswrd
chatchannel: 770891102601084928
map: val
ip: 192.168.1.204
port: 27023
password: psswrd
chatchannel: 770891102601084928
map: island
ip: 192.168.1.206
port: 27025
password: psswrd
chatchannel: 770891102601084928
So far i have tried
serverlist = []
settings = await self.config.guild(ctx.guild).all()
for cluster in settings["clusters"]:
for name, server in cluster["servers"].items():
serverlist.extend(settings[cluster]["servers"])
await ctx.send(serverlist)
and some other probably noob logic to get it formatted how i want but with this many nested dicts i am super lost.
Eventually i'll make it into an embed. but right now i'm just trying to better understand how to manipulate dictionaries from my config to display it in the discord better.
I would like to print this all at one time as one message too.
If anyone could hold my hand a bit on this and show an example using my config it would be much appreciated :)