-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbots.rb
76 lines (62 loc) · 1.92 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
75
76
require 'twitter_ebooks'
require 'yaml'
require './module_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..126
end
def on_startup
@logic = ModuleLogic.new
@top100 = @logic.model.keywords.take(100).collect { |x| x.downcase }
#generate()
scheduler.every '30m' do
# Tweet something every 24 hours
# See https://github.com/jmettraux/rufus-scheduler
# tweet("hi")
# pictweet("hi", "cuteselfie.jpg")
delay do
generate()
end
end
end
def generate()
tweet(@logic.generate)
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")
tokens = Ebooks::NLP.tokenize(tweet.text).collect { |x| x.downcase }
if (tokens & @top100).uniq.count > 2
favorite(tweet) #if rand < 0.5
end
end
end
# Make a MyBot and attach it to an account
MyBot.new("modulargridREAL") do |bot|
config = YAML.load_file('secrets.yml')
bot.access_token = config['access_token']
bot.access_token_secret = config['access_token_secret']
end