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