Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

re-adding fun plugin as an example; updated readme

  • Loading branch information...
commit 17449be74981c9757a9b4fbbb8fd388d5252f2e7 1 parent f32f3a1
@joshwand authored
Showing with 102 additions and 0 deletions.
  1. +7 −0 README.textile
  2. +95 −0 plugins-example/fun.rb
View
7 README.textile
@@ -29,6 +29,13 @@ Example:
@campfire-bot -c config.yml -e production -p ./plugins@
+h2. Plugins
+
+See plugins-example/fun.rb for an example plugin.
+
+The old plugins that used to be bundled with campfire-bot are now in their own repo: "campfire-bot-plugins":https://github.com/campfire-bot-plugins
+
+
h2. Known issues
h3. [BUG] Bus Error
View
95 plugins-example/fun.rb
@@ -0,0 +1,95 @@
+class Fun < CampfireBot::Plugin
+ on_command 'say', :say
+ on_message Regexp.new("^#{bot.config['nickname']},\\s+(should|can|will|shall) (i|he|she|we|they) do it\\?", Regexp::IGNORECASE), :do_or_do_not
+ on_message Regexp.new("^(good morning|morning|m0ink|hello|hi|hey|whassup|what's up|yo|hola|ola|'sup|sup)(,)*\\s*(#{bot.config['nickname']}).*$", Regexp::IGNORECASE), :greet
+ on_message /(how's it|how are|how're) (ya |you )*(going|doing|doin).*/, :howareya
+ on_command "blame", :blame
+ on_command "trout", :trout
+ on_command "slap", :trout
+ on_command "troutslap", :trout
+ # on_speaker 'Tim R.', :agree_with_tim
+ # on_message /undo it/i, :do_it
+ # on_message /(^|\s)do it/i, :undo_it
+ # at_time 1.minute.from_now, :do_it
+
+ def initialize
+ @last_agreed = 20.minutes.ago
+ @log = Logging.logger["CampfireBot::Plugin::Fun"]
+ end
+
+ def say(m)
+ m.speak(m[:message])
+ end
+
+ def do_it(m = nil)
+ m.speak('Do it!')
+ end
+
+ def undo_it(m)
+ m.speak('Undo it!')
+ end
+
+ def do_or_do_not(m)
+ responses = ['Do it!', 'Don\'t do it!', 'Undo it!']
+ m.speak(responses.choice)
+ end
+
+ def agree_with_tim(m)
+ m.speak('I agree with Tim.') unless @last_agreed > 15.minutes.ago
+ @last_agreed = Time.now
+ end
+
+ def greet(m)
+ messages = ['Howdy', 'Wassup', 'Greets', 'Hello', 'Hey there', "It's a", 'Good day']
+ m.speak("#{messages.choice} #{m[:person].split(' ')[0]}")
+ end
+
+ def howareya(m)
+ messages = ["just great", "peachy", "mas o menos",
+ "you know how it is", "eh, ok", "pretty good. how about you?"]
+ m.speak(messages[rand(messages.size)])
+ end
+
+ def blame(m)
+ # TODO: capture user-submitted entries to a yaml file and regurgitate them
+ # TODO: put all the default ones in a separate yaml
+ if m[:message].strip.length > 0
+ blamed = m[:message].strip
+ else
+ users = m[:room].users.delete_if {|u| u[:name] == bot.campfire.me[:name]}.map {|u| u[:name]}
+ others = ["nobody", "my", "Microsoft", "Steve Jobs", "the terrorists", "your",
+ "Project Management", "Development", "Management", "Corporate", "Cartman", "the user",
+ "the liberal media", "Wall Street"]
+
+ # mostly blame the other users
+ if rand(10) >= 2
+ blamed = users.choice
+ else
+ blamed = others.choice
+ end
+
+ end
+
+ case blamed
+ when "nobody"
+ blamestring = "It's nobody's fault"
+ when "your", "my"
+ blamestring = "It's all #{blamed} fault"
+ else
+ blamestring = "It's all #{blamed}'s fault"
+ blamestring = "It's all #{blamed}' fault" if blamed[-1].chr == "s"
+ end
+
+ m.speak blamestring
+ end
+
+ def trout(m)
+ if m[:message].strip.length > 0
+ selected_user_name = m[:message].strip
+ else
+ users = m[:room].users.map{|u| u[:name] }
+ selected_user_name = users.choice
+ end
+ m.speak("#{m[:person]} slaps #{selected_user_name} #{["upside the head", "in the face", "on the rear", "where it counts", "in the knees", "ineffectually", "in the elbow", "on the funny bone", "in the ear", "on the nose", "in the teeth"].choice} with a #{%w(good-sized large decaying moldy spiked sabre-toothed surprised disappointed dramatic enraged rabid bug-eyed rotten foul-smelling demonic cluestick-holding).choice} trout")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.