Skip to content

Instantly share code, notes, and snippets.

@squarism
Forked from muffinista/bot.rb
Created November 26, 2011 06:00
Show Gist options
  • Save squarism/1395133 to your computer and use it in GitHub Desktop.
Save squarism/1395133 to your computer and use it in GitHub Desktop.
bot reply test
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require 'chatterbot/dsl'
require 'pokerthing'
exclude "http://" # block spam tweet
blacklist "jerkface, assbutt" # block jerks or self
#debug_mode true
puts "Bot listening."
bot = Chatterbot::Bot.new
loop do
trap('TERM') { puts 'Exiting...'; exit }
trap('INT') { puts 'Exiting...'; exit }
# File.open('tweet.dat') do |f|
# @tweet = Marshal.load(f)
# end
begin
bot.replies do |tweet|
puts "got tweet from @#{tweet[:user][:screen_name]}! id:#{tweet[:id_str]}"
puts " it says: #{tweet[:text]}"
File.open('tweet.dat', 'w+') do |f|
Marshal.dump(tweet, f)
#exit
end
tweet_text = tweet[:text].to_s
tweet_array = tweet_text.gsub(/#{bot.config[:handle]}/,'').lstrip.squeeze.split(' ')
if tweet_array[0] == 'deal'
hand = Pokerthing::Deck.new.deal 5
hand_text = "#USER# #{Pokerthing.format_tweet(hand)}"
bot.reply hand_text, tweet
# these are required to stop infinite replying from happening
bot.update_since_id tweet
bot.store_local_config
# puts bot.config_file
# puts bot.config[:since_id]
puts "replied with #{hand_text} to #{tweet_user(tweet)}"
else
puts "spam"
end
end
# twitter is overcapacity error
rescue JSON::ParserError
puts "fail whale."
end
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment