public string Help(string command) { StringBuilder sb = new StringBuilder(); if (!Methods.ContainsKey(command)) { return(command + " not found in " + CSObject.GetType().Name); } foreach (MethodInfo mi in Methods[command]) { HelpAttribute ha = mi.GetCustomAttribute <HelpAttribute>(); if (ha != null) { sb.Append(ha.HelpText + "\n"); } ParameterInfo[] pi = mi.GetParameters(); sb.AppendFormat("{0} {1}(", mi.ReturnType.Name.ToLower(), mi.Name); if (pi.Length != 0) { sb.AppendFormat("{0} {1}", pi[0].ParameterType.Name.ToLower(), pi[0].Name); } for (int i = 1; i < pi.Length; i++) { sb.AppendFormat(", {0} {1}", pi[i].ParameterType.Name.ToLower(), pi[i].Name); } sb.Append(")"); List <object> attrs = mi.GetCustomAttributes(false).ToList(); if (attrs.Count > 0) { sb.AppendFormat("\n[{0}", attrs[0].GetType().Name); for (int i = 1; i < attrs.Count; i++) { sb.AppendFormat(",{0}", attrs[i].GetType().Name); } sb.Append("]"); } } return(sb.ToString()); }
public void Readme() { using (StreamWriter writer = new StreamWriter(DIRECTORY + "README.TXT")) { writer.WriteLine("== Hello UpThere! =="); writer.WriteLine("This project hasn't been updated to use Twitch API v5 (this currently uses v2!)"); writer.WriteLine("As such, it doesn't actually connect to the Twitch API. Feel free to play with"); writer.WriteLine("the following features:"); writer.WriteLine(" -Any commands listed in the COMMANDS reference below, such as"); writer.WriteLine(" !splat"); writer.WriteLine(" !ping google.com 3"); writer.WriteLine(" !roll 3d6"); writer.WriteLine(" !asynchronous"); writer.WriteLine(" !help roll"); writer.WriteLine(" -Write your own commands by creating cs files in the"); writer.WriteLine(" UserScripts/Autoload directory."); writer.WriteLine(" -Open notepad (or other application), and input the following commands"); writer.WriteLine(" !play notepad"); writer.WriteLine(" !type \"hello world\" "); writer.WriteLine(" !rightclick"); writer.WriteLine(" "); StringBuilder sb = new StringBuilder(); writer.WriteLine("==CREATING COMMANDS=="); writer.WriteLine("Any command tagged as 'viewerpermitted' can be run by viewers"); writer.WriteLine("For Virilay, to allow viewers access to this command"); writer.WriteLine(" void Roll(string dieroll)"); writer.WriteLine("Add the following code"); writer.WriteLine(" [ViewerPermitted]"); writer.WriteLine(" void Roll(string dieroll)"); writer.WriteLine("If you wanted to add help text when users type !help, use the"); writer.WriteLine("help attribute."); writer.WriteLine(""); writer.WriteLine("Use Console.WriteLine or return to report text"); writer.WriteLine("If you want to use an external framework, add the dlls to"); writer.WriteLine("UserScripts/dll. Remember to also create a text file!"); writer.WriteLine(""); writer.WriteLine("==RULES REFERENCE=="); foreach (Lieutenant lt in _lieutenants.Values) { writer.WriteLine("=" + lt.CSObject.ToString().ToUpper() + "="); foreach (string key in lt.Methods.Keys) { foreach (MethodInfo mi in lt.Methods[key]) { sb.AppendFormat("{0} {1}(", mi.ReturnType.Name.ToLower(), mi.Name); ParameterInfo[] pis = mi.GetParameters(); if (pis.Length > 0) { sb.AppendFormat("{0} {1}", pis[0].ParameterType.Name.ToLower(), pis[0].Name); for (int i = 1; i < pis.Length; i++) { sb.AppendFormat(", {0} {1}", pis[i].ParameterType.Name.ToLower(), pis[i].Name); } } sb.AppendFormat(")"); writer.WriteLine(sb.ToString()); sb.Clear(); HelpAttribute ha = mi.GetCustomAttribute <HelpAttribute>(); if (ha != null) { writer.WriteLine(ha.HelpText); } foreach (CustomAttributeData attr in mi.CustomAttributes) { writer.WriteLine("[" + attr.AttributeType.Name + "]"); } writer.WriteLine(); } } } writer.WriteLine(""); writer.WriteLine("=TYPES="); writer.WriteLine("INTEGER"); writer.WriteLine("An integer number. Fractions not allowed"); writer.WriteLine(""); writer.WriteLine("UINT"); writer.WriteLine("An unsigned integer number. Negative numbers, and fractions are not allowed. 0 is permitted."); writer.WriteLine(""); writer.WriteLine("DOUBLE, FLOAT, DECIMAL"); writer.WriteLine("A number that decimals, such as -3.3, 3, or 2"); writer.WriteLine(""); writer.WriteLine("CHAR"); writer.WriteLine("A single character, such as 'a', '1', or 1."); writer.WriteLine(""); writer.WriteLine("STRING"); writer.WriteLine("Many characters, such as 3d6+2"); writer.WriteLine("If you want to include space, surround the words with \", such as:"); writer.WriteLine("\t\"This is a string\""); } Process.Start("README.txt"); }