Added Lowercase & Invisible Hashtag Policies

main
SleepingCrows 2024-08-15 19:09:33 -04:00
parent d8800c3193
commit e036d4b53f
1 changed files with 33 additions and 0 deletions

View File

@ -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<NostrRelayOK> {
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<NostrRelayOK> {
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<NostrRelayOK> {
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);
}
}