Skip to content

Commit

Permalink
Fix: AiScriptのreadlineの修正をPlay以外にも適用 (misskey-dev#12841)
Browse files Browse the repository at this point in the history
* add AiScriptReadline() in api.ts

* apply AiScriptReadline on flash.vue

* AiScriptReadline → aiScriptReadline

* Update flash.vue

* Update scratchpad.vue

* Update WidgetAiscript.vue

* Update WidgetAiscriptApp.vue

* Update WidgetButton.vue

* Update plugin.ts
  • Loading branch information
FineArchs authored Jan 4, 2024
1 parent da154c8 commit f8d5a46
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 80 deletions.
12 changes: 2 additions & 10 deletions packages/frontend/src/pages/flash/flash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkAsUi from '@/components/MkAsUi.vue';
import { AsUiComponent, AsUiRoot, registerAsUiLib } from '@/scripts/aiscript/ui.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import MkFolder from '@/components/MkFolder.vue';
import MkCode from '@/components/MkCode.vue';
import { defaultStore } from '@/store.js';
Expand Down Expand Up @@ -162,15 +162,7 @@ async function run() {
THIS_ID: values.STR(flash.value.id),
THIS_URL: values.STR(`${url}/play/${flash.value.id}`),
}, {
in: (q) => {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ result: a }) => {
ok(a ?? '');
});
});
},
in: aiScriptReadline,
out: (value) => {
// nop
},
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/pages/scratchpad.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { Interpreter, Parser, utils } from '@syuilo/aiscript';
import MkContainer from '@/components/MkContainer.vue';
import MkButton from '@/components/MkButton.vue';
import MkCodeEditor from '@/components/MkCodeEditor.vue';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import * as os from '@/os.js';
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
Expand Down Expand Up @@ -86,19 +86,7 @@ async function run() {
root.value = _root.value;
}),
}), {
in: (q) => {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
in: aiScriptReadline,
out: (value) => {
if (value.type === 'str' && value.value.toLowerCase().replace(',', '').includes('hello world')) {
claimAchievement('outputHelloWorldOnScratchpad');
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { Interpreter, Parser, utils, values } from '@syuilo/aiscript';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { inputText } from '@/os.js';
import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions, pageViewInterruptors } from '@/store.js';

Expand All @@ -19,19 +19,7 @@ export async function install(plugin: Plugin): Promise<void> {
plugin: plugin,
storageKey: 'plugins:' + plugin.id,
}), {
in: (q): Promise<string> => {
return new Promise(ok => {
inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
in: aiScriptReadline,
out: (value): void => {
console.log(value);
},
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/scripts/aiscript/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { customEmojis } from '@/custom-emojis.js';
import { url, lang } from '@/config.js';
import { nyaize } from '@/scripts/nyaize.js';

export function aiScriptReadline(q: string): Promise<string> {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ result: a }) => {
ok(a ?? '');
});
});
}

export function createAiScriptEnv(opts) {
return {
USER_ID: $i ? values.STR($i.id) : values.NULL,
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/widgets/WidgetAiscript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, Wid
import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js';
import MkContainer from '@/components/MkContainer.vue';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';

Expand Down Expand Up @@ -69,19 +69,7 @@ const run = async () => {
storageKey: 'widget',
token: $i?.token,
}), {
in: (q) => {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
in: aiScriptReadline,
out: (value) => {
logs.value.push({
id: Math.random().toString(),
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/widgets/WidgetAiscriptApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Interpreter, Parser } from '@syuilo/aiscript';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js';
import MkAsUi from '@/components/MkAsUi.vue';
import MkContainer from '@/components/MkContainer.vue';
Expand Down Expand Up @@ -64,19 +64,7 @@ async function run() {
root.value = _root.value;
}),
}, {
in: (q) => {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
in: aiScriptReadline,
out: (value) => {
// nop
},
Expand Down
16 changes: 2 additions & 14 deletions packages/frontend/src/widgets/WidgetButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Interpreter, Parser } from '@syuilo/aiscript';
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
import { GetFormResultType } from '@/scripts/form.js';
import * as os from '@/os.js';
import { createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { $i } from '@/account.js';
import MkButton from '@/components/MkButton.vue';

Expand Down Expand Up @@ -56,19 +56,7 @@ const run = async () => {
storageKey: 'widget',
token: $i?.token,
}), {
in: (q) => {
return new Promise(ok => {
os.inputText({
title: q,
}).then(({ canceled, result: a }) => {
if (canceled) {
ok('');
} else {
ok(a);
}
});
});
},
in: aiScriptReadline,
out: (value) => {
// nop
},
Expand Down

0 comments on commit f8d5a46

Please sign in to comment.