cinch-altcoin 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +46 -0
  3. data/lib/cinch/plugins/cinch-altcoin.rb +151 -0
  4. metadata +65 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Richard Banks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ cinch-altcoin
2
+ =============
3
+
4
+ ***Description:***
5
+
6
+ The *AltCoin* plugin allows users to query cryptocoin market data using three different APIs.
7
+
8
+ ***Dependencies:***
9
+
10
+ - JSON
11
+ - Open-URI
12
+ - OStruct
13
+
14
+ All of these dependencies are available on Ruby 1.9+ out of the box.
15
+
16
+ ***Configuration:***
17
+
18
+ In order for this plugin to work the following is required to insert into bot.rb for operation.
19
+
20
+ At the beginning of Eve.rb in the required scripts section put this:
21
+
22
+ require 'cinch-altcoin'
23
+
24
+ In the c.plugins section of bot.rb put this:
25
+
26
+ [Cinch::Plugins::AltCoin]
27
+
28
+ No API keys are needed for this plugin as it utilizes a RESTful API and does not query data that isn't public.
29
+
30
+ ***Usage:***
31
+
32
+ The bot comes with a comprehensive help system and the *AltCoin* plugin was incorporated by default. You can use the !help coinquery command to get a full list of commands:
33
+
34
+ * **!coin (altcoin) (conventional currency)**: This will query the API and return the value of (altcoin) in (conventional currency).
35
+ * !**coin market (altcoin) (altcoin/conventional currency)**: This will query the API and return the current market data of (altcoin) in (altcoin/conventional currency).
36
+ * **!coin pairs**: This will notice you a list of all the valid pairs of currency you can use to query the bot. This does not include all conventional currency.
37
+
38
+ Here are some examples of the plugin in use:
39
+
40
+ > [23:29:41] <@Namaste> !coin market btc usd
41
+ > [23:29:42] <@Eve> Namaste, BTC - USD | Last Price: 633 USD - High:
42
+ > 634.501 USD - Low: 601 USD - Average: 607.971 USD - Selling Price: 634 USD - Buying Price: 605 USD
43
+ >
44
+ > [23:29:57] <@Namaste> !coin btc usd
45
+ > [23:29:59] <@Eve> Namaste, the current BTC price in USD is 587.45.
46
+
@@ -0,0 +1,151 @@
1
+ require 'cinch'
2
+ require 'ostruct'
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ module Cinch
7
+ module Plugins
8
+ class AltCoin
9
+ include Cinch::Plugin
10
+
11
+ set :plugin_name, 'coinquery'
12
+ set :help, <<-USAGE.gsub(/^ {6}/, '')
13
+ You can use the bot to check market and value data on nearly every cryptocoin!
14
+ Usage:
15
+ * !coin <altcoin> <conventional currency>: This will query the API and return the value of <altcoin> in <conventional currency>.
16
+ * !coin market <altcoin> <altcoin/conventional currency>: This will query the API and return the current market data of <altcoin> in <altcoin/conventional currency>.
17
+ * !coin pairs: This will notice you a list of all the valid pairs of currency you can use to query the bot. This does not include all conventional currency.
18
+ USAGE
19
+
20
+ TickerURL = 'https://www.cryptonator.com/api/full/'
21
+
22
+ ConversionURL = 'http://rate-exchange.appspot.com/currency?from=USD&to='
23
+
24
+ MarketURL = 'http://data.bter.com/api/1/ticker/'
25
+
26
+ def error(data, nick, pair)
27
+ eMSG = data['message']
28
+ if eMSG
29
+ m.reply "#{nick}, #{eMSG} '#{pair}'"
30
+ end
31
+ else
32
+ m.reply "I'm sorry, there's been an unspecified error, #{nick}."
33
+ end
34
+
35
+ match /coin (.+?) (.+)/i, method: :value
36
+
37
+ def value(m, cur1, cur2)
38
+ return if cur1 == "market"
39
+
40
+ data = JSON.parse(open("#{TickerURL}#{cur1}-#{cur2}").read)
41
+ info = data['ticker']
42
+ success = data['success']
43
+
44
+ return error(data, nick, pair) if success == false
45
+
46
+ if success == true
47
+ price = info['price']
48
+ target = info['target']
49
+ base = info['base']
50
+
51
+ price = sprintf("%.2f", price)
52
+ price = price.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
53
+
54
+ m.reply "#{m.user.nick}, the current #{base} price in #{target} is #{price}."
55
+ return
56
+ end
57
+ m.reply "Error: #{$!}"
58
+ end
59
+
60
+ def conversion(original, currency, value)
61
+ data = JSON.parse(open("#{ConversionURL}#{currency}&q=#{value}").read)
62
+
63
+ return false if data['err']
64
+
65
+ cValue = data['v']
66
+ cValue = sprintf("%.2f", cValue)
67
+ cValue = cValue.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
68
+
69
+ return cValue
70
+ end
71
+
72
+ match /coin pairs/i, method: :list_pairs
73
+
74
+ def list_pairs(m)
75
+ pairs = JSON.parse(open("http://data.bter.com/api/1/pairs").read)
76
+ pairs = pairs.to_s.gsub(/_/, ' ').split(", ")
77
+
78
+ m.user.notice "#{pairs.join(", ").to_s}"
79
+ m.user.notice "If you are trying to compare a cryptocoin to a conventional currency try \"!coin market <cryptocurrency> <conventional currency>\""
80
+ end
81
+
82
+ match /coin market (.+?) (.+)/i, method: :market
83
+
84
+ def market(m, cur1, cur2)
85
+ return if check_ignore(m.user)
86
+
87
+ data = JSON.parse(open("#{MarketURL}#{cur1}_usd").read)
88
+
89
+ alt = JSON.parse(open("#{MarketURL}#{cur1}_#{cur2}").read)
90
+ pair = "#{cur1}_#{cur2}"
91
+ pairs = JSON.parse(open("http://data.bter.com/api/1/pairs").read)
92
+
93
+ original = "USD"
94
+
95
+ currency = cur2
96
+
97
+ testVar = "1.00"
98
+
99
+ if pairs.include? pair.downcase
100
+ last = alt['last']
101
+ high = alt['high']
102
+ low = alt['low']
103
+ avg = alt['avg']
104
+ sell = alt['sell']
105
+ buy = alt['buy']
106
+
107
+ m.reply "#{m.user.nick}, #{cur1.upcase} - #{cur2.upcase} | Last Price: #{last} #{cur2.upcase} - High: #{high} #{cur2.upcase} - Low: #{low} #{cur2.upcase} - Average: #{avg} #{cur2.upcase} - Selling Price: #{sell} #{cur2.upcase} - Buying Price: #{buy} #{cur2.upcase}"
108
+ end
109
+
110
+ if !pairs.include? pair.downcase
111
+ if data['result'] == 'true'
112
+
113
+ return m.reply "#{m.user.nick}, I'm sorry, I can't find #{cur2.upcase} in my conversion array! If you're trying to compare cryptocoin pairs you can type !coin pairs to get valid pairs!" if conversion(original, currency, testVar) == false
114
+
115
+ last = data['last']
116
+ last = conversion(original, currency, last)
117
+
118
+ high = data['high']
119
+ high = conversion(original, currency, high)
120
+
121
+ low = data['low']
122
+ low = conversion(original, currency, low)
123
+
124
+ avg = data['avg']
125
+ avg = conversion(original, currency, avg)
126
+
127
+ sell = data['sell']
128
+ sell = conversion(original, currency, sell)
129
+
130
+ buy = data['buy']
131
+ buy = conversion(original, currency, buy)
132
+
133
+ currency = currency.upcase
134
+
135
+ m.reply "#{m.user.nick}, #{cur1.upcase} - #{currency} | Last Price: #{last} #{currency} - High: #{high} #{currency} - Low: #{low} #{currency} - Average: #{avg} #{currency} - Selling Price: #{sell} #{currency} - Buying Price: #{buy} #{currency}"
136
+
137
+ return
138
+ end
139
+ m.reply "I'm sorry, there seems to be a problem finding your query!"
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ ## Written by Richard Banks.
147
+ ## E-mail: namaste@rawrnet.net
148
+ ## Github: Namasteh
149
+ ## Website: www.rawrnet.net
150
+ ## IRC: irc.sinsira.net #Eve
151
+ ## If you like this plugin please consider tipping me on gittip
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-altcoin
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Richard Banks
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cinch
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2'
30
+ description: A Cinch plugin to get information on all altcoins.
31
+ email:
32
+ - namaste@rawrnet.net
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - lib/cinch/plugins/cinch-altcoin.rb
40
+ homepage: https://github.com/Namasteh/cinch-altcoin
41
+ licenses:
42
+ - MIT
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.9.1
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A Cinch plugin to get information on all altcoins.
65
+ test_files: []