diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2018-08-09 20:04:01 +0000 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2018-09-14 16:26:09 +0000 |
commit | a6a44133c4157fa9989a507627c2dca1540ae26b (patch) | |
tree | 816fc2b388196c2743a1aeb1c61b8ee9986a02fe | |
parent | abff9e96b66319c3113e24ac4bc99e174cdc52e4 (diff) |
refactor known spam into a list
-rw-r--r-- | modules/m_spamfilter.sh | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/modules/m_spamfilter.sh b/modules/m_spamfilter.sh index b7346e1..683d7cd 100644 --- a/modules/m_spamfilter.sh +++ b/modules/m_spamfilter.sh @@ -34,17 +34,22 @@ readonly SPAMFILTER_CHANNELS="${config_module_spamfilter_channels}" readonly BOT_PASS="${config_server_passwd}" # known spam trigger constants -readonly SPAM1='blog by freenode staff' -readonly SPAM2='IRC investigative journalists' -readonly SPAM3='IRC ad service' -readonly SPAM4="Australia's #1 hacker" -readonly SPAM5='SP9002_@efnet' -readonly SPAM6='/!\ ATTN: ' -readonly SPAM7='acquisition by Private' -readonly SPAM8='"denial" on the freenode blog' -readonly SPAM9=' ICO scam' -readonly SPAM10='Oh, and about those donations she speaks of:' - +readonly SPAM=( + 'blog by freenode staff' + 'IRC investigative journalists' + 'IRC ad service' + "Australia's #1 hacker" + 'SP9002_@efnet' + '/!\ ATTN: ' + 'acquisition by Private' + '"denial" on the freenode blog' + ' ICO scam' + 'Oh, and about those donations she speaks of:' + 'kaniini has invited you' +) + + +## setup/teardown ## module_spamfilter_INIT() { @@ -63,6 +68,9 @@ module_spamfilter_REHASH() return 0 } + +## events ## + module_spamfilter_on_JOIN() { local whojoined= @@ -119,22 +127,37 @@ DBG_CONDITIONS ${sender} ${target} ${log_line} ${chat_log} DBG_UNREGISTERED ${sender} # this chat is from an unregistered user - relay it to the channel unless it is known spam - case "${query}" in - *$SPAM10*|*$SPAM9*|*$SPAM8*|*$SPAM7*|*$SPAM6*|*$SPAM5*|*$SPAM4*|*$SPAM3*|*$SPAM2*|*$SPAM1*) + if is_spam "${query}" + then DBG_SPAM ${sender} - ;; - *) [ "$(echo ${query})" ] && send_msg "${channel}" "(${sender} said): ${query}" -# echo "(${sender} said): ${query}" > ${II_DIR}/${channel}/in - ;; - esac + else + send_msg "${channel}" "(${sender} said): ${query}" + #echo "(${sender} said): ${query}" > ${II_DIR}/${channel}/in + fi # supress further handling of this message return 1 } +## helpers ## + +is_spam() +{ + local needle=$1 + local haystack=("${SPAM[@]}") + local straw + + [ -z "$(echo ${needle})" ] && return 0 + + for straw in "${haystack[@]}"; do [[ ${needle} = *"${straw}"* ]] && return 0 ; done ; + + return 1 +} + + ## DEBUG ## DBG_JOIN() { (( $DEBUG )) || return ; local whojoined=$1 ; local channel=$2 ; echo "[SPAMFILTER]: whojoined=${whojoined} channel=${channel}" ; } |