diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 082709153..848bf4bb4 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -481,6 +481,8 @@ descendingOrder: "降順" scratchpad: "スクラッチパッド" scratchpadDescription: "スクラッチパッドは、AiScriptの実験環境を提供します。Misskeyと対話するコードの記述、実行、結果の確認ができます。" output: "出力" +script: "スクリプト" +disablePagesScript: "Pagesのスクリプトを無効にする" _theme: explore: "テーマを探す" @@ -813,6 +815,9 @@ _pages: message: "押したときに表示するメッセージ" variable: "送信する変数" no-variable: "なし" + callAiScript: "AiScript呼び出し" + _callAiScript: + functionName: "関数名" radioButton: "選択肢" _radioButton: @@ -975,6 +980,7 @@ _pages: _splitStrByLine: arg1: "テキスト" ref: "変数" + aiScriptVar: "AiScript変数" fn: "関数" _fn: slots: "スロット" diff --git a/migration/1586708940386-pageAiScript.ts b/migration/1586708940386-pageAiScript.ts new file mode 100644 index 000000000..fdd6e76b9 --- /dev/null +++ b/migration/1586708940386-pageAiScript.ts @@ -0,0 +1,14 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class pageAiScript1586708940386 implements MigrationInterface { + name = 'pageAiScript1586708940386' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "page" ADD "script" character varying(16384) NOT NULL DEFAULT ''`, undefined); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "page" DROP COLUMN "script"`, undefined); + } + +} diff --git a/package.json b/package.json index 98ca48014..8fa0129cb 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@koa/cors": "3.0.0", "@koa/multer": "2.0.2", "@koa/router": "8.0.8", - "@syuilo/aiscript": "0.1.2", + "@syuilo/aiscript": "0.1.4", "@types/bcryptjs": "2.4.2", "@types/bull": "3.12.1", "@types/cbor": "5.0.0", diff --git a/src/client/components/page/page.button.vue b/src/client/components/page/page.button.vue index eeb56d5ec..148fdc8e9 100644 --- a/src/client/components/page/page.button.vue +++ b/src/client/components/page/page.button.vue @@ -28,7 +28,7 @@ export default Vue.extend({ text: this.script.interpolate(this.value.content) }); } else if (this.value.action === 'resetRandom') { - this.script.aiScript.updateRandomSeed(Math.random()); + this.script.aoiScript.updateRandomSeed(Math.random()); this.script.eval(); } else if (this.value.action === 'pushEvent') { this.$root.api('page-push', { @@ -43,6 +43,8 @@ export default Vue.extend({ type: 'success', text: this.script.interpolate(this.value.message) }); + } else if (this.value.action === 'callAiScript') { + this.script.callAiScript(this.value.fn); } } } diff --git a/src/client/components/page/page.counter.vue b/src/client/components/page/page.counter.vue index 781a1bd54..f7557c003 100644 --- a/src/client/components/page/page.counter.vue +++ b/src/client/components/page/page.counter.vue @@ -27,7 +27,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } }, diff --git a/src/client/components/page/page.number-input.vue b/src/client/components/page/page.number-input.vue index 9ee2730fa..9ea1ebb64 100644 --- a/src/client/components/page/page.number-input.vue +++ b/src/client/components/page/page.number-input.vue @@ -27,7 +27,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } } diff --git a/src/client/components/page/page.radio-button.vue b/src/client/components/page/page.radio-button.vue index fda0a0392..dd5cbcbde 100644 --- a/src/client/components/page/page.radio-button.vue +++ b/src/client/components/page/page.radio-button.vue @@ -28,7 +28,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } } diff --git a/src/client/components/page/page.switch.vue b/src/client/components/page/page.switch.vue index 416c36e9a..79d871df8 100644 --- a/src/client/components/page/page.switch.vue +++ b/src/client/components/page/page.switch.vue @@ -27,7 +27,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } } diff --git a/src/client/components/page/page.text-input.vue b/src/client/components/page/page.text-input.vue index fcc181d67..843d541de 100644 --- a/src/client/components/page/page.text-input.vue +++ b/src/client/components/page/page.text-input.vue @@ -27,7 +27,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } } diff --git a/src/client/components/page/page.textarea-input.vue b/src/client/components/page/page.textarea-input.vue index d1cf9813c..5ba22e7c5 100644 --- a/src/client/components/page/page.textarea-input.vue +++ b/src/client/components/page/page.textarea-input.vue @@ -27,7 +27,7 @@ export default Vue.extend({ }, watch: { v() { - this.script.aiScript.updatePageVar(this.value.name, this.v); + this.script.aoiScript.updatePageVar(this.value.name, this.v); this.script.eval(); } } diff --git a/src/client/components/page/page.vue b/src/client/components/page/page.vue index 977d384b3..0f1769fc8 100644 --- a/src/client/components/page/page.vue +++ b/src/client/components/page/page.vue @@ -6,30 +6,57 @@ diff --git a/src/client/pages/page-editor/els/page-editor.el.if.vue b/src/client/pages/page-editor/els/page-editor.el.if.vue index 5e531a7ab..0c40e41d8 100644 --- a/src/client/pages/page-editor/els/page-editor.el.if.vue +++ b/src/client/pages/page-editor/els/page-editor.el.if.vue @@ -10,16 +10,16 @@
- + - + - + - +
@@ -45,7 +45,7 @@ export default Vue.extend({ value: { required: true }, - aiScript: { + aoiScript: { required: true, }, }, diff --git a/src/client/pages/page-editor/els/page-editor.el.section.vue b/src/client/pages/page-editor/els/page-editor.el.section.vue index 8de796e6d..97f063a28 100644 --- a/src/client/pages/page-editor/els/page-editor.el.section.vue +++ b/src/client/pages/page-editor/els/page-editor.el.section.vue @@ -11,7 +11,7 @@
- +
@@ -37,7 +37,7 @@ export default Vue.extend({ value: { required: true }, - aiScript: { + aoiScript: { required: true, }, }, diff --git a/src/client/pages/page-editor/els/page-editor.el.text.vue b/src/client/pages/page-editor/els/page-editor.el.text.vue index 00b6cd8a3..c6722236e 100644 --- a/src/client/pages/page-editor/els/page-editor.el.text.vue +++ b/src/client/pages/page-editor/els/page-editor.el.text.vue @@ -2,7 +2,7 @@ -
+
@@ -40,7 +40,7 @@ export default Vue.extend({ diff --git a/src/client/pages/page-editor/els/page-editor.el.textarea.vue b/src/client/pages/page-editor/els/page-editor.el.textarea.vue index fd7584968..d31da5dfa 100644 --- a/src/client/pages/page-editor/els/page-editor.el.textarea.vue +++ b/src/client/pages/page-editor/els/page-editor.el.textarea.vue @@ -55,6 +55,7 @@ export default Vue.extend({ background: transparent; color: var(--fg); font-size: 14px; + box-sizing: border-box; } } diff --git a/src/client/pages/page-editor/page-editor.blocks.vue b/src/client/pages/page-editor/page-editor.blocks.vue index 4d7293231..bfc75cada 100644 --- a/src/client/pages/page-editor/page-editor.blocks.vue +++ b/src/client/pages/page-editor/page-editor.blocks.vue @@ -1,6 +1,6 @@ @@ -31,7 +31,7 @@ export default Vue.extend({ type: Array, required: true }, - aiScript: { + aoiScript: { required: true, }, }, diff --git a/src/client/pages/page-editor/page-editor.script-block.vue b/src/client/pages/page-editor/page-editor.script-block.vue index 4f30b7136..7e3bbf0c8 100644 --- a/src/client/pages/page-editor/page-editor.script-block.vue +++ b/src/client/pages/page-editor/page-editor.script-block.vue @@ -2,7 +2,7 @@ @@ -24,30 +24,33 @@
+
+ +
{{ $t('_pages.script.blocks._fn.slots') }} - +
- +
- +
@@ -85,7 +88,7 @@ export default Vue.extend({ required: false, default: false }, - aiScript: { + aoiScript: { required: true, }, name: { @@ -153,7 +156,7 @@ export default Vue.extend({ if (this.value.type && this.value.type.startsWith('fn:')) { const fnName = this.value.type.split(':')[1]; - const fn = this.aiScript.getVarByName(fnName); + const fn = this.aoiScript.getVarByName(fnName); const empties = []; for (let i = 0; i < fn.value.slots.length; i++) { @@ -199,9 +202,9 @@ export default Vue.extend({ deep: true }); - this.$watch('aiScript.variables', () => { + this.$watch('aoiScript.variables', () => { if (this.type != null && this.value) { - this.error = this.aiScript.typeCheck(this.value); + this.error = this.aoiScript.typeCheck(this.value); } }, { deep: true @@ -223,7 +226,7 @@ export default Vue.extend({ }, _getExpectedType(slot: number) { - return this.aiScript.getExpectedType(this.value, slot); + return this.aoiScript.getExpectedType(this.value, slot); } } }); @@ -258,6 +261,7 @@ export default Vue.extend({ font-size: 16px; background: transparent; color: var(--fg); + box-sizing: border-box; } > textarea { diff --git a/src/client/pages/page-editor/page-editor.vue b/src/client/pages/page-editor/page-editor.vue index b3350e0c6..6177663b7 100644 --- a/src/client/pages/page-editor/page-editor.vue +++ b/src/client/pages/page-editor/page-editor.vue @@ -46,7 +46,7 @@ - + @@ -62,7 +62,7 @@ @input="v => updateVariable(v)" @remove="() => removeVariable(variable)" :key="variable.name" - :ai-script="aiScript" + :aoi-script="aoiScript" :name="variable.name" :title="variable.name" :draggable="true" @@ -73,11 +73,10 @@ - - -
- {{ $t('_pages.content') }} - {{ $t('_pages.variables') }} + + +
+
@@ -86,6 +85,9 @@