Fix command parameter name saving and other things

This commit is contained in:
Norbi Peti 2021-04-06 23:17:31 +02:00
parent fd63e995ff
commit c49fac5ce5
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 19 additions and 19 deletions

View file

@ -49,10 +49,12 @@ val saveConfigComments = TaskKey[Seq[File]]("saveConfigComments")
saveConfigComments := { saveConfigComments := {
val sv = (Compile / sources).value val sv = (Compile / sources).value
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)") val clRegex = Pattern.compile("class (\\w+).* extends ((?:\\w|\\d)+)")
val objRegex = Pattern.compile("object (\\w+)") val objRegex = Pattern.compile("object (\\w+)")
val subRegex = Pattern.compile("def `?(\\w+)`?\\((?:((?:\\w|\\d)+): ((?:\\w|[\\[\\].]|\\d)+),?\\s*)+\\)") val subRegex = Pattern.compile("def `?(\\w+)`?")
val config = new YamlConfiguration() val subParamRegex = Pattern.compile("((?:\\w|\\d)+): ((?:\\w|\\d)+)")
val configConfig = new YamlConfiguration()
val commandConfig = new YamlConfiguration()
def getConfigComments(line: String, clKey: String, comment: String, justCommented: Boolean): (String, String, Boolean) = { def getConfigComments(line: String, clKey: String, comment: String, justCommented: Boolean): (String, String, Boolean) = {
val clMatcher = clRegex.matcher(line) val clMatcher = clRegex.matcher(line)
@ -69,7 +71,7 @@ saveConfigComments := {
if (clKey != null) { if (clKey != null) {
val matcher = cdataRegex.matcher(line) val matcher = cdataRegex.matcher(line)
if (matcher.find()) if (matcher.find())
config.set(s"$clKey.${matcher.group(1)}", comment.trim) configConfig.set(s"$clKey.${matcher.group(1)}", comment.trim)
} }
else { else {
val matcher = objRegex.matcher(line) val matcher = objRegex.matcher(line)
@ -79,7 +81,7 @@ saveConfigComments := {
else if (clName.contains("Plugin")) "global" else if (clName.contains("Plugin")) "global"
else null else null
if (compKey != null) if (compKey != null)
config.set(s"${compKey}.generalDescriptionInsteadOfAConfig", comment.trim) configConfig.set(s"${compKey}.generalDescriptionInsteadOfAConfig", comment.trim)
} }
} }
(clKey, null, false) (clKey, null, false)
@ -106,33 +108,31 @@ saveConfigComments := {
val clMatcher = clRegex.matcher(line) val clMatcher = clRegex.matcher(line)
if (pkg == null && line.startsWith("package ")) if (pkg == null && line.startsWith("package "))
pkg = line.substring("package ".length) pkg = line.substring("package ".length)
/*else if (clName == null && (line.contains("object") || line.contains("class"))
&& !line.contains("import")) {
val i = line.indexOf("class")
val j = if (i == -1) line.indexOf("object") + "object ".length else i + "class ".length
clName = line.substring(j)
}*/
else if (clName == null && objMatcher.find()) else if (clName == null && objMatcher.find())
clName = objMatcher.group(1) clName = objMatcher.group(1)
else if (clName == null && clMatcher.find()) else if (clName == null && clMatcher.find())
clName = clMatcher.group(1) clName = clMatcher.group(1)
val subMatcher = subRegex.matcher(line) val subMatcher = subRegex.matcher(line)
val subParamMatcher = subParamRegex.matcher(line)
val sub = line.contains("@Subcommand") || line.contains("@Command2.Subcommand") val sub = line.contains("@Subcommand") || line.contains("@Command2.Subcommand")
if (subCommand || sub) //This line or the previous one had the annotation if (subCommand || sub) //This line or the previous one had the annotation
if (subMatcher.find()) { if (subMatcher.find()) {
val groups = (2 to subMatcher.groupCount()).map(subMatcher.group) /*val groups = (2 to subMatcher.groupCount()).map(subMatcher.group)
val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1)) val pairs = for (i <- groups.indices by 2) yield (groups(i), groups(i + 1))*/
val mname = subMatcher.group(1) val mname = subMatcher.group(1)
print(s"$pkg.$clName.$mname(") val params = Iterator.continually(()).takeWhile(_ => subParamMatcher.find())
for ((name, ty) <- pairs) print(s"$name: $ty, ") .map(_ => subParamMatcher.group(1)).drop(1)
println(")") val section = commandConfig.createSection(s"$pkg.$clName.$mname")
section.set("method", s"$mname()")
section.set("params", params.mkString(" "))
} }
subCommand = sub subCommand = sub
} }
config.save("target/configHelp.yml") configConfig.save("target/configHelp.yml")
commandConfig.save("target/commands.yml")
}.recover[Unit]({ case t => t.printStackTrace() }) }.recover[Unit]({ case t => t.printStackTrace() })
} }
Seq(file("target/configHelp.yml")) Seq(file("target/configHelp.yml"), file("target/commands.yml"))
} }
resourceGenerators in Compile += saveConfigComments resourceGenerators in Compile += saveConfigComments

View file

@ -160,8 +160,8 @@ import java.util.Optional
private def stopStarting(): Unit = { private def stopStarting(): Unit = {
this synchronized { this synchronized {
starting = false starting = false
notifyAll()
} }
notifyAll()
} }
private def handleReady(event: java.util.List[GuildCreateEvent]): Unit = { //System.out.println("Got ready event"); private def handleReady(event: java.util.List[GuildCreateEvent]): Unit = { //System.out.println("Got ready event");