/// <summary> /// Load config of bot /// </summary> public static int Load() { if (Directory.Exists(Variables.ConfigurationDirectory) == false) { Directory.CreateDirectory(Variables.ConfigurationDirectory); } if (!File.Exists(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + Paths.ConfigFile)) { Console.WriteLine("Error: unable to find config file in configuration/" + Paths.ConfigFile); Console.WriteLine("You can get a configuration file here: https://github.com/benapetr/wikimedia-bot/blob/master/configuration/wmib.conf"); return(2); } ConfigurationData = File2Dict(); IRC.Username = RetrieveConfig("username"); IRC.NetworkHost = RetrieveConfig("network"); IRC.NickName = RetrieveConfig("nick"); IRC.LoginNick = RetrieveConfig("nick"); IRC.Hostname = RetrieveConfig("host", "wikimedia/bot/wm-bot"); System.DebugChan = RetrieveConfig("debug"); System.MaxGrantableRoleLevel = RetrieveConfig("maximal_grantable_role_level", System.MaxGrantableRoleLevel); System.ModulesToLoad = RetrieveConfig("modules", ""); Network.BouncerPort = RetrieveConfig("bouncerp", Network.BouncerPort); WebPages.WebpageURL = RetrieveConfig("web", ""); IRC.LoginPw = RetrieveConfig("password", ""); IRC.Interval = RetrieveConfig("interval", IRC.Interval); MySQL.MysqlPw = RetrieveConfig("mysql_pw"); MySQL.Mysqldb = RetrieveConfig("mysql_db", MySQL.Mysqldb); MySQL.MysqlUser = RetrieveConfig("mysql_user"); MySQL.MysqlPort = RetrieveConfig("mysql_port", MySQL.MysqlPort); MySQL.MysqlHost = RetrieveConfig("mysql_host"); WebPages.Css = RetrieveConfig("style_html_file", ""); Network.SystemPort = RetrieveConfig("system_port", Network.SystemPort); Postgres.DBNM = RetrieveConfig("pg_name"); Postgres.Host = RetrieveConfig("pg_host"); Postgres.Pass = RetrieveConfig("pg_pass"); Postgres.Unwritten = RetrieveConfig("pg_unwritten_log", Postgres.Unwritten); Postgres.Port = RetrieveConfig("pg_port", Postgres.Port); Postgres.User = RetrieveConfig("pg_user"); if (string.IsNullOrEmpty(IRC.LoginNick)) { Console.WriteLine("Error there is no login for bot (nick key is missing?)"); return(1); } if (string.IsNullOrEmpty(IRC.NetworkHost)) { Console.WriteLine("Error irc server is wrong (network key is missing?)"); return(4); } if (string.IsNullOrEmpty(IRC.NickName)) { Console.WriteLine("Error there is no username for bot"); return(6); } System.prefix = RetrieveConfig("system_prefix", System.prefix); IRC.UsingBouncer = bool.Parse(RetrieveConfig("serverIO", "false")); Syslog.Log("Loading instances"); Instance.PrimaryInstance = Instance.CreateInstance(IRC.NickName, Network.BouncerPort); int CurrentInstance = 0; while (CurrentInstance < 20) { if (!ConfigurationData.ContainsKey("instancename" + CurrentInstance)) { break; } string InstanceName = ConfigurationData["instancename" + CurrentInstance]; Syslog.DebugLog("Instance found: " + InstanceName); if (IRC.UsingBouncer) { Syslog.DebugLog("Using bouncer, looking for instance port"); if (!ConfigurationData.ContainsKey("instanceport" + CurrentInstance)) { Syslog.WriteNow("Instance " + InstanceName + " has invalid port, not using", true); continue; } int port = int.Parse(ConfigurationData["instanceport" + CurrentInstance]); Instance.CreateInstance(InstanceName, port); } else { Instance.CreateInstance(InstanceName); } CurrentInstance++; } if (!File.Exists(Paths.GetChannelFile())) { Console.WriteLine("Error there is no channel file (" + Paths.GetChannelFile() + ") to load channels from"); return(20); } List <string> channels = new List <string>(File.ReadAllLines(Paths.GetChannelFile())); foreach (string x in channels) { string name = x.Replace(" ", ""); if (!string.IsNullOrEmpty(name)) { lock (Channels) { Channels.Add(new Channel(name)); } } } if (!string.IsNullOrEmpty(Configuration.System.DebugChan) && !channels.Contains(Configuration.System.DebugChan)) { lock (Channels) { Channels.Add(new Channel(Configuration.System.DebugChan)); } Syslog.DebugLog("Debug channel was missing in channel list (fixed by join)"); } Syslog.Log("Channels were all loaded, linking databases"); // Now when all chans are loaded let's link them together lock (Channels) { foreach (Channel channel in Channels) { channel.InitializeShares(); } } Syslog.Log("Channel db's working"); if (!Directory.Exists(Paths.DumpDir)) { Directory.CreateDirectory(Paths.DumpDir); } return(0); }