]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - contrib/plugins/vandale.rb
initial import of rbot
[user/henk/code/ruby/rbot.git] / contrib / plugins / vandale.rb
1 #----------------------------------------------------------------#
2 # Filename: vandale.rb
3 # Description: Rbot plugin. Looks up a word in the Dutch VanDale
4 #       dictionary
5 # Author: eWoud - ewoud.nuyts<AT>student.kuleuven.ac.be
6 # requires GnuVD www.djcbsoftware.nl/projecten/gnuvd/
7 #----------------------------------------------------------------#
8
9 class VanDalePlugin < Plugin
10   def help(plugin, topic="")
11     "vandale [<word>] => Look up in the VanDale dictionary"
12   end
13   def privmsg(m)
14         case m.params
15         when (/^([\w-]+)$/)
16                 ret = Array.new
17                 Utils.safe_exec("/usr/local/bin/gnuvd", m.params).each{|line| if line.length > 5 then ret << line end}
18                 m.reply ret.delete_at(0)
19                 while ret[0] =~ /^[[:alpha:]_]*[0-9]/ 
20                         m.reply ret.delete_at(0)
21                 end
22                 while ret[0] =~ /^[0-9]/
23                         m.reply ret.delete_at(0)
24                 end
25                 i = 0
26                 while i < ret.length
27                         ret[i] = ret[i].slice(/^[[:graph:]_]*/)
28                         if ret[i].length == 0 or ret[i] =~ /^[0-9]/
29                         then
30                                 ret.delete_at(i)
31                         else
32                                 i = i+1
33                         end
34                 end
35                 if ret.length != 0 then
36                         m.reply "zie ook " + ret.join(", ")
37                 end
38                 return
39         when nil
40                 m.reply "incorrect usage: " + help(m.plugin)
41                 return
42         else
43                 m.reply "incorrect usage: " + help(m.plugin)
44                 return
45         end
46   end
47 end
48 plugin = VanDalePlugin.new
49 plugin.register("vandale")