Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mattetti/twitter_game_bot

A twitter bot
https://github.com/mattetti/twitter_game_bot

Last synced: about 11 hours ago
JSON representation

A twitter bot

Awesome Lists containing this project

README

        

= Twitter Game Bot

Just a simple bot skeleton which can be used by game developers to post content to twitter on a regular basis.

Implementation example:

require 'twitter_game_bot'
require 'CGI'

class MyGame < SCEA::TweetBot

trigger_hourly :tweet_top_player_changes
trigger_daily :tweet_top_5, "14:00 - PST"
trigger_weekly :tweet_weekly_stats, "Monday - 15:00 - PST"

twitter_credentials :login => 'mnr', :password => 'sekrit'
game_api_credentials :login => 'mnr', :password => 'sekrit'
game_api_url 'http://mnr.com/beatit/'

def tweet_top_player_changes
last_top_5 = load_data[:last_top_5]
top_5 = game_api.top_5.to_hash # expected -> {1 => 'James', 2 => 'Peter', 3 => 'Louisa'}
save_data(:last_top_5, top_5)
diff = top_5.diff(last_top_5)
diff.each do |position, name|
tweet "#{CGI.escape(name)} is now #{position.ordinalize}"
end
end

def tweet_top_5
# let's convert {2 => 'Peter', 1 => 'James', 3 => 'Louisa'} to
# [[1,'James'], [2,'Peter'], [3,'Louisa']]
sorted_top_5 = game_api.top_5.sort
msg = sorted_top_5.map do |position, name|
"#{position.ordinalize}: #{CGI.escape(name)}"
end.join(' ')
tweet msg
end

def tweet_weekly_stats
# TODO
end

end

== Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2010 Matt Aimonetti. See LICENSE for details.