Skip to content
Snippets Groups Projects
Commit 8798b19e authored by Richard Banks's avatar Richard Banks
Browse files

Added support for all currencies and updated the README to reflect changes

parent 3a175dbb
Branches master
Tags v1.1
No related merge requests found
......@@ -6,7 +6,8 @@ A bitcoin plugin/gem for your Cinch IRC bot
## Features ##
- **Retrieve BTC value:** Retrieves and returns to the channel the value of one BTC in USD on the command !btcv
- **Retrieve BTC value:** Retrieves and returns to the channel the value of one BTC in any currency on the command !btcv [Currency]
- **Convert BTC to Any Currency:** You can use the command !btc [currency] [BTC Value]
- **Help provided:** There is a help block in the plugin that you can trigger using !help bitcoin
## Usage ##
......
Gem::Specification.new do |s|
s.name = "cinch-bitcoin"
s.version = '1.0.1'
s.version = '1.1'
s.authors = ["Richard Banks"]
s.email = ["namaste@rawrnet.net"]
s.license = 'MIT'
s.homepage = "https://github.com/RawrNet/cinch-bitcoin"
s.summary = "A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin in USD."
s.description = "A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin in USD. " +
s.summary = "A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin in the specified currency."
s.description = "A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin in the specified currency. " +
"You can visit irc://rawr.sinsira.net #Lobby to get help, report issues " +
", test the gem, or just chat."
......
# @author Richard Banks <namaste@rawrnet.net>
# Feel free to join us in #Lobby on irc://rawr.sinsira.net where you can test this gem and get help!
require 'cinch'
require 'ostruct'
require 'open-uri'
......@@ -14,17 +10,61 @@ module Cinch
set :plugin_name, 'bitcoin'
set :help, <<-USAGE.gsub(/^ {6}/, '')
Just a seen plugin!
Bitcoin plugin that fetches results from Blockchain.info!
Usage:
* !btcv: Returns the latest value of 1 (one) Bitcoin in USD
* !btcv <currency>: Returns the latest value of 1 (one) Bitcoin in <currency>
* !btc <currency> <Bitcoin amount>: Returns the value of <Bitcoin amount> in <currency>.
USAGE
match /btcv/
match /btcv (\w{3})/
def execute(m)
def execute(m, currency)
data = JSON.parse(open("http://blockchain.info/ticker").read)
value = data['USD']['15m']
m.reply "Current value of 1 BTC in USD is: #{value}", true
coins = ['USD', 'CNY', 'JPY', 'SGD', 'HKD', 'CAD', 'NZD', 'AUD', 'CLP', 'GBP', 'HKK', 'SEK', 'ISK', 'CHF', 'BRL', 'EUR', 'RUB', 'PLN', 'THB', 'KRW', 'TWD']
currency = currency.upcase
if !coins.include?(currency)
m.reply "That currency isn't in my database!"
m.user.notice "You can use: #{coins}"
return
end
value = data[currency]['15m']
value = value.round(2).to_f
value = value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
symbol = data[currency]['symbol']
m.reply "Current value of 1 BTC in #{currency} is: #{symbol}#{value}", true
end
match /btc (\w{3}) (.+)/, method: :conversion
def conversion(m, currency, btc)
data = JSON.parse(open("http://blockchain.info/ticker").read)
coins = ['USD', 'CNY', 'JPY', 'SGD', 'HKD', 'CAD', 'NZD', 'AUD', 'CLP', 'GBP', 'HKK', 'SEK', 'ISK', 'CHF', 'BRL', 'EUR', 'RUB', 'PLN', 'THB', 'KRW', 'TWD']
currency = currency.upcase
if !coins.include?(currency)
m.reply "That currency isn't in my database!"
m.user.notice "You can use: #{coins}"
return
end
value = data[currency]['15m']
value = value.round(2).to_f
symbol = data[currency]['symbol']
btc = btc.to_f
conv = (btc * value).round(2)
conv = conv.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
m.reply "The value of #{btc}BTC is #{symbol}#{conv}.", true
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment