diff --git a/boodoo.rb b/boodoo.rb index 95c76a1..b1a6950 100644 --- a/boodoo.rb +++ b/boodoo.rb @@ -18,6 +18,24 @@ module Ebooks::Boodoo value end + def obscure_curse(len) + s = [] + c = ['!', '@', '$', '%', '^', '&', '*'] + len.times do + s << c.sample + end + s.join('') + end + + def obscure_curses(tweet) + # TODO: Ignore banned terms that are part of @-mentions + $banned_terms.each do |term| + re = Regexp.new("\\b#{term}\\b", "i") + tweet.gsub!(re, Ebooks::Boodoo.obscure_curse(term.size)) + end + tweet + end + def parse_array(value, array_splitter=nil) array_splitter ||= / *[,;]+ */ value.split(array_splitter).map(&:strip) @@ -40,17 +58,6 @@ class Ebooks::TweetMeta end end -class Ebooks::Boodoo::Model < Ebooks::Model - def valid_tweet?(tokens, limit) - tweet = NLP.reconstruct(tokens) - found_banned = $banned_words.any? do |word| - re = Regexp.new("\\b#{word}\\b", "i") - re.match tweet - end - tweet.length <= limit && !found_banned && !NLP.unmatched_enclosers?(tweet) - end -end - class Ebooks::Boodoo::BoodooBot < Ebooks::Bot @required_fields = ['consumer_key', 'consumer_secret', 'access_token', 'access_token_secret', @@ -122,9 +129,9 @@ class Ebooks::Boodoo::BoodooBot < Ebooks::Bot def make_model! log "Updating model: #{@model_path}" - Ebooks::Boodoo::Model.consume(@archive_path).save(@model_path) + Ebooks::Model.consume(@archive_path).save(@model_path) log "Loading model..." - @model = Ebooks::Boodoo::Model.load(@model_path) + @model = Ebooks::Model.load(@model_path) end def can_run? diff --git a/bots.rb b/bots.rb index c444a25..d8bff3d 100644 --- a/bots.rb +++ b/bots.rb @@ -22,8 +22,9 @@ class UserInfo end end -class CloneBot < BoodooBot +class BoodooBot attr_accessor :original, :model, :model_path, :auth_name, :archive_path, :archive + attr_accessor :followers, :following # alias_method :oauth_token, :access_token # alias_method :oauth_token_secret, :access_token_secret def configure @@ -69,8 +70,8 @@ class CloneBot < BoodooBot # @have_talked = {} if can_run? - get_archive! unless has_archive? - make_model! unless has_model? + get_archive! + make_model! else missing_fields.each {|missing| log "Can't run without #{missing}" @@ -211,6 +212,18 @@ class CloneBot < BoodooBot end end + # Prefilter for banned terms before tweeting + def tweet(text, *args) + text = obscure_curses(text) + super(text, *args) + end + + # Prefilter for banned terms before replying + def reply(ev, text, opts={}) + text = obscure_curses(text) + super(ev, text, opts) + end + private def load_model! return if @model @@ -222,7 +235,7 @@ class CloneBot < BoodooBot end end -CloneBot.new(SETTINGS['BOT_NAME']) do |bot| - # CloneBot#configure does everything! +BoodooBot.new(SETTINGS['BOT_NAME']) do |bot| + # BoodooBot#configure does everything! bot end