コード例 #1
0
 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());
     }
 }
コード例 #2
0
 public void Init(YAMLConfiguration conf)
 {
     try
     {
         Config = conf;
         string token = Config.ReadString("discord.token", null);
         if (token == null)
         {
             Logger.Output(LogType.INFO, "Discord bot not configured!");
             return;
         }
         Client = new DiscordClient();
         Client.MessageReceived += messageReceived;
         Client.ExecuteAndWait(async() => await Client.Connect(token, TokenType.Bot));
     }
     catch (Exception ex)
     {
         Logger.Output(LogType.ERROR, ex.ToString());
     }
 }
コード例 #3
0
 public void Init(YAMLConfiguration conf)
 {
     try
     {
         Config = conf;
         string token = Config.ReadString("discord.token", null);
         if (token == null)
         {
             Logger.Output(LogType.INFO, "Discord bot not configured!");
             return;
         }
         Client = new DiscordClient();
         Client.MessageReceived += messageReceived;
         Client.ExecuteAndWait(async () => await Client.Connect(token, TokenType.Bot));
     }
     catch (Exception ex)
     {
         Logger.Output(LogType.ERROR, ex.ToString());
     }
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 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;
     }
 }
コード例 #6
0
        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;
            }
        }