diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index 17f7e42c..993fdd68 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -238,7 +238,7 @@ namespace TShockAPI var def = field.GetValue(defaults); - sb.AppendLine("# {0} ".SFormat(name)); + sb.AppendLine("## {0} ".SFormat(name)); sb.AppendLine("**Type:** {0} ".SFormat(type)); sb.AppendLine("**Description:** {0} ".SFormat(desc)); sb.AppendLine("**Default:** \"{0}\" ".SFormat(def)); diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index b1c592cc..741ee9f1 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.IO; using System.Linq; using System.Text; @@ -122,9 +123,6 @@ namespace TShockAPI [Description("")] public static readonly string heal; - - - static Permissions() { foreach (var field in typeof(Permissions).GetFields()) @@ -132,6 +130,42 @@ namespace TShockAPI field.SetValue(null, field.Name); } } + + static List GetCommands(string perm) + { + if (Commands.ChatCommands.Count < 1) + Commands.InitCommands(); + return Commands.ChatCommands.Where(c => c.Permission == perm).ToList(); + } + + static void DumpDescriptions() + { + var sb = new StringBuilder(); + foreach (var field in typeof(Permissions).GetFields()) + { + var name = field.Name; + + var descattr = field.GetCustomAttributes(false).FirstOrDefault(o => o is DescriptionAttribute) as DescriptionAttribute; + var desc = descattr != null && !string.IsNullOrWhiteSpace(descattr.Description) ? descattr.Description : "None"; + + var commands = GetCommands(name); + foreach (var c in commands) + { + for (var i = 0; i < c.Names.Count; i++) + { + c.Names[i] = "/" + c.Names[i]; + } + } + var strs = commands.Select(c => c.Name + (c.Names.Count > 1 ? "({0})".SFormat(string.Join(" ", c.Names.ToArray(), 1, c.Names.Count - 1)) : "")); + + sb.AppendLine("## {0} ".SFormat(name)); + sb.AppendLine("**Description:** {0} ".SFormat(desc)); + sb.AppendLine("**Commands:** {0} ".SFormat(strs.Count() > 0 ? string.Join(" ", strs) : "None")); + sb.AppendLine(); + } + + File.WriteAllText("PermissionsDescriptions.txt", sb.ToString()); + } } [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]