reddit_bot 1.1.8 → 1.2.0

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
2
  SHA1:
3
- metadata.gz: 955203c78488b77ca15aaed4e4701ed2db5542f2
4
- data.tar.gz: 34d0202710a3414d667a0bcd7d8d3ee1293c4904
3
+ metadata.gz: 5c023e24b1aa289bee8f5a718ebdcd3d4dc64acc
4
+ data.tar.gz: 73f61de52f02b15c75607cb99d042b4590424f4d
5
5
  SHA512:
6
- metadata.gz: a6e8b902086a792a4c65a42721058ab5d65a7d9707fff1b771fc51aa796685a63f5f820f74f2d4357a74c4974260934b718b9fc5d7ea7fa55d74061b59a00d6b
7
- data.tar.gz: a5b9473a6e09e317b9075a7bb1744f899624356ae960f0c96049a7223265f1ebf89cdb894b50f705261fb3f4d565f63423a0a312b1c46ef171e8ad056512385f
6
+ metadata.gz: da386cce14eeb419ef0fc23968bed4a7a3c94c3ae797ff96ddfa1defb2f802d68cb4dfaee5b79b920049108eb9b978a343de8031b862ca1f0b632ed8d425cc3b
7
+ data.tar.gz: 6fc65d233f2572e8bbb9847c3a2dd99a3cb99834e4c7250f9cf4d91d554e078dcee1ec766960149c6de5b9a9344c0a3b13b203609593efa111597675dd3a691a
data/README.md CHANGED
@@ -79,6 +79,10 @@ probably Gemfile:
79
79
  TODO: Write usage instructions here
80
80
  TODO: manual on how to create bots with Reddit web interface and run via bash console
81
81
 
82
+ To update the gem version in Gemfile.lock when using Gemfile like this: `gem "reddit_bot", "~>1.1.0"`, do the:
83
+
84
+ $ bundle update reddit_bot
85
+
82
86
  #### Contributing and License
83
87
 
84
88
  Bug reports and pull requests are welcome.
@@ -1,10 +1,7 @@
1
1
  STDOUT.sync = true
2
-
3
2
  require "pp"
4
3
 
5
- require_relative File.join "../..",
6
- *("../download_with_retry" if ENV["LOGNAME"] == "nakilon"),
7
- "download_with_retry"
4
+ require "net_http_utils" if Gem.loaded_specs.include? "net_http_utils"
8
5
 
9
6
  if ENV["DEV"]
10
7
  require_relative "../lib/reddit_bot"
@@ -12,10 +9,6 @@ else
12
9
  require "reddit_bot"
13
10
  end
14
11
 
15
- RedditBot.init *File.read("secrets").split, ignore_captcha: true if RedditBot::VERSION <= "0.1.3"
16
-
17
- require_relative File.join "../..",
18
- *(".." if ENV["LOGNAME"] == "nakilon"),
19
- "awsstatus/2.rb"
12
+ require_relative "#{Dir.home}/beat.rb" unless Gem::Platform.local.os == "darwin"
20
13
 
21
14
  require "yaml"
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- json (1.8.3)
5
- reddit_bot (1.1.5)
4
+ json (2.0.2)
5
+ reddit_bot (1.1.8)
6
6
  json
7
7
 
8
8
  PLATFORMS
@@ -12,4 +12,4 @@ DEPENDENCIES
12
12
  reddit_bot (~> 1.1.5)
13
13
 
14
14
  BUNDLED WITH
15
- 1.11.2
15
+ 1.12.0
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- json (1.8.3)
5
- reddit_bot (1.1.5)
4
+ json (2.0.2)
5
+ reddit_bot (1.1.8)
6
6
  json
7
7
 
8
8
  PLATFORMS
@@ -12,4 +12,4 @@ DEPENDENCIES
12
12
  reddit_bot (~> 1.1.5)
13
13
 
14
14
  BUNDLED WITH
15
- 1.11.2
15
+ 1.12.0
@@ -1,3 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "reddit_bot", "~>1.1.5"
4
+ gem "net_http_utils", ?0, gist: "97549ceb58d21e1fcbc0e6cdaf92fce8"
@@ -1,15 +1,22 @@
1
+ GIT
2
+ remote: https://gist.github.com/97549ceb58d21e1fcbc0e6cdaf92fce8.git
3
+ revision: 54c47ab3f9665f3e35a8e94fdd267e3743c736a9
4
+ specs:
5
+ net_http_utils (0)
6
+
1
7
  GEM
2
8
  remote: https://rubygems.org/
3
9
  specs:
4
- json (1.8.3)
5
- reddit_bot (1.1.7)
10
+ json (2.0.2)
11
+ reddit_bot (1.1.8)
6
12
  json
7
13
 
8
14
  PLATFORMS
9
15
  ruby
10
16
 
11
17
  DEPENDENCIES
18
+ net_http_utils (= 0)!
12
19
  reddit_bot (~> 1.1.5)
13
20
 
14
21
  BUNDLED WITH
15
- 1.12.5
22
+ 1.13.1
@@ -5,19 +5,16 @@ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: tr
5
5
  SUBREDDIT = "codcompetitive"
6
6
 
7
7
  loop do
8
- AWSStatus::touch
8
+ Hearthbeat.beat "u_OpTicNaDeBoT_r_CoDCompetitive", 70 unless Gem::Platform.local.os == "darwin"
9
9
  catch :loop do
10
10
 
11
11
  text = " Live Streams\n\n" + [].tap do |list|
12
12
 
13
13
  throw :loop unless statuses = JSON.parse(
14
- DownloadWithRetry::download_with_retry("http://streamapi.majorleaguegaming.com/service/streams/all")[/\{.+\}/m]
14
+ NetHTTPUtils.request_data("http://streamapi.majorleaguegaming.com/service/streams/all")[/\{.+\}/m]
15
15
  )["data"]["items"]
16
16
  begin
17
- JSON.parse DownloadWithRetry::download_with_retry(
18
- # DownloadWithRetry::download_with_retry("http://www.majorleaguegaming.com/api/channels/all.js?fields=id,name,slug,subtitle,game_id,stream_name,type,default_tab,is_hidden,chat_is_disabled,image_1_1,image_16_9,image_16_9_small,image_16_9_medium,image_background,url,embed_code,stream_featured,stream_sort_order,tags,tag_names,children,description,subscription_url,donate_url,donate_text,partner_embed")
19
- "http://www.majorleaguegaming.com/api/channels/all.js?fields=name,url,tags,stream_name"
20
- )
17
+ JSON.parse NetHTTPUtils.request_data "http://www.majorleaguegaming.com/api/channels/all.js?fields=name,url,tags,stream_name"
21
18
  rescue JSON::ParserError
22
19
  puts "JSON::ParserError"
23
20
  sleep 60
@@ -40,14 +37,20 @@ loop do
40
37
  # 0. see 'client_id' here https://www.twitch.tv/settings/connections and 'client_secret' from local ./readme file
41
38
  # 1. get 'code' by visiting in browser: https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=*******&redirect_uri=http://www.example.com/unused/redirect/uri&scope=channel_read channel_feed_read
42
39
  # 2. NetHTTPUtils.request_data("https://api.twitch.tv/kraken/oauth2/token", :post, form: {client_id: "*******", client_secret: "*****", grant_type: "authorization_code", redirect_uri: "http://www.example.com/unused/redirect/uri", code: "*******"})
43
- JSON.parse(DownloadWithRetry::download_with_retry(
44
- "https://api.twitch.tv/kraken/streams?game=#{CGI::escape "Call of Duty: Black Ops III"}&access_token=#{File.read("twitch.token").strip}&client_id=#{File.read("client.id").strip}&channel=Ricky,ACHES,Lacefield,Clayster,Enable,Zoomaa,Attach,TheFEARS,PHiZZURP,MiRx1,SaintsRF,StuDyy,SpaceLyTV,NAMELESS,Scumperjumper,FORMAL,Crimsix,Karma,Loony,Slacked,Octane,MJChino,Diabolic_TV,ImTheIvy,Senderxz,Jkap,John,SlasheRAL,Apathy,ColtHavok,MikeSwarley,ParasiteTV,TyreeLegal,Silly,Blfire,methodz,TwiZzyTV,Mochila,Remy,Xotic16,AquA,Faccento,Nagafen,Tylerfelo,TheoryCoD,ColeChanTV,happyy97,goonjar,Burns,Dedo,Neslo,TeeCM,K1lla93,NeLsoNNaTeR,ProoFy,Whea7s,MBoZe,Merk,Nadeshot,ReeP,Sharp,TeePee,Braaain2015,Nolsonn,QwiKeRTHaNu,Zedenyer1,Jurd,Tommey,Swanny,MadCatEU,Rated_EU1,BsportJoshh,Sy_Vortex,TheMarkyB,Peatie95,urbandm,TreiZer0,iDqvee,Tojor,MethodZ_TV,Gotaga,WailersWL,TCM_Moose,RampageSkrapz,Reedy,fighta71,Swiftazor,BacabecNZ,Zeuss_Gaming,Hopeyy,GuydraCOD,mattmrx,Maven,CouRageJD,Revan,BriceyHD,Benson,PHILWHI7"
45
- ))["streams"].each do |channel|
46
- list << "* [](#twitch) [](#live) [**#{
47
- channel["channel"]["display_name"]
48
- }**](#{
49
- channel["channel"]["url"]
50
- })"
40
+ [
41
+ "Call of Duty: Infinite Warfare",
42
+ "Call of Duty: Modern Warfare Remastered",
43
+ "Call of Duty 4: Modern Warfare",
44
+ ].each do |game|
45
+ (JSON.parse(
46
+ NetHTTPUtils.request_data "https://api.twitch.tv/kraken/streams?game=#{CGI::escape game}&access_token=#{File.read("twitch.token").strip}&client_id=#{File.read("client.id").strip}&channel=Ricky,ACHES,Lacefield,Clayster,Enable,Zoomaa,Attach,TheFEARS,PHiZZURP,MiRx1,SaintsRF,StuDyy,SpaceLyTV,NAMELESS,Scumperjumper,FORMAL,Crimsix,Karma,Loony,Slacked,Octane,MJChino,Diabolic_TV,ImTheIvy,Senderxz,Jkap,John,SlasheRAL,Apathy,ColtHavok,MikeSwarley,ParasiteTV,TyreeLegal,Silly,Blfire,methodz,TwiZzyTV,Mochila,Remy,Xotic16,AquA,Faccento,Nagafen,Tylerfelo,TheoryCoD,ColeChanTV,happyy97,goonjar,Burns,Dedo,Neslo,TeeCM,K1lla93,NeLsoNNaTeR,ProoFy,Whea7s,MBoZe,Merk,Nadeshot,ReeP,Sharp,TeePee,Braaain2015,Nolsonn,QwiKeRTHaNu,Zedenyer1,Jurd,Tommey,Swanny,MadCatEU,Rated_EU1,BsportJoshh,Sy_Vortex,TheMarkyB,Peatie95,urbandm,TreiZer0,iDqvee,Tojor,MethodZ_TV,Gotaga,WailersWL,TCM_Moose,RampageSkrapz,Reedy,fighta71,Swiftazor,BacabecNZ,Zeuss_Gaming,Hopeyy,GuydraCOD,mattmrx,Maven,CouRageJD,Revan,BriceyHD,Benson,PHILWHI7"
47
+ )["streams"] || []).each do |channel|
48
+ list << "* [](#twitch) [](#live) [**#{
49
+ channel["channel"]["display_name"]
50
+ }**](#{
51
+ channel["channel"]["url"]
52
+ })"
53
+ end
51
54
  end
52
55
 
53
56
  end.join(" \n") + "\n"
@@ -72,6 +75,7 @@ loop do
72
75
  end
73
76
  next puts "nothing to change" if prefix + text + postfix == settings["description"]
74
77
 
78
+ puts "updating sidebar..."
75
79
  settings["description"] = prefix + text + postfix
76
80
  _ = BOT.json :post, "/api/site_admin", settings.to_a
77
81
  fail _.inspect if _ != {"json"=>{"errors"=>[]}} && !(_["json"]["errors"].map(&:first) - ["BAD_CAPTCHA"]).empty?
@@ -4,8 +4,8 @@ GEM
4
4
  addressable (2.4.0)
5
5
  fastimage (1.7.0)
6
6
  addressable (~> 2.3, >= 2.3.5)
7
- json (1.8.3)
8
- reddit_bot (1.1.5)
7
+ json (2.0.2)
8
+ reddit_bot (1.1.8)
9
9
  json
10
10
 
11
11
  PLATFORMS
@@ -16,4 +16,4 @@ DEPENDENCIES
16
16
  reddit_bot (~> 1.1.5)
17
17
 
18
18
  BUNDLED WITH
19
- 1.11.2
19
+ 1.12.0
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- json (1.8.3)
5
- reddit_bot (1.1.5)
4
+ json (2.0.2)
5
+ reddit_bot (1.1.8)
6
6
  json
7
7
 
8
8
  PLATFORMS
@@ -12,4 +12,4 @@ DEPENDENCIES
12
12
  reddit_bot (~> 1.1.5)
13
13
 
14
14
  BUNDLED WITH
15
- 1.11.2
15
+ 1.12.0
@@ -9,7 +9,7 @@ loop do
9
9
  # next unless msg["data"]["author"] == "nakilon" if ENV["LOGNAME"] == "nakilon"
10
10
  next puts "bad destination: #{msg["data"]["dest"]}" unless msg["data"]["dest"] == "CPTFlairBot3"
11
11
  case msg["data"]["subject"]
12
- when "casualpokemontrades", "relaxedpokemontrades"
12
+ when "casualpokemontrades"#, "relaxedpokemontrades"
13
13
  unless /^(?<name>\S+)\n(?<id>\d\d\d\d-\d\d\d\d-\d\d\d\d)\n(?<css_class>\S+)$/ =~ msg["data"]["body"]
14
14
  puts "invalid message for #{msg["data"]["subject"]}: %p" % msg["data"]["body"] if ENV["LOGNAME"] == "nakilon"
15
15
  # puts "marking invalid message as read: %p" % msg["data"]["body"]
@@ -1,11 +1,10 @@
1
1
  require_relative "../boilerplate"
2
2
 
3
+ BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true
3
4
  SUBREDDIT = "sexypizza"
4
- BOT = RedditBot::Bot.new YAML.load(File.read "secrets.yaml"), ignore_captcha: true#, subreddit: SUBREDDIT
5
-
6
5
 
7
6
  loop do
8
- AWSStatus::touch
7
+ Hearthbeat.beat "u_SexyPizzaBot_r_sexypizza", 3610 unless Gem::Platform.local.os == "darwin"
9
8
  puts "LOOP #{Time.now}"
10
9
 
11
10
  flairs = BOT.json(:get, "/r/#{SUBREDDIT}/api/flairlist", {limit: 1000})["users"]
@@ -16,14 +15,20 @@ loop do
16
15
  "--------------|-----------------\n" +
17
16
  flairs.
18
17
  group_by{ |flair| flair["flair_text"] }.
19
- # reject{ |flair, | flair.empty? }.
20
18
  sort_by{ |_, group| -group.size }.
21
19
  map{ |flair, group| "#{flair} | #{group.size}" }.
22
- # map{ |flair, group| "#{flair} | #{group.size} | #{group.map{ |u| u["user"] }.join ", "}" }.
23
20
  join("\n")
24
- puts text
25
21
 
26
- p BOT.wiki_edit SUBREDDIT, "toppings", text
22
+ if text != BOT.json(:get, "/r/#{SUBREDDIT}/wiki/toppings")["data"]["content_md"]
23
+ puts "editing wiki page '/r/#{SUBREDDIT}/wiki/toppings'"
24
+ pp text
25
+ p json :post,
26
+ "/r/#{SUBREDDIT}/api/wiki/edit",
27
+ page: "toppings",
28
+ content: text
29
+ else
30
+ puts "nothing to change"
31
+ end
27
32
 
28
33
  sleep 3600
29
34
  end
@@ -4,8 +4,8 @@ GEM
4
4
  addressable (2.3.8)
5
5
  fastimage (1.7.0)
6
6
  addressable (~> 2.3, >= 2.3.5)
7
- json (1.8.3)
8
- reddit_bot (1.1.5)
7
+ json (2.0.2)
8
+ reddit_bot (1.1.8)
9
9
  json
10
10
 
11
11
  PLATFORMS
@@ -16,4 +16,4 @@ DEPENDENCIES
16
16
  reddit_bot (~> 1.1.5)
17
17
 
18
18
  BUNDLED WITH
19
- 1.11.2
19
+ 1.13.1
@@ -1,8 +1,8 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- json (1.8.3)
5
- reddit_bot (1.1.7)
4
+ json (2.0.2)
5
+ reddit_bot (1.1.8)
6
6
  json
7
7
 
8
8
  PLATFORMS
@@ -12,4 +12,4 @@ DEPENDENCIES
12
12
  reddit_bot (~> 1.1.0)
13
13
 
14
14
  BUNDLED WITH
15
- 1.12.3
15
+ 1.13.1
data/lib/reddit_bot.rb CHANGED
@@ -8,7 +8,7 @@ require "json"
8
8
 
9
9
 
10
10
  module RedditBot
11
- VERSION = "1.1.8" # :nodoc:
11
+ VERSION = "1.2.0" # :nodoc:
12
12
 
13
13
  class Bot
14
14
 
@@ -50,17 +50,17 @@ module RedditBot
50
50
  response
51
51
  end
52
52
 
53
- # [subreddit] +String+ subreddit name without "/r" prefix
54
- # [page] +String+ page name without "/wiki/" prefix
55
- # [text] :nodoc:
56
- def wiki_edit subreddit, page, text
57
- puts "editing wiki page '/r/#{subreddit}/wiki/#{page}'"
58
- json :post,
59
- "/r/#{subreddit}/api/wiki/edit",
60
- page: page,
61
- content: text
62
- # ["previous", result["data"]["children"].last["id"]],
63
- end
53
+ # # [subreddit] +String+ subreddit name without "/r" prefix
54
+ # # [page] +String+ page name without "/wiki/" prefix
55
+ # # [text] :nodoc:
56
+ # def wiki_edit subreddit, page, text
57
+ # puts "editing wiki page '/r/#{subreddit}/wiki/#{page}'"
58
+ # json :post,
59
+ # "/r/#{subreddit}/api/wiki/edit",
60
+ # page: page,
61
+ # content: text
62
+ # # ["previous", result["data"]["children"].last["id"]],
63
+ # end
64
64
 
65
65
  # [reason] :nodoc:
66
66
  # [thing_id] +String+ fullname of a "link, commenr or message"
@@ -98,6 +98,36 @@ module RedditBot
98
98
  end
99
99
  end
100
100
 
101
+ # :yields: JSON objects: ["data"] part of post or self.post
102
+ def new_posts caching = false
103
+ cache = lambda do |id, &block|
104
+ next block.call unless caching
105
+ require "fileutils"
106
+ FileUtils.mkdir_p "cache"
107
+ filename = "cache/#{Digest::MD5.hexdigest id.inspect}"
108
+ next YAML.load File.read filename if File.exist? filename
109
+ block.call.tap do |data|
110
+ File.write filename, YAML.dump(data)
111
+ end
112
+ end
113
+ Enumerator.new do |e|
114
+ after = {}
115
+ loop do
116
+ args = [:get, "/r/#{@subreddit}/new", {limit: 100}.merge(after)]
117
+ result = cache.call(args){ json *args }
118
+ fail if result.keys != %w{ kind data }
119
+ fail if result["kind"] != "Listing"
120
+ fail if result["data"].keys != %w{ modhash children after before }
121
+ result["data"]["children"].each do |post|
122
+ fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
123
+ e << post["data"]
124
+ end
125
+ break unless marker = result["data"]["after"]
126
+ after = {after: marker}
127
+ end
128
+ end
129
+ end
130
+
101
131
  # :yields: JSON objects: ["data"] part of post or self.post, top level comment (["children"] element)
102
132
  def each_new_post_with_top_level_comments
103
133
  json(:get, "/r/#{@subreddit}/new")["data"]["children"].each do |post|
@@ -239,7 +269,7 @@ module RedditBot
239
269
  x-ratelimit-used
240
270
  x-ratelimit-reset
241
271
  }.map{ |key| "#{key}=#{response.to_hash[key]}" }.join ", " \
242
- if ENV["LOGNAME"] == "nakilon"
272
+ if Gem::Platform.local.os == "darwin"
243
273
  # if response.to_hash["x-ratelimit-remaining"]
244
274
  # p response.to_hash["x-ratelimit-remaining"][0]
245
275
  # fail response.to_hash["x-ratelimit-remaining"][0]
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.1.8
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json