mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 05:07:46 +02:00
feat(scripting): module exports
- add currentSide global - add script name rule - add displayName
This commit is contained in:
@ -6,6 +6,7 @@ import me.rhunk.snapenhance.common.scripting.bindings.AbstractBinding
|
||||
import me.rhunk.snapenhance.common.scripting.bindings.BindingsContext
|
||||
import me.rhunk.snapenhance.common.scripting.ktx.contextScope
|
||||
import me.rhunk.snapenhance.common.scripting.ktx.putFunction
|
||||
import me.rhunk.snapenhance.common.scripting.ktx.scriptable
|
||||
import me.rhunk.snapenhance.common.scripting.ktx.scriptableObject
|
||||
import me.rhunk.snapenhance.common.scripting.type.ModuleInfo
|
||||
import org.mozilla.javascript.Function
|
||||
@ -39,6 +40,7 @@ class JSModule(
|
||||
putConst("info", this, scriptableObject {
|
||||
putConst("name", this, moduleInfo.name)
|
||||
putConst("version", this, moduleInfo.version)
|
||||
putConst("displayName", this, moduleInfo.displayName)
|
||||
putConst("description", this, moduleInfo.description)
|
||||
putConst("author", this, moduleInfo.author)
|
||||
putConst("minSnapchatVersion", this, moduleInfo.minSnapchatVersion)
|
||||
@ -145,7 +147,16 @@ class JSModule(
|
||||
|
||||
moduleObject.putFunction("require") { args ->
|
||||
val bindingName = args?.get(0).toString()
|
||||
moduleBindings[bindingName]?.getObject()
|
||||
val (namespace, path) = bindingName.takeIf {
|
||||
it.startsWith("@") && it.contains("/")
|
||||
}?.let {
|
||||
it.substring(1).substringBefore("/") to it.substringAfter("/")
|
||||
} ?: (null to "")
|
||||
|
||||
when (namespace) {
|
||||
"modules" -> scriptRuntime.getModuleByName(path)?.moduleObject?.scriptable("module")?.scriptable("exports")
|
||||
else -> moduleBindings[bindingName]?.getObject()
|
||||
}
|
||||
}
|
||||
|
||||
evaluateString(moduleObject, content, moduleInfo.name, 1, null)
|
||||
|
@ -54,12 +54,17 @@ open class ScriptRuntime(
|
||||
}
|
||||
|
||||
return ModuleInfo(
|
||||
name = properties["name"] ?: throw Exception("Missing module name"),
|
||||
name = properties["name"]?.also {
|
||||
if (!it.matches(Regex("[a-z_]+"))) {
|
||||
throw Exception("Invalid module name : Only lowercase letters and underscores are allowed")
|
||||
}
|
||||
} ?: throw Exception("Missing module name"),
|
||||
version = properties["version"] ?: throw Exception("Missing module version"),
|
||||
displayName = properties["displayName"],
|
||||
description = properties["description"],
|
||||
author = properties["author"],
|
||||
minSnapchatVersion = properties["minSnapchatVersion"]?.toLong(),
|
||||
minSEVersion = properties["minSEVersion"]?.toLong(),
|
||||
minSnapchatVersion = properties["minSnapchatVersion"]?.toLongOrNull(),
|
||||
minSEVersion = properties["minSEVersion"]?.toLongOrNull(),
|
||||
grantedPermissions = properties["permissions"]?.split(",")?.map { it.trim() } ?: emptyList(),
|
||||
)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package me.rhunk.snapenhance.common.scripting.type
|
||||
data class ModuleInfo(
|
||||
val name: String,
|
||||
val version: String,
|
||||
val displayName: String? = null,
|
||||
val description: String? = null,
|
||||
val author: String? = null,
|
||||
val minSnapchatVersion: Long? = null,
|
||||
|
Reference in New Issue
Block a user