cosgrove 0.0.4.0pre3 → 0.0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4199a721cb39937e39933953807d5c4260530443cad30ef3158c899f3dcb673f
4
- data.tar.gz: 9e59b88a764d8039d58ff8104beafc79dbc01bfbdb73f6f2f5de0d311cbe157b
3
+ metadata.gz: ac52acfd0be7b7e7002d387b8fce1a1117445b85013718d37ccadfba1ecdbe26
4
+ data.tar.gz: 493af9d457fb7a85f6a7884213231d2205586c8dc90c8565fb917a0a7c2c6053
5
5
  SHA512:
6
- metadata.gz: 4a0ed9862bee58cdfcf793f7606b3c59a7ddb5c90db3d0b620937adce79caff76f1343eff326aba285a2b3fc8231f8703234ca9d89dddd760be61d1f8f991e2d
7
- data.tar.gz: d7fbcaebb0f4fa4f947e0438f333a8a1b4a6d56ef785f508c43b47f503170aca9a846e113cbbae4512521da2490237b898cac9cd610ba746572147d086896cf3
6
+ metadata.gz: dccc4c63467587e805a4f3b0f264a482c0c0169c45a7c1de463427d8e95ad1211ea512d52665e16f3c7472760ab77627a2f0cd8c942981b7f818569d8801bbe3
7
+ data.tar.gz: 6f3245b5cfcb629cae002adf24b59f61dddd31b37ff00476bb69a173df84f5dc197221f1cdb3a026b9ff3003d31e4903d660f8d491765bc3e8308636bd149e67
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
- Gemfile.lock
3
2
  *.rbc
4
3
  /.config
5
4
  /coverage/
@@ -43,7 +42,7 @@ build-iPhoneSimulator/
43
42
 
44
43
  # for a library or gem, you might want to ignore these files since the code is
45
44
  # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
45
+ Gemfile.lock
47
46
  # .ruby-version
48
47
  # .ruby-gemset
49
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
@@ -5,9 +5,9 @@ Cosgrove is a STEEM Centric Discord Bot Framework that allows you to write your
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
7
  ## New features
8
-
9
- * Support for SteemApi (replacing SteemData)
10
- * Optimized interactive messages to update as data is queried
8
+
9
+ * Engine support provided by the `Cosgrove::Utils` module.
10
+ * Bug fixes
11
11
  * Gem updates.
12
12
 
13
13
  ## Features
@@ -27,6 +27,8 @@ One example of a bot that uses this framework is [@banjo](https://steemit.com/st
27
27
  * Callback `on_success_upvote_job` which can be used to, for example, reply to the post after being upvoted.
28
28
  * Market data now uses Bittrex instead of Poloniex.
29
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
30
32
 
31
33
  ## Installation
32
34
 
@@ -65,6 +67,11 @@ Add a config file to your `ruby` project called `config.yml`:
65
67
  :steem_account:
66
68
  :steem_posting_wif:
67
69
  :steem_api_url: https://api.steemit.com
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
68
75
  :discord:
69
76
  :log_mode: info
70
77
  ```
@@ -87,21 +94,19 @@ SecureRandom.hex(32)
87
94
  4. Give that URL to the Discord server/guild owner and have them authorize the bot.
88
95
  5. Set the `token` and `client_id` in your bot constructor (see below).
89
96
 
90
- ## SteemSQL
97
+ ## HiveSQL
91
98
 
92
- Some features provided by `cosgrove` require access to [SteemSQL](http://steemsql.com/), which is a Microsoft SQL database containing all the Steem blockchain data.
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.
93
100
 
94
101
  **Please note:**
95
102
 
96
- > SteemSQL has moved to a monthly subscription model and the default free account/password “steemit/steemit” has been disabled.
97
-
98
- If you intend to use SteemSQL, you can provide the credentials in `authorize-steem-sql.sh`, then use this terminal command to enable SteemSQL just before running your bot. Copy the example `example-authorize-steem-sql.sh` and add your credentials:
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:
99
104
 
100
105
  ```bash
101
- source path/to/authorize-steem-sql.sh
106
+ source path/to/authorize-hive-sql.sh
102
107
  ```
103
108
 
104
- Features that currently require SteemSQL:
109
+ Features that currently require HiveSQL:
105
110
 
106
111
  * Details in `$mvests` command
107
112
  * Any command that tries to suggest account names
@@ -127,6 +132,34 @@ end
127
132
  bot.run
128
133
  ```
129
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
+
130
163
  ## Tests
131
164
 
132
165
  * Clone the client repository into a directory of your choice:
@@ -147,6 +180,7 @@ bot.run
147
180
  See my previous Ruby How To posts in: [#radiator](https://steemit.com/created/radiator) [#ruby](https://steemit.com/created/ruby)
148
181
 
149
182
  Also see:
183
+ * [Cosgrove: Database Update](https://steemit.com/radiator/@inertia/cosgrove-database-update)
150
184
  * [Introducing: Cosgrove - A STEEM Centric Discord Bot Framework](https://steemit.com/radiator/@inertia/introducing-cosgrove-a-steem-centric-discord-bot-framework)
151
185
  * [How to Write a Discord Bot in Ruby](https://steemit.com/radiator/@inertia/how-to-write-a-discord-bot-in-ruby)
152
186
 
@@ -9,7 +9,7 @@ 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}
12
+ spec.summary = %q{Cosgrove Discord Bot}
13
13
  spec.description = %q{STEEM centric Discord bot.}
14
14
  spec.homepage = 'https://github.com/steem-third-party/cosgrove'
15
15
  spec.license = 'CC0-1.0'
@@ -17,27 +17,27 @@ Gem::Specification.new do |spec|
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.2pre3'
30
+ spec.add_dependency 'radiator', '~> 0.4', '>= 0.4.8'
31
+ spec.add_dependency 'hive_sql', '~> 1.0', '>= 1.0.2'
32
32
  spec.add_dependency 'discordrb', '~> 3.2', '>= 3.2.1'
33
33
  spec.add_dependency 'ai4r', '~> 1.13', '>= 1.13'
34
34
  spec.add_dependency 'steem-slap', '~> 0.0', '>= 0.0.2'
35
- spec.add_dependency 'activesupport', '~> 5.1', '>= 5.1.1'
36
- spec.add_dependency 'railties', '~> 5.1', '>= 5.1.1'
35
+ spec.add_dependency 'activesupport', '~> 6.0', '>= 6.0.3'
36
+ spec.add_dependency 'railties', '~> 6.0', '>= 6.0.3'
37
37
  spec.add_dependency 'rdiscount', '~> 2.2', '>= 2.2.0.1'
38
38
  spec.add_dependency 'phantomjs', '~> 2.1', '>= 2.1.1.0'
39
39
  spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.5'
40
40
  spec.add_dependency 'wolfram-alpha', '~> 0.3', '>= 0.3.1'
41
- spec.add_dependency 'rmagick', '~> 2.16', '>= 2.16.0'
41
+ spec.add_dependency 'rmagick', '~> 3.1', '>= 3.1.0'
42
42
  spec.add_dependency 'awesome_print', '~> 1.7', '>= 1.7.0'
43
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,10 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'yaml'
4
+ require 'active_support/all'
4
5
  require 'action_view'
5
6
  require 'radiator'
6
7
  require 'awesome_print'
7
- require 'steem_api'
8
8
  # require 'pry' # for binding.pry
9
9
 
10
10
  Bundler.require
@@ -13,7 +13,7 @@ defined? Thread.report_on_exception and Thread.report_on_exception = true
13
13
 
14
14
  module Cosgrove
15
15
  PWD = Dir.pwd.freeze
16
- KNOWN_CHAINS = [:steem, :test]
16
+ KNOWN_CHAINS = [:steem, :test, :hive]
17
17
 
18
18
  require 'cosgrove/version'
19
19
  require 'cosgrove/phantomjs'
@@ -25,5 +25,6 @@ module Cosgrove
25
25
  require 'cosgrove/market'
26
26
  require 'cosgrove/upvote_job'
27
27
  require 'cosgrove/comment_job'
28
+ require 'cosgrove/find_communities_job'
28
29
  require 'cosgrove/bot'
29
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
@@ -27,8 +27,8 @@ module Cosgrove
27
27
  end
28
28
 
29
29
  def add_all_messages
30
- # A user typed a link to steemit.com
31
- 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|
32
32
  link = event.content.split(' ').first
33
33
  Cosgrove::latest_steemit_link[event.channel.name] = link
34
34
  append_link_details(event, link)
@@ -41,7 +41,7 @@ module Cosgrove
41
41
  help << "`$slap [target]` - does a slap on the `target`"
42
42
  help << "`$verify <account> [chain]` - check `account` association with Discord users (`chain` default `steem`)"
43
43
  help << "`$register <account> [chain]` - associate `account` with your Discord user (`chain` default `steem`)"
44
- 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"
45
45
  help.join("\n")
46
46
  end
47
47
 
@@ -49,12 +49,12 @@ module Cosgrove
49
49
  "cosgrove: #{Cosgrove::VERSION} :: https://github.com/steem-third-party/cosgrove"
50
50
  end
51
51
 
52
- self.command :verify do |event, key, chain = :steem|
52
+ self.command :verify do |event, key, chain = :hive|
53
53
  return if event.channel.pm? && !cosgrove_allow_pm_commands
54
54
  cb_account = nil
55
55
 
56
56
  if key.nil?
57
- 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}"
58
58
  return
59
59
  end
60
60
 
@@ -86,7 +86,7 @@ module Cosgrove
86
86
  end
87
87
  end
88
88
 
89
- self.command :register do |event, account_name, chain = :steem|
89
+ self.command :register do |event, account_name, chain = :hive|
90
90
  return if event.channel.pm? && !cosgrove_allow_pm_commands
91
91
 
92
92
  discord_id = event.author.id
@@ -111,7 +111,7 @@ module Cosgrove
111
111
  end
112
112
 
113
113
  memo_key = cb_account.memo_key(discord_id)
114
- 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)
115
115
 
116
116
  if !!op
117
117
  cb_account.add_discord_id(discord_id)
@@ -127,7 +127,7 @@ module Cosgrove
127
127
 
128
128
  "Ok. #{chain.to_s.upcase} account #{account.name} has been registered with <@#{discord_id}>."
129
129
  else
130
- "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."
131
131
  end
132
132
  end
133
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,6 +36,14 @@ module Cosgrove
36
36
  [chain[:steem_api_failover_urls]].flatten.compact
37
37
  end
38
38
 
39
+ def hive_api_url
40
+ chain[:hive_api_url]
41
+ end
42
+
43
+ def hive_api_failover_urls
44
+ [chain[:hive_api_failover_urls]].flatten.compact
45
+ end
46
+
39
47
  def test_api_url
40
48
  chain[:test_api_url]
41
49
  end
@@ -44,6 +52,14 @@ module Cosgrove
44
52
  [chain[:test_api_failover_urls]].flatten.compact
45
53
  end
46
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
+
47
63
  def steem_account
48
64
  chain[:steem_account]
49
65
  end
@@ -52,10 +68,22 @@ module Cosgrove
52
68
  chain[:steem_posting_wif]
53
69
  end
54
70
 
71
+ def hive_account
72
+ chain[:hive_account]
73
+ end
74
+
75
+ def hive_posting_wif
76
+ chain[:hive_posting_wif]
77
+ end
78
+
55
79
  def test_posting_wif
56
80
  chain[:test_posting_wif]
57
81
  end
58
82
 
83
+ def meeseeker_url
84
+ chain[:meeseeker][:url]
85
+ end
86
+
59
87
  def discord_channels
60
88
  return ENV['CHANNELS'].to_s.split(' ') if !!ENV['CHANNELS']
61
89