Obscure banned terms (comic book style)

This commit is contained in:
Joel McCoy
2014-12-29 13:38:09 -05:00
parent 003b17fd44
commit 73ab3c8a06
2 changed files with 38 additions and 18 deletions

View File

@@ -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?