weechat-scripts/elektroda.py

62 lines
2.8 KiB
Python

import weechat
__author__ = "Sergiusz 'q3k' Bazanski <q3k@q3k.org>"
# Copyright (c) 2014, Sergiusz 'q3k' Bazanski <q3k@q3k.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
weechat.register("elektroda-antifilter", "q3k", "1.0", "BSD 2-clause",
"A script to bypass word filters on #www.elektroda.pl on "
"pirc", "", "")
TARGET_SERVER = 'irc.pirc.pl'
TARGET_CHANNEL = '#www.elektroda.pl'
# will mask words containing these parts:
BAD_WORDS = ['kurw', 'chuj', 'pierd', 'jeb', 'kutas', 'pizd', 'fuck']
HIDDEN = u'\u2063'
def on_sent_privmsg(data, signal, server, args):
"""Makes 'bad' words masked."""
# wow, the weechat API is... interesting
parsed = weechat.info_get_hashtable('irc_message_parse', {'message': args})
if server == TARGET_SERVER and parsed['channel'] == TARGET_CHANNEL:
targets, message = parsed['arguments'].split(':', 1)
message = message.decode('utf-8')
for word in BAD_WORDS:
while message.find(word) >= 0:
# split line on both sides of word
start = message.find(word)
end = start + len(word)
first, second = message[:start], message[end:]
# hide word
word_middle = len(word) / 2
word_hidden = word[:word_middle] + HIDDEN + word[word_middle:]
# now splice line back together
message = first + word_hidden + second
message = message.encode('utf-8')
args = "PRIVMSG " + targets + " :" + message
return args
weechat.hook_modifier('irc_out1_privmsg', 'on_sent_privmsg', '')