Created
September 12, 2014 00:17
-
-
Save anonymous/f24d901a3e39fada0543 to your computer and use it in GitHub Desktop.
How I created my twitter bots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First, I should say that I had help. I have a lovely friend and I'm not sure whether or not she'd want to be mentioned here, but she was there for me when I ran into headaches. This was a HECK of a lot of work to do on a Windows machine. I understand it's easier on Mac. | |
I created the bot using the scripts at this repository: | |
https://github.com/mispy/twitter_ebooks | |
I worked with these two tutorials to get me through the process when I got stuck: | |
http://blog.boodoo.co/how-to-make-an-_ebooks/ | |
https://github.com/trommel/ebooks_tutorial | |
Read through BOTH of these before you get started. I found them near the end and they'd have saved me a LOT of headaches. | |
I used the Twitter export method using my entire archive. I've been updating with live tweets but that's a whole 'nother setup. What I found, personally, is that when attempting to download using the: ebooks archive method, I have to use my Ubuntu box vs. my Windows 7 (your experience may vary and I'm told Mac works as well as Ubuntu) | |
I host the bot on a free https://heroku.com/ dyno (pro tip, when you've got a Heroku repository set up, you have to actually go in and add a dyno to your account or it won't run!) | |
When it came to actually pushing the repository to heroku, I had to use these steps: | |
http://stackoverflow.com/a/18676454 | |
and used Git Bash vs. the command line to do so. If I do so using the command line, it doesn't work for me. | |
Sufficeth to say that the command line is your friend if you try this. I may be able to provide a little help, but I'm not so great with Ruby that I feel terribly comfortable. What I will do, however, is paste below a version of the bots.rb file which my friend gave me permission to share and which makes my bot truly awesome. You'll have to fill in details of "your_bot" and the name of your tweets.model file (if it's not just tweets.model) | |
-- | |
#!/usr/bin/env ruby | |
require 'set' | |
require 'twitter_ebooks' | |
Ebooks::Bot.new("your_bot") do |bot| | |
# Consumer details come from registering an app at https://dev.twitter.com/ | |
# OAuth details can be fetched with https://github.com/marcel/twurl although dev.twitter.com is better for doing all. Also the keys below have been renamed to be careful. | |
bot.consumer_key = "" | |
bot.consumer_secret = "" | |
bot.oauth_token = "" | |
bot.oauth_token_secret = "" | |
model = Ebooks::Model.load('model/tweets.model') | |
# mstea_ebooks only randomly tweets a person once per session | |
tweeted = Set.new() | |
bot.on_message do |dm| | |
length = dm[:text].length | |
bot.reply(dm, model.make_response(dm[:text], 140 - length)) | |
end | |
bot.on_follow do |user| | |
bot.follow(user[:screen_name]) | |
end | |
bot.on_mention do |tweet, meta| | |
# Avoid infinite reply chains (very small chance of crosstalk) | |
next if tweet[:user][:screen_name].include?('ebooks') && rand > 0.05 | |
length = tweet[:text].length + meta[:reply_prefix].length | |
response = model.make_response(tweet[:text], 140 - length) | |
bot.reply(tweet, meta[:reply_prefix] + response) | |
end | |
bot.on_timeline do |tweet, meta| | |
next if tweet[:retweeted_status] || tweet[:text].start_with?('RT') | |
next unless rand < 0.05 | |
# mstea_ebooks only randomly tweets a person once per run | |
next if tweeted.include? tweet[:user][:screen_name] | |
tweeted << tweet[:user][:screen_name] | |
# Reply to a tweet in the bot's timeline | |
positive_words = tweet[:text] + ' good happy fun great positive perfect' | |
length = tweet[:text].length + meta[:reply_prefix].length | |
response = model.make_response(positive_words, 140 - length) | |
bot.reply(tweet, meta[:reply_prefix] + response) | |
end | |
bot.scheduler.every '1h' do | |
bot.tweet(model.make_statement(140)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment