From e036d4b53fc8c102931f2694f79a5a943f8a005d Mon Sep 17 00:00:00 2001 From: SleepingCrows Date: Thu, 15 Aug 2024 19:09:33 -0400 Subject: [PATCH] Added Lowercase & Invisible Hashtag Policies --- policy.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/policy.ts b/policy.ts index de5bffc..529a45b 100644 --- a/policy.ts +++ b/policy.ts @@ -3,9 +3,40 @@ import { AntiDuplicationPolicy, HashtagPolicy, PubkeyBanPolicy, RegexPolicy, Key const kv = await Deno.openKv(); +export class LowercaseHashtagPolicy implements NPolicy { + async call(event: NostrEvent): Promise { + for (const [name, value] of event.tags) { + if (name === 't' && value !== value.toLowerCase()) { + return ['OK', event.id, false, 'blocked: uppercase letters in t tag']; + } + } + + return ['OK', event.id, true, '']; + } +} + +export class InvisibleHashtagPolicy implements NPolicy { + async call(event: NostrEvent): Promise { + if (event.kind === 1) { + const content = event.content.toLowerCase(); + + for (const [name, value] of event.tags) { + if (name === 't' && !content.includes(`#${value.toLowerCase()}`)) { + return ['OK', event.id, false, 'blocked: invisible hashtag']; + } + } + } + + return ['OK', event.id, true, '']; + } +} + + export default class AppPolicy implements NPolicy { async call(event: NostrEvent): Promise { const policy = new PipePolicy([ + new LowercaseHashtagPolicy(), + new InvisibleHashtagPolicy(), new RegexPolicy(/This is a post from *(.+)!/igm), new KeywordPolicy([ 'NSFW sexual content', @@ -268,3 +299,5 @@ export default class AppPolicy implements NPolicy { return policy.call(event); } } + +