summaryrefslogtreecommitdiff
path: root/rbot/plugins/fortune.rb
blob: 6d077c85322cd9ce5d27ed56c61af03329b0e25a (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
class FortunePlugin < Plugin
  def help(plugin, topic="")
    "fortune [<module>] => get a (short) fortune, optionally specifying fortune db"
  end
  def privmsg(m)
    case m.params
    when (/\B-/)
      m.reply "incorrect usage: " + help(m.plugin)
      return
    when (/^([\w-]+)$/)
      db = $1
    when nil
      db = "fortunes"
    else
      m.reply "incorrect usage: " + help(m.plugin)
      return
    end
    fortune = nil
    ["/usr/games/fortune", "/usr/bin/fortune", "/usr/local/bin/fortune"].each {|f|
      if FileTest.executable? f
        fortune = f
        break
      end
    }
    m.reply "fortune not found" unless fortune
    ret = Utils.safe_exec(fortune, "-n", "255", "-s", db)
    m.reply ret.gsub(/\t/, "  ").split(/\n/).join(" ")
    return
  end
end
plugin = FortunePlugin.new
plugin.register("fortune")