wip
This commit is contained in:
parent
8b2e862de0
commit
d40a0392cd
|
@ -34,7 +34,7 @@ export default defineComponent({
|
|||
},
|
||||
|
||||
created() {
|
||||
this.hpml = new Hpml(this, this.page, {
|
||||
this.hpml = new Hpml(this.page, {
|
||||
randomSeed: Math.random(),
|
||||
visitor: this.$store.state.i,
|
||||
url: url,
|
||||
|
|
|
@ -21,7 +21,7 @@ import { applyTheme, lightTheme } from '@/scripts/theme';
|
|||
import { isDeviceDarkmode } from '@/scripts/is-device-darkmode';
|
||||
import { createPluginEnv } from '@/scripts/aiscript/api';
|
||||
import { i18n, lang } from './i18n';
|
||||
import { stream, sound, isMobile } from '@/os';
|
||||
import { stream, sound, isMobile, dialog } from '@/os';
|
||||
|
||||
console.info(`Misskey v${version}`);
|
||||
|
||||
|
@ -131,6 +131,7 @@ app.use(router);
|
|||
app.use(i18n);
|
||||
app.use(VueHotkey);
|
||||
app.use(VAnimateCss);
|
||||
// eslint-disable-next-line vue/component-definition-name-casing
|
||||
app.component('fa', FontAwesomeIcon);
|
||||
|
||||
widgets(app);
|
||||
|
@ -204,13 +205,13 @@ stream.on('emojiAdded', data => {
|
|||
for (const plugin of store.state.deviceUser.plugins.filter(p => p.active)) {
|
||||
console.info('Plugin installed:', plugin.name, 'v' + plugin.version);
|
||||
|
||||
const aiscript = new AiScript(createPluginEnv(app, {
|
||||
const aiscript = new AiScript(createPluginEnv({
|
||||
plugin: plugin,
|
||||
storageKey: 'plugins:' + plugin.id
|
||||
}), {
|
||||
in: (q) => {
|
||||
return new Promise(ok => {
|
||||
app.dialog({
|
||||
dialog({
|
||||
title: q,
|
||||
input: {}
|
||||
}).then(({ canceled, result: a }) => {
|
||||
|
|
|
@ -73,7 +73,7 @@ export default defineComponent({
|
|||
methods: {
|
||||
async run() {
|
||||
this.logs = [];
|
||||
const aiscript = new AiScript(createAiScriptEnv(this, {
|
||||
const aiscript = new AiScript(createAiScriptEnv({
|
||||
storageKey: 'scratchpad'
|
||||
}), {
|
||||
in: (q) => {
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
import { utils, values } from '@syuilo/aiscript';
|
||||
import { jsToVal } from '@syuilo/aiscript/built/interpreter/util';
|
||||
import { store } from '@/store';
|
||||
import * as os from '@/os';
|
||||
|
||||
// TODO: vm引数は消せる(各種操作がstoreに移動し、かつstoreが複数ファイルで共有されるようになったため)
|
||||
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.os.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.os.dialog({
|
||||
const confirm = await os.dialog({
|
||||
type: type ? type.value : 'question',
|
||||
showCancelButton: true,
|
||||
title: title.value,
|
||||
|
@ -28,7 +29,7 @@ export function createAiScriptEnv(vm, opts) {
|
|||
if (token) utils.assertString(token);
|
||||
apiRequests++;
|
||||
if (apiRequests > 16) return values.NULL;
|
||||
const res = await vm.os.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]) => {
|
||||
|
@ -43,40 +44,39 @@ export function createAiScriptEnv(vm, opts) {
|
|||
};
|
||||
}
|
||||
|
||||
// TODO: vm引数は消せる(各種操作がstoreに移動し、かつstoreが複数ファイルで共有されるようになったため)
|
||||
export function createPluginEnv(vm, opts) {
|
||||
export function createPluginEnv(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 }),
|
||||
...createAiScriptEnv({ ...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 });
|
||||
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 });
|
||||
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 });
|
||||
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 });
|
||||
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 });
|
||||
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 });
|
||||
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 });
|
||||
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 });
|
||||
store.commit('registerNotePostInterruptor', { pluginId: opts.plugin.id, handler });
|
||||
}),
|
||||
'Plugin:open_url': values.FN_NATIVE(([url]) => {
|
||||
window.open(url.value, '_blank');
|
||||
|
|
|
@ -6,6 +6,7 @@ import { AiScript, utils, values } from '@syuilo/aiscript';
|
|||
import { createAiScriptEnv } from '../aiscript/api';
|
||||
import { collectPageVars } from '../collect-page-vars';
|
||||
import { initLib } from './lib';
|
||||
import * as os from '@/os';
|
||||
|
||||
type Fn = {
|
||||
slots: string[];
|
||||
|
@ -30,19 +31,19 @@ export class Hpml {
|
|||
enableAiScript: boolean;
|
||||
};
|
||||
|
||||
constructor(vm: any, page: Hpml['page'], opts: Hpml['opts']) {
|
||||
constructor(page: Hpml['page'], opts: Hpml['opts']) {
|
||||
this.page = page;
|
||||
this.variables = this.page.variables;
|
||||
this.pageVars = collectPageVars(this.page.content);
|
||||
this.opts = opts;
|
||||
|
||||
if (this.opts.enableAiScript) {
|
||||
this.aiscript = new AiScript({ ...createAiScriptEnv(vm, {
|
||||
this.aiscript = new AiScript({ ...createAiScriptEnv({
|
||||
storageKey: 'pages:' + this.page.id
|
||||
}), ...initLib(this)}, {
|
||||
in: (q) => {
|
||||
return new Promise(ok => {
|
||||
vm.os.dialog({
|
||||
os.dialog({
|
||||
title: q,
|
||||
input: {}
|
||||
}).then(({ canceled, result: a }) => {
|
||||
|
|
Loading…
Reference in New Issue