From dc721bcaa8c5d5a56cbb032edaa3a3fb2ff35e03 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 28 Mar 2023 18:52:53 -0500 Subject: [PATCH] Return proper NIP-20 responses --- src/pipeline.test.ts | 4 ++-- src/policies/hellthread-policy.ts | 2 +- src/policies/keyword-policy.ts | 2 +- src/policies/pubkey-ban-policy.ts | 2 +- src/policies/rate-limit-policy.ts | 2 +- src/policies/read-only-policy.ts | 2 +- src/policies/regex-policy.ts | 2 +- src/policies/whitelist-policy.ts | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pipeline.test.ts b/src/pipeline.test.ts index f046ef2..9d5ba68 100644 --- a/src/pipeline.test.ts +++ b/src/pipeline.test.ts @@ -14,7 +14,7 @@ Deno.test('passes events through multiple policies', async () => { ]); assertEquals(result.action, 'reject'); - assertEquals(result.msg, 'The relay is read-only.'); + assertEquals(result.msg, 'blocked: the relay is read-only'); }); Deno.test('short-circuits on the first reject', async () => { @@ -26,7 +26,7 @@ Deno.test('short-circuits on the first reject', async () => { ]); assertEquals(result.action, 'reject'); - assertEquals(result.msg, 'The relay is read-only.'); + assertEquals(result.msg, 'blocked: the relay is read-only'); }); Deno.test('accepts when all policies accept', async () => { diff --git a/src/policies/hellthread-policy.ts b/src/policies/hellthread-policy.ts index 9f05171..cc5d31f 100755 --- a/src/policies/hellthread-policy.ts +++ b/src/policies/hellthread-policy.ts @@ -16,7 +16,7 @@ const hellthreadPolicy: Policy = (msg, opts) => { return { id: msg.event.id, action: 'reject', - msg: `Event rejected due to ${p.length} "p" tags (${limit} is the limit).`, + msg: `blocked: rejected due to ${p.length} "p" tags (${limit} is the limit).`, }; } } diff --git a/src/policies/keyword-policy.ts b/src/policies/keyword-policy.ts index 7487dd3..d4ffdef 100644 --- a/src/policies/keyword-policy.ts +++ b/src/policies/keyword-policy.ts @@ -15,7 +15,7 @@ const keywordPolicy: Policy> = ({ event: { id, content } }, wor return { id, action: 'reject', - msg: 'Event contains a banned word or phrase.', + msg: 'blocked: contains a banned word or phrase.', }; } diff --git a/src/policies/pubkey-ban-policy.ts b/src/policies/pubkey-ban-policy.ts index 3fb68ba..c8bba10 100644 --- a/src/policies/pubkey-ban-policy.ts +++ b/src/policies/pubkey-ban-policy.ts @@ -18,7 +18,7 @@ const pubkeyBanPolicy: Policy> = ({ event: { id, pubkey } }, pu return { id, action: 'reject', - msg: 'Pubkey is banned.', + msg: 'blocked: pubkey is banned.', }; } diff --git a/src/policies/rate-limit-policy.ts b/src/policies/rate-limit-policy.ts index f368bd6..4359bc6 100755 --- a/src/policies/rate-limit-policy.ts +++ b/src/policies/rate-limit-policy.ts @@ -33,7 +33,7 @@ const rateLimitPolicy: Policy = async (msg, opts) => { return { id: msg.event.id, action: 'reject', - msg: 'Rate-limited.', + msg: 'rate-limited: too many requests', }; } } diff --git a/src/policies/read-only-policy.ts b/src/policies/read-only-policy.ts index 34fb709..f390799 100755 --- a/src/policies/read-only-policy.ts +++ b/src/policies/read-only-policy.ts @@ -4,7 +4,7 @@ import type { Policy } from '../types.ts'; const readOnlyPolicy: Policy = (msg) => ({ id: msg.event.id, action: 'reject', - msg: 'The relay is read-only.', + msg: 'blocked: the relay is read-only', }); export default readOnlyPolicy; diff --git a/src/policies/regex-policy.ts b/src/policies/regex-policy.ts index e51da4e..c50c1b6 100644 --- a/src/policies/regex-policy.ts +++ b/src/policies/regex-policy.ts @@ -8,7 +8,7 @@ const regexPolicy: Policy = ({ event: { id, content } }, regex) => { return { id, action: 'reject', - msg: 'Event matches a banned expression.', + msg: 'blocked: text matches a banned expression.', }; } diff --git a/src/policies/whitelist-policy.ts b/src/policies/whitelist-policy.ts index da9f2f4..f7bbaa8 100644 --- a/src/policies/whitelist-policy.ts +++ b/src/policies/whitelist-policy.ts @@ -25,7 +25,7 @@ const whitelistPolicy: Policy> = ({ event: { id, pubkey } }, pu return { id, action: 'reject', - msg: 'Only certain pubkeys are allowed.', + msg: 'blocked: only certain pubkeys are allowed to post', }; };