EarwigBot: YAML Config File Manager
This handles all tasks involving reading and writing to our config file, including encrypting and decrypting passwords and making a new config file from scratch at the inital bot run.
BotConfig has a few attributes and methods, including the following:
BotConfig also has some methods used in config loading:
Decrypt an object in our config tree.
_decryption_cipher is used as our key, retrieved using getpass() in load() if it wasn’t already specified. If this is called when passwords are not encrypted (check with is_encrypted()), nothing will happen. We’ll also keep track of this node if load() is called again (i.e. to reload) and automatically decrypt it.
Example usage:
>>> config.decrypt(config.irc, "frontend", "nickservPassword")
# decrypts config.irc["frontend"]["nickservPassword"]
Load, or reload, our config file.
First, check if we have a valid config file, and if not, notify the user. If there is no config file at all, offer to make one, otherwise exit.
Data from the config file is stored in six ConfigNodes (components, wiki, irc, commands, tasks, metadata) for easy access (as well as the lower-level data attribute). If passwords are encrypted, we’ll use getpass() for the key and then decrypt them. If the config is being reloaded, encrypted items will be automatically decrypted if they were decrypted earlier.
Return a list of tasks scheduled to run at the specified time.
The schedule data comes from our config file’s schedule field, which is stored as self.data["schedule"].
Based on:
with modifications.
EarwigBot: Permissions Database Manager
Controls the permissions.db file, which stores the bot’s owners and admins for the purposes of using certain dangerous IRC commands.
Add a nick/ident/host combo to the bot admins list.
Add a nick/ident/host combo to the bot owners list.
Get the value of the attribute key of a given user.
Raises KeyError if the key or user is not found.
Return True if there is an exact match for this rule.
Remove a nick/ident/host combo to the bot admins list.