Class: EventMachine::IRC::Channel

Inherits:
SynchronizedStore show all
Defined in:
lib/eventmachine/irc/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SynchronizedStore

#each_value, #keys, #method_missing

Constructor Details

#initialize(name) ⇒ Channel

Returns a new instance of Channel.



610
611
612
613
614
615
616
617
# File 'lib/eventmachine/irc/server.rb', line 610

def initialize(name)
	super()

	@topic = "There is no topic"
	@name = name
	@oper = []
	carp "create channel:#{@name}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EventMachine::IRC::SynchronizedStore

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



607
608
609
# File 'lib/eventmachine/irc/server.rb', line 607

def name
  @name
end

#topic(msg = nil, client = nil) ⇒ Object (readonly)

Returns the value of attribute topic.



607
608
609
# File 'lib/eventmachine/irc/server.rb', line 607

def topic
  @topic
end

Instance Method Details

#add(client) ⇒ Object



619
620
621
622
# File 'lib/eventmachine/irc/server.rb', line 619

def add(client)
	@oper << client.nick if @oper.empty? and @store.empty?
	self[client.nick] = client
end

#is_member?(m) ⇒ Boolean Also known as: has_nick?

Returns:

  • (Boolean)


688
689
690
# File 'lib/eventmachine/irc/server.rb', line 688

def is_member?(m)
	values.include?(m)
end

#join(client) ⇒ Object



628
629
630
631
632
633
634
635
636
# File 'lib/eventmachine/irc/server.rb', line 628

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

#mode(u) ⇒ Object



684
685
686
# File 'lib/eventmachine/irc/server.rb', line 684

def mode(u)
	return @oper.include?(u.nick) ? '@' : ''
end

#nicksObject



680
681
682
# File 'lib/eventmachine/irc/server.rb', line 680

def nicks
	return keys
end

#notice(msg, client) ⇒ Object



665
666
667
668
669
# File 'lib/eventmachine/irc/server.rb', line 665

def notice(msg, client)
	each_user {|user|
		user.reply :notice, client.userprefix, @name, msg if user != client
	}
end

#part(client, msg) ⇒ Object



638
639
640
641
642
643
644
645
646
# File 'lib/eventmachine/irc/server.rb', line 638

def part(client, msg)
	return false if !is_member? client
	each_user {|user|
		user.reply :part, client.userprefix, @name, msg
	}
	remove client
	Server.channel_store.delete(@name) if self.empty?
	return true
end

#privatemsg(msg, client) ⇒ Object



659
660
661
662
663
# File 'lib/eventmachine/irc/server.rb', line 659

def privatemsg(msg, client)
	each_user {|user|
		user.reply :privmsg, client.userprefix, @name, msg if user != client
	}
end

#quit(client, msg) ⇒ Object



648
649
650
651
652
653
654
655
656
657
# File 'lib/eventmachine/irc/server.rb', line 648

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
	}
	Server.channel_store.delete(@name) if self.empty?
end

#remove(client) ⇒ Object



624
625
626
# File 'lib/eventmachine/irc/server.rb', line 624

def remove(client)
	delete(client.nick)
end