Browse files

Adding two more examples (nice idea on the dice dale)

  • Loading branch information...
1 parent a782e17 commit 589762618f5a96f34fd866575e63092523baa6bf @raggi committed Nov 13, 2009
Showing with 27 additions and 0 deletions.
  1. +15 −0 examples/dice.bot
  2. +12 −0 examples/fortune.bot
View
15 examples/dice.bot
@@ -0,0 +1,15 @@
+class Dice
+ attr_accessor :client
+ def on_message(sender, content, event)
+ return if sender['name'] == 'bot'
+ case content
+ when /(\d+)[dD](\d+)(?:\+(\d+))/
+ results = Array.new($1.to_i){ 1+rand($2.to_i) }
+ total = results.inject { |t,v| t + v }
+ total += $3.to_i if $3
+ client.send_message "#{total} from #{results.inspect} #{"+#{$3}" if $3}"
+ end
+ end
+end
+
+use Dice.new
View
12 examples/fortune.bot
@@ -0,0 +1,12 @@
+class Fortune
+ attr_accessor :client
+ def on_message(sender, content, event)
+ return if sender['name'] == 'bot'
+ case content
+ when /!fortune/
+ client.send_message `fortune`
+ end
+ end
+end
+
+use Fortune.new

0 comments on commit 5897626

Please sign in to comment.