-
Notifications
You must be signed in to change notification settings - Fork 3
/
fembot.rb
69 lines (58 loc) · 1.8 KB
/
fembot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'chatterbot/dsl'
require 'redis'
require 'yaml'
require 'json'
conf = YAML.load_file('config.yml')
tags = {}
redis = Redis.new()
blklist = []
blklist = JSON.parse(redis.get('blacklist')) unless redis.get('blacklist').nil?
blacklist blklist
for response in conf['responses'].keys
for hashtag in conf['responses'][response]
tags[hashtag] = [] unless tags.include?(hashtag)
tags[hashtag] << response
end
end
# create a since_id if none exists.
# this keeps us from resending old tweets
# if the bot goes up on another system
# if redis.get('since').nil?
# # searching #fembot is a hurried hack
# search('#fembot') do |tweet|
# redis.set 'since', tweet.id
# end
# end
#
puts redis.get('since')
loop do
begin
replies do |tweet|
if tweet.text.downcase.include?(conf['blacklist_text'])
blklist << tweet.from_user
redis.set 'blacklist', blklist.to_json
blacklist blklist
end
reply "#USER# I'm a feminist robot!", tweet
end
for hashtag in tags.keys
since_id=(redis.get('since'))
search(hashtag) do |tweet|
redis.set tweet.from_user, [hashtag].to_json if redis.get(tweet.from_user).nil?
reply "#{tweet_user(tweet)} #{tags[hashtag][0]}", tweet unless JSON.parse(redis.get(tweet.from_user)).include?(hashtag)
puts 'tweeted at ' + tweet.from_user + ' for saying ' + hashtag unless JSON.parse(redis.get(tweet.from_user)).include?(hashtag)
redis.set 'since', tweet.id
puts redis.get('since')
user_tags = JSON.parse(redis.get(tweet.from_user)) << hashtag
redis.set tweet.from_user, user_tags.to_json
redis.incr(hashtag)
break
end
end
puts '.'
redis.save
sleep 90 * (Random.rand(9) + 1)
rescue Twitter::Error::TooManyRequests
sleep 1000
end
end