-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinition_bot.rb
executable file
·80 lines (58 loc) · 1.64 KB
/
definition_bot.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
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env ruby
require 'rubygems'
require 'chatterbot/dsl'
require './tweet'
# remove this to send out tweets
# debug_mode
# remove this to update the db
no_update
# remove this to get less output when running
verbose
# here's a list of users to ignore
# blacklist "abc", "def"
# here's a list of things to exclude from searches
# exclude "hi", "spammer", "junk"
# search "keyword" do |tweet|
# reply "Hey #USER# nice to meet you!", tweet
# end
# replies do |tweet|
# reply "Yes #USER#, you are very kind to say that!", tweet
# end
STARTUP_TIME = Time.now
threads = []
def replying_to_requests
replied_to_tweet_ids = []
while true
replies do |tweet|
# Possible calls:
# define #{word}
initial_match = tweet.text.match(/(?:define) (\w*-?\w*)/i)
if initial_match
match = initial_match.captures.first.match(/(\w.*\w)/)
end
if initial_match && STARTUP_TIME < tweet.created_at && !replied_to_tweet_ids.include?(tweet.id)
sleep(30)
if match && !(match.captures.nil? || match.captures.empty?)
reply ("#USER# " + Tweet.new(match.captures.first).message), tweet
else
reply ("#USER# I'm sorry, I don't know what you're asking me to define!"), tweet
end
replied_to_tweet_ids << tweet.id
end
sleep(30)
end
# To avoid tweeting too often
sleep(60)
update_config
end
end
def standard_tweeting
while true
tweet Tweet.new.message
# sleep for, on average, half a day.
sleep(rand(86400))
end
end
threads << Thread.new { replying_to_requests }
threads << Thread.new { standard_tweeting }
threads.each(&:join)