-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Namasteh/master
Version Update Merge
- Loading branch information
Showing
17 changed files
with
1,154 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,71 @@ | ||
require 'cinch' | ||
require 'ostruct' | ||
require 'open-uri' | ||
require 'json' | ||
|
||
module Cinch | ||
module Plugins | ||
class Bitcoin | ||
include Cinch::Plugin | ||
|
||
set :plugin_name, 'bitcoin' | ||
set :help, <<-USAGE.gsub(/^ {6}/, '') | ||
Just a seen plugin! | ||
Usage: | ||
* !btcv: Returns the latest value of 1 (one) Bitcoin in USD | ||
USAGE | ||
|
||
match /btcv/ | ||
|
||
def execute(m) | ||
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 | ||
end | ||
end | ||
end | ||
end | ||
require 'cinch' | ||
require 'ostruct' | ||
require 'open-uri' | ||
require 'json' | ||
|
||
module Cinch | ||
module Plugins | ||
class Bitcoin | ||
include Cinch::Plugin | ||
|
||
set :plugin_name, 'bitcoin' | ||
set :help, <<-USAGE.gsub(/^ {6}/, '') | ||
Bitcoin plugin that fetches results from Blockchain.info! | ||
Usage: | ||
* !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 (\w{3})/ | ||
|
||
def execute(m, currency) | ||
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 | ||
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 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'cinch' | ||
require 'yaml' | ||
|
||
module Cinch | ||
module Helpers | ||
|
||
def check_auth(user) | ||
reload | ||
user.refresh | ||
|
||
return false unless !user.authname.nil? | ||
|
||
if ((@storage.key?(user.nick)) && (@storage[user.nick].key? 'auth')) | ||
auth = @storage[user.nick]['auth'] | ||
return auth == user.authname | ||
end | ||
end | ||
|
||
def reload | ||
if File.exist?('docs/userinfo.yaml') | ||
@storage = YAML.load_file('docs/userinfo.yaml') | ||
else | ||
@storage = {} | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.