cosgrove 0.0.3.5 → 0.0.4.1

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
- SHA1:
3
- metadata.gz: bac465f9c2b8fa574b8c2eacb612a88c7ea82cae
4
- data.tar.gz: 64e6e6994059bd030276924844d3e129a690121e
2
+ SHA256:
3
+ metadata.gz: 15526294d5a338ed4f81a05cb015250914c2b95ec3b62dd3d28a9db927d60bd7
4
+ data.tar.gz: e13d831d7ab03b6bb4e4c620a28f09d8fcb67474a9ad68f21c8406e25f6b3d07
5
5
  SHA512:
6
- metadata.gz: 777b4dc3e3d5bf5d339b7a8dc6203ad43e39e4722e55c0b7ff40a7dfcfa4ac1690dbe358275e4d83d4cdfdfeba439fdd8339ef3f97d092d9b8b3a631a6de607b
7
- data.tar.gz: cd909b21d15bdaef5a9d4961f51c971e277accea8d146b790eb8ad4c0cc3f94721cca82d4f010501c222e55a8a89f50f9685c7420427500a53431b88fd619e7a
6
+ metadata.gz: f3009261e6c0ec7d7f3e626381d561787ae15cfa5b229557bd18980d51c51001a5d80c22184925ad2c8b7b0d4187fa73367698a94fddefab200a39ad9ce94af3
7
+ data.tar.gz: d326e18c087632dfca9302356ad71359a48ac5cf650bf6f29646a85591360276283d9387cd654d24b6c8022f3f00e04a3a729d21d012b0e7d9a0e7fafb21cc41
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
@@ -1,5 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'mechanize', git: 'https://github.com/sparklemotion/mechanize.git', branch: 'upgrade_net-http-persistent'
3
+ gem 'mechanize'
4
+ gem 'pry'
5
+ gem 'irb'
6
+ gem 'rb-readline'
7
+ gem 'hive_sql'
4
8
 
5
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,32 +9,28 @@ 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
- spec.add_development_dependency 'minitest', '~> 5.9', '>= 5.9.0'
24
- spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.3'
23
+ spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
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.11'
29
- # spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
28
+ spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.19'
30
29
 
31
- spec.add_dependency 'radiator', '~> 0.3', '>= 0.3.15'
32
- spec.add_dependency 'steem_data', '~> 0.0', '>= 0.0.3'
33
- spec.add_dependency 'steem_api', '~> 1.1', '>= 1.1.1rc1'
34
- 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'
35
32
  spec.add_dependency 'discordrb', '~> 3.2', '>= 3.2.1'
36
33
  spec.add_dependency 'ai4r', '~> 1.13', '>= 1.13'
37
- spec.add_dependency 'mongoid', '~> 6.1', '>= 6.1.0'
38
34
  spec.add_dependency 'steem-slap', '~> 0.0', '>= 0.0.2'
39
35
  spec.add_dependency 'activesupport', '~> 5.1', '>= 5.1.1'
40
36
  spec.add_dependency 'railties', '~> 5.1', '>= 5.1.1'
@@ -42,6 +38,6 @@ Gem::Specification.new do |spec|
42
38
  spec.add_dependency 'phantomjs', '~> 2.1', '>= 2.1.1.0'
43
39
  spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.5'
44
40
  spec.add_dependency 'wolfram-alpha', '~> 0.3', '>= 0.3.1'
45
- spec.add_dependency 'rmagick', '~> 2.16', '>= 2.16.0'
41
+ spec.add_dependency 'rmagick', '~> 3.1', '>= 3.1.0'
46
42
  spec.add_dependency 'awesome_print', '~> 1.7', '>= 1.7.0'
47
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=
@@ -4,25 +4,15 @@ require 'yaml'
4
4
  require 'action_view'
5
5
  require 'radiator'
6
6
  require 'awesome_print'
7
- require 'steem_data'
8
- require 'steem_api'
9
- require 'golos_cloud'
10
- # require 'irb' # for binding.irb
11
7
  # require 'pry' # for binding.pry
12
8
 
13
9
  Bundler.require
14
10
 
15
11
  defined? Thread.report_on_exception and Thread.report_on_exception = true
16
12
 
17
- SteemData.load
18
-
19
- # This will cause a nil to be returned instead of raising an error, allowing us
20
- # to fall back to SteemApi and/or RPC.
21
- Mongoid.raise_not_found_error = false
22
-
23
13
  module Cosgrove
24
14
  PWD = Dir.pwd.freeze
25
- KNOWN_CHAINS = [:steem, :golos, :test]
15
+ KNOWN_CHAINS = [:steem, :test, :hive]
26
16
 
27
17
  require 'cosgrove/version'
28
18
  require 'cosgrove/phantomjs'
@@ -34,5 +24,6 @@ module Cosgrove
34
24
  require 'cosgrove/market'
35
25
  require 'cosgrove/upvote_job'
36
26
  require 'cosgrove/comment_job'
27
+ require 'cosgrove/find_communities_job'
37
28
  require 'cosgrove/bot'
38
29
  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,13 +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
- mongo_behind_warning(event)
64
56
  if key.nil?
65
- 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}"
66
58
  return
67
59
  end
68
60
 
@@ -94,10 +86,9 @@ module Cosgrove
94
86
  end
95
87
  end
96
88
 
97
- self.command :register do |event, account_name, chain = :steem|
89
+ self.command :register do |event, account_name, chain = :hive|
98
90
  return if event.channel.pm? && !cosgrove_allow_pm_commands
99
91
 
100
- mongo_behind_warning(event)
101
92
  discord_id = event.author.id
102
93
 
103
94
  if discord_id.to_i == 0
@@ -120,7 +111,7 @@ module Cosgrove
120
111
  end
121
112
 
122
113
  memo_key = cb_account.memo_key(discord_id)
123
- 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)
124
115
 
125
116
  if !!op
126
117
  cb_account.add_discord_id(discord_id)
@@ -136,7 +127,7 @@ module Cosgrove
136
127
 
137
128
  "Ok. #{chain.to_s.upcase} account #{account.name} has been registered with <@#{discord_id}>."
138
129
  else
139
- "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."
140
131
  end
141
132
  end
142
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