cosgrove 0.0.4.0 → 0.0.4.1

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: ff3f036ba917f7455da365ef3547eafe5757a635f291a035694797ea6d31da43
4
- data.tar.gz: af18bf058e2d89039fab1b1327ef2a202dca88fc280fe00a809b7d7740547b6f
3
+ metadata.gz: 15526294d5a338ed4f81a05cb015250914c2b95ec3b62dd3d28a9db927d60bd7
4
+ data.tar.gz: e13d831d7ab03b6bb4e4c620a28f09d8fcb67474a9ad68f21c8406e25f6b3d07
5
5
  SHA512:
6
- metadata.gz: a7e64f13973dfa9e6a8410aa829fbaf6c05f62ba34cae137ad91856404ac92c97bb0abdd4b671284248353f025e0cdc2f1aa116e43a7907b258531b7076ca71f
7
- data.tar.gz: a1520125f682b8d32f0fa73de626990313faa493dafed65d7a3ff8fd7ce95545ed1dc4d7c69cfbce1c33503b466dfe442804bccb6a8a2afe2db595f8d8ae0319
6
+ metadata.gz: f3009261e6c0ec7d7f3e626381d561787ae15cfa5b229557bd18980d51c51001a5d80c22184925ad2c8b7b0d4187fa73367698a94fddefab200a39ad9ce94af3
7
+ data.tar.gz: d326e18c087632dfca9302356ad71359a48ac5cf650bf6f29646a85591360276283d9387cd654d24b6c8022f3f00e04a3a729d21d012b0e7d9a0e7fafb21cc41
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,8 @@ 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; dropped mongodb support)
10
- * Optimized interactive messages to update as data is acquired in realtime
8
+
9
+ * Engine support provided by the `Cosgrove::Utils` module.
11
10
  * Bug fixes
12
11
  * Gem updates.
13
12
 
@@ -28,6 +27,8 @@ One example of a bot that uses this framework is [@banjo](https://steemit.com/st
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
 
@@ -66,6 +67,11 @@ Add a config file to your `ruby` project called `config.yml`:
66
67
  :steem_account:
67
68
  :steem_posting_wif:
68
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
69
75
  :discord:
70
76
  :log_mode: info
71
77
  ```
@@ -88,21 +94,19 @@ SecureRandom.hex(32)
88
94
  4. Give that URL to the Discord server/guild owner and have them authorize the bot.
89
95
  5. Set the `token` and `client_id` in your bot constructor (see below).
90
96
 
91
- ## SteemSQL
97
+ ## HiveSQL
92
98
 
93
- 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.
94
100
 
95
101
  **Please note:**
96
102
 
97
- > SteemSQL has moved to a monthly subscription model and the default free account/password “steemit/steemit” has been disabled.
98
-
99
- 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:
100
104
 
101
105
  ```bash
102
- source path/to/authorize-steem-sql.sh
106
+ source path/to/authorize-hive-sql.sh
103
107
  ```
104
108
 
105
- Features that currently require SteemSQL:
109
+ Features that currently require HiveSQL:
106
110
 
107
111
  * Details in `$mvests` command
108
112
  * Any command that tries to suggest account names
@@ -128,6 +132,34 @@ end
128
132
  bot.run
129
133
  ```
130
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
+
131
163
  ## Tests
132
164
 
133
165
  * Clone the client repository into a directory of your choice:
@@ -9,8 +9,8 @@ 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
15
  spec.license = 'CC0-1.0'
16
16
 
@@ -23,12 +23,12 @@ Gem::Specification.new do |spec|
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.2'
30
+ spec.add_dependency 'radiator', '~> 0.4', '>= 0.4.8'
31
+ spec.add_dependency 'hive_sql'#, '~> 1.0', '>= 1.0.0'
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'
@@ -38,6 +38,6 @@ Gem::Specification.new do |spec|
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=
@@ -4,7 +4,6 @@ require 'yaml'
4
4
  require 'action_view'
5
5
  require 'radiator'
6
6
  require 'awesome_print'
7
- require 'steem_api'
8
7
  # require 'pry' # for binding.pry
9
8
 
10
9
  Bundler.require
@@ -13,7 +12,7 @@ defined? Thread.report_on_exception and Thread.report_on_exception = true
13
12
 
14
13
  module Cosgrove
15
14
  PWD = Dir.pwd.freeze
16
- KNOWN_CHAINS = [:steem, :test]
15
+ KNOWN_CHAINS = [:steem, :test, :hive]
17
16
 
18
17
  require 'cosgrove/version'
19
18
  require 'cosgrove/phantomjs'
@@ -25,5 +24,6 @@ module Cosgrove
25
24
  require 'cosgrove/market'
26
25
  require 'cosgrove/upvote_job'
27
26
  require 'cosgrove/comment_job'
27
+ require 'cosgrove/find_communities_job'
28
28
  require 'cosgrove/bot'
29
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
@@ -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
 
@@ -0,0 +1,47 @@
1
+ module Cosgrove
2
+ class FindCommunitiesJob
3
+ def perform(event, args, limit = 1000, chain = :hive)
4
+ chain = chain.to_s.downcase.to_sym
5
+ terms = args.map{|term| "%#{term.downcase.strip}%"}
6
+
7
+ all_communities = case chain
8
+ # when :steem then SteemApi::Tx::Custom::Community.where('id >= 217640816').op('updateProps').order(id: :desc).limit(limit)
9
+ when :hive then HiveSQL::Tx::Custom::Community.where('id >= 217640816').op('updateProps').order(id: :desc).limit(limit)
10
+ end
11
+
12
+ all_communities = all_communities.select("*, (SELECT [Accounts].[recovery_account] FROM [Accounts] WHERE [Accounts].[name] = JSON_VALUE([TxCustoms].[json_metadata], '$[1].community')) AS community_owner")
13
+
14
+ communities = all_communities.all
15
+
16
+ terms.each do |term|
17
+ communities = communities.where("LOWER([TxCustoms].[json_metadata]) LIKE ? OR required_posting_auth LIKE ? OR (SELECT [Accounts].[recovery_account] FROM [Accounts] WHERE [Accounts].[name] = JSON_VALUE([TxCustoms].[json_metadata], '$[1].community')) = ?", term, term, term)
18
+ end
19
+
20
+ event.channel.start_typing if !!event
21
+
22
+ if communities.none?
23
+ msg = "Unable to find communities with: `#{args.join(' ')}`"
24
+
25
+ guess_communities = all_communities.all
26
+
27
+ terms.each do |term|
28
+ pattern = term.chars.each.map{ |c| c }.join('%')
29
+ pattern = pattern.gsub('%%', '%')
30
+ guess_communities = guess_communities.where("LOWER(JSON_VALUE([TxCustoms].[json_metadata], '$[1].props.title')) LIKE ?", pattern)
31
+ end
32
+
33
+ if guess_communities.any? && !!(guess = guess_communities.sample.payload['props']['title'] rescue nil)
34
+ msg += "\nDid you mean: #{guess}"
35
+ end
36
+
37
+ if !!event
38
+ event << msg
39
+ end
40
+
41
+ return []
42
+ end
43
+
44
+ communities
45
+ end
46
+ end
47
+ end