this post was submitted on 16 Mar 2025
26 points (100.0% liked)

Haupteingang

641 readers
77 users here now

Die Standard-Community von feddit.org

In dieser Community geht es ausschließlich um alles rund um die Instanz!

Regeln:

founded 8 months ago
MODERATORS
 

cross-posted from: https://lemmy.ca/post/40761824

Sorry everyone I know how much you love the attention she gives you, but I've implemented some quick and dirty filtering for private messaging.

We now have the ability to automatically mark PM's as deleted or read, depending on content inside of them. If we accidentally filter something you legitimately wanted (ie, not Nicole) please let me know.

If any other instances would like to implement this, here's the code. Note that you'll need to set your hostname at the top here for some reason I haven't exactly identified.

SET lemmy.protocol_and_hostname = 'https://lemmy.ca/';

CREATE TABLE private_message_filters (
    id SERIAL PRIMARY KEY,
    phrase TEXT NOT NULL,
    behavior VARCHAR(10) NOT NULL CHECK (behavior IN ('delete', 'mark_read'))
);

CREATE OR REPLACE FUNCTION filter_private_messages()
RETURNS trigger AS $$
DECLARE
    banned_phrase_record private_message_filters%ROWTYPE;
BEGIN
    FOR banned_phrase_record IN 
        SELECT * FROM private_message_filters
    LOOP
        IF LOWER(TRIM(NEW.content)) ILIKE '%' || LOWER(TRIM(banned_phrase_record.phrase)) || '%' THEN
            IF banned_phrase_record.behavior = 'delete' THEN
                NEW.deleted := true;
                RETURN NEW;
            ELSIF banned_phrase_record.behavior = 'mark_read' THEN
                NEW.read := true;
                RETURN NEW;
            END IF;
        END IF;
    END LOOP;
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trg_filter_private_messages
AFTER INSERT ON private_message
FOR EACH ROW
EXECUTE FUNCTION filter_private_messages();

To add filter words:

insert into private_message_filters (behavior, phrase) values ('delete', 'spamtestdelete');
insert into private_message_filters (behavior, phrase) values ('mark_read', 'spamtestread');

If you want to quickly disable / enable filtering while testing:

ALTER TABLE private_message DISABLE TRIGGER trg_filter_private_messages;
ALTER TABLE private_message ENABLE TRIGGER trg_filter_private_messages;

I'll leave it up to you to figure out what phrases to filter on. MAKE SURE YOU TEST. If there's an error, private messaging could break completely. You should not get an error message from the UI while sending a message with a banned word.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 16 points 21 hours ago (2 children)

Ja. Ich weiß nicht, wer die Fotos verschickt, aber sie wurden offensichtlich ohne Zustimmung der gezeigten Person während einer Videokonferenz aufgenommen.
Sowas sollte hier geblockt werden.

[–] [email protected] 13 points 21 hours ago

Und nicht vergessen: Es ist Spam. Wenn das durchgeht, dann gehen halt auch DMs mit Spam und sonstigen unangenehmen Inhalten durch. Wir brauchen auf jeden Fall die passende Infrastruktur bevor die Spammer auftauchen.

[–] tja 5 points 21 hours ago

Während einer Videokonferenz oder will jemand ihr einen Trojaner installiert har? Manche Bilder sahen eher weniger nach Videokonferenz aus oder?