9 config[:hidden_methods] ||= []
10 hidden = config[:hidden_methods].map { |m| m.to_s }
12 commands = protected_instance_methods(false) - hidden
15 commands = public_instance_methods(false) - hidden
19 send(command, "Commands I know: \0037 #{commands.sort * ', '}")
24 socket.puts "PRIVMSG #{config[:channel]} :\01ACTION #{data * ' '}\01"
28 def say(data, channel = config[:channel])
29 data = data.join(" ") if data.is_a?(Array)
30 data.split("\n").each do |message|
31 message = filters(:say).inject(message) do |string, filter|
33 end if filters(:say).size.nonzero?
35 fragment, message = message[0..450], message[450..-1]
36 socket.puts "PRIVMSG #{channel} :#{fragment}"
47 puts "Saved session data. ;)"
52 socket.puts "QUIT :#{data.shift}"
57 socket.puts "NICK :#{nick = data.shift}"
67 say "#{Client.last_nick}: #{string}" if Client.last_nick
70 def pm(data, nick = Client.last_nick)
74 # filter :say => :drunk_say
75 # filter :listen => :google_translate
76 def filter(type_and_methods)
77 type = type_and_methods.keys.first
78 Array(type_and_methods[type]).each do |method|
81 when Symbol, String then proc { |message| send(method, message) }
89 $filters[type.to_sym] ||= Set.new
93 $filters.clear if $filters
96 def help_method(options = {})
97 # help_method :svn => [ :add_repo, :clear_repos ]
98 options.each do |method, wraps|
99 define_method(method) do |*data|
100 wraps.map! { |m| m.to_s }
103 wraps -= protected_instance_methods(false)
106 send(command, "Commands for `#{method}': #{wraps.sort * ', '}")
108 config[:hidden_methods] ||= Set.new
109 config[:hidden_methods] += wraps.map { |m| m.to_s }
126 # needs_gem 'hpricot' => [ :method1, :method2 ]
127 config[:failed_methods] ||= Set.new
129 hash.keys.each { |gem| require gem }
131 config[:failed_methods] += Array(hash[gem])
134 def method_added(method)
135 config[:failed_methods] ||= Set.new
136 remove_method method if config[:failed_methods].include?(method)