-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfour_chan.rb
78 lines (62 loc) · 2.21 KB
/
four_chan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'cinch'
require 'ostruct'
require 'open-uri'
require 'json'
require 'cgi'
require_relative "config/check_ignore"
module Cinch
module Plugins
class FourChan
include Cinch::Plugin
set :plugin_name, '4chan'
set :help, <<-USAGE.gsub(/^ {6}/, '')
Searches 4chan.
Usage:
* !4chan <board> <terms>: This will search 4chan for results matching your request.
USAGE
match /4chan (.+?) (.+)/i
def execute(m, board, query)
return if check_ignore(m.user)
data = search(m, board, query)
return m.reply "No results found on /#{board}/ for \"#{query}\"." if data.empty?
search_result(m, data)
end
def search(m, board, terms)
chan_logo = "3::54chan:"
data = JSON.parse(open("https://a.4cdn.org/#{board}/catalog.json").read)
results = []
for i in data
for j in i['threads']
subject = j['sub']
comment = j['com']
replies = j['replies']
images = j['images']
id = j['no']
semantic = j['semantic_url']
if subject == nil
subject = "No subject"
end
if comment == nil
comment = "No comment"
end
comment_s = CGI.unescape_html(comment).gsub( %r{</?[^>]+?>}, ' ' )
comment_s = comment_s[0..200] # We need to limit the characters for 4chan comments
if subject.downcase.include? terms.downcase or comment.downcase.include? terms.downcase
results.push("%s /#{board}/ %s - %s (R:%s | I:%s) [ https://boards.4chan.org/#{board}/thread/%s/%s ]" % [chan_logo, subject, comment_s, replies, images, id, semantic])
end
end
end
return results
end
def search_result(m, data)
data[0..2].each{|i| m.reply i}
end
end
end
end
## Written by Richard Banks for Eve-Bot "The Project for a Top-Tier IRC bot.
## E-mail: namaste@rawrnet.net
## Github: Namasteh
## Website: www.rawrnet.net
## IRC: irc.sinsira.net #Eve
## If you like this plugin please consider tipping me on gittip