code: function getReply(bot, username, message) {
  	var filename = "./" + username + ".json";
  
  	// See if the bot knows this user yet (in its current memory).
  	var userData = bot.getUservars(username);
  	if (!userData) {
  		// See if a local file exists for stored user variables.
  		try {
  			var stats = fs.statSync(filename);
  			if (stats) {
  				var jsonText = fs.readFileSync(filename);
  				userData = JSON.parse(jsonText);
  				bot.setUservars(username, userData);
  			}
  		} catch(e) {}
  	}
  
  	// Wrap the reply promise so we can export user variables before
  	// we return it up the stack.
  	return new Promise(function(resolve, reject) {
  		bot.reply(username, message).then(function(reply) {
  			// Export user variables to disk.
  			userData = bot.getUservars(username);
  			fs.writeFile(filename, JSON.stringify(userData, null, 2), function(err) {
  				if (err) {
  					console.error("Failed to write file", filename, err);
  				}
  			});
  
  			resolve(reply);
  		}).catch(reject);
  	})
  }
docs: The meat of the logic is in here. This function gets a reply from the bot, and persists user data to disk as a local file named "./$USERNAME.json" where $USERNAME is the username.