#!/usr/bin/env perl use strict; use warnings; use utf8; weechat::register("bad_word_filter", "tyil", "0.1", "AGPL-3.0", "Do your part in keeping Christian channels safe and friendly", "", ""); weechat::hook_modifier("input_text_for_buffer", "catch_send", ""); sub catch_send { my ($data, $modifier_name, $buffer, $msg) = @_; my $buffer_name = weechat::buffer_get_string($buffer, 'name'); # These are the channels (or really, buffers) on which self-harm # protections should be enabled. my @christian_channels = ( 'freenode.##t', 'rizon.#chat', 'rizon.#stew', ); # These are the words that may not be spoken. my @bad_words = ( 'cuck', 'fag', 'kike', 'negro', 'nigga', 'nigger', ); # First, the message can be returned as is unless this message is sent # into a Christian channel. my $christian_context = 0; for my $channel (@christian_channels) { if ($channel eq $buffer_name) { $christian_context = 1; } } return $msg unless $christian_context; # Next, see if there are any bad words in this message. for my $bad_word (@bad_words) { next unless $msg =~ m/$bad_word/; # BAD WORD DETECTED weechat::print($buffer, 'The power word "'.$bad_word.'" is unfit for this channel.'); return ""; } # It's a safe message, just return it. return $msg; }