Ejemplo n.º 1
0
        internal void Initialize()
        {
            L.W("ADA CFG", "Initializing ADA Plugin Configs");
            var jconfig = AdaBotCore.AdaClient.ConfigJson;

            var gconfs = (JObject)jconfig["guild_config"];

            foreach (var kvp in gconfs)
            {
                var guild = ulong.Parse(kvp.Key);
                var gconf = (JObject)kvp.Value;

                var gcf = new AdaGuildConfig();
                gcf.ModLogChannel  = gconf["modlog"] != null ? (ulong?)gconf["modlog"] : null;
                gcf.DeleteCommands = gconf["delete_commands"] != null ? (bool?)gconf["delete_commands"] : null;
                gcf.CommandPrefix  = gconf["command_prefix"] != null ? (string)gconf["command_prefix"] : null;
                gcf.MuteRole       = gconf["mute_role"] != null ? (ulong?)gconf["mute_role"] : null;
                var jma = gconf["mod_actions"] != null ? (JArray)gconf["mod_actions"] : new JArray();
                foreach (var xjma in jma)
                {
                    var xma = (JObject)xjma;
                    var ma  = new AdaModAction
                    {
                        ActionType = (AdaModActionType)(byte)xma["type"],
                        Issued     = (DateTime)xma["issued"],
                        Issuer     = (ulong)xma["issuer"],
                        Reason     = (string)xma["reason"],
                        Until      = (DateTime)xma["until"],
                        UserId     = (ulong)xma["user"]
                    };
                    gcf.ModActions.Add(ma);
                }

                this.GuildConfigs[guild] = gcf;
            }

            var confnode = (JArray)jconfig["conf_manager"];
            var confs    = new Dictionary <string, JObject>();

            foreach (var xconf in confnode)
            {
                var type = (string)xconf["type"];
                var conf = (JObject)xconf["config"];
                confs.Add(type, conf);
            }

            var @as = AdaBotCore.PluginManager.PluginAssemblies;
            var ts  = @as.SelectMany(xa => xa.DefinedTypes);
            var pt  = typeof(IAdaPluginConfig);

            foreach (var t in ts)
            {
                if (!pt.IsAssignableFrom(t.AsType()) || !t.IsClass || t.IsAbstract)
                {
                    continue;
                }

                L.W("ADA PLG", "Type {0} is a plugin config", t.ToString());
                var iplg = (IAdaPluginConfig)Activator.CreateInstance(t.AsType());
                var icfg = iplg.DefaultConfig;
                if (confs.ContainsKey(t.ToString()))
                {
                    icfg.Load(confs[t.ToString()]);
                }
                this.DeclaredConfigs.Add(t.AsType(), icfg);
            }
            L.W("ADA CFG", "Done");
        }
Ejemplo n.º 2
0
 internal void SetGuildConfig(ulong guild_id, AdaGuildConfig conf)
 {
     this.GuildConfigs[guild_id] = conf;
     this.WriteConfigs();
 }