Class: Erasmus::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/erasmus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, flag = '!') ⇒ Channel

Returns a new instance of Channel.



90
91
92
93
94
95
96
# File 'lib/erasmus.rb', line 90

def initialize(channel, flag='!')
	@name = channel
	@flag = flag
	
	@flags = {}
	@blacklists = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



88
89
90
# File 'lib/erasmus.rb', line 88

def name
  @name
end

#serverObject

Returns the value of attribute server.



87
88
89
# File 'lib/erasmus.rb', line 87

def server
  @server
end

Instance Method Details

#allowed?(user) ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/erasmus.rb', line 144

def allowed?(user)
	begin
		@blacklists.each do |blacklist|
			blacklist.call(user)
		end
	rescue NotAllowedException
		return false
	rescue => detail
		say("Uh oh: #{detail}")
		return false
	else
		return true
	end
end

#handle_flag(user, host, flag, arguments) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/erasmus.rb', line 134

def handle_flag(user, host, flag, arguments)
	if allowed? user
		begin
			@flags[flag].call(user, host, arguments)
		rescue NoMethodError
			#say("Sorry, there's no action associated with the flag #{flag}.")
		end
	end
end

#handle_hilight(user, host, message) ⇒ Object



132
133
# File 'lib/erasmus.rb', line 132

def handle_hilight(user, host, message)
end

#handle_public_message(user, host, message) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/erasmus.rb', line 122

def handle_public_message(user, host, message)
	if message =~ /^#{@server.nick}: (.*)$/
		handle_hilight(user, host, $1)
	elsif message =~ /^#{@flag}(\S+)\s(.*)$/
		command = $1
		arguments = $2.split(/\s/)
		handle_flag(user, host, command, arguments)
	end
end

#hilight_user(user, message) ⇒ Object



110
111
112
# File 'lib/erasmus.rb', line 110

def hilight_user(user, message)
	@server.say_to_channel(@name, "#{user}: #{message}")
end

#joinObject



98
99
100
# File 'lib/erasmus.rb', line 98

def join
	@server.say "JOIN ##{@name}"
end

#notice_channel(message) ⇒ Object



118
119
120
# File 'lib/erasmus.rb', line 118

def notice_channel(message)
	@server.notice_channel(@name, message)
end

#notice_user(user, message) ⇒ Object



114
115
116
# File 'lib/erasmus.rb', line 114

def notice_user(user, message)
	@server.notice_user(user, message)
end

#part(message = 'Bai~') ⇒ Object



102
103
104
# File 'lib/erasmus.rb', line 102

def part(message='Bai~')
	@server.say "PART ##{@name} :#{message}"
end

#say(message) ⇒ Object



106
107
108
# File 'lib/erasmus.rb', line 106

def say(message)
	@server.say_to_channel(@name, message)
end