cosgrove 0.0.2 → 0.0.3rc1

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
  SHA1:
3
- metadata.gz: e5e5cfb51b16658b05b8c58d32f848b18d42ac2e
4
- data.tar.gz: 08f1f4ad0169c0512c6c415f76f4d6e0ad6d4f15
3
+ metadata.gz: fe7cb0da9ef53e623117b7abb364748436eb0836
4
+ data.tar.gz: 02a2f8d029e6195789bfc782d4788e9433cb853c
5
5
  SHA512:
6
- metadata.gz: f78010b967c9ebfd56ffa15d65b4a7c7db4c40971c909f4f2e64b8f1c20f9614ee3b59a5832d8859cfd485cb1f888e9ca6bbbd7e61d41e4d2edc218dcb559737
7
- data.tar.gz: d9273d53aa1d6e71e0f24600c472e2ef3d73677242992736b43e20e44d0c1662d7694f1b85d4702c07a6cb2d866936cc06aebd716e73b2bbb182dba1431f22fe
6
+ metadata.gz: '0983ecb03bc98fc988dac73ac9c8e2536afa914b39aa03feca0c3ccc964b9dc3aa38e2220ebf542fc0d8f75205c5513b28bb86c6ec675c125c947f83bf461e55'
7
+ data.tar.gz: 1393a41d3cd24cb51d29cd39de009d8ccc29a272f52be17ff6aca72645b537b63606d474abe2299583e18a408e68fda7fc7d4cd8afe91c6416d3a69c4d55f45c
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'mechanize', git: 'https://github.com/sparklemotion/mechanize.git', branch: 'upgrade_net-http-persistent'
4
+ gem 'steem_api', github: 'steem-third-party/steem_api'
5
+
3
6
  gemspec
@@ -1,20 +1,47 @@
1
+ GIT
2
+ remote: git://github.com/steem-third-party/steem_api.git
3
+ revision: de44a65a21fa9f31db2a160132713a46b7cc7330
4
+ specs:
5
+ steem_api (1.0.0)
6
+ activerecord (>= 4, < 6)
7
+ activerecord-sqlserver-adapter (>= 4, < 6)
8
+ awesome_print (~> 1.7, >= 1.7.0)
9
+ nokogiri (~> 1.8)
10
+ rest-client (~> 2.0)
11
+ tiny_tds (~> 1.3)
12
+
13
+ GIT
14
+ remote: https://github.com/sparklemotion/mechanize.git
15
+ revision: f68b1a0bdeee9ec7c9a8b7854f8e6b81d62c43b2
16
+ branch: upgrade_net-http-persistent
17
+ specs:
18
+ mechanize (2.7.5)
19
+ domain_name (~> 0.5, >= 0.5.1)
20
+ http-cookie (~> 1.0)
21
+ mime-types (>= 1.17.2)
22
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
23
+ net-http-persistent (>= 2.5.2)
24
+ nokogiri (~> 1.6)
25
+ ntlm-http (~> 0.1, >= 0.1.1)
26
+ webrobots (>= 0.0.9, < 0.2)
27
+
1
28
  PATH
2
29
  remote: .
3
30
  specs:
4
- cosgrove (0.0.2)
31
+ cosgrove (0.0.3rc1)
5
32
  activesupport (~> 5.1, >= 5.1.1)
6
33
  ai4r (~> 1.13, >= 1.13)
7
34
  awesome_print (~> 1.7, >= 1.7.0)
8
35
  discordrb (~> 3.2, >= 3.2.1)
36
+ golos_cloud (~> 1.0, >= 1.0.0)
9
37
  mechanize (~> 2.7, >= 2.7.5)
10
38
  mongoid (~> 6.1, >= 6.1.0)
11
39
  phantomjs (~> 2.1, >= 2.1.1.0)
12
- radiator (~> 0.3, >= 0.3.1)
40
+ radiator (~> 0.3, >= 0.3.15)
13
41
  railties (~> 5.1, >= 5.1.1)
14
42
  rdiscount (~> 2.2, >= 2.2.0.1)
15
43
  rmagick (~> 2.16, >= 2.16.0)
16
44
  steem-slap (~> 0.0, >= 0.0.2)
17
- steem_api (~> 1.1, >= 1.1.0)
18
45
  steem_data (~> 0.0, >= 0.0.3)
19
46
  wolfram-alpha (~> 0.3, >= 0.3.1)
20
47
 
@@ -40,7 +67,7 @@ GEM
40
67
  activemodel (= 5.1.4)
41
68
  activesupport (= 5.1.4)
42
69
  arel (~> 8.0)
43
- activerecord-sqlserver-adapter (5.1.2)
70
+ activerecord-sqlserver-adapter (5.1.5)
44
71
  activerecord (~> 5.1.0)
45
72
  tiny_tds
46
73
  activesupport (5.1.4)
@@ -53,14 +80,14 @@ GEM
53
80
  ai4r (1.13)
54
81
  arel (8.0.0)
55
82
  awesome_print (1.8.0)
56
- bitcoin-ruby (0.0.11)
83
+ bitcoin-ruby (0.0.14)
57
84
  bson (4.2.2)
58
85
  builder (3.2.3)
59
- coderay (1.1.2)
60
86
  concurrent-ruby (1.0.5)
87
+ connection_pool (2.2.1)
61
88
  crack (0.4.3)
62
89
  safe_yaml (~> 1.0.0)
63
- crass (1.0.2)
90
+ crass (1.0.3)
64
91
  discordrb (3.2.1)
65
92
  discordrb-webhooks (~> 3.2.0.1)
66
93
  opus-ruby
@@ -75,11 +102,17 @@ GEM
75
102
  erubi (1.7.0)
76
103
  event_emitter (0.2.6)
77
104
  ffi (1.9.18)
105
+ golos_cloud (1.0.0)
106
+ activerecord (>= 4, < 6)
107
+ activerecord-sqlserver-adapter (>= 4, < 6)
108
+ nokogiri (~> 1.8)
109
+ rest-client (~> 2.0)
110
+ tiny_tds (~> 1.3)
78
111
  hashdiff (0.3.7)
79
- hashie (3.5.6)
112
+ hashie (3.5.7)
80
113
  http-cookie (1.0.3)
81
114
  domain_name (~> 0.5)
82
- i18n (0.9.0)
115
+ i18n (0.9.1)
83
116
  concurrent-ruby (~> 1.0)
84
117
  json (2.1.0)
85
118
  little-plugger (1.1.4)
@@ -89,21 +122,12 @@ GEM
89
122
  loofah (2.1.1)
90
123
  crass (~> 1.0.2)
91
124
  nokogiri (>= 1.5.9)
92
- mechanize (2.7.5)
93
- domain_name (~> 0.5, >= 0.5.1)
94
- http-cookie (~> 1.0)
95
- mime-types (>= 1.17.2)
96
- net-http-digest_auth (~> 1.1, >= 1.1.1)
97
- net-http-persistent (~> 2.5, >= 2.5.2)
98
- nokogiri (~> 1.6)
99
- ntlm-http (~> 0.1, >= 0.1.1)
100
- webrobots (>= 0.0.9, < 0.2)
101
125
  method_source (0.9.0)
102
126
  mime-types (3.1)
103
127
  mime-types-data (~> 3.2015)
104
128
  mime-types-data (3.2016.0521)
105
129
  mini_portile2 (2.3.0)
106
- minitest (5.10.3)
130
+ minitest (5.11.1)
107
131
  minitest-line (0.6.4)
108
132
  minitest (~> 5.0)
109
133
  minitest-proveit (1.0.0)
@@ -113,9 +137,10 @@ GEM
113
137
  mongoid (6.2.1)
114
138
  activemodel (~> 5.1)
115
139
  mongo (>= 2.4.1, < 3.0.0)
116
- multi_json (1.12.2)
140
+ multi_json (1.13.1)
117
141
  net-http-digest_auth (1.4.1)
118
- net-http-persistent (2.9.4)
142
+ net-http-persistent (3.0.0)
143
+ connection_pool (~> 2.2)
119
144
  netrc (0.11.0)
120
145
  nokogiri (1.8.1)
121
146
  mini_portile2 (~> 2.3.0)
@@ -123,14 +148,11 @@ GEM
123
148
  opus-ruby (1.0.1)
124
149
  ffi
125
150
  phantomjs (2.1.1.0)
126
- pry (0.11.1)
127
- coderay (~> 1.1.0)
128
- method_source (~> 0.9.0)
129
- public_suffix (3.0.0)
151
+ public_suffix (3.0.1)
130
152
  rack (2.0.3)
131
- rack-test (0.7.0)
153
+ rack-test (0.8.2)
132
154
  rack (>= 1.0, < 3)
133
- radiator (0.3.3)
155
+ radiator (0.3.15)
134
156
  awesome_print (~> 1.7, >= 1.7.0)
135
157
  bitcoin-ruby (~> 0.0, >= 0.0.11)
136
158
  ffi (~> 1.9, >= 1.9.18)
@@ -149,7 +171,7 @@ GEM
149
171
  method_source
150
172
  rake (>= 0.8.7)
151
173
  thor (>= 0.18.1, < 2.0)
152
- rake (12.1.0)
174
+ rake (12.3.0)
153
175
  rbnacl (3.4.0)
154
176
  ffi
155
177
  rdiscount (2.2.0.1)
@@ -165,36 +187,30 @@ GEM
165
187
  simplecov-html (~> 0.10.0)
166
188
  simplecov-html (0.10.2)
167
189
  steem-slap (0.0.3)
168
- steem_api (1.1.0)
169
- activerecord (>= 4, < 6)
170
- activerecord-sqlserver-adapter (>= 4, < 6)
171
- nokogiri (~> 1.8)
172
- rest-client (~> 2.0)
173
- tiny_tds (~> 1.3)
174
190
  steem_data (0.0.3)
175
191
  mongoid (~> 6.1, >= 6.1.0)
176
192
  thor (0.20.0)
177
193
  thread_safe (0.3.6)
178
194
  tiny_tds (1.3.0)
179
195
  mini_portile2 (~> 2.0)
180
- tzinfo (1.2.3)
196
+ tzinfo (1.2.4)
181
197
  thread_safe (~> 0.1)
182
198
  unf (0.1.4)
183
199
  unf_ext
184
200
  unf_ext (0.0.7.4)
185
201
  vcr (3.0.3)
186
- webmock (3.1.0)
202
+ webmock (3.2.1)
187
203
  addressable (>= 2.3.6)
188
204
  crack (>= 0.3.2)
189
205
  hashdiff
190
206
  webrobots (0.1.2)
191
- websocket (1.2.4)
207
+ websocket (1.2.5)
192
208
  websocket-client-simple (0.3.0)
193
209
  event_emitter
194
210
  websocket
195
211
  wolfram-alpha (0.3.1)
196
212
  nokogiri
197
- yard (0.9.9)
213
+ yard (0.9.12)
198
214
 
199
215
  PLATFORMS
200
216
  ruby
@@ -202,15 +218,16 @@ PLATFORMS
202
218
  DEPENDENCIES
203
219
  bundler (~> 1.15, >= 1.15.4)
204
220
  cosgrove!
221
+ mechanize!
205
222
  minitest (~> 5.9, >= 5.9.0)
206
223
  minitest-line (~> 0.6, >= 0.6.3)
207
224
  minitest-proveit (~> 1.0, >= 1.0.0)
208
- pry (~> 0.10, >= 0.10.3)
209
225
  rake (~> 12.1, >= 12.1.0)
210
226
  simplecov (~> 0.11, >= 0.11.2)
227
+ steem_api!
211
228
  vcr (~> 3.0, >= 3.0.3)
212
229
  webmock (~> 3.0, >= 3.0.1)
213
230
  yard (~> 0.8, >= 0.8.7.6)
214
231
 
215
232
  BUNDLED WITH
216
- 1.15.4
233
+ 1.16.0.pre.3
data/README.md CHANGED
@@ -65,7 +65,7 @@ Add a config file to your `ruby` project called `config.yml`:
65
65
  :steem_posting_wif:
66
66
  :golos_account:
67
67
  :golos_posting_wif:
68
- :steem_api_url: https://steemd.steemit.com
68
+ :steem_api_url: https://api.steemit.com
69
69
  :golos_api_url: https://ws.golos.io
70
70
  :discord:
71
71
  :log_mode: info
@@ -26,11 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
27
27
  spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
28
28
  spec.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7.6'
29
- spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
29
+ # spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
30
30
 
31
- spec.add_dependency 'radiator', '~> 0.3', '>= 0.3.1'
31
+ spec.add_dependency 'radiator', '~> 0.3', '>= 0.3.15'
32
32
  spec.add_dependency 'steem_data', '~> 0.0', '>= 0.0.3'
33
- spec.add_dependency 'steem_api', '~> 1.1', '>= 1.1.0'
33
+ spec.add_dependency 'golos_cloud', '~> 1.0', '>= 1.0.0'
34
34
  spec.add_dependency 'discordrb', '~> 3.2', '>= 3.2.1'
35
35
  spec.add_dependency 'ai4r', '~> 1.13', '>= 1.13'
36
36
  spec.add_dependency 'mongoid', '~> 6.1', '>= 6.1.0'
@@ -5,7 +5,8 @@ require 'action_view'
5
5
  require 'radiator'
6
6
  require 'awesome_print'
7
7
  require 'steem_data'
8
- # require 'pry'
8
+ # require 'irb' # for binding.irb
9
+ # require 'pry' # for binding.pry
9
10
 
10
11
  Bundler.require
11
12
 
@@ -13,6 +14,10 @@ defined? Thread.report_on_exception and Thread.report_on_exception = true
13
14
 
14
15
  SteemData.load
15
16
 
17
+ # This will cause a nil to be returned instead of raising an error, allowing us
18
+ # to fall back to SteemApi and/or RPC.
19
+ Mongoid.raise_not_found_error = false
20
+
16
21
  module Cosgrove
17
22
  PWD = Dir.pwd.freeze
18
23
  KNOWN_CHAINS = [:steem, :golos, :test]
@@ -8,13 +8,13 @@ module Cosgrove
8
8
  ACCOUNTS_FILE ||= "#{Cosgrove::PWD}/accounts.yml".freeze
9
9
  DISCORD_IDS = 'discord_ids'.freeze
10
10
 
11
- attr_accessor :chain, :account_name, :discord_ids
11
+ attr_accessor :account_name, :discord_ids
12
12
 
13
13
  def initialize(account_name, chain = :steem)
14
- raise "Unknown Chain: #{chain}" unless Cosgrove::KNOWN_CHAINS.include? chain.to_sym
14
+ @chain = chain.to_sym
15
+ raise "Unknown Chain: #{@chain}" unless Cosgrove::KNOWN_CHAINS.include? @chain
15
16
 
16
17
  @account_name = account_name.to_s.downcase
17
- @chain = chain
18
18
  @discord_ids = []
19
19
 
20
20
  if !!details
@@ -27,6 +27,8 @@ module Cosgrove
27
27
 
28
28
  discord_id = discord_id.to_s.split('@').last.split('>').first.to_i
29
29
 
30
+ return nil if discord_id == 0
31
+
30
32
  Account.yml[chain.to_s].each do |k, v|
31
33
  ids = v[DISCORD_IDS]
32
34
  return Account.new(k, chain) if !!ids && ids.include?(discord_id)
@@ -38,7 +40,7 @@ module Cosgrove
38
40
  def self.find_by_memo_key(memo_key, secure, chain = :steem)
39
41
  Account.yml[chain.to_s].each do |k, v|
40
42
  v[DISCORD_IDS].each do |discord_id|
41
- return Account.new(k, chain) if Account.gen_memo_key(k, discord_id, chain, secure) == memo_key
43
+ return Account.new(k, chain) if Account.gen_memo_key(k, discord_id, secure, chain) == memo_key
42
44
  end
43
45
  end
44
46
 
@@ -75,9 +77,12 @@ module Cosgrove
75
77
  end
76
78
 
77
79
  def chain_account
80
+ return @chain_account if !!@chain_account
81
+
78
82
  if !!@account_name
79
- response = api(chain).get_accounts([@account_name])
80
- account = response.result.first
83
+ api(@chain).get_accounts([@account_name]) do |accounts, errors|
84
+ @chain_account = accounts.first
85
+ end
81
86
  end
82
87
  end
83
88
  private
@@ -58,6 +58,7 @@ module Cosgrove
58
58
 
59
59
  self.command :verify do |event, key, chain = :steem|
60
60
  return if event.channel.pm? && !cosgrove_allow_pm_commands
61
+ cb_account = nil
61
62
 
62
63
  mongo_behind_warning(event)
63
64
  if key.nil?
@@ -72,12 +73,10 @@ module Cosgrove
72
73
  else
73
74
  discord_id = key.split('@').last.split('>').first.to_i
74
75
  cb_account = Cosgrove::Account.find_by_discord_id(discord_id, chain)
75
-
76
- account = if !!cb_account
77
- find_account(cb_account.account_name, event)
78
- end
79
76
  end
80
77
 
78
+ account = cb_account.chain_account if account.nil? && !!cb_account
79
+
81
80
  if !!account && !!cb_account && cb_account.discord_ids.any?
82
81
  if cb_account.hidden?
83
82
  "#{chain.to_s.upcase} account `#{account.name}` has been registered."
@@ -99,10 +98,19 @@ module Cosgrove
99
98
  return if event.channel.pm? && !cosgrove_allow_pm_commands
100
99
 
101
100
  mongo_behind_warning(event)
102
- account = find_account(account_name, event)
103
101
  discord_id = event.author.id
104
102
 
105
- return nil unless !!account
103
+ if discord_id.to_i == 0
104
+ event.respond 'Problem with discord id.'
105
+ return
106
+ end
107
+
108
+ account = find_account(account_name, event, chain)
109
+
110
+ if account.nil?
111
+ event.respond 'Try again later.'
112
+ return
113
+ end
106
114
 
107
115
  cb_account = Cosgrove::Account.new(account.name, chain)
108
116
 
@@ -112,26 +120,7 @@ module Cosgrove
112
120
  end
113
121
 
114
122
  memo_key = cb_account.memo_key(discord_id)
115
- op = SteemData::AccountOperation.type('transfer').
116
- where(account: steem_account, from: account.name, to: steem_account, memo: {'$regex' => ".*#{memo_key}.*"}).last
117
-
118
- if op.nil?
119
- # Fall back to RPC. The transaction is so new, SteemData hasn't seen it
120
- # yet, SteemData is behind, or there is no such transfer.
121
-
122
- response = api(chain).get_account_history(steem_account, -1000, 1000)
123
- op = response.result.map do |history|
124
- e = history.last.op
125
- type = e.first
126
- next unless type == 'transfer'
127
- o = e.last
128
- next unless o.from == account.name
129
- next unless o.to == steem_account
130
- next unless o.memo =~ /.*#{memo_key}.*/
131
-
132
- o
133
- end.compact.last
134
- end
123
+ op = find_transfer(chain: chain, account: steem_account, from: account.name, to: steem_account, memo_key: memo_key)
135
124
 
136
125
  if !!op
137
126
  cb_account.add_discord_id(discord_id)
@@ -6,23 +6,15 @@ module Cosgrove
6
6
  include Support
7
7
 
8
8
  def perform(event, slug, template, message = nil)
9
+ chain = :steem
9
10
  author_name, permlink = parse_slug slug
10
- muted = muted by: steem_account, chain: :steem
11
+ muted = muted by: steem_account, chain: chain
11
12
 
12
- posts = SteemData::Post.root_posts.where(author: author_name, permlink: permlink)
13
+ author = find_author(chain: chain, author_name: author_name)
13
14
 
14
- post = posts.first
15
- author = SteemData::Account.find_by(name: author_name)
15
+ return if author.nil?
16
16
 
17
- if post.nil?
18
- # Fall back to RPC
19
- response = api(:steem).get_content(author_name, permlink)
20
- unless response.result.author.empty?
21
- post = response.result
22
- created = Time.parse(post.created + 'Z')
23
- cashout_time = Time.parse(post.cashout_time + 'Z')
24
- end
25
- end
17
+ post = find_comment(chain: chain, author: author_name, permlink: permlink)
26
18
 
27
19
  if post.nil?
28
20
  cannot_find_input(event)
@@ -32,6 +24,11 @@ module Cosgrove
32
24
  created ||= post.created
33
25
  cashout_time ||= post.cashout_time
34
26
 
27
+ if created.class == String
28
+ created = Time.parse(created + 'Z')
29
+ cashout_time = Time.parse(cashout_time + 'Z')
30
+ end
31
+
35
32
  nope = if post.nil?
36
33
  "Sorry, couldn't find that."
37
34
  elsif cashout_time < Time.now.utc
@@ -53,7 +50,7 @@ module Cosgrove
53
50
  'Unable to vote.'
54
51
  # elsif template == :welcome && author.post_count != 1
55
52
  # 'Sorry, this function is intended to welcome new authors.'
56
- elsif SteemData::Post.where(author: steem_account, parent_permlink: post.permlink).any?
53
+ elsif find_comment(chain: :steem, author: steem_account, parent_permlink: post.permlink).any?
57
54
  title = post.title
58
55
  title = post.permlink if title.empty?
59
56
  "I already commented on #{title} by #{post.author}."