130 lines
4.1 KiB
TypeScript
Executable File
130 lines
4.1 KiB
TypeScript
Executable File
import type { Policy } from '../types.ts';
|
|
|
|
/** Policy options for `hellthreadPolicy`. */
|
|
interface Hellthread {
|
|
/** Total number of "p" tags a kind 1 note may have before it's rejected. Default: `100` */
|
|
limit?: number;
|
|
}
|
|
|
|
/**
|
|
* Reject messages that tag too many participants.
|
|
*
|
|
* This policy is useful to prevent unwanted notifications by limiting the number of "p" tags a kind 1 event may have.
|
|
* Only kind 1 events are impacted by this policy, since kind 3 events will commonly exceed this number.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* // Reject events with more than 15 mentions.
|
|
* hellthreadPolicy(msg, { limit: 15 });
|
|
* ```
|
|
*/
|
|
const tagPolicy: Policy<Hellthread> = (msg, opts) => {
|
|
const limit = 0;
|
|
|
|
if (msg.event.kind === 4) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'accept',
|
|
msg: '',
|
|
};
|
|
};
|
|
|
|
if (msg.event.kind === 14) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'accept',
|
|
msg: '',
|
|
};
|
|
};
|
|
if (msg.event.kind === 0) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'accept',
|
|
msg: '',
|
|
};
|
|
};
|
|
|
|
let mastodon: (string | number)[] = ['bae.st','bsky','liberal.city','mastodon.bot','botsin.space','a2mi.social','.au','masto.host','mastodon.online','social.beaware.live','nofan.xyz','mastodon.social','mstdn','mathstodon','universeodon','infosec', 'mastdn', 'kitty.social', 'c.im', '.jp', '.de', '.fr', 'toot', 'mastodon', 'misskey', 'journa.host', 'social', 'eldritchcafe', 'hachyderm', 'kinky.business']
|
|
|
|
const p = msg.event.tags.filter((tag) => tag[0] === 'p');
|
|
const e = msg.event.tags.filter((tag) => tag[0] === 'e');
|
|
const g = msg.event.tags.filter((tag) => tag[0] === 'g');
|
|
const a = msg.event.tags.filter((tag) => tag[0] === 'a');
|
|
const d = msg.event.tags.filter((tag) => tag[0] === 'd');
|
|
const h = msg.event.tags.filter((tag) => tag[0] === 'h');
|
|
const i = msg.event.tags.filter((tag) => tag[0] === 'i');
|
|
const k = msg.event.tags.filter((tag) => tag[0] === 'k');
|
|
const l = msg.event.tags.filter((tag) => tag[0] === 'l');
|
|
const q = msg.event.tags.filter((tag) => tag[0] === 'q');
|
|
const t = msg.event.tags.filter((tag) => tag[0] === 't');
|
|
const alt = msg.event.tags.filter((tag) => tag[0] === 'alt');
|
|
const content = msg.event.tags.filter((tag) => tag[0] === 'content-warning');
|
|
const image = msg.event.tags.filter((tag) => tag[0] === 'image');
|
|
const relay = msg.event.tags.filter((tag) => tag[0] === 'relay');
|
|
const client = msg.event.tags.filter((tag) => tag[0] === 'client');
|
|
const proxy = msg.event.tags.filter((tag) => tag[0] === 'proxy');
|
|
const blockheight = msg.event.tags.filter((tag) => tag[0] === 'blockheight');
|
|
/**
|
|
if (blockheight.length > limit) {
|
|
if (blockheight.length > limit) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'reject',
|
|
msg: `Nostr Bots: BlockHeight`,
|
|
};
|
|
}
|
|
}
|
|
|
|
if (t.length > limit) {
|
|
if (t.length > limit) {
|
|
if (t.toString().indexOf('gnostr') > -1) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'reject',
|
|
msg: `Nostr Bots: gnostr`,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
**/
|
|
if (proxy.length > limit) {
|
|
for (let search of mastodon) {
|
|
if (proxy.length > limit) {
|
|
if(proxy.toString().indexOf('noauthority') > -1 || proxy.toString().indexOf('iddqd') > -1) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'accept',
|
|
msg: `Fediverse Accept`,
|
|
};
|
|
}
|
|
if (proxy.toString().indexOf(search) > -1) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'reject',
|
|
msg: `Fediverse Block: ` + search,
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (client.length > limit || d.length > limit || a.length > limit || h.length > limit || i.length > limit || k.length > limit || l.length > limit || q.length > limit || t.length > limit || alt.length > limit || content.length > limit || image.length > limit || relay.length > limit || g.length > limit || e.length > limit || p.length > limit) {
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'accept',
|
|
msg: ``,
|
|
};
|
|
}
|
|
|
|
return {
|
|
id: msg.event.id,
|
|
action: 'reject',
|
|
msg: ``,
|
|
};
|
|
};
|
|
|
|
export default tagPolicy;
|
|
|
|
export type { TAG };
|