Skip to content

Instantly share code, notes, and snippets.

@nilsding
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsding/151e40038d2e8932c605 to your computer and use it in GitHub Desktop.
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.
# 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