Added Lowercase & Invisible Hashtag Policies
parent
d8800c3193
commit
e036d4b53f
33
policy.ts
33
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<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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue