-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbots.rb
74 lines (61 loc) · 1.79 KB
/
bots.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
require 'twitter_ebooks'
require 'yaml'
require './astro_logic.rb'
# This is an example bot definition with event handlers commented out
# You can define and instantiate as many bots as you like
class MyBot < Ebooks::Bot
# Configuration here applies to all MyBots
def configure
# Consumer details come from registering an app at https://dev.twitter.com/
# Once you have consumer details, use "ebooks auth" for new access tokens
config = YAML.load_file('secrets.yml')
self.consumer_key = config['consumer_key']
self.consumer_secret = config['consumer_secret']
# Users to block instead of interacting with
self.blacklist = ['tnietzschequote']
# Range in seconds to randomize delay when bot.delay is called
self.delay_range = 1..6
end
def on_startup
@logic = AstroLogic.new
generate()
scheduler.every '24h' do
# Tweet something every 24 hours
# See https://github.com/jmettraux/rufus-scheduler
# tweet("hi")
# pictweet("hi", "cuteselfie.jpg")
generate()
end
end
def generate()
@logic.generate.each do |pair|
time,string = pair
log "#{time}: #{string}"
scheduler.at time do
tweet(string)
end
end
end
def on_message(dm)
# Reply to a DM
# reply(dm, "secret secrets")
end
def on_follow(user)
# Follow a user back
# follow(user.screen_name)
end
def on_mention(tweet)
# Reply to a mention
# reply(tweet, "oh hullo")
end
def on_timeline(tweet)
# Reply to a tweet in the bot's timeline
# reply(tweet, "nice tweet")
end
end
# Make a MyBot and attach it to an account
MyBot.new("plan9astro") do |bot|
config = YAML.load_file('secrets.yml')
bot.access_token = config['access_token']
bot.access_token_secret = config['access_token_secret']
end