Skip to content

Commit

Permalink
Nostr/0.4対応
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolat committed Jun 13, 2024
1 parent d740d4e commit a2db0ce
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Nostrリレーから投稿を取得して表示するWebアプリです。
1. 下記のサイトから最新版のSSPをダウンロードしssp.exeを起動します。
[独立伺か研究施設 ばぐとら研究所](http://ssp.shillest.net/)
2. [アンゴルモア](https://nikolat.github.io/angolmois/)を開きます。
3. しばらくすると投稿が表示され、同時に起動しているゴーストが投稿内容を喋り出します。
3. 「SSTPを有効化する」にチェックを入れると投稿が表示され、同時に起動しているゴーストが投稿内容を喋り出します。

### ゴースト側のカスタマイズ(伺か経験者向け)
angolmoisは[SSTP](http://ssp.shillest.net/ukadoc/manual/spec_sstp.html) over HTTPによりSSTPサーバーと通信を行います。
Expand All @@ -24,23 +24,27 @@ Sender: angolmois
Event: OnNostr
Option: nobreak
Script: \0おはノスー!\e
Reference0: Nostr/0.1
Reference1: おはノスー!
Reference2: nosuta
Reference3: のす太
Reference4: https://sample.com/avatar.png
Reference0: Nostr/0.4
Reference1: 1
Reference2: おはノスー!
Reference3: nosuta
Reference4: のす太
Reference5: https://sample.com/avatar.png
Reference6: note1...
Reference7: npub1...
```
ゴーストはOnNostrイベントに対して独自に[SakuraScript](http://ssp.shillest.net/ukadoc/manual/list_sakura_script.html)を応答することで通知内容をカスタマイズして表現することができます。
ゴーストは[OnNostrイベント](https://ssp.shillest.net/ukadoc/manual/list_shiori_event_ex.html#OnNostr)に対して独自に[SakuraScript](http://ssp.shillest.net/ukadoc/manual/list_sakura_script.html)を応答することで通知内容をカスタマイズして表現することができます。
以下に[YAYA](https://github.com/YAYA-shiori/yaya-shiori/wiki)による応答実装例を示します。
```
ExternalEvent.OnNostr
{
_protocol_version = reference[0]
if _protocol_version != 'Nostr/0.1'
_kind = reference[1]
if _protocol_version != 'Nostr/0.4' || _kind != 1
return
_note = reference[1]
_name = reference[2]
_display_name = reference[3]
_note = reference[2]
_name = reference[3]
_display_name = reference[4]
"\C\0\_q\f[bold,true]%(SHIORI3FW.EscapeAllTags(_display_name))\f[bold,default] /
@%(SHIORI3FW.EscapeAllTags(_name))\n/
%(SHIORI3FW.EscapeDangerousTags(_note))/
Expand Down
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

43 changes: 35 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,29 @@ declare global {
}

//DirectSSTPを送信する関数
async function sendSSTP(note: string, ifGhost: string, name?: string, display_name?: string, picture?: string) {
async function sendSSTP(content: string, ifGhost: string, name?: string, display_name?: string, picture?: string, note?: string, npub?: string) {
if (!(<HTMLInputElement>document.getElementById('sstp-enable')).checked) {
return;
}
const index = (<HTMLSelectElement>document.getElementById('sstp-target')).selectedIndex;
const hwnd = hwnds[index];
const script = '\\0' + note.replace(/\\/g, '\\\\').replace(/\n/g, '\\n') + '\\e';
if (name) {
const res: string = await SSTPSend([hwnd, script, ifGhost, note.replace(/\n/g, '\\n'), name, display_name, picture]);
const script = '\\0' + content.replace(/\\/g, '\\\\').replace(/\n/g, '\\n') + '\\e';
if (!ifGhost) {
const res: string = await SSTPSend([
hwnd,
script,
ifGhost,
1,
content.replace(/\n/g, '\\n'),
name,
display_name,
picture,
note,
npub,
]);
}
else {
const res: string = await SSTPSend([hwnd, note.replace(/\n/g, '\\n'), ifGhost]);
const res: string = await SSTPSend([hwnd, content.replace(/\n/g, '\\n'), ifGhost]);
}
}

Expand All @@ -322,7 +333,7 @@ declare global {
mes.push(`IfGhost: ${ifGhost}`);
}
mes.push(`Script: ${script}`);
mes.push(`Reference0: ${(ifGhost ? 'Nostr-Bottle/0.1' : 'Nostr/0.1')}`);
mes.push(`Reference0: ${(ifGhost ? 'Nostr-Bottle/0.1' : 'Nostr/0.4')}`);
for (let i = 3; i < data.length; i++) {
mes.push(`Reference${(i - 2)}: ${data[i]}`);
}
Expand Down Expand Up @@ -561,7 +572,15 @@ declare global {
const SSTPButton = document.createElement('button');
SSTPButton.textContent = 'Send SSTP';
SSTPButton.addEventListener('click', function(ev: MouseEvent) {
sendSSTP(event.content, '', profile.name ? profile.name : '', profile.display_name ? profile.display_name : '', profile.picture ? profile.picture : '');
sendSSTP(
event.content,
'',
profile.name ?? '',
profile.display_name ?? '',
profile.picture ?? '',
nip19.noteEncode(event.id),
nip19.npubEncode(event.pubkey),
);
});
dt.appendChild(SSTPButton);
//Change ID Button
Expand Down Expand Up @@ -627,7 +646,15 @@ declare global {
}
//ゴーストにDirectSSTPを送信
if ((<HTMLInputElement>document.getElementById(tabID)).checked && isNewest) {
sendSSTP(event.content, '', profile.name ? profile.name : '', profile.display_name ? profile.display_name : '', profile.picture ? profile.picture : '');
sendSSTP(
event.content,
'',
profile.name ?? '',
profile.display_name ?? '',
profile.picture ?? '',
nip19.noteEncode(event.id),
nip19.npubEncode(event.pubkey),
);
}
};
const oneose = () => {
Expand Down

0 comments on commit a2db0ce

Please sign in to comment.