cinch-bitcoin 1.0.1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/cinch/plugins/bitcoin.rb +71 -31
  3. metadata +12 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: 6cb315d13bdc324dc4e61baa1b1b1cfc3f90bca2
4
- data.tar.gz: 0eca5cba1c33e8aff11bf65bdb72a406ca307856
2
+ SHA1:
3
+ metadata.gz: 722128b145f5b5c1ea0b76384a0735306a94fc31
4
+ data.tar.gz: a45cdf2f0f613339707d9e96718f3bffb80fcbc9
5
5
  SHA512:
6
- metadata.gz: a02db9114e1c4ba76b25b94d13d2afd6a652616289730df2c4bc2301d3706a41ec6eee9de7d52104094954646ab19d70d869124078bbcb3f4cee66f76ecc2d71
7
- data.tar.gz: 1d85802137dcf4616df9450a71845fd9d1b78c9f3a91fb084d95c50693cebb7b29126035cf761492f554fdc9e07b803f54786975bfeb5dcf7c8e627ed80fbb64
6
+ metadata.gz: e38c2fdf308eb4ac5ee282c2f3d2275313eb7d6b1b4989d349703809334c7f3f474fe43bd7964d8adf89aee2b6a5fbe7d21f3ef3d2dd624bb3f7221d79d7b1a5
7
+ data.tar.gz: dccdfbc5e09bdf70683692a2f5b04f13823c9c597f517d4bf82f2a5f77c6ae73e47ffaf6d1fd5908008711c707e276579f11ab30d1278711a65548015f6dc6bf
@@ -1,31 +1,71 @@
1
- # @author Richard Banks <namaste@rawrnet.net>
2
-
3
- # Feel free to join us in #Lobby on irc://rawr.sinsira.net where you can test this gem and get help!
4
-
5
- require 'cinch'
6
- require 'ostruct'
7
- require 'open-uri'
8
- require 'json'
9
-
10
- module Cinch
11
- module Plugins
12
- class Bitcoin
13
- include Cinch::Plugin
14
-
15
- set :plugin_name, 'bitcoin'
16
- set :help, <<-USAGE.gsub(/^ {6}/, '')
17
- Just a seen plugin!
18
- Usage:
19
- * !btcv: Returns the latest value of 1 (one) Bitcoin in USD
20
- USAGE
21
-
22
- match /btcv/
23
-
24
- def execute(m)
25
- data = JSON.parse(open("http://blockchain.info/ticker").read)
26
- value = data['USD']['15m']
27
- m.reply "Current value of 1 BTC in USD is: #{value}", true
28
- end
29
- end
30
- end
31
- end
1
+ require 'cinch'
2
+ require 'ostruct'
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ module Cinch
7
+ module Plugins
8
+ class Bitcoin
9
+ include Cinch::Plugin
10
+
11
+ set :plugin_name, 'bitcoin'
12
+ set :help, <<-USAGE.gsub(/^ {6}/, '')
13
+ Bitcoin plugin that fetches results from Blockchain.info!
14
+ Usage:
15
+ * !btcv <currency>: Returns the latest value of 1 (one) Bitcoin in <currency>
16
+ * !btc <currency> <Bitcoin amount>: Returns the value of <Bitcoin amount> in <currency>.
17
+ USAGE
18
+
19
+ match /btcv (\w{3})/
20
+
21
+ def execute(m, currency)
22
+ data = JSON.parse(open("http://blockchain.info/ticker").read)
23
+
24
+ coins = ['USD', 'CNY', 'JPY', 'SGD', 'HKD', 'CAD', 'NZD', 'AUD', 'CLP', 'GBP', 'HKK', 'SEK', 'ISK', 'CHF', 'BRL', 'EUR', 'RUB', 'PLN', 'THB', 'KRW', 'TWD']
25
+
26
+ currency = currency.upcase
27
+
28
+ if !coins.include?(currency)
29
+ m.reply "That currency isn't in my database!"
30
+ m.user.notice "You can use: #{coins}"
31
+ return
32
+ end
33
+
34
+ value = data[currency]['15m']
35
+ value = value.round(2).to_f
36
+ value = value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
37
+
38
+ symbol = data[currency]['symbol']
39
+
40
+ m.reply "Current value of 1 BTC in #{currency} is: #{symbol}#{value}", true
41
+ end
42
+
43
+ match /btc (\w{3}) (.+)/, method: :conversion
44
+
45
+ def conversion(m, currency, btc)
46
+ data = JSON.parse(open("http://blockchain.info/ticker").read)
47
+
48
+ coins = ['USD', 'CNY', 'JPY', 'SGD', 'HKD', 'CAD', 'NZD', 'AUD', 'CLP', 'GBP', 'HKK', 'SEK', 'ISK', 'CHF', 'BRL', 'EUR', 'RUB', 'PLN', 'THB', 'KRW', 'TWD']
49
+
50
+ currency = currency.upcase
51
+
52
+ if !coins.include?(currency)
53
+ m.reply "That currency isn't in my database!"
54
+ m.user.notice "You can use: #{coins}"
55
+ return
56
+ end
57
+ value = data[currency]['15m']
58
+ value = value.round(2).to_f
59
+
60
+ symbol = data[currency]['symbol']
61
+
62
+ btc = btc.to_f
63
+
64
+ conv = (btc * value).round(2)
65
+ conv = conv.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
66
+
67
+ m.reply "The value of #{btc}BTC is #{symbol}#{conv}.", true
68
+ end
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-bitcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Banks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.0
27
- description: ! 'A gem/plugin for the Cinch IRC Framework that returns the value of
28
- Bitcoin in USD. You can visit irc://rawr.sinsira.net #Lobby to get help, report
29
- issues , test the gem, or just chat.'
27
+ description: 'A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin
28
+ in the specified currency. You can visit irc://rawr.sinsira.net #Lobby to get help,
29
+ report issues , test the gem, or just chat.'
30
30
  email:
31
31
  - namaste@rawrnet.net
32
32
  executables: []
@@ -44,19 +44,19 @@ require_paths:
44
44
  - lib
45
45
  required_ruby_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ! '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubyforge_project: ! '[none]'
57
- rubygems_version: 2.1.11
56
+ rubyforge_project: "[none]"
57
+ rubygems_version: 2.2.2
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: A gem/plugin for the Cinch IRC Framework that returns the value of Bitcoin
61
- in USD.
61
+ in the specified currency.
62
62
  test_files: []