ceiling_cat 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ceiling_cat +1 -1
- data/lib/ceiling_cat.rb +1 -1
- data/lib/ceiling_cat/plugins/about.rb +12 -4
- data/lib/ceiling_cat/room.rb +5 -5
- data/lib/ceiling_cat/services/campfire/room.rb +7 -6
- data/lib/ceiling_cat/services/irc.rb +3 -0
- data/lib/ceiling_cat/services/irc/connection.rb +24 -0
- data/lib/ceiling_cat/services/irc/event.rb +18 -0
- data/lib/ceiling_cat/services/irc/room.rb +113 -0
- data/lib/ceiling_cat/setup.rb +4 -0
- data/lib/ceiling_cat/user.rb +2 -2
- data/lib/ceiling_cat/version.rb +1 -1
- data/setup/Chatfile +8 -0
- metadata +30 -10
data/bin/ceiling_cat
CHANGED
data/lib/ceiling_cat.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
# General
|
2
|
-
%w{version setup connection errors event user room plugins/base services/campfire storage/base storage/hash storage/yaml}.each do |file|
|
2
|
+
%w{version setup connection errors event user room plugins/base services/campfire services/irc storage/base storage/hash storage/yaml}.each do |file|
|
3
3
|
require "ceiling_cat/#{file}"
|
4
4
|
end
|
@@ -31,13 +31,21 @@ module CeilingCat
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def list_users
|
34
|
-
members = room.
|
35
|
-
|
34
|
+
members = room.users_in_room(:type => "member")
|
35
|
+
if members.size > 0
|
36
|
+
reply "#{room.list_of_users_in_room(:type => "member")} #{pluralize(members.size, "is a", "are")} #{pluralize(members.size, "registered user")}."
|
37
|
+
else
|
38
|
+
reply "There are no registered users in the room at this time."
|
39
|
+
end
|
36
40
|
end
|
37
41
|
|
38
42
|
def list_guests
|
39
|
-
guests = room.
|
40
|
-
|
43
|
+
guests = room.users_in_room(:type => "guest")
|
44
|
+
if guests.size > 0
|
45
|
+
reply "#{room.list_of_users_in_room(:type => "guest")} #{pluralize(guests.size, "is a", "are")} #{pluralize(guests.size, "guest")}."
|
46
|
+
else
|
47
|
+
reply "There are no guests in the room at this time."
|
48
|
+
end
|
41
49
|
end
|
42
50
|
end
|
43
51
|
end
|
data/lib/ceiling_cat/room.rb
CHANGED
@@ -66,11 +66,11 @@ module CeilingCat
|
|
66
66
|
|
67
67
|
def list_of_users_in_room(type=nil)
|
68
68
|
users = users_in_room(type)
|
69
|
-
|
70
|
-
|
71
|
-
return users.collect{|user| user
|
72
|
-
|
73
|
-
return
|
69
|
+
if users.size > 1
|
70
|
+
last_user = users.pop
|
71
|
+
return users.collect{|user| user.name }.join(", ") + " and #{ last_user.name}"
|
72
|
+
elsif users.size == 1
|
73
|
+
return users.first.name
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -72,17 +72,18 @@ module CeilingCat
|
|
72
72
|
@users_in_room = @campfire_room.users
|
73
73
|
end
|
74
74
|
|
75
|
-
@users_in_room.
|
76
|
-
|
75
|
+
@users_in_room.collect{ |user_in_room|
|
76
|
+
user = CeilingCat::User.new(user_in_room[:name], :id => user_in_room[:id], :role => user_in_room[:type])
|
77
|
+
unless is_me?(user)
|
77
78
|
if opts[:type].present?
|
78
|
-
if user
|
79
|
-
|
79
|
+
if user.role.to_s.downcase == opts[:type].downcase
|
80
|
+
user
|
80
81
|
end
|
81
82
|
else
|
82
|
-
|
83
|
+
user
|
83
84
|
end
|
84
85
|
end
|
85
|
-
|
86
|
+
}
|
86
87
|
end
|
87
88
|
|
88
89
|
def say(something_to_say)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'irc-socket'
|
2
|
+
|
3
|
+
module CeilingCat
|
4
|
+
module IRC
|
5
|
+
class Connection < CeilingCat::Connection
|
6
|
+
attr_accessor :irc
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def irc
|
13
|
+
return @irc if @irc
|
14
|
+
server = @server || 'irc.freenode.org'
|
15
|
+
port = @port || 6667
|
16
|
+
@irc = IRCSocket.new(server)
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_user_count
|
20
|
+
1000
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CeilingCat
|
2
|
+
module IRC
|
3
|
+
class Event < CeilingCat::Event
|
4
|
+
|
5
|
+
def type
|
6
|
+
case @type
|
7
|
+
when "EnterMessage", :entrance
|
8
|
+
:entrance
|
9
|
+
when "TextMessage", :chat
|
10
|
+
:chat
|
11
|
+
when "LeaveMessage", "KickMessage", :exit
|
12
|
+
:exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module CeilingCat
|
2
|
+
module IRC
|
3
|
+
class Room < CeilingCat::Room
|
4
|
+
attr_accessor :user_names, :ops_names
|
5
|
+
|
6
|
+
def initialize(opts={})
|
7
|
+
super
|
8
|
+
@ops_names = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def irc
|
12
|
+
@connection.irc
|
13
|
+
end
|
14
|
+
|
15
|
+
def watch
|
16
|
+
puts "Watching room..."
|
17
|
+
irc.connect
|
18
|
+
if irc.connected?
|
19
|
+
irc.nick config.nickname
|
20
|
+
irc.pass config.password if config.password.present?
|
21
|
+
irc.user config.nickname, "+B", "*", config.nickname
|
22
|
+
|
23
|
+
while line = irc.read
|
24
|
+
# Join a channel after MOTD
|
25
|
+
if line.split[1] == '376'
|
26
|
+
irc.join config.room
|
27
|
+
elsif line.split[1] == "353"
|
28
|
+
@user_names = line.match(/:.+\s353\s.+[\s@]?\s#.+\s:(.+)/i)[1].split
|
29
|
+
irc.privmsg "chanserv", "access #{config.room} list"
|
30
|
+
elsif match = line.match(/:.+\sNOTICE.+:\d\s+(\w+)\s+\+(\w+)/)
|
31
|
+
@ops_names << match[1] if match[2].include?("O")
|
32
|
+
@ops_names.uniq!
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "Received: #{line}"
|
36
|
+
begin
|
37
|
+
if message = message_parts(line)
|
38
|
+
user = CeilingCat::User.new(message[:name], :role => user_role(message[:name]))
|
39
|
+
if !is_me?(user)
|
40
|
+
event = CeilingCat::Campfire::Event.new(self, message[:body], user, :type => message[:type])
|
41
|
+
event.handle
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
rescue Interrupt
|
50
|
+
puts "Leaving room..."
|
51
|
+
irc.part("#{config.room}")
|
52
|
+
rescue => e
|
53
|
+
puts e.message
|
54
|
+
puts e.backtrace.join("\n")
|
55
|
+
retry
|
56
|
+
end
|
57
|
+
|
58
|
+
def say(something_to_say)
|
59
|
+
Array(something_to_say).each do |line|
|
60
|
+
irc.privmsg config.room, line
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def users_in_room(opts={})
|
65
|
+
@user_names.collect {|user_name|
|
66
|
+
user_name = user_name.sub(/^@/,"")
|
67
|
+
user = CeilingCat::User.new(user_name, :role => user_role(user_name))
|
68
|
+
unless is_me?(user)
|
69
|
+
if opts[:type].present?
|
70
|
+
if user.role.to_s.downcase == opts[:type].downcase
|
71
|
+
user
|
72
|
+
end
|
73
|
+
else
|
74
|
+
user
|
75
|
+
end
|
76
|
+
end
|
77
|
+
}.compact
|
78
|
+
end
|
79
|
+
|
80
|
+
def user_role(name)
|
81
|
+
if @ops_names.include?(name)
|
82
|
+
"member"
|
83
|
+
else
|
84
|
+
"guest"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def is_me?(user)
|
89
|
+
user.name == me.name
|
90
|
+
end
|
91
|
+
|
92
|
+
def me
|
93
|
+
@me ||= CeilingCat::User.new(config.nickname, :role => "member")
|
94
|
+
end
|
95
|
+
|
96
|
+
def message_parts(message)
|
97
|
+
if message =~ /\sPRIVMSG\s/
|
98
|
+
parts = message.match /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(#.+):(.+)/i
|
99
|
+
return {:name => parts[1], :body => parts[5], :type => :chat}
|
100
|
+
elsif message =~ /\sJOIN\s/
|
101
|
+
parts = message.match /^:(.+?)!(.+?)@(.+?)\s(.+)\s:(#.+)/i
|
102
|
+
return {:name => parts[1], :body => nil, :type => :entrance}
|
103
|
+
elsif message =~ /PING\s/
|
104
|
+
puts "Sent: PONG"
|
105
|
+
irc.pong message.match(/PING\s:(.+)/)[1]
|
106
|
+
return nil
|
107
|
+
else
|
108
|
+
return nil
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/ceiling_cat/setup.rb
CHANGED
@@ -38,6 +38,10 @@ module CeilingCat
|
|
38
38
|
connection = CeilingCat::Campfire::Connection.new(self.config)
|
39
39
|
room = CeilingCat::Campfire::Room.new(:connection => connection, :room_name => self.config.room)
|
40
40
|
room.watch
|
41
|
+
when 'irc'
|
42
|
+
connection = CeilingCat::IRC::Connection.new(self.config)
|
43
|
+
room = CeilingCat::IRC::Room.new(:connection => connection, :room_name => self.config.room)
|
44
|
+
room.watch
|
41
45
|
else
|
42
46
|
raise CeilingCat::UnsupportedChatServiceError.new("#{self.config.service} is not a supported chat service.")
|
43
47
|
end
|
data/lib/ceiling_cat/user.rb
CHANGED
data/lib/ceiling_cat/version.rb
CHANGED
data/setup/Chatfile
CHANGED
@@ -4,11 +4,19 @@ require 'ceiling_cat/plugins/calc'
|
|
4
4
|
require 'ceiling_cat/plugins/greeter'
|
5
5
|
|
6
6
|
CeilingCat::Setup.configure do |config|
|
7
|
+
# Campfire Settings. Only use one service per chatfile
|
7
8
|
config.service = 'campfire'
|
8
9
|
config.subdomain = 'username'
|
9
10
|
config.token = '12345abcde' # The API token of the account Ceiling Cat will use. Available at https://<subdomain>.campfirenow.com/member/edit
|
10
11
|
config.room = 'Test Room'
|
11
12
|
config.ssl = true
|
13
|
+
|
14
|
+
# IRC Settings. Only use one service per chatfile
|
15
|
+
# config.service = 'irc'
|
16
|
+
# config.server = 'irc.freenode.org'
|
17
|
+
# config.nick = 'nickname'
|
18
|
+
# config.password = 'Q7Af6laDKza2SOM'
|
19
|
+
# config.room = '#my_room'
|
12
20
|
|
13
21
|
config.plugins = [CeilingCat::Plugin::About,
|
14
22
|
CeilingCat::Plugin::Greeter,
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ceiling_cat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.9
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Warren
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: tinder
|
@@ -66,9 +66,25 @@ dependencies:
|
|
66
66
|
type: :runtime
|
67
67
|
version_requirements: *id003
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
|
-
name:
|
69
|
+
name: irc-socket
|
70
70
|
prerelease: false
|
71
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - "="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 21
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 0
|
80
|
+
- 1
|
81
|
+
version: 1.0.1
|
82
|
+
type: :runtime
|
83
|
+
version_requirements: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
prerelease: false
|
87
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
88
|
none: false
|
73
89
|
requirements:
|
74
90
|
- - "="
|
@@ -80,11 +96,11 @@ dependencies:
|
|
80
96
|
- 0
|
81
97
|
version: 2.6.0
|
82
98
|
type: :development
|
83
|
-
version_requirements: *
|
99
|
+
version_requirements: *id005
|
84
100
|
- !ruby/object:Gem::Dependency
|
85
101
|
name: ruby-debug
|
86
102
|
prerelease: false
|
87
|
-
requirement: &
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
88
104
|
none: false
|
89
105
|
requirements:
|
90
106
|
- - ">="
|
@@ -94,11 +110,11 @@ dependencies:
|
|
94
110
|
- 0
|
95
111
|
version: "0"
|
96
112
|
type: :development
|
97
|
-
version_requirements: *
|
113
|
+
version_requirements: *id006
|
98
114
|
- !ruby/object:Gem::Dependency
|
99
115
|
name: fakeweb
|
100
116
|
prerelease: false
|
101
|
-
requirement: &
|
117
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
102
118
|
none: false
|
103
119
|
requirements:
|
104
120
|
- - ">="
|
@@ -108,7 +124,7 @@ dependencies:
|
|
108
124
|
- 0
|
109
125
|
version: "0"
|
110
126
|
type: :development
|
111
|
-
version_requirements: *
|
127
|
+
version_requirements: *id007
|
112
128
|
description: Ceiling Cat is watching you chat. A Campfire chat bot!
|
113
129
|
email:
|
114
130
|
- chris@zencoder.com
|
@@ -144,6 +160,10 @@ files:
|
|
144
160
|
- lib/ceiling_cat/services/campfire/connection.rb
|
145
161
|
- lib/ceiling_cat/services/campfire/event.rb
|
146
162
|
- lib/ceiling_cat/services/campfire/room.rb
|
163
|
+
- lib/ceiling_cat/services/irc.rb
|
164
|
+
- lib/ceiling_cat/services/irc/connection.rb
|
165
|
+
- lib/ceiling_cat/services/irc/event.rb
|
166
|
+
- lib/ceiling_cat/services/irc/room.rb
|
147
167
|
- bin/ceiling_cat
|
148
168
|
homepage: http://zencoder.com
|
149
169
|
licenses: []
|