Module: Snoo::Moderation
- Defined in:
- lib/snoo/moderation.rb
Overview
Methods for moderating on reddit, including tasks such as removing, approving, and distinguishing
Instance Method Summary collapse
-
#approve(id) ⇒ Object
Approve a thing.
-
#distinguish(id, how = "yes") ⇒ Object
Distinguish a thing.
-
#get_modlog(subreddit, opts = {}) ⇒ Hash
Gets a moderation log This is a tricky function, and may break a lot.
-
#get_modqueue(subreddit, opts = {}) ⇒ Object
Get the modqueue, or a subset of it (dear god).
-
#leave_contributor(id) ⇒ Object
Removes you from a subreddits list of contributors.
-
#leave_moderator(id) ⇒ Object
Removes you from a subreddits moderators.
-
#remove(id, spam = false) ⇒ Object
Removes a thing.
Instance Method Details
#approve(id) ⇒ Object
Approve a thing
11 12 13 14 |
# File 'lib/snoo/moderation.rb', line 11 def approve id logged_in? post('/api/approve', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#distinguish(id, how = "yes") ⇒ Object
Distinguish a thing
21 22 23 24 25 |
# File 'lib/snoo/moderation.rb', line 21 def distinguish id, how = "yes" logged_in? hows = %w{yes no admin special} post('/api/distinguish', body: {id: id, how: how, uh: @modhash, api_type: 'json'}) end |
#get_modlog(subreddit, opts = {}) ⇒ Hash
Gets a moderation log This is a tricky function, and may break a lot. Blame the lack of a real api
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/snoo/moderation.rb', line 69 def get_modlog subreddit, opts = {} logged_in? = { limit: 100 }.merge opts data = Nokogiri::HTML.parse(get("/r/#{subreddit}/about/log", query: ).body).css('.modactionlisting tr') processed = { data: [], first: data[0]['data-fullname'], first_date: Time.parse(data[0].children[0].child['datetime']), last: data[-1]['data-fullname'], last_date: Time.parse(data[-1].children[0].child['datetime']), } data.each do |tr| processed[:data] << { fullname: tr['data-fullname'], time: Time.parse(tr.children[0].child['datetime']), author: tr.children[1].child.content, action: tr.children[2].child['class'].split[1], description: tr.children[3].content, href: tr.children[3].css('a').count == 0 ? nil : tr.children[3].css('a')[0]['href'] } end return processed end |
#get_modqueue(subreddit, opts = {}) ⇒ Object
Get the modqueue, or a subset of it (dear god)
102 103 104 105 106 107 108 109 |
# File 'lib/snoo/moderation.rb', line 102 def get_modqueue subreddit, opts={} logged_in? = { limit: 100 }.merge opts get("/r/#{subreddit}/about/modqueue.json", query: ) end |
#leave_contributor(id) ⇒ Object
Removes you from a subreddits list of contributors
32 33 34 35 |
# File 'lib/snoo/moderation.rb', line 32 def leave_contributor id logged_in? post('/api/leavecontributor', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#leave_moderator(id) ⇒ Object
Removes you from a subreddits moderators
42 43 44 45 |
# File 'lib/snoo/moderation.rb', line 42 def leave_moderator id logged_in? post('/api/leavemoderator', body: {id: id, uh: @modhash, api_type: 'json'}) end |
#remove(id, spam = false) ⇒ Object
Removes a thing
52 53 54 55 |
# File 'lib/snoo/moderation.rb', line 52 def remove id, spam = false logged_in? post('/api/remove', body: {id: id, spam: spam, uh: @modhash, api_type: 'json'}) end |