Last active
August 29, 2015 14:21
-
-
Save nilsding/151e40038d2e8932c605 to your computer and use it in GitHub Desktop.
random_cardcast -- A Twittbot (https://github.com/nilsding/twittbot) botpart which tweets random cards from a Cardcast pack.
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
# random_cardcast.rb | |
# (c) 2015 nilsding | |
# License: MIT (http://opensource.org/licenses/MIT) | |
# | |
# echo "gem 'httparty'" >> ../Gemfile && bundle install | |
require 'httparty' | |
require 'json' | |
Twittbot::BotPart.new :random_cardcast do | |
every @config[:wait], :minutes do | |
bot.tweet get_new_card | |
end | |
def get_new_card | |
cardcast_cards_url = "https://api.cardcastgame.com/v1/decks/#{@config[:deck]}/cards" | |
deck = JSON.parse HTTParty.get(cardcast_cards_url).body | |
calls = make_calls deck | |
responses = make_responses deck | |
calls.sample.gsub "\x00" do | |
response = responses.sample | |
responses.delete_at responses.index(response) | |
response | |
end | |
end | |
def make_calls(deck) | |
deck['calls'].map do |c| | |
c['text'] * "\x00" # ____ == \x00 | |
end.flatten | |
end | |
def make_responses(deck) | |
deck['responses'].map do |r| | |
r['text'] | |
end.flatten | |
end | |
end |
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
--- | |
:wait: 15 | |
:deck: "4W5FN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment