Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

zomg whitespace

  • Loading branch information...
commit 3f36201b3fe0a0eafec177b97c44fe4b848e9e15 1 parent c03314e
@nate nate authored
Showing with 95 additions and 96 deletions.
  1. +7 −7 README.mkd
  2. +1 −1  ceiling_cat.gemspec
  3. +2 −2 examples/Chatfile
  4. +4 −4 lib/ceiling_cat/connection.rb
  5. +4 −4 lib/ceiling_cat/errors.rb
  6. +3 −3 lib/ceiling_cat/event.rb
  7. +2 −2 lib/ceiling_cat/plugins/about.rb
  8. +5 −5 lib/ceiling_cat/plugins/base.rb
  9. +5 −5 lib/ceiling_cat/plugins/calc.rb
  10. +1 −1  lib/ceiling_cat/plugins/call_and_response.rb
  11. +1 −2  lib/ceiling_cat/plugins/campfire_account_monitor.rb
  12. +9 −9 lib/ceiling_cat/plugins/days.rb
  13. +2 −2 lib/ceiling_cat/plugins/greeter.rb
  14. +2 −2 lib/ceiling_cat/plugins/notifo.rb
  15. +1 −1  lib/ceiling_cat/services/campfire/connection.rb
  16. +2 −2 lib/ceiling_cat/services/campfire/event.rb
  17. +2 −2 lib/ceiling_cat/services/irc/event.rb
  18. +6 −6 lib/ceiling_cat/services/irc/room.rb
  19. +6 −6 lib/ceiling_cat/setup.rb
  20. +1 −1  lib/ceiling_cat/storage/yaml.rb
  21. +2 −2 lib/ceiling_cat/user.rb
  22. +2 −2 setup/Chatfile
  23. +1 −1  spec/ceiling_cat/connection_spec.rb
  24. +5 −5 spec/ceiling_cat/plugins/about_spec.rb
  25. +4 −4 spec/ceiling_cat/plugins/calc_spec.rb
  26. +6 −6 spec/ceiling_cat/plugins/days_spec.rb
  27. +1 −1  spec/ceiling_cat/plugins/greeter_spec.rb
  28. +5 −5 spec/ceiling_cat/plugins/notifo_spec.rb
  29. +1 −1  spec/ceiling_cat/room_spec.rb
  30. +2 −2 spec/ceiling_cat/services/irc/room_spec.rb
View
14 README.mkd
@@ -21,19 +21,19 @@ Install the gem. You can use bundler and a Gemfile:
or you can install it from the command line:
$ gem install ceiling_cat
-
+
Once it's installed you'll see some directions on getting started, which are paraphrased here.
In your Ceiling Cat's directory run
$ ceiling_cat setup
-
+
to create the basic structure of a Ceiling Cat app. This will copy a Chatfile and Rakefile over for you and create a plugins folder.
Edit your Chatfile with your Campfire credentials (more services coming soon) and then run
$ ceiling_cat
-
+
and Ceiling Cat will start watching the room you specified.
You mentioned something about plugins...
@@ -44,7 +44,7 @@ If you've loaded the About plugin, type
!plugins
!commands
-
+
in chat to see a list of the plugins you have currently loaded and the commands that each makes available. These commands are scoped by user role, so make sure you're on a registered (non-guest) account to see everything.
### About ###
@@ -95,7 +95,7 @@ Can I make my own plugins?
Ceiling Cat comes with several plugins for you to use right away, but you can also create your own. Just run
$ rake plugin:create name=plugin_name
-
+
where plugin_name is the name of your plugin, and the skeleton of a plugin will be created in the plugins folder. Require it in your Chatfile, add it to the plugins array in CeilingCat::Setup, and Ceiling Cat will start using your plugin while it watches you chat.
Take a look at plugins/base.rb in the gem to see what methods are available to you.
@@ -106,12 +106,12 @@ Ceiling Cat can write to memory or to a YAML file. Set that up in your Chatfile
CeilingCat::Storage::Yaml.file = "ceilingcat.yml"
config.storage = CeilingCat::Storage::Yaml
-
+
Once that's done all you have to do is call
store["foo"] = "bar"
store["foo"] #=> bar
-
+
and Ceiling Cat will store your data. Use YAML if you want your data to be persistent, or don't set anything and Ceiling Cat will write to memory.
Contributing
View
2  ceiling_cat.gemspec
@@ -32,7 +32,7 @@ campfire = ["lib/ceiling_cat/services/campfire.rb",
"lib/ceiling_cat/services/campfire/connection.rb",
"lib/ceiling_cat/services/campfire/event.rb",
"lib/ceiling_cat/services/campfire/room.rb"]
-
+
irc = ["lib/ceiling_cat/services/irc.rb",
"lib/ceiling_cat/services/irc/connection.rb",
"lib/ceiling_cat/services/irc/event.rb",
View
4 examples/Chatfile
@@ -17,11 +17,11 @@ CeilingCat::Setup.configure do |config|
# config.nick = 'nickname'
# config.password = 'Q7Af6laDKza2SOM'
# config.room = '#my_room'
-
+
config.plugins = [CeilingCat::Plugin::About,
CeilingCat::Plugin::Greeter,
CeilingCat::Plugin::Calc]
-
+
# Some plugins require storage
CeilingCat::Storage::Yaml.file = "ceilingcat.yml"
config.storage = CeilingCat::Storage::Yaml
View
8 lib/ceiling_cat/connection.rb
@@ -1,19 +1,19 @@
module CeilingCat
class Connection
attr_accessor :config
-
+
def initialize(config)
@config=config
@config.storage ||= CeilingCat::Storage::Hash
end
-
+
def plugins
self.config.plugins
end
-
+
def storage
self.config.storage
end
-
+
end
end
View
8 lib/ceiling_cat/errors.rb
@@ -5,13 +5,13 @@ def initialize(message)
super message
end
end
-
+
# Gem Specific Errors
class CeilingCatError < StandardError; end
-
+
class UnsupportedChatServiceError < CeilingCatError; end
-
+
class NotImplementedError < CeilingCatError; end
-
+
class ReloadException < CeilingCatError; end
end
View
6 lib/ceiling_cat/event.rb
@@ -9,8 +9,8 @@ def initialize(room, body,user,opts={})
@type = opts[:type]
@time = opts[:time] || Time.now
end
-
- def handle
+
+ def handle
@room.plugins.each do |plugin|
puts "running #{plugin}"
begin
@@ -21,7 +21,7 @@ def handle
end
end
end
-
+
def type # assume that all messages are just text unless the specific room type overrides it.
@type || :chat
end
View
4 lib/ceiling_cat/plugins/about.rb
@@ -29,7 +29,7 @@ def list_commands
messages << "Run commands with '![command]' or '#{room.me.name}: [command]'"
reply messages
end
-
+
def list_users
members = room.users_in_room(:type => "member")
if members.size > 0
@@ -38,7 +38,7 @@ def list_users
reply "There are no registered users in the room at this time."
end
end
-
+
def list_guests
guests = room.users_in_room(:type => "guest")
if guests.size > 0
View
10 lib/ceiling_cat/plugins/base.rb
@@ -47,11 +47,11 @@ def event
def room
event.room
end
-
+
def store
self.class.store
end
-
+
def self.store
CeilingCat::Setup.config ? CeilingCat::Setup.config.storage : CeilingCat::Storage::Hash
end
@@ -67,7 +67,7 @@ def user
def reply(message)
room.say(message)
end
-
+
def words
body.split
end
@@ -79,11 +79,11 @@ def body_without_command(command,text=body)
def body_without_nick(text=body)
text.sub(/^#{room.me.name}:?\s*/i,'').strip
end
-
+
def body_without_nick_or_command(command,text=body)
body_without_command(command, body_without_nick(text).sub(/^#{command}/i,"!#{command}"))
end
-
+
def pluralize(n, singular, plural=nil)
if n == 1
"#{singular}"
View
10 lib/ceiling_cat/plugins/calc.rb
@@ -1,22 +1,22 @@
module CeilingCat
module Plugin
- class Calc < CeilingCat::Plugin::Base
+ class Calc < CeilingCat::Plugin::Base
def self.commands
[{:command => "calculate", :description => "Performs basic math functions - '!calculate 7*5'", :method => "calculate", :public => true}]
end
-
+
def self.description
"A basic calculator, for all your mathin' needs!"
end
-
+
def self.name
"Calculator"
end
-
+
def self.public?
true
end
-
+
def calculate
begin
math = body.gsub(/[^\d+-\/*\(\)\.]/,"") # Removing anything but numbers, operators, and parens
View
2  lib/ceiling_cat/plugins/call_and_response.rb
@@ -10,7 +10,7 @@ def handle
end
super
end
-
+
end
def self.commands
View
3  lib/ceiling_cat/plugins/campfire_account_monitor.rb
@@ -13,7 +13,7 @@ def handle
user_count = room.connection.total_user_count
max_users = room.connection.config.max_users || 100
if room.plugin_installed?("notifo") && user_count > max_users-2
- room.plugin("notifo").new(@event).deliver("#{user_count} of #{max_users} max connections to Campfire.")
+ room.plugin("notifo").new(@event).deliver("#{user_count} of #{max_users} max connections to Campfire.")
end
end
super
@@ -45,4 +45,3 @@ def total_users
end
end
end
-
View
18 lib/ceiling_cat/plugins/days.rb
@@ -7,7 +7,7 @@ def self.commands
[{:command => "today", :description => "Find out if there's anything special about today.", :method => "about", :public => true},
{:command => "add holiday", :description => "Add a holiday - '!add holiday 1/19/2011'", :method => "add_to_holidays"}]
end
-
+
def about(date=Date.today)
begin
if self.class.is_a_holiday?(date)
@@ -21,11 +21,11 @@ def about(date=Date.today)
reply "Sorry, that's not a valid date."
end
end
-
+
def self.description
"Holidays and times you shouldn't expect to see us in chat."
end
-
+
def add_to_holidays
date = body_without_command("add holiday")
if date.empty?
@@ -39,7 +39,7 @@ def add_to_holidays
end
end
end
-
+
def self.is_a_weekend?(date=Date.today)
if is_a_date?(date)
date = Date.parse(date.to_s)
@@ -48,11 +48,11 @@ def self.is_a_weekend?(date=Date.today)
raise NotADateError
end
end
-
+
def self.holidays
store["holidays"] ||= []
end
-
+
def self.add_to_holidays(days)
dates = Array(days).collect do |day|
if is_a_date?(day)
@@ -73,10 +73,10 @@ def self.remove_from_holidays(days)
raise NotADateError
end
end
-
+
store["holidays"] = holidays - dates
end
-
+
def self.is_a_holiday?(date=Date.today)
if is_a_date?(date)
holidays.include? Date.parse(date.to_s)
@@ -84,7 +84,7 @@ def self.is_a_holiday?(date=Date.today)
raise NotADateError
end
end
-
+
def self.is_a_date?(date_string)
begin
return true if Date.parse(date_string.to_s)
View
4 lib/ceiling_cat/plugins/greeter.rb
@@ -17,11 +17,11 @@ def handle
super
end
end
-
+
def self.name
"Greeter"
end
-
+
def self.description
"Welcomes visitors and memebrs to chat."
end
View
4 lib/ceiling_cat/plugins/notifo.rb
@@ -28,7 +28,7 @@ def self.active?
false
end
end
-
+
def active?
self.class.active?
end
@@ -45,7 +45,7 @@ def self.add_users(users)
store["notifo_users"] ||= []
store["notifo_users"] = (Array(store["notifo_users"]) + Array(users)).uniq
end
-
+
def self.remove_users(users)
store["notifo_users"] ||= []
store["notifo_users"] = (Array(store["notifo_users"]) - Array(users)).uniq
View
2  lib/ceiling_cat/services/campfire/connection.rb
@@ -11,7 +11,7 @@ def initialize(config)
def campfire
@campfire = Tinder::Campfire.new(self.config.subdomain, :token => self.config.token, :ssl => self.config.ssl)
end
-
+
def total_user_count
users = 0
@campfire.rooms.each do |room|
View
4 lib/ceiling_cat/services/campfire/event.rb
@@ -1,7 +1,7 @@
module CeilingCat
module Campfire
class Event < CeilingCat::Event
-
+
def type
case @type
when "EnterMessage", :entrance
@@ -12,7 +12,7 @@ def type
:exit
end
end
-
+
end
end
end
View
4 lib/ceiling_cat/services/irc/event.rb
@@ -1,7 +1,7 @@
module CeilingCat
module IRC
class Event < CeilingCat::Event
-
+
def type
case @type
when "EnterMessage", :entrance
@@ -12,7 +12,7 @@ def type
:exit
end
end
-
+
end
end
end
View
12 lib/ceiling_cat/services/irc/room.rb
@@ -19,7 +19,7 @@ def watch
irc.nick config.nickname
irc.pass config.password if config.password.present?
irc.user config.nickname, "+B", "*", config.nickname
-
+
while line = irc.read
# Join a channel after MOTD
if line.split[1] == '376'
@@ -31,7 +31,7 @@ def watch
@ops_names << match[1] if match[2].include?("O")
@ops_names.uniq!
end
-
+
puts "Received: #{line}"
begin
if message = message_parts(line)
@@ -60,7 +60,7 @@ def say(something_to_say)
irc.privmsg config.room, line
end
end
-
+
def users_in_room(opts={})
@user_names.collect {|user_name|
user_name = user_name.sub(/^@/,"")
@@ -76,7 +76,7 @@ def users_in_room(opts={})
end
}.compact
end
-
+
def user_role(name)
if @ops_names.include?(name)
"member"
@@ -84,7 +84,7 @@ def user_role(name)
"guest"
end
end
-
+
def is_me?(user)
user.name == me.name
end
@@ -92,7 +92,7 @@ def is_me?(user)
def me
@me ||= CeilingCat::User.new(config.nickname, :role => "member")
end
-
+
def message_parts(message)
if message =~ /\sPRIVMSG\s/
parts = message.match /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(#.+):(.+)/i
View
12 lib/ceiling_cat/setup.rb
@@ -2,16 +2,16 @@
module CeilingCat
class Setup
-
+
attr_accessor :config
-
+
class << self
# Class-level config. This is set by the +configure+ class method,
# and is used if no configuration is passed to the +initialize+
# method.
attr_accessor :config
end
-
+
# Configures the connection at the class level. When the +ceiling_cat+ bin
# file is loaded, it evals the file referenced by the first
# command-line parameter. This file can configure the connection
@@ -27,11 +27,11 @@ def self.configure
def config=(config)
@config = config.kind_of?(Hash) ? OpenStruct.new(config) : config
end
-
+
def initialize(_config = nil)
self.config = _config || self.class.config
end
-
+
def connect
case self.config.service.downcase
when 'campfire'
@@ -46,6 +46,6 @@ def connect
raise CeilingCat::UnsupportedChatServiceError.new("#{self.config.service} is not a supported chat service.")
end
end
-
+
end
end
View
2  lib/ceiling_cat/storage/yaml.rb
@@ -14,7 +14,7 @@ def file=(f)
@file
end
- # Sets the key +k+ to the value +v+
+ # Sets the key +k+ to the value +v+
def []=(k, v)
internal[k] = v
persist!
View
4 lib/ceiling_cat/user.rb
@@ -7,11 +7,11 @@ def initialize(name, opts={})
@id = opts[:id] || rand(10000000)
@role = opts[:role] || "guest"
end
-
+
def to_s
short_name
end
-
+
def short_name
@name.to_s.split.compact.first
end
View
4 setup/Chatfile
@@ -17,11 +17,11 @@ CeilingCat::Setup.configure do |config|
# config.nick = 'nickname'
# config.password = 'Q7Af6laDKza2SOM'
# config.room = '#my_room'
-
+
config.plugins = [CeilingCat::Plugin::About,
CeilingCat::Plugin::Greeter,
CeilingCat::Plugin::Calc]
-
+
# Some plugins require storage
CeilingCat::Storage::Yaml.file = "ceilingcat.yml"
config.storage = CeilingCat::Storage::Yaml
View
2  spec/ceiling_cat/connection_spec.rb
@@ -9,7 +9,7 @@
cc.config.plugins.should include(CeilingCat::Plugin::About)
end
end
-
+
describe "creating an instance" do
it "uses the defaul if there's no storage option passed" do
config = OpenStruct.new({:service => 'campfire', :subdomain => 'user', :token => '1234abcd', :room => 'Room'})
View
10 spec/ceiling_cat/plugins/about_spec.rb
@@ -6,10 +6,10 @@
subdomain = "subdomain"
token = "1234abcd"
plugins = [CeilingCat::Plugin::About]
-
+
FakeWeb.register_uri(:get, "https://#{token}:X@#{subdomain}.campfirenow.com/rooms.json", :body => fixture('campfire/rooms.json'), :status => ["200"])
FakeWeb.register_uri(:get, "https://#{token}:X@#{subdomain}.campfirenow.com/users/me.json", :body => fixture('campfire/me.json'), :status => ["200"])
-
+
@connection = CeilingCat::Campfire::Connection.new(OpenStruct.new({:service => 'campfire', :subdomain => subdomain, :token => token, :room => 'Room 1', :plugins => plugins}))
@room = CeilingCat::Campfire::Room.new(:connection => @connection, :room_name => @connection.config.room)
end
@@ -26,7 +26,7 @@
CeilingCat::Plugin::About.new(event).handle
end
end
-
+
describe "calling the commands command" do
it "should not list public commands" do
event = CeilingCat::Event.new(@room,"!commands", @guest_user)
@@ -35,7 +35,7 @@
end
end
end
-
+
describe "a registered user" do
before(:each) do
@registered_user = CeilingCat::User.new("Guest", :id => 12345, :role => "member")
@@ -48,7 +48,7 @@
CeilingCat::Plugin::About.new(event).handle
end
end
-
+
describe "calling the commands command" do
it "should not list public commands" do
event = CeilingCat::Event.new(@room,"!commands", @registered_user)
View
8 spec/ceiling_cat/plugins/calc_spec.rb
@@ -6,10 +6,10 @@
subdomain = "subdomain"
token = "1234abcd"
plugins = [CeilingCat::Plugin::Calc]
-
+
FakeWeb.register_uri(:get, "https://#{token}:X@#{subdomain}.campfirenow.com/rooms.json", :body => fixture('campfire/rooms.json'), :status => ["200"])
FakeWeb.register_uri(:get, "https://#{token}:X@#{subdomain}.campfirenow.com/users/me.json", :body => fixture('campfire/me.json'), :status => ["200"])
-
+
@connection = CeilingCat::Campfire::Connection.new(OpenStruct.new({:service => 'campfire', :subdomain => subdomain, :token => token, :room => 'Room 1', :plugins => plugins}))
@room = CeilingCat::Campfire::Room.new(:connection => @connection, :room_name => @connection.config.room)
end
@@ -25,13 +25,13 @@
@room.should_receive(:say).with("20*5 = 100")
CeilingCat::Plugin::Calc.new(event).handle
end
-
+
it "should strip out any non-math information" do
event = CeilingCat::Event.new(@room,"!calculate 20*5 `ls`", @guest_user)
@room.should_receive(:say).with("20*5 = 100")
CeilingCat::Plugin::Calc.new(event).handle
end
-
+
it "should be friendly if the mathing fails" do
event = CeilingCat::Event.new(@room,"!calculate the mass of your mom", @guest_user)
@room.should_receive(:say).with("I don't think that's an equation. Want to try something else?")
View
12 spec/ceiling_cat/plugins/days_spec.rb
@@ -52,7 +52,7 @@
it "should return true if Date.parse works" do
CeilingCat::Plugin::Days.is_a_date?("8/24/2011").should == true
end
-
+
it "should return true if Date.parse works" do
CeilingCat::Plugin::Days.is_a_date?("next tuesday").should == true
end
@@ -71,13 +71,13 @@
CeilingCat::Plugin::Days.is_a_holiday?("8/24/2011").should == false
end
end
-
+
describe "a weekend holiday" do
before(:each) do
@holiday = "8/20/2011"
CeilingCat::Plugin::Days.add_to_holidays(@holiday)
end
-
+
it "the weekend check should return true" do
CeilingCat::Plugin::Days.is_a_weekend?(@holiday).should == true
end
@@ -86,13 +86,13 @@
CeilingCat::Plugin::Days.is_a_holiday?(@holiday).should == true
end
end
-
+
describe "a week day holiday" do
before(:each) do
@holiday = "8/24/2011"
CeilingCat::Plugin::Days.add_to_holidays(@holiday)
end
-
+
it "the weekend check should return false" do
CeilingCat::Plugin::Days.is_a_weekend?(@holiday).should == false
end
@@ -151,7 +151,7 @@
end
end
end
-
+
describe "from a registered user" do
before(:each) do
@registered_user = CeilingCat::User.new("Guest", :id => 12345, :role => "member")
View
2  spec/ceiling_cat/plugins/greeter_spec.rb
@@ -29,7 +29,7 @@
CeilingCat::Plugin::Greeter.new(event).handle
end
end
-
+
describe "from a registered user" do
before(:each) do
@guest_user = CeilingCat::User.new("Member", :id => 12345, :role => "member")
View
10 spec/ceiling_cat/plugins/notifo_spec.rb
@@ -62,21 +62,21 @@
CeilingCat::Plugin::Notifo.active?.should == false
end
end
-
+
describe "credentials set without users" do
it "should be false" do
CeilingCat::Plugin::Notifo.set_credentials("username","api_secret")
CeilingCat::Plugin::Notifo.active?.should == false
end
end
-
+
describe "users set without credentials" do
it "should be false" do
CeilingCat::Plugin::Notifo.add_users("zencoder")
CeilingCat::Plugin::Notifo.active?.should == false
end
end
-
+
describe "users and credentials set" do
it "should be true" do
CeilingCat::Plugin::Notifo.add_users("zencoder")
@@ -92,7 +92,7 @@
CeilingCat::Plugin::Notifo.add_users("ceiling_cat")
CeilingCat::Plugin::Notifo.set_credentials("username","api_secret")
end
-
+
describe "from a guest user" do
before(:each) do
@guest_user = CeilingCat::User.new("Guest", :id => 12345, :role => "guest")
@@ -130,7 +130,7 @@
end
end
end
-
+
describe "from a registered user" do
before(:each) do
@registered_user = CeilingCat::User.new("Member", :id => 12345, :role => "member")
View
2  spec/ceiling_cat/room_spec.rb
@@ -1,5 +1,5 @@
# require 'spec_helper'
-#
+#
# describe "CampfireRoom" do
# describe "creating an instance" do
# it "loads the Chatfile and sets config" do
View
4 spec/ceiling_cat/services/irc/room_spec.rb
@@ -6,7 +6,7 @@
@connection = CeilingCat::IRC::Connection.new(OpenStruct.new({:service => 'irc', :room => '#room_1', :nick => "test bot"}))
@room = CeilingCat::IRC::Room.new(:connection => @connection, :room_name => @connection.config.room)
end
-
+
describe "parsing messages" do
it "gets name, body, and event type from a chat message" do
parts = @room.message_parts(":chriswarren!~chriswarr@50.0.132.2 PRIVMSG #ceilingcat_test :!status")
@@ -14,7 +14,7 @@
parts[:body].should == "!status"
parts[:type].should == :chat
end
-
+
it "gets name, body, and event type from a JOIN message" do
parts = @room.message_parts(":chriswarren!~chriswarr@50.0.132.2 JOIN :#ceilingcat_test")
parts[:name].should == "chriswarren"
Please sign in to comment.
Something went wrong with that request. Please try again.