Sun, 20 May 2018 02:16:48 +0200
riddim.plugins.servercontact: Query for XEP-0157: Contact Addresses for XMPP Services
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 | local http = require "net.http"; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 | local t_insert, t_remove = table.insert, table.remove; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 | local now = os.time; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 | local debug = function() end; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 | local ttl = 3600; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 | local data = { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 | rfc = { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 | source = "http://www.ietf.org/download/rfc-index.txt", |
114
d11cf84975c5
plugins.ietf: HTTPS URLs (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
111
diff
changeset
|
11 | links = "https://tools.ietf.org/html/rfc%s", |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 | }, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 | draft = { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 | source = "http://www.ietf.org/download/id-index.txt", |
114
d11cf84975c5
plugins.ietf: HTTPS URLs (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
111
diff
changeset
|
15 | links = "https://tools.ietf.org/html/%s", |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 | }, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 | } |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 | function data.rfc:update(cb) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 | debug("fetch %s", self.source); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 | http.request(self.source, { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 | headers = { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 | ["If-Modified-Since"] = self.updated_at |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 | and os.date("!%a, %d %b %Y %H:%M:%S %Z", self.updated_at) or nil; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 | } |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 | }, function (data, code) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 | debug("got status %d", code); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 | if code == 200 then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 | debug("got %d bytes of data", #data); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 | self.data = data |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 | :gsub("\n\n[^\n]+%b()\n%-+\n\n", "\n\n") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 | :gsub("\n ", " ") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 | :gsub("\n\n ", "\n") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 | :gsub("\n ", " "); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 | -- TODO Can this be made better? |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 | self.updated_at = now(); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 | self.expires = now() + ttl; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 | cb(); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 | end); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 | data.draft.update = data.rfc.update; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 | function data.rfc:_search(string, cb) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 | debug("really search for %s", string); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 | local number = tonumber(string); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 | local link, match, matches; |
110
e5903656c21a
plugins.ietf: Report number of matches
Kim Alvefur <zash@zash.se>
parents:
93
diff
changeset
|
50 | local count = 0 |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 | if number then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 | number = ("%04d"):format(number); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 | debug("search for RFC%s", number); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 | link, match = self.data:match("\n(" .. number .. ")%s*([^\n]*)"); |
110
e5903656c21a
plugins.ietf: Report number of matches
Kim Alvefur <zash@zash.se>
parents:
93
diff
changeset
|
55 | count = 1 |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 | else |
111 | 57 | local pat = string:gsub("[-()%[]", "%%%1") |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 | :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end) |
111 | 59 | :gsub("\n+", " "):gsub("\\n", "") |
60 | :gsub("%w", function(s) return '['..s:lower()..s:upper()..']' end) | |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 | debug("fulltext search for \"%s\"", pat); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 | --link, match = self.data:match("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)"); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 | for l,m in self.data:gmatch("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)") do |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 | link, match = l, m |
110
e5903656c21a
plugins.ietf: Report number of matches
Kim Alvefur <zash@zash.se>
parents:
93
diff
changeset
|
65 | count = count + 1 |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 | -- Note: This allways returns the last result. |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 | -- FIXME Decide on what to do if >1 results. |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 | --[[ |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 | matches = {}; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 | for link, match in g do |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 | t_insert(matches, {link=link, match=match}); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 | matches = t_remove(matches); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 | matches.link, matches.match; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 | --]] |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 | if match then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 | debug("matched %d bytes, number is %s", #match, link); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 | if #match > 300 then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 | cb("Match was too big"); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 | return |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 | local remove = { |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 | Also = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 | Format = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 | --Obsoleted = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 | Obsoletes = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 | --Updated = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 | Updates = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 | --Status = true, |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 | }; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 | match = match:gsub("%s*\n%s+", " ") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 | match = match:gsub("%s*%b()", function(s) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 | local first = s:match("%(([^: ]*)"); return first and remove[first] and "" or s |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 | end); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 | link = self.links:format(link); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 | match = match:gsub("%. ", ".\n", 1); -- Add a newline between title and authors |
110
e5903656c21a
plugins.ietf: Report number of matches
Kim Alvefur <zash@zash.se>
parents:
93
diff
changeset
|
100 | if count > 1 then link = link .. " (" .. count .. " more matches)" end |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 | cb(match .. "\n" .. link); |
135
87e58c58a08d
plugins.ietf: Include a link in reply if an RFC number was given but no match found
Kim Alvefur <zash@zash.se>
parents:
114
diff
changeset
|
102 | elseif number then |
87e58c58a08d
plugins.ietf: Include a link in reply if an RFC number was given but no match found
Kim Alvefur <zash@zash.se>
parents:
114
diff
changeset
|
103 | cb("Sorry, no match, try " .. self.links:format(number)); |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 | else |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 | cb("Sorry, no match"); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 | function data.draft:_search(string, cb) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 | debug("really search for %s", string); |
111 | 111 | local pat = string:gsub("[-()%[]", "%%%1") |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 | :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end) |
111 | 113 | :gsub("\n+", " "):gsub("\\n", "") |
114 | :gsub("%w", function(s) return '['..s:lower()..s:upper()..']' end) | |
93
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 | debug("fulltext search for \"%s\"", pat); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 | local match = self.data:match("\n([^\n]-"..pat.."[^\n]*)") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 | if match then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 | debug("match: %s", match); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 | local match, link = match:match("(.-)%s(%b<>)") |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 | link = link and self.links:format(link:sub(2,-2)) or "no link"; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 | cb(match .. "\n" .. link); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 | else |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 | cb("Sorry, no match"); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 | function data.rfc:search(string, cb) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 | debug("search for %s", string); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 | if not self.data then --or self.expires < now() then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 | self:update(function() self:_search(string,cb) end); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 | return |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 | else |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 | self:_search(string,cb) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 | data.draft.search = data.rfc.search; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 | function riddim.plugins.ietf(bot) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 | if bot.stream.debug then |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 | function debug(...) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 | return bot.stream:debug(...) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 | end |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 | bot:hook("commands/rfc", function(command) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 | local rfc = data.rfc; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 | debug("search for %s", command.param); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 | return rfc:search(command.param, function(match) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 | command:reply(match) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 | end) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 | end) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 | |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 | bot:hook("commands/draft", function(command) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 | local draft = data.draft; |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 | debug("search for %s", command.param); |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 | return draft:search(command.param, function(match) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 | command:reply(match) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 | end) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 | end) |
ab58062505e2
Import ietf, RFC and ID lookup plugin.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 | end |