forked from simonszu/ebooks-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bots.rb
63 lines (51 loc) · 1.76 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
require 'twitter_ebooks'
# 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
self.consumer_key = "${CONSUMER_KEY}" # Your app consumer key
self.consumer_secret = "${CONSUMER_SECRET}" # Your app 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
@model = Ebooks::Model.load("model/${USER}.model")
end
def on_startup
scheduler.every '30m' do
# Tweet something every 24 hours
# See https://github.com/jmettraux/rufus-scheduler
# tweet("hi")
# pictweet("hi", "cuteselfie.jpg")
tweet(@model.make_statement(280))
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, @model.make_statement(280))
end
def on_timeline(tweet)
# Reply to a tweet in the bot's timeline
# reply(tweet, "nice tweet")
end
def on_favorite(user, tweet)
# Follow user who just favorited bot's tweet
follow(user.screen_name)
end
end
# Make a MyBot and attach it to an account
MyBot.new("${BOT_USER}") do |bot|
bot.access_token = "${ACCESS_TOKEN}" # Token connecting the app to this account
bot.access_token_secret = "${ACCESS_TOKEN_SECRET}" # Secret connecting the app to this account
end