module.exports = (lib) => {
  var kats = {
    main: [
      "allowedMimes",
      "debugchannel",
      "disallowedHosts",
      "maxFileSize"
    ]
  };
  
  lib.trigger.add({
    name: 'cfg',
    call: /^!cfg/i,
    level: 100,
    active: 0,
    func: (e) => {
      // irc, main, websrv, trigger
      var msg = e.message.replace('!cfg.','');
      if(msg.match(/=/)) {
        var tmp = e.message.split('=');
        var value = tmp[1].trim();
        var cmd = tmp[0].trim().split('.');
        
        if(cmd.length == 2) {
          var kat = cmd[0];
          if(kat in kats) {
            var key = cmd[1];
            if(kats[kat].indexOf(key) !== -1) {
              e.reply("kat: "+kat+" ; key: "+key+" ; val: "+value);
            }
            else {
              e.reply("key not found");
            }
          }
          else {
            e.reply("kat not found");
          }
        }
        else {
          e.reply("nope");
        }
      }
      else {
        var cmd = msg.trim().split('.');
        var kat = cmd[0];
        if(kat in kats) {
          var key = cmd[1];
          if(kats[kat].indexOf(key) !== -1) {
            lib.config.read(cb => {
              e.reply(kat+"."+key+" = "+JSON.stringify(cb));
            }, kat, key);
          }
          else {
            e.reply("key not found");
          }
        }
        else {
          e.reply("kat not found");
        }
      }
    },
    desc: 'cfg'
  });
};