random_cardcast -- A Twittbot (https://github.com/nilsding/twittbot) botpart which tweets random cards from a Cardcast pack.
# 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 |
--- | |
:wait: 15 | |
:deck: "4W5FN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment