-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirc_channel.rb
More file actions
88 lines (73 loc) · 1.96 KB
/
irc_channel.rb
File metadata and controls
88 lines (73 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class IRCChannel < SynchronizedStore
include NetUtils
attr_reader :name, :topic
alias each_user each_value
def initialize(name)
super()
@topic = "There is no topic"
@name = name
@oper = []
carp "create channel:#{@name}"
end
def add(client)
@oper << client.nick if @oper.empty? and @store.empty?
self[client.nick] = client
end
def remove(client)
delete(client.nick)
end
def join(client)
return false if is_member? client
add client
#send join to each user in the channel
each_user {|user|
user.reply :join, client.userprefix, @name
}
return true
end
def part(client, msg)
return false if !is_member? client
each_user {|user|
user.reply :part, client.userprefix, @name, msg
}
remove client
return true
end
def quit(client, msg)
#remove client should happen before sending notification
#to others since we dont want a notification to ourselves
#after quit.
remove client
each_user {|user|
user.reply :quit, client.userprefix, @name, msg if user!= client
}
end
def privatemsg(msg, client)
each_user {|user|
user.reply :privmsg, client.userprefix, @name, msg if user != client
}
end
def notice(msg, client)
each_user {|user|
user.reply :notice, client.userprefix, @name, msg if user != client
}
end
def topic(msg=nil,client=nil)
return @topic if msg.nil?
@topic = msg
each_user {|user|
user.reply :topic, client.userprefix, @name, msg
}
return @topic
end
def nicks
return keys
end
def mode(u)
return @oper.include?(u.nick) ? '@' : ''
end
def is_member?(m)
values.include?(m)
end
alias has_nick? is_member?
end