void InitGitHub() { try { GitHub = new GitHubClient() { Bot = this, ClientToken = Configuration.ReadString("dircbot.github.token", "") }; GitHubConfig = new YAMLConfiguration(File.ReadAllText("data/repositories.yml")); AnnounceGitChannels = new List<string>(); foreach (string chan in BaseChannels) { if (Configuration.ReadString("dircbot.irc-servers." + ServerName + ".channels." + chan.Replace("#", "") + ".announce_github", "false").StartsWith("t")) { Logger.Output(LogType.INFO, "Watching commits in channel: " + chan); AnnounceGitChannels.Add("#" + chan); } } GitHub.FetchRateLimit(); foreach (string author in GitHubConfig.GetKeys(null)) { foreach (string repository in GitHubConfig.GetKeys(author)) { YAMLConfiguration repoConfig = GitHubConfig.GetConfigurationSection(author + "." + repository); bool hasIssues = repoConfig.ReadString("has_issues", "false").StartsWith("t"); bool hasComments = repoConfig.ReadString("has_comments", "false").StartsWith("t"); bool hasPulls = repoConfig.ReadString("has_pulls", "false").StartsWith("t"); GitHub.WatchRepository(author + "/" + repository, hasIssues, hasComments, hasPulls); Logger.Output(LogType.INFO, "Watching: " + author + "/" + repository); } } GitHub.StartWatching(); } catch (Exception ex) { Logger.Output(LogType.ERROR, "Failed to initialize GitHubEngine: " + ex.ToString()); } }
/// <summary> /// Global program entry point. /// </summary> static void Main(string[] args) { Console.WriteLine("Initializing!"); Configuration = new YAMLConfiguration(GetConfig()); List <Task> tasks = new List <Task>(); DiscordBot = new dDiscordBot(); Task.Factory.StartNew(() => DiscordBot.Init(Configuration)); foreach (string server in Configuration.GetKeys("dircbot.irc-servers")) { Console.WriteLine("Preparing server: " + server); tasks.Add(Task.Factory.StartNew(() => { dIRCBot core = new dIRCBot(); lock (presentBotsLock) { PresentBots.Add(core); } core.ServerName = server; core.Init(); })); } while (tasks.Count > 0) { for (int i = 0; i < tasks.Count; i++) { if (tasks[i].IsCompleted) { tasks.RemoveAt(i--); } } Thread.Sleep(100); } Logger.Output(LogType.INFO, "Quitting cleanly."); }
void InitGitHub() { try { GitHub = new GitHubClient() { Bot = this, ClientToken = Configuration.ReadString("dircbot.github.token", "") }; GitHubConfig = new YAMLConfiguration(File.ReadAllText("data/repositories.yml")); AnnounceGitChannels = new List <string>(); foreach (string chan in BaseChannels) { if (Configuration.ReadString("dircbot.irc-servers." + ServerName + ".channels." + chan.Replace("#", "") + ".announce_github", "false").StartsWith("t")) { Logger.Output(LogType.INFO, "Watching commits in channel: " + chan); AnnounceGitChannels.Add("#" + chan); } } GitHub.FetchRateLimit(); foreach (string author in GitHubConfig.GetKeys(null)) { foreach (string repository in GitHubConfig.GetKeys(author)) { YAMLConfiguration repoConfig = GitHubConfig.GetConfigurationSection(author + "." + repository); bool hasIssues = repoConfig.ReadString("has_issues", "false").StartsWith("t"); bool hasComments = repoConfig.ReadString("has_comments", "false").StartsWith("t"); bool hasPulls = repoConfig.ReadString("has_pulls", "false").StartsWith("t"); GitHub.WatchRepository(author + "/" + repository, hasIssues, hasComments, hasPulls); Logger.Output(LogType.INFO, "Watching: " + author + "/" + repository); } } GitHub.StartWatching(); } catch (Exception ex) { Logger.Output(LogType.ERROR, "Failed to initialize GitHubEngine: " + ex.ToString()); } }
void PrepareConfig() { try { ServerAddress = Configuration.ReadString("dircbot.irc-servers." + ServerName + ".server", ""); ServerPort = Utilities.StringToUShort(Configuration.ReadString("dircbot.irc-servers." + ServerName + ".port", "")); Name = Configuration.ReadString("dircbot.irc-servers." + ServerName + ".username", ""); BaseChannels.Clear(); foreach (string channel in Configuration.GetKeys("dircbot.irc-servers." + ServerName + ".channels")) { BaseChannels.Add(channel); } Prefixes = Configuration.ReadStringList("dircbot.prefixes").ToArray(); } catch (Exception ex) { Logger.Output(LogType.ERROR, "Failed to load config: " + ex.GetType().Name + ": " + ex.Message); } }
public List<string> dScriptCheck(string rawYAML) { string fixedYAML = CleandScript(rawYAML); List<string> warnings = new List<string>(); YAMLConfiguration file; try { file = new YAMLConfiguration(fixedYAML); } catch (Exception ex) { Warn(warnings, WarnType.ERROR, "Failed to read YAML: " + ex.Message); return warnings; } List<string> scripts = file.GetKeys(null); for (int i = 0; i < scripts.Count; i++) { dScriptCheckScript(warnings, scripts[i], file.GetConfigurationSection(scripts[i])); } return warnings; }
public List <string> dScriptCheck(string rawYAML) { string fixedYAML = CleandScript(rawYAML); List <string> warnings = new List <string>(); YAMLConfiguration file; try { file = new YAMLConfiguration(fixedYAML); } catch (Exception ex) { Warn(warnings, WarnType.ERROR, "Failed to read YAML: " + ex.Message); return(warnings); } List <string> scripts = file.GetKeys(null); for (int i = 0; i < scripts.Count; i++) { dScriptCheckScript(warnings, scripts[i], file.GetConfigurationSection(scripts[i])); } return(warnings); }
public void dScriptCheckScript(List<String> warnings, string scriptname, YAMLConfiguration script) { string script_type = script.ReadString("type", null); if (string.IsNullOrEmpty(script_type)) { Warn(warnings, WarnType.ERROR, "Missing script type for script '" + scriptname + "'! Ignoring contents."); return; } switch (script_type) { case "interact": if (!script.HasKey(null, "steps")) { Warn(warnings, WarnType.ERROR, "Missing STEPS key for script '" + scriptname + "'!"); } break; case "yaml data": // Note: Nothing required here break; case "entity": { if (!script.HasKey(null, "entity_type")) { Warn(warnings, WarnType.MINOR, "Missing ENTITY_TYPE key for script '" + scriptname + "'!"); } List<string> keys = script.GetKeys(null); foreach (string key in keys) { if (key != "entity_type" && key != "type") { bool exists = false; for (int i = 0; i < AllMeta.Mechanisms.Count; i++) { if (AllMeta.Mechanisms[i].Objectd.ToLower() == "dentity" && AllMeta.Mechanisms[i].Name.ToLower() == key) { exists = true; break; } } if (!exists) { Warn(warnings, WarnType.WARNING, "Unrecognized entity mechanism '" + key + "' for " + scriptname); } } } } break; case "custom": // Note: Nothing required here // TODO: tags: and requirements: script checks break; case "assignment": if (!script.HasKey(null, "interact scripts")) { Warn(warnings, WarnType.MINOR, "Missing INTERACT SCRIPTS key for script '" + scriptname + "'!"); } if (!script.HasKey(null, "actions")) { Warn(warnings, WarnType.MINOR, "Missing ACTIONS key for script '" + scriptname + "'!"); } // TODO: all actions, validate break; case "task": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } List<string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List<object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "procedure": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } List<string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List<object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "world": { if (!script.HasKey(null, "events")) { Warn(warnings, WarnType.ERROR, "Missing EVENTS key for script '" + scriptname + "'!"); } List<string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List<object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } keys = script.GetKeys("events"); for (int i = 0; i < keys.Count; i++) { if (script.IsList("events." + keys[i])) { ValidateEvent(warnings, keys[i], scriptname + ".events"); List<object> scriptData = script.ReadList("events." + keys[i]); ReadScriptData(warnings, scriptData, scriptname + ".events." + keys[i], ""); } else { Warn(warnings, WarnType.ERROR, "Invalid EVENTS sub-key '" + keys[i] + "' for " + scriptname); } } } break; case "book": // TODO: Book required keys break; case "command": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } // TODO: Command required keys List<string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (keys[i].ToLower() != "aliases" && script.IsList(keys[i])) { List<object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "format": if (!script.HasKey(null, "format")) { Warn(warnings, WarnType.ERROR, "Missing FORMAT key for script '" + scriptname + "'!"); } // TODO: Validate format line break; case "inventory": // TODO: Inventory required keys break; case "item": if (!script.HasKey(null, "material")) { Warn(warnings, WarnType.ERROR, "Missing MATERIAL key for script '" + scriptname + "'!"); } // TODO: Validate inputs break; case "map": // TODO: Map required keys break; case "version": // TODO: Version required keys break; default: Warn(warnings, WarnType.ERROR, "Unknown script type '" + script_type + "' for script '" + scriptname + "'!"); break; } }
public void dScriptCheckScript(List <String> warnings, string scriptname, YAMLConfiguration script) { string script_type = script.ReadString("type", null); if (string.IsNullOrEmpty(script_type)) { Warn(warnings, WarnType.ERROR, "Missing script type for script '" + scriptname + "'! Ignoring contents."); return; } switch (script_type) { case "interact": if (!script.HasKey(null, "steps")) { Warn(warnings, WarnType.ERROR, "Missing STEPS key for script '" + scriptname + "'!"); } break; case "yaml data": // Note: Nothing required here break; case "entity": { if (!script.HasKey(null, "entity_type")) { Warn(warnings, WarnType.MINOR, "Missing ENTITY_TYPE key for script '" + scriptname + "'!"); } List <string> keys = script.GetKeys(null); foreach (string key in keys) { if (key != "entity_type" && key != "type") { bool exists = false; for (int i = 0; i < AllMeta.Mechanisms.Count; i++) { if (AllMeta.Mechanisms[i].Objectd.ToLower() == "dentity" && AllMeta.Mechanisms[i].Name.ToLower() == key) { exists = true; break; } } if (!exists) { Warn(warnings, WarnType.WARNING, "Unrecognized entity mechanism '" + key + "' for " + scriptname); } } } } break; case "custom": // Note: Nothing required here // TODO: tags: and requirements: script checks break; case "assignment": if (!script.HasKey(null, "interact scripts")) { Warn(warnings, WarnType.MINOR, "Missing INTERACT SCRIPTS key for script '" + scriptname + "'!"); } if (!script.HasKey(null, "actions")) { Warn(warnings, WarnType.MINOR, "Missing ACTIONS key for script '" + scriptname + "'!"); } // TODO: all actions, validate break; case "task": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } List <string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List <object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "procedure": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } List <string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List <object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "world": { if (!script.HasKey(null, "events")) { Warn(warnings, WarnType.ERROR, "Missing EVENTS key for script '" + scriptname + "'!"); } List <string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (script.IsList(keys[i])) { List <object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } keys = script.GetKeys("events"); for (int i = 0; i < keys.Count; i++) { if (script.IsList("events." + keys[i])) { ValidateEvent(warnings, keys[i], scriptname + ".events"); List <object> scriptData = script.ReadList("events." + keys[i]); ReadScriptData(warnings, scriptData, scriptname + ".events." + keys[i], ""); } else { Warn(warnings, WarnType.ERROR, "Invalid EVENTS sub-key '" + keys[i] + "' for " + scriptname); } } } break; case "book": // TODO: Book required keys break; case "command": { if (!script.HasKey(null, "script")) { Warn(warnings, WarnType.ERROR, "Missing SCRIPT key for script '" + scriptname + "'!"); } // TODO: Command required keys List <string> keys = script.GetKeys(null); for (int i = 0; i < keys.Count; i++) { if (keys[i].ToLower() != "aliases" && script.IsList(keys[i])) { List <object> scriptData = script.ReadList(keys[i]); ReadScriptData(warnings, scriptData, scriptname + "." + keys[i], ""); } } } break; case "format": if (!script.HasKey(null, "format")) { Warn(warnings, WarnType.ERROR, "Missing FORMAT key for script '" + scriptname + "'!"); } // TODO: Validate format line break; case "inventory": // TODO: Inventory required keys break; case "item": if (!script.HasKey(null, "material")) { Warn(warnings, WarnType.ERROR, "Missing MATERIAL key for script '" + scriptname + "'!"); } // TODO: Validate inputs break; case "map": // TODO: Map required keys break; case "version": // TODO: Version required keys break; default: Warn(warnings, WarnType.ERROR, "Unknown script type '" + script_type + "' for script '" + scriptname + "'!"); break; } }
/// <summary> /// Global program entry point. /// </summary> static void Main(string[] args) { Console.WriteLine("Initializing!"); Configuration = new YAMLConfiguration(GetConfig()); List<Task> tasks = new List<Task>(); DiscordBot = new dDiscordBot(); Task.Factory.StartNew(() => DiscordBot.Init(Configuration)); foreach (string server in Configuration.GetKeys("dircbot.irc-servers")) { Console.WriteLine("Preparing server: " + server); tasks.Add(Task.Factory.StartNew(() => { dIRCBot core = new dIRCBot(); lock (presentBotsLock) { PresentBots.Add(core); } core.ServerName = server; core.Init(); })); } while (tasks.Count > 0) { for (int i = 0; i < tasks.Count; i++) { if (tasks[i].IsCompleted) { tasks.RemoveAt(i--); } } Thread.Sleep(100); } Logger.Output(LogType.INFO, "Quitting cleanly."); }