reddit_bot 1.9.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/reddit_bot.rb +15 -21
  3. data/reddit_bot.gemspec +2 -8
  4. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 99ebebd30c2e4bfa221cc6b78c6521f4eb2e5c7b
4
- data.tar.gz: 79b8d91f910d5ca649f8350f1009bb6c21afd702
2
+ SHA256:
3
+ metadata.gz: 3c3199231c10b288c884d65c85854b15ee912c98e24cac2399f723f774d20739
4
+ data.tar.gz: '09030416b2e85f8b7925f1b587c438a1f14647e548e9538cce4e4ac541b54f2a'
5
5
  SHA512:
6
- metadata.gz: 9049548db4c55006a9fd9dd7fef394cb3b973ea3df7047a25528dcd2495e230acaa8217fd17ffa8128e9f23784bd292875d6e01015c785d465c3acc7c51db0b9
7
- data.tar.gz: 6e9849c6d4d3c7ed2eacc8b404f256764e0756e773d567ab7004d7f0a041bbdb5b722106d4fbba281b1ef0f8b6898d551b7742b19a232b942058523e8235a669
6
+ metadata.gz: 41e7d08da3df2bc5e81aa05f19ac6262ba8bd03904c8c019de7da0236f432982b1d1940a623d211e0cfae3f4a2127c29b68d9dffe74c5b81eb8581e370a5c865
7
+ data.tar.gz: 79859fd99f824e8ed7771cf016b7001b90592c3d02d395a8f5c8ef686758b2788009cb7bb0b2ad95ffeb1303d22ea26a637f0dc691506c7c6b965d05abe8730c
data/lib/reddit_bot.rb CHANGED
@@ -1,58 +1,48 @@
1
- STDOUT.sync = true
2
-
3
- require "openssl"
4
1
  require "json"
5
2
  require "yaml"
6
3
 
7
4
  require "nethttputils"
8
5
 
9
6
  module RedditBot
10
- require "logger"
11
7
  class << self
12
- attr_accessor :logger
8
+ attr_reader :logger
13
9
  end
14
- self.logger = Logger.new STDOUT
10
+ require "logger"
11
+ @logger = Logger.new STDOUT
12
+ @logger.level = Logger::WARN
13
+ @logger.level = ENV["LOGLEVEL_#{name}"].to_sym if ENV.include? "LOGLEVEL_#{name}"
15
14
 
16
15
  class Bot
17
16
  attr_reader :name
18
17
 
19
18
  def initialize secrets, **kwargs
20
19
  @name, @secret_password, @user_agent, *@secret_auth = secrets.values_at *%i{ login password user_agent client_id client_secret }
21
- # @ignore_captcha = true
22
- # @ignore_captcha = kwargs[:ignore_captcha] if kwargs.has_key?(:ignore_captcha)
23
20
  @subreddit = kwargs[:subreddit]
24
21
  end
25
22
 
26
23
  def json mtd, path, _form = []
27
- form = Hash[_form]
24
+ form = _form.to_h
28
25
  response = begin
29
26
  JSON.load resp_with_token mtd, path, form.merge({api_type: "json"})
30
27
  rescue JSON::ParserError
31
28
  $!.message.slice! 1000..-1
32
29
  raise
33
30
  end
34
- if response.is_a?(Hash) && response["json"] && # for example, flairlist.json and {"error": 403} do not have it
35
- !response["json"]["errors"].empty?
31
+ return response unless response.is_a?(Hash) && response["json"] && !response["json"]["errors"].empty?
32
+ # for example, flairlist.json and {"error": 403} do not have it
36
33
  Module.nesting[1].logger.error "ERROR OCCURED on #{[mtd, path]}"
37
34
  fail "unknown how to handle multiple errors" if 1 < response["json"]["errors"].size
38
35
  Module.nesting[1].logger.error "error: #{response["json"]["errors"]}"
39
36
  error, description = response["json"]["errors"].first
40
- case error
37
+ case error
41
38
  when "ALREADY_SUB" ; Module.nesting[1].logger.warn "was rejected by moderator if you didn't see in dups"
42
- # when "BAD_CAPTCHA" ; update_captcha
43
- # json mtd, path, form.merger( {
44
- # iden: @iden_and_captcha[0],
45
- # captcha: @iden_and_captcha[1],
46
- # } ) unless @ignore_captcha
47
39
  when "RATELIMIT"
48
40
  fail error unless description[/\Ayou are doing that too much\. try again in (\d) minutes\.\z/]
49
41
  Module.nesting[1].logger.info "retrying in #{$1.to_i + 1} minutes"
50
42
  sleep ($1.to_i + 1) * 60
51
43
  return json mtd, path, _form
52
44
  else ; fail error
53
- end
54
45
  end
55
- response
56
46
  end
57
47
 
58
48
  # # [subreddit] +String+ subreddit name without "/r" prefix
@@ -138,8 +128,11 @@ module RedditBot
138
128
  result = cache.call(args){ json *args }
139
129
  fail if result.keys != %w{ kind data }
140
130
  fail if result["kind"] != "Listing"
141
- fail result["data"].keys.inspect unless result["data"].keys == %w{ after dist modhash whitelist_status children before } ||
142
- result["data"].keys == %w{ modhash dist children after before }
131
+ fail result["data"].keys.inspect unless [
132
+ %w{ after dist modhash whitelist_status children before },
133
+ %w{ modhash dist children after before },
134
+ %w{ after dist modhash geo_filter children before },
135
+ ].include? result["data"].keys
143
136
  @@skip_erroneous_descending_ids[ result["data"]["children"].map do |post|
144
137
  fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
145
138
  post["data"].dup.tap do |data|
@@ -282,6 +275,7 @@ module RedditBot
282
275
 
283
276
  require "cgi"
284
277
  def self.tweet2titleNtext tweet
278
+ pp tweet if ENV["TEST"]
285
279
  text = ""
286
280
  contains_media = false
287
281
  up = ->s{ s.split.map{ |w| "^#{w}" }.join " " }
data/reddit_bot.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "reddit_bot"
3
- spec.version = "1.9.0"
3
+ spec.version = "1.11.0"
4
4
  spec.summary = "Simple library for Reddit bots"
5
5
 
6
6
  spec.author = "Victor Maslov aka Nakilon"
@@ -9,14 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.metadata = {"source_code_uri" => "https://github.com/Nakilon/reddit_bot"}
10
10
 
11
11
  spec.add_dependency "json_pure"
12
- spec.add_dependency "nethttputils", "~>0.4.1.0"
13
- # spec.add_development_dependency "bundler", "~> 1.11"
14
- # spec.add_development_dependency "rake", "~> 10.0"
15
- # spec.add_development_dependency "rspec", "~> 3.0"
12
+ spec.add_dependency "nethttputils", "~>0.4.4.0"
16
13
  spec.required_ruby_version = ">= 2.0.0"
17
14
 
18
15
  spec.files = %w{ LICENSE.txt reddit_bot.gemspec lib/reddit_bot.rb }
19
16
  end
20
-
21
- # spec.test_files = ["spec/"]
22
- # spec.post_install_message = ""
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov aka Nakilon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-16 00:00:00.000000000 Z
11
+ date: 2023-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_pure
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.1.0
33
+ version: 0.4.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.1.0
40
+ version: 0.4.4.0
41
41
  description:
42
42
  email: nakilon@gmail.com
43
43
  executables: []
@@ -67,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.5.2.3
70
+ rubygems_version: 3.2.3
72
71
  signing_key:
73
72
  specification_version: 4
74
73
  summary: Simple library for Reddit bots