Skip to content

Accessing and Writing config.json

Innocent Bystander edited this page Aug 8, 2015 · 1 revision

High-level

bot.config.exists(["<keyname>", "<keyname>", ...])

  • checks whether config["<keyname>"]["<keyname>"][...] exists
  • returns None if the key path cannot be found

bot.get_config_option("<keyname>")

  • gets value stored in config["<keyname>"]
  • returns None if <keyname> cannot be found

bot.get_config_suboption("<conversation id>", "<keyname>")

  • gets value stored in config["conversations"]["<conversation id>"]["<keyname>"]
  • if <keyname> cannot be found, retrieve config["<keyname>"] (fallback to bot.get_config_option("<keyname>"))
  • returns None if <keyname> cannot be found in either location

Low-level

bot.config.get_by_path(["<keyname>", "<keyname>", ...])

  • retrieve configuration by the specified path hierarchy
  • raises KeyError or TypeError if keys don't exist

bot.config.set_by_path(["<keyname>", "<keyname>", ...], <somevalue>)

  • raises TypeError if it cannot create the path
  • can only create a new key if all the preceding keys are available
  • WARNING: INCORRECT USAGE OF THIS COMMAND CAN CORRUPT config.json - PLEASE USE WITH CARE

# ## ###

Clone this wiki locally