cosgrove 0.0.4.0pre1 → 0.0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30ef938779ca56743ce5f8a4fa9612e251dc98d92fd0b7f92d30cf6fcbb9cc13
4
- data.tar.gz: 31e31742772dc409ca264638289b13eab63952686d5d4eb10e7d0a87b318d16e
3
+ metadata.gz: efb209c5f0f662a9349985ef8ab92f9d1fe1c0a3258f0de835dbcde2ec5ceb82
4
+ data.tar.gz: 8e68041725387f5f185e70b2bcbb17dc967369a4c902d67ef762aeb502c0e5a4
5
5
  SHA512:
6
- metadata.gz: a39ed8012f5c4baa02be75eafdd19def80d4f27d55f924a1b0214592843a0f33bc2db5ebf2620e57e6c5fc5ba21df5ed8fe6d73dfc97943d5dd3764217fb51cb
7
- data.tar.gz: 0a0d21235b281c8085e90e65f675c6300f7825a78594e4aa475f60e593889284d3a8237915d15d0104f149da0b8ca5ef08e4a2a6ed5ed9e882f466f0e0824374
6
+ metadata.gz: 61c5b3993d782a364df886c529d5067b5a406394884712cc475d4773ce01ff23244847ce2dd62545a0c6d9d7bb0fa1b0e7120675a298a09cbc98dc18596e8dd7
7
+ data.tar.gz: 95c8ea965a0403663a0bb2bcbbfa892aee092f1e1fe8c0f6e00dccc0c12f6b3d4c6f1e313b68167a10cc9dca7dfd7b2c8fa937fb3a91d7e9c3fc9ed1334f1d92
data/.gitignore CHANGED
@@ -42,7 +42,7 @@ build-iPhoneSimulator/
42
42
 
43
43
  # for a library or gem, you might want to ignore these files since the code is
44
44
  # intended to run in multiple environments; otherwise, check them in:
45
- # Gemfile.lock
45
+ Gemfile.lock
46
46
  # .ruby-version
47
47
  # .ruby-gemset
48
48
 
data/Gemfile CHANGED
@@ -2,5 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'mechanize'
4
4
  gem 'pry'
5
+ gem 'irb'
6
+ gem 'rb-readline'
7
+ gem 'hive_sql'
5
8
 
6
9
  gemspec
data/README.md CHANGED
@@ -4,11 +4,10 @@ Cosgrove is a STEEM Centric Discord Bot Framework that allows you to write your
4
4
 
5
5
  One example of a bot that uses this framework is [@banjo](https://steemit.com/steemdata/@inertia/introducing-banjo) on SteemSpeak.
6
6
 
7
- Many (not all) features work on Golos as well.
8
-
9
7
  ## New features
10
-
11
- * Added support for SteemApi as a fallback to SteemData.
8
+
9
+ * Engine support provided by the `Cosgrove::Utils` module.
10
+ * Bug fixes
12
11
  * Gem updates.
13
12
 
14
13
  ## Features
@@ -28,6 +27,8 @@ Many (not all) features work on Golos as well.
28
27
  * Callback `on_success_upvote_job` which can be used to, for example, reply to the post after being upvoted.
29
28
  * Market data now uses Bittrex instead of Poloniex.
30
29
  * `operators` to keep track of steem accounts that can do things like block upvotes (by blockchain mute).
30
+ * Support for HiveSQL
31
+ * Optimized interactive messages to update as data is acquired in realtime
31
32
 
32
33
  ## Installation
33
34
 
@@ -65,10 +66,12 @@ Add a config file to your `ruby` project called `config.yml`:
65
66
  :chain:
66
67
  :steem_account:
67
68
  :steem_posting_wif:
68
- :golos_account:
69
- :golos_posting_wif:
70
69
  :steem_api_url: https://api.steemit.com
71
- :golos_api_url: https://ws.golos.io
70
+ :steem_engine_api_url: https://api.steem-engine.com/rpc
71
+ :hive_engine_api_url: https://api.hive-engine.com/rpc
72
+ :hive_account:
73
+ :hive_posting_wif:
74
+ :hive_api_url: https://api.steem.house
72
75
  :discord:
73
76
  :log_mode: info
74
77
  ```
@@ -91,6 +94,24 @@ SecureRandom.hex(32)
91
94
  4. Give that URL to the Discord server/guild owner and have them authorize the bot.
92
95
  5. Set the `token` and `client_id` in your bot constructor (see below).
93
96
 
97
+ ## HiveSQL
98
+
99
+ Some features provided by `cosgrove` require access to [HiveSQL](http://hivesql.io/), which is a Microsoft SQL database containing all the Steem blockchain data.
100
+
101
+ **Please note:**
102
+
103
+ If you intend to use HiveSQL, you can provide the credentials in `authorize-hive-sql.sh`, then use this terminal command to enable HiveSQL just before running your bot. Copy the example `example-authorize-hive-sql.sh` and add your credentials:
104
+
105
+ ```bash
106
+ source path/to/authorize-hive-sql.sh
107
+ ```
108
+
109
+ Features that currently require HiveSQL:
110
+
111
+ * Details in `$mvests` command
112
+ * Any command that tries to suggest account names
113
+ * `$upvote` (when checking for dailly limits)
114
+
94
115
  ## Usage
95
116
 
96
117
  Cosgrove is based on `discordrb`, see: https://github.com/meew0/discordrb
@@ -111,6 +132,34 @@ end
111
132
  bot.run
112
133
  ```
113
134
 
135
+ ### Engine Lookups
136
+
137
+ Here's an example of a bot that does Engine API calls when you type: `$bal ENG alice`
138
+
139
+ ```ruby
140
+ require 'cosgrove'
141
+
142
+ include Cosgrove::Utils
143
+
144
+ bot = Cosgrove::Bot.new
145
+
146
+ bot.command :bal do |event, *args|
147
+ symbol = args[0].strip.upcase
148
+ account = args[0].strip.downcase
149
+ params = {
150
+ query: {
151
+ symbol: symbol,
152
+ account: account
153
+ }
154
+ }
155
+ result = steem_engine_contracts(:findOne, params)
156
+
157
+ "#{result['balance']}'s '#{result['symbol']}: #{result['balance']}"
158
+ end
159
+
160
+ bot.run
161
+ ```
162
+
114
163
  ## Tests
115
164
 
116
165
  * Clone the client repository into a directory of your choice:
@@ -131,6 +180,7 @@ bot.run
131
180
  See my previous Ruby How To posts in: [#radiator](https://steemit.com/created/radiator) [#ruby](https://steemit.com/created/ruby)
132
181
 
133
182
  Also see:
183
+ * [Cosgrove: Database Update](https://steemit.com/radiator/@inertia/cosgrove-database-update)
134
184
  * [Introducing: Cosgrove - A STEEM Centric Discord Bot Framework](https://steemit.com/radiator/@inertia/introducing-cosgrove-a-steem-centric-discord-bot-framework)
135
185
  * [How to Write a Discord Bot in Ruby](https://steemit.com/radiator/@inertia/how-to-write-a-discord-bot-in-ruby)
136
186
 
@@ -9,27 +9,26 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Anthony Martin']
10
10
  spec.email = ['cosgrove@martin-studio.com']
11
11
 
12
- spec.summary = %q{Cosgrove Discord Bo t}
13
- spec.description = %q{STEEM centric Discord bot.}
12
+ spec.summary = %q{Cosgrove Discord Bot}
13
+ spec.description = %q{Hive centric Discord bot.}
14
14
  spec.homepage = 'https://github.com/steem-third-party/cosgrove'
15
- spec.license = 'CC0 1.0'
15
+ spec.license = 'CC0-1.0'
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency 'bundler', '~> 1.15', '>= 1.15.4'
20
+ spec.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
21
21
  spec.add_development_dependency 'rake', '~> 12.1', '>= 12.1.0'
22
22
  spec.add_development_dependency 'minitest-proveit', '~> 1.0', '>= 1.0.0'
23
23
  spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
24
24
  spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.4'
25
25
  spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
26
- spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
26
+ spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
27
27
  spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
28
- spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.16'
28
+ spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.19'
29
29
 
30
- spec.add_dependency 'radiator', '~> 0.4', '>= 0.4.3'
31
- spec.add_dependency 'steem_api', '~> 1.1', '>= 1.1.1rc1'
32
- spec.add_dependency 'golos_cloud', '~> 1.1', '>= 1.1.1rc1'
30
+ spec.add_dependency 'radiator', '~> 0.4', '>= 0.4.8'
31
+ spec.add_dependency 'hive_sql'#, '~> 1.0', '>= 1.0.0'
33
32
  spec.add_dependency 'discordrb', '~> 3.2', '>= 3.2.1'
34
33
  spec.add_dependency 'ai4r', '~> 1.13', '>= 1.13'
35
34
  spec.add_dependency 'steem-slap', '~> 0.0', '>= 0.0.2'
@@ -39,6 +38,6 @@ Gem::Specification.new do |spec|
39
38
  spec.add_dependency 'phantomjs', '~> 2.1', '>= 2.1.1.0'
40
39
  spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.5'
41
40
  spec.add_dependency 'wolfram-alpha', '~> 0.3', '>= 0.3.1'
42
- spec.add_dependency 'rmagick', '~> 2.16', '>= 2.16.0'
41
+ spec.add_dependency 'rmagick', '~> 3.1', '>= 3.1.0'
43
42
  spec.add_dependency 'awesome_print', '~> 1.7', '>= 1.7.0'
44
43
  end
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ export HIVESQL_HOST=vip.hivesql.io
4
+ export HIVESQL_USERNAME=
5
+ export HIVESQL_PASSWORD=
@@ -1,11 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'yaml'
4
+ require 'active_support'
4
5
  require 'action_view'
5
6
  require 'radiator'
6
7
  require 'awesome_print'
7
- require 'steem_api'
8
- require 'golos_cloud'
9
8
  # require 'pry' # for binding.pry
10
9
 
11
10
  Bundler.require
@@ -14,7 +13,7 @@ defined? Thread.report_on_exception and Thread.report_on_exception = true
14
13
 
15
14
  module Cosgrove
16
15
  PWD = Dir.pwd.freeze
17
- KNOWN_CHAINS = [:steem, :test]
16
+ KNOWN_CHAINS = [:steem, :test, :hive]
18
17
 
19
18
  require 'cosgrove/version'
20
19
  require 'cosgrove/phantomjs'
@@ -26,5 +25,6 @@ module Cosgrove
26
25
  require 'cosgrove/market'
27
26
  require 'cosgrove/upvote_job'
28
27
  require 'cosgrove/comment_job'
28
+ require 'cosgrove/find_communities_job'
29
29
  require 'cosgrove/bot'
30
30
  end
@@ -1,4 +1,5 @@
1
1
  require 'digest/bubblebabble'
2
+ require "yaml/store"
2
3
 
3
4
  module Cosgrove
4
5
  class Account
@@ -10,7 +11,7 @@ module Cosgrove
10
11
 
11
12
  attr_accessor :account_name, :discord_ids
12
13
 
13
- def initialize(account_name, chain = :steem)
14
+ def initialize(account_name, chain = :hive)
14
15
  @chain = chain.to_sym
15
16
  raise "Unknown Chain: #{@chain}" unless Cosgrove::KNOWN_CHAINS.include? @chain
16
17
 
@@ -22,14 +23,14 @@ module Cosgrove
22
23
  end
23
24
  end
24
25
 
25
- def self.find_by_discord_id(discord_id, chain = :steem)
26
- return if Account.yml[chain.to_s].nil?
26
+ def self.find_by_discord_id(discord_id, chain = :hive)
27
+ return if Account.chain_data(chain.to_s).nil?
27
28
 
28
29
  discord_id = discord_id.to_s.split('@').last.split('>').first.to_i
29
30
 
30
31
  return nil if discord_id == 0
31
32
 
32
- Account.yml[chain.to_s].each do |k, v|
33
+ Account.chain_data(chain.to_s).each do |k, v|
33
34
  ids = v[DISCORD_IDS]
34
35
  return Account.new(k, chain) if !!ids && ids.include?(discord_id)
35
36
  end
@@ -37,8 +38,8 @@ module Cosgrove
37
38
  return nil
38
39
  end
39
40
 
40
- def self.find_by_memo_key(memo_key, secure, chain = :steem)
41
- Account.yml[chain.to_s].each do |k, v|
41
+ def self.find_by_memo_key(memo_key, secure, chain = :hive)
42
+ Account.chain_data(chain.to_s).each do |k, v|
42
43
  v[DISCORD_IDS].each do |discord_id|
43
44
  return Account.new(k, chain) if Account.gen_memo_key(k, discord_id, secure, chain) == memo_key
44
45
  end
@@ -47,13 +48,9 @@ module Cosgrove
47
48
  return nil
48
49
  end
49
50
 
50
- def chain_data
51
- @chain_data ||= Account.yml[@chain.to_s] || {}
52
- end
53
-
54
- def details
55
- chain_data[@account_name] ||= {}
56
- chain_data[@account_name]
51
+ def details(chain = :hive)
52
+ Account.chain_data(chain.to_s)[@account_name] ||= {}
53
+ Account.chain_data(chain.to_s)[@account_name]
57
54
  end
58
55
 
59
56
  def hidden?
@@ -69,7 +66,7 @@ module Cosgrove
69
66
  details[DISCORD_IDS] << discord_id.to_i
70
67
  details[DISCORD_IDS] = details[DISCORD_IDS].uniq
71
68
 
72
- Account.save_yml!
69
+ Account.save_chain_data!(:hive)
73
70
  end
74
71
 
75
72
  def memo_key(discord_id)
@@ -111,5 +108,21 @@ module Cosgrove
111
108
  {}
112
109
  end
113
110
  end
111
+
112
+ def self.store
113
+ @store ||= YAML::Store.new(ACCOUNTS_FILE)
114
+ end
115
+
116
+ def self.save_chain_data!(chain, data = @chain_data)
117
+ store.transaction {
118
+ store[chain] = data
119
+ }
120
+ end
121
+
122
+ def self.chain_data(chain)
123
+ store.transaction {
124
+ @chain_data = store[chain] || {}
125
+ }
126
+ end
114
127
  end
115
128
  end
@@ -3,10 +3,9 @@ require 'discordrb'
3
3
  module Cosgrove
4
4
  require 'cosgrove/snark_commands'
5
5
 
6
- cattr_accessor :latest_steemit_link, :latest_golos_link
6
+ cattr_accessor :latest_steemit_link
7
7
 
8
8
  @@latest_steemit_link = {}
9
- @@latest_golosio_link = {}
10
9
 
11
10
  class Bot < Discordrb::Commands::CommandBot
12
11
  include Support
@@ -28,18 +27,12 @@ module Cosgrove
28
27
  end
29
28
 
30
29
  def add_all_messages
31
- # A user typed a link to steemit.com
32
- self.message(content: /http[s]*:\/\/steemit\.com\/.*/, ignore_bots: false) do |event|
30
+ # A user typed a link to steemit.com (or some condenser site)
31
+ self.message(content: /http[s]*:\/\/.*\/(.*\/)?@.+\/.+/, ignore_bots: false) do |event|
33
32
  link = event.content.split(' ').first
34
33
  Cosgrove::latest_steemit_link[event.channel.name] = link
35
34
  append_link_details(event, link)
36
35
  end
37
-
38
- # A user typed a link to golos.io.
39
- self.message(content: /http[s]*:\/\/golos\.io\/.*/, ignore_bots: false) do |event|
40
- link = event.content.split(' ').first
41
- Cosgrove::latest_golosio_link[event.channel.name] = link
42
- end
43
36
  end
44
37
 
45
38
  def add_all_commands
@@ -48,7 +41,7 @@ module Cosgrove
48
41
  help << "`$slap [target]` - does a slap on the `target`"
49
42
  help << "`$verify <account> [chain]` - check `account` association with Discord users (`chain` default `steem`)"
50
43
  help << "`$register <account> [chain]` - associate `account` with your Discord user (`chain` default `steem`)"
51
- help << "`$upvote [url]` - upvote from #{steem_account}; empty or `^` to upvote last steemit link"
44
+ help << "`$upvote [url]` - upvote from #{hive_account}; empty or `^` to upvote last steemit link"
52
45
  help.join("\n")
53
46
  end
54
47
 
@@ -56,12 +49,12 @@ module Cosgrove
56
49
  "cosgrove: #{Cosgrove::VERSION} :: https://github.com/steem-third-party/cosgrove"
57
50
  end
58
51
 
59
- self.command :verify do |event, key, chain = :steem|
52
+ self.command :verify do |event, key, chain = :hive|
60
53
  return if event.channel.pm? && !cosgrove_allow_pm_commands
61
54
  cb_account = nil
62
55
 
63
56
  if key.nil?
64
- event.respond "To create an account: https://steemit.com/enter_email?r=#{steem_account}"
57
+ event.respond "To create an account: https://hive.blog/enter_email?r=#{hive_account}"
65
58
  return
66
59
  end
67
60
 
@@ -93,7 +86,7 @@ module Cosgrove
93
86
  end
94
87
  end
95
88
 
96
- self.command :register do |event, account_name, chain = :steem|
89
+ self.command :register do |event, account_name, chain = :hive|
97
90
  return if event.channel.pm? && !cosgrove_allow_pm_commands
98
91
 
99
92
  discord_id = event.author.id
@@ -118,7 +111,7 @@ module Cosgrove
118
111
  end
119
112
 
120
113
  memo_key = cb_account.memo_key(discord_id)
121
- op = find_transfer(chain: chain, account: steem_account, from: account.name, to: steem_account, memo_key: memo_key)
114
+ op = find_transfer(chain: chain, account: hive_account, from: account.name, to: hive_account, memo_key: memo_key)
122
115
 
123
116
  if !!op
124
117
  cb_account.add_discord_id(discord_id)
@@ -134,7 +127,7 @@ module Cosgrove
134
127
 
135
128
  "Ok. #{chain.to_s.upcase} account #{account.name} has been registered with <@#{discord_id}>."
136
129
  else
137
- "To register `#{account.name}` with <@#{discord_id}>, send `0.001 #{core_asset}` or `0.001 #{debt_asset}` to `#{steem_account}` with memo: `#{memo_key}`\n\nThen type `$register #{account.name}` again."
130
+ "To register `#{account.name}` with <@#{discord_id}>, send `0.001 #{core_asset}` or `0.001 #{debt_asset}` to `#{hive_account}` with memo: `#{memo_key}`\n\nThen type `$register #{account.name}` again."
138
131
  end
139
132
  end
140
133
 
@@ -6,9 +6,9 @@ module Cosgrove
6
6
  include Support
7
7
 
8
8
  def perform(event, slug, template, message = nil)
9
- chain = :steem
9
+ chain = :hive
10
10
  author_name, permlink = parse_slug slug
11
- muted = muted by: steem_account, chain: chain
11
+ muted = muted by: hive_account, chain: chain
12
12
 
13
13
  author = find_author(chain: chain, author_name: author_name)
14
14
 
@@ -50,7 +50,7 @@ module Cosgrove
50
50
  'Unable to vote.'
51
51
  # elsif template == :welcome && author.post_count != 1
52
52
  # 'Sorry, this function is intended to welcome new authors.'
53
- elsif find_comment(chain: :steem, author_name: steem_account, parent_permlink: post.permlink).any?
53
+ elsif find_comment(chain: :hive, author_name: hive_account, parent_permlink: post.permlink).any?
54
54
  title = post.title
55
55
  title = post.permlink if title.empty?
56
56
  "I already commented on #{title} by #{post.author}."
@@ -65,7 +65,7 @@ module Cosgrove
65
65
  comment = {
66
66
  type: :comment,
67
67
  parent_permlink: post.permlink,
68
- author: steem_account,
68
+ author: hive_account,
69
69
  permlink: "re-#{post.author.gsub(/[^a-z0-9\-]+/, '-')}-#{post.permlink}-#{now.utc.strftime('%Y%m%dt%H%M%S%Lz')}", # e.g.: 20170225t235138025z
70
70
  title: '',
71
71
  body: merge(template, message, event.author.username),
@@ -36,12 +36,12 @@ module Cosgrove
36
36
  [chain[:steem_api_failover_urls]].flatten.compact
37
37
  end
38
38
 
39
- def golos_api_url
40
- chain[:golos_api_url]
39
+ def hive_api_url
40
+ chain[:hive_api_url]
41
41
  end
42
42
 
43
- def golos_api_failover_urls
44
- [chain[:golos_api_failover_urls]].flatten.compact
43
+ def hive_api_failover_urls
44
+ [chain[:hive_api_failover_urls]].flatten.compact
45
45
  end
46
46
 
47
47
  def test_api_url
@@ -52,6 +52,14 @@ module Cosgrove
52
52
  [chain[:test_api_failover_urls]].flatten.compact
53
53
  end
54
54
 
55
+ def steem_engine_api_url
56
+ (chain[:steem_engine_api_url] rescue nil) || 'https://api.steem-engine.com/rpc'
57
+ end
58
+
59
+ def hive_engine_api_url
60
+ (chain[:hive_engine_api_url] rescue nil) || 'https://api.hive-engine.com/rpc'
61
+ end
62
+
55
63
  def steem_account
56
64
  chain[:steem_account]
57
65
  end
@@ -60,18 +68,22 @@ module Cosgrove
60
68
  chain[:steem_posting_wif]
61
69
  end
62
70
 
63
- def golos_account
64
- chain[:golos_account]
71
+ def hive_account
72
+ chain[:hive_account]
65
73
  end
66
74
 
67
- def golos_posting_wif
68
- chain[:golos_posting_wif]
75
+ def hive_posting_wif
76
+ chain[:hive_posting_wif]
69
77
  end
70
78
 
71
79
  def test_posting_wif
72
80
  chain[:test_posting_wif]
73
81
  end
74
82
 
83
+ def meeseeker_url
84
+ chain[:meeseeker][:url]
85
+ end
86
+
75
87
  def discord_channels
76
88
  return ENV['CHANNELS'].to_s.split(' ') if !!ENV['CHANNELS']
77
89