feat: add setArg to plugin v2 (#729)
# PR Checklist - [ ] Have you checked if it works normally in all models? *Ignore this if it doesn't use models.* - [ ] Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions? - [ ] Have you added type definitions? # Description It would be nice if plugins could change their settings directly in the db. This PR introduces an API that makes this simple.
This commit is contained in:
@@ -230,6 +230,15 @@ export async function loadV2Plugin(plugins:RisuPlugin[]){
|
||||
},
|
||||
onUnload: (func:() => void|Promise<void>) => {
|
||||
pluginV2.unload.add(func)
|
||||
},
|
||||
setArg: (arg: string, value: string | number) => {
|
||||
const db = getDatabase();
|
||||
const [name, realArg] = arg.split("::");
|
||||
for (const plug of db.plugins) {
|
||||
if (plug.name === name) {
|
||||
plug.realArg[realArg] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,6 +258,7 @@ export async function loadV2Plugin(plugins:RisuPlugin[]){
|
||||
const addRisuReplacer = globalThis.__pluginApis__.addRisuReplacer
|
||||
const removeRisuReplacer = globalThis.__pluginApis__.removeRisuReplacer
|
||||
const onUnload = globalThis.__pluginApis__.onUnload
|
||||
const setArg = globalThis.__pluginApis__.setArg
|
||||
|
||||
${data}
|
||||
})();`
|
||||
|
||||
Reference in New Issue
Block a user