mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 19:35:12 +00:00
MisskeyPagesにイベント送信ボタンを追加
This commit is contained in:
parent
5ae6b0058f
commit
64397708fd
5 changed files with 72 additions and 3 deletions
|
@ -2030,6 +2030,10 @@ pages:
|
||||||
_dialog:
|
_dialog:
|
||||||
content: "内容"
|
content: "内容"
|
||||||
resetRandom: "乱数をリセット"
|
resetRandom: "乱数をリセット"
|
||||||
|
pushEvent: "イベントを送信させる"
|
||||||
|
_pushEvent:
|
||||||
|
event: "イベント名"
|
||||||
|
message: "押したときに表示するメッセージ"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
categories:
|
categories:
|
||||||
|
|
|
@ -8,8 +8,15 @@
|
||||||
<template #label>{{ $t('blocks._button.action') }}</template>
|
<template #label>{{ $t('blocks._button.action') }}</template>
|
||||||
<option value="dialog">{{ $t('blocks._button._action.dialog') }}</option>
|
<option value="dialog">{{ $t('blocks._button._action.dialog') }}</option>
|
||||||
<option value="resetRandom">{{ $t('blocks._button._action.resetRandom') }}</option>
|
<option value="resetRandom">{{ $t('blocks._button._action.resetRandom') }}</option>
|
||||||
|
<option value="pushEvent">{{ $t('blocks._button._action.pushEvent') }}</option>
|
||||||
</ui-select>
|
</ui-select>
|
||||||
<ui-input v-if="value.action === 'dialog'" v-model="value.content"><span>{{ $t('blocks._button._action._dialog.content') }}</span></ui-input>
|
<template v-if="value.action === 'dialog'">
|
||||||
|
<ui-input v-model="value.content"><span>{{ $t('blocks._button._action._dialog.content') }}</span></ui-input>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="value.action === 'pushEvent'">
|
||||||
|
<ui-input v-model="value.event"><span>{{ $t('blocks._button._action._pushEvent.event') }}</span></ui-input>
|
||||||
|
<ui-input v-model="value.message"><span>{{ $t('blocks._button._action._pushEvent.message') }}</span></ui-input>
|
||||||
|
</template>
|
||||||
</section>
|
</section>
|
||||||
</x-container>
|
</x-container>
|
||||||
</template>
|
</template>
|
||||||
|
@ -43,6 +50,8 @@ export default Vue.extend({
|
||||||
if (this.value.text == null) Vue.set(this.value, 'text', '');
|
if (this.value.text == null) Vue.set(this.value, 'text', '');
|
||||||
if (this.value.action == null) Vue.set(this.value, 'action', 'dialog');
|
if (this.value.action == null) Vue.set(this.value, 'action', 'dialog');
|
||||||
if (this.value.content == null) Vue.set(this.value, 'content', null);
|
if (this.value.content == null) Vue.set(this.value, 'content', null);
|
||||||
|
if (this.value.event == null) Vue.set(this.value, 'event', null);
|
||||||
|
if (this.value.message == null) Vue.set(this.value, 'message', null);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -27,6 +27,16 @@ export default Vue.extend({
|
||||||
} else if (this.value.action === 'resetRandom') {
|
} else if (this.value.action === 'resetRandom') {
|
||||||
this.script.aiScript.updateRandomSeed(Math.random());
|
this.script.aiScript.updateRandomSeed(Math.random());
|
||||||
this.script.eval();
|
this.script.eval();
|
||||||
|
} else if (this.value.action === 'pushEvent') {
|
||||||
|
this.$root.api('page-push', {
|
||||||
|
pageId: this.script.page.id,
|
||||||
|
event: this.value.event
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$root.dialog({
|
||||||
|
type: 'success',
|
||||||
|
text: this.script.interpolate(this.value.message)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,10 @@ class Script {
|
||||||
public aiScript: ASEvaluator;
|
public aiScript: ASEvaluator;
|
||||||
private onError: any;
|
private onError: any;
|
||||||
public vars: Record<string, any>;
|
public vars: Record<string, any>;
|
||||||
|
public page: Record<string, any>;
|
||||||
|
|
||||||
constructor(aiScript, onError) {
|
constructor(page, aiScript, onError) {
|
||||||
|
this.page = page;
|
||||||
this.aiScript = aiScript;
|
this.aiScript = aiScript;
|
||||||
this.onError = onError;
|
this.onError = onError;
|
||||||
this.eval();
|
this.eval();
|
||||||
|
@ -113,7 +115,7 @@ export default Vue.extend({
|
||||||
icon: faStickyNote
|
icon: faStickyNote
|
||||||
});
|
});
|
||||||
const pageVars = this.getPageVars();
|
const pageVars = this.getPageVars();
|
||||||
this.script = new Script(new ASEvaluator(this.page.variables, pageVars, {
|
this.script = new Script(this.page, new ASEvaluator(this.page.variables, pageVars, {
|
||||||
randomSeed: Math.random(),
|
randomSeed: Math.random(),
|
||||||
user: page.user,
|
user: page.user,
|
||||||
visitor: this.$store.state.i,
|
visitor: this.$store.state.i,
|
||||||
|
|
44
src/server/api/endpoints/page-push.ts
Normal file
44
src/server/api/endpoints/page-push.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import $ from 'cafy';
|
||||||
|
import define from '../define';
|
||||||
|
import { ID } from '../../../misc/cafy-id';
|
||||||
|
import { publishMainStream } from '../../../services/stream';
|
||||||
|
import { Users, Pages } from '../../../models';
|
||||||
|
import { ApiError } from '../error';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
requireCredential: true,
|
||||||
|
secure: true,
|
||||||
|
|
||||||
|
params: {
|
||||||
|
pageId: {
|
||||||
|
validator: $.type(ID)
|
||||||
|
},
|
||||||
|
|
||||||
|
event: {
|
||||||
|
validator: $.str
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchPage: {
|
||||||
|
message: 'No such page.',
|
||||||
|
code: 'NO_SUCH_PAGE',
|
||||||
|
id: '4a13ad31-6729-46b4-b9af-e86b265c2e74'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, async (ps, user) => {
|
||||||
|
const page = await Pages.findOne(ps.pageId);
|
||||||
|
if (page == null) {
|
||||||
|
throw new ApiError(meta.errors.noSuchPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
publishMainStream(user.id, 'pageEvent', {
|
||||||
|
pageId: ps.pageId,
|
||||||
|
event: ps.event,
|
||||||
|
user: await Users.pack(user, page.userId, {
|
||||||
|
detail: true
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue