summaryrefslogtreecommitdiff
path: root/data/rbot/contrib/plugins/vandale.rb
blob: 7b806c85f0861b8f76ccdcd09d7a5c8f54e158fa (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
#----------------------------------------------------------------#
# Filename: vandale.rb
# Description: Rbot plugin. Looks up a word in the Dutch VanDale
# 	dictionary
# Author: eWoud - ewoud.nuyts<AT>student.kuleuven.ac.be
# requires GnuVD www.djcbsoftware.nl/projecten/gnuvd/
#----------------------------------------------------------------#

class VanDalePlugin < Plugin
  def help(plugin, topic="")
    "vandale [<word>] => Look up in the VanDale dictionary"
  end
  def privmsg(m)
	case m.params
	when (/^([\w-]+)$/)
		ret = Array.new
		Utils.safe_exec("/usr/local/bin/gnuvd", m.params).each{|line| if line.length > 5 then ret << line end}
		m.reply ret.delete_at(0)
		while ret[0] =~ /^[[:alpha:]_]*[0-9]/ 
			m.reply ret.delete_at(0)
		end
		while ret[0] =~ /^[0-9]/
			m.reply ret.delete_at(0)
		end
		i = 0
		while i < ret.length
			ret[i] = ret[i].slice(/^[[:graph:]_]*/)
			if ret[i].length == 0 or ret[i] =~ /^[0-9]/
			then
				ret.delete_at(i)
			else
				i = i+1
			end
		end
		if ret.length != 0 then
			m.reply "zie ook " + ret.join(", ")
		end
		return
	when nil
		m.reply "incorrect usage: " + help(m.plugin)
		return
	else
		m.reply "incorrect usage: " + help(m.plugin)
		return
	end
  end
end
plugin = VanDalePlugin.new
plugin.register("vandale")