Skip to content

Commit

Permalink
feat: #55 Contains and not-contains constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
xurizaemon committed Dec 19, 2024
1 parent b0933f6 commit db5f1fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/mastodon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MegalodonInterface, Mastodon } from 'megalodon'
import { Status } from 'megalodon/lib/src/entities/status';
import { Constraint } from "./constraint";
import { convert } from 'html-to-text';

export function initMastodonAgent() {
return new Mastodon('mastodon',
Expand Down Expand Up @@ -44,17 +45,20 @@ export async function getNewToots(client: Mastodon, uid: string, lastTootTime: D
const newPost = new Date(status.created_at) > lastTootTime;
const isPublic = status.visibility === 'public';
const isNotMention = status.mentions.length === 0;
const text = convert(status.content ?? '', { wordwrap: false, preserveNewlines: false });
const regex = new RegExp(`${constraint.relayMarker}`, 'm');
const containsMarker = text.match(regex) !== null;
const isSelfFaved = status.favourited;

if (constraint.relayCriteria === 'favedBySelf' && !isSelfFaved) {
return false;
}

if (constraint.relayCriteria === 'containsMarker' && !status.content.match(/constraint.relayMarker/)) {
if (constraint.relayCriteria === 'containsMarker' && !containsMarker) {
return false;
}

if (constraint.relayCriteria === 'notContainsMarker' && status.content.match(/constraint.relayMarker/)) {
if (constraint.relayCriteria === 'notContainsMarker' && containsMarker) {
return false;
}

Expand Down

0 comments on commit db5f1fd

Please sign in to comment.