Class: CeilingCat::IRC::Room
- Inherits:
-
Room
- Object
- Room
- CeilingCat::IRC::Room
show all
- Defined in:
- lib/ceiling_cat/services/irc/room.rb
Instance Attribute Summary collapse
Attributes inherited from Room
#connection, #room
Instance Method Summary
collapse
Methods inherited from Room
#available_commands, #config, #list_of_users_in_room, #plugin, #plugin_descriptions, #plugin_installed?, #plugins, #store
Constructor Details
#initialize(opts = {}) ⇒ Room
Returns a new instance of Room.
6
7
8
9
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 6
def initialize(opts={})
super
@ops_names = []
end
|
Instance Attribute Details
#ops_names ⇒ Object
Returns the value of attribute ops_names.
4
5
6
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 4
def ops_names
@ops_names
end
|
#user_names ⇒ Object
Returns the value of attribute user_names.
4
5
6
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 4
def user_names
@user_names
end
|
Instance Method Details
#irc ⇒ Object
11
12
13
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 11
def irc
@connection.irc
end
|
#is_me?(user) ⇒ Boolean
88
89
90
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 88
def is_me?(user)
user.name == me.name
end
|
#me ⇒ Object
92
93
94
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 92
def me
@me ||= CeilingCat::User.new(config.nickname, :role => "member")
end
|
#message_parts(message) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 96
def message_parts(message)
if message =~ /\sPRIVMSG\s/
parts = message.match /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(#.+):(.+)/i
return {:name => parts[1], :body => parts[5], :type => :chat}
elsif message =~ /\sJOIN\s/
parts = message.match /^:(.+?)!(.+?)@(.+?)\s(.+)\s:(#.+)/i
return {:name => parts[1], :body => nil, :type => :entrance}
elsif message =~ /PING\s/
puts "Sent: PONG"
irc.pong message.match(/PING\s:(.+)/)[1]
return nil
else
return nil
end
end
|
#say(something_to_say) ⇒ Object
58
59
60
61
62
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 58
def say(something_to_say)
Array(something_to_say).each do |line|
irc.privmsg config.room, line
end
end
|
#user_role(name) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 80
def user_role(name)
if @ops_names.include?(name)
"member"
else
"guest"
end
end
|
#users_in_room(opts = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 64
def users_in_room(opts={})
@user_names.collect {|user_name|
user_name = user_name.sub(/^@/,"")
user = CeilingCat::User.new(user_name, :role => user_role(user_name))
unless is_me?(user)
if opts[:type].present?
if user.role.to_s.downcase == opts[:type].downcase
user
end
else
user
end
end
}.compact
end
|
#watch ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ceiling_cat/services/irc/room.rb', line 15
def watch
puts "Watching room..."
irc.connect
if irc.connected?
irc.nick config.nickname
irc.pass config.password if config.password.present?
irc.user config.nickname, "+B", "*", config.nickname
while line = irc.read
if line.split[1] == '376'
irc.join config.room
elsif line.split[1] == "353"
@user_names = line.match(/:.+\s353\s.+[\s@]?\s#.+\s:(.+)/i)[1].split
irc.privmsg "chanserv", "access #{config.room} list"
elsif match = line.match(/:.+\sNOTICE.+:\d\s+(\w+)\s+\+(\w+)/)
@ops_names << match[1] if match[2].include?("O")
@ops_names.uniq!
end
puts "Received: #{line}"
begin
if message = message_parts(line)
user = CeilingCat::User.new(message[:name], :role => user_role(message[:name]))
if !is_me?(user)
event = CeilingCat::Campfire::Event.new(self, message[:body], user, :type => message[:type])
event.handle
end
end
rescue => e
raise e
end
end
end
rescue Interrupt
puts "Leaving room..."
irc.part("#{config.room}")
rescue => e
puts e.message
puts e.backtrace.join("\n")
retry
end
|