summaryrefslogtreecommitdiff
path: root/src/client/scripts/aiscript/api.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/scripts/aiscript/api.ts')
-rw-r--r--src/client/scripts/aiscript/api.ts60
1 files changed, 9 insertions, 51 deletions
diff --git a/src/client/scripts/aiscript/api.ts b/src/client/scripts/aiscript/api.ts
index 7e3a668871..f5618bd14c 100644
--- a/src/client/scripts/aiscript/api.ts
+++ b/src/client/scripts/aiscript/api.ts
@@ -1,22 +1,22 @@
import { utils, values } from '@syuilo/aiscript';
-import { jsToVal } from '@syuilo/aiscript/built/interpreter/util';
+import { store } from '@/store';
+import * as os from '@/os';
-// TODO: vue3に移行した折にはvmを渡す必要は無くなるはず
-export function createAiScriptEnv(vm, opts) {
+export function createAiScriptEnv(opts) {
let apiRequests = 0;
return {
- USER_ID: vm.$store.getters.isSignedIn ? values.STR(vm.$store.state.i.id) : values.NULL,
- USER_NAME: vm.$store.getters.isSignedIn ? values.STR(vm.$store.state.i.name) : values.NULL,
- USER_USERNAME: vm.$store.getters.isSignedIn ? values.STR(vm.$store.state.i.username) : values.NULL,
+ USER_ID: store.getters.isSignedIn ? values.STR(store.state.i.id) : values.NULL,
+ USER_NAME: store.getters.isSignedIn ? values.STR(store.state.i.name) : values.NULL,
+ USER_USERNAME: store.getters.isSignedIn ? values.STR(store.state.i.username) : values.NULL,
'Mk:dialog': values.FN_NATIVE(async ([title, text, type]) => {
- await vm.$root.dialog({
+ await os.dialog({
type: type ? type.value : 'info',
title: title.value,
text: text.value,
});
}),
'Mk:confirm': values.FN_NATIVE(async ([title, text, type]) => {
- const confirm = await vm.$root.dialog({
+ const confirm = await os.dialog({
type: type ? type.value : 'question',
showCancelButton: true,
title: title.value,
@@ -28,7 +28,7 @@ export function createAiScriptEnv(vm, opts) {
if (token) utils.assertString(token);
apiRequests++;
if (apiRequests > 16) return values.NULL;
- const res = await vm.$root.api(ep.value, utils.valToJs(param), token ? token.value : (opts.token || null));
+ const res = await os.api(ep.value, utils.valToJs(param), token ? token.value : (opts.token || null));
return utils.jsToVal(res);
}),
'Mk:save': values.FN_NATIVE(([key, value]) => {
@@ -42,45 +42,3 @@ export function createAiScriptEnv(vm, opts) {
}),
};
}
-
-// TODO: vue3に移行した折にはvmを渡す必要は無くなるはず
-export function createPluginEnv(vm, opts) {
- const config = new Map();
- for (const [k, v] of Object.entries(opts.plugin.config || {})) {
- config.set(k, jsToVal(opts.plugin.configData[k] || v.default));
- }
-
- return {
- ...createAiScriptEnv(vm, { ...opts, token: opts.plugin.token }),
- //#region Deprecated
- 'Mk:register_post_form_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerPostFormAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- 'Mk:register_user_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerUserAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- 'Mk:register_note_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- //#endregion
- 'Plugin:register_post_form_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerPostFormAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- 'Plugin:register_user_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerUserAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- 'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => {
- vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler });
- }),
- 'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => {
- vm.$store.commit('registerNoteViewInterruptor', { pluginId: opts.plugin.id, handler });
- }),
- 'Plugin:register_note_post_interruptor': values.FN_NATIVE(([handler]) => {
- vm.$store.commit('registerNotePostInterruptor', { pluginId: opts.plugin.id, handler });
- }),
- 'Plugin:open_url': values.FN_NATIVE(([url]) => {
- window.open(url.value, '_blank');
- }),
- 'Plugin:config': values.OBJ(config),
- };
-}