From f07047d1e89586a3bcaf36d6d2667e89e1a49d1e Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Apr 2020 19:38:19 +0900 Subject: AiScript関連 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/scripts/create-aiscript-env.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/client/scripts/create-aiscript-env.ts (limited to 'src/client/scripts/create-aiscript-env.ts') diff --git a/src/client/scripts/create-aiscript-env.ts b/src/client/scripts/create-aiscript-env.ts new file mode 100644 index 0000000000..75f402e13e --- /dev/null +++ b/src/client/scripts/create-aiscript-env.ts @@ -0,0 +1,28 @@ +import { utils, values } from '@syuilo/aiscript'; + +export function createAiScriptEnv(vm) { + return { + USER_ID: values.STR(vm.$store.state.i.id), + USER_USERNAME: values.STR(vm.$store.state.i.username), + 'Mk:dialog': values.FN_NATIVE(async ([title, text, type]) => { + await vm.$root.dialog({ + type: type ? type.value : 'info', + title: title.value, + text: text.value, + }); + }), + 'Mk:confirm': values.FN_NATIVE(async ([title, text]) => { + const confirm = await vm.$root.dialog({ + type: 'warning', + showCancelButton: true, + title: title.value, + text: text.value, + }); + return confirm.canceled ? values.FALSE : values.TRUE + }), + 'Mk:api': values.FN_NATIVE(async ([ep, param, token]) => { + const res = await vm.$root.api(ep.value, utils.valToJs(param), token || null); + return utils.jsToVal(res); + }), + }; +} -- cgit v1.2.3-freya