blob: 99292f1cc5b86c7637a80d7501b784b733a56ec4 (
plain)
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
79
80
81
82
83
|
# Author: Michael Brailsford <brailsmt@yahoo.com>
# aka brailsmt
# Purpose: To respond to requests for information from the ri command line
# utility.
class RiPlugin < Plugin
@@handlers = {
"ri" => "ri_handler",
"msgri" => "msgri_handler"
}
#{{{
def initialize
super
@cache = Hash.new
end
#}}}
#{{{
def privmsg(m)
if not m.params
m.reply "uhmm... whatever"
return
end
meth = self.method(@@handlers[m.plugin])
meth.call(m)
end
#}}}
#{{{
def cleanup
@cache = nil
end
#}}}
#{{{
def ri_handler(m)
response = ""
if @cache[m.params]
response = @cache[m.params]
else
IO.popen("-") {|p|
if(p)
response = p.readlines.join "\n"
@cache[m.params] = response
else
$stderr = $stdout
exec("ri", m.params)
end
}
@cache[m.params] = response
end
@bot.say m.sourcenick, response
m.reply "Finished \"ri #{m.params}\""
end
#}}}
#{{{
def msgri_handler(m)
response = ""
tell_nick, query = m.params.split()
if @cache[query]
response = @cache[query]
else
IO.popen("-") {|p|
if(p)
response = p.readlines.join "\n"
@cache[m.params] = response
else
$stderr = $stdout
exec("ri", query)
end
}
@cache[query] = response
end
@bot.say tell_nick, response
m.reply "Finished telling #{tell_nick} about \"ri #{query}\""
end
#}}}
end
plugin = RiPlugin.new
plugin.register("ri")
plugin.register("msgri")
|