Class | ::Bot |
In: |
lib/rbot/core/utils/filters.rb
lib/rbot/core/utils/wordlist.rb lib/rbot/core/utils/extends.rb lib/rbot/core/remote.rb |
Parent: | Object |
This method clears the filter list and installs the identity filter
# File lib/rbot/core/utils/filters.rb, line 142 142: def clear_filters 143: @filters ||= {} 144: @filters.clear 145: 146: @filter_group ||= {} 147: @filter_group.clear 148: 149: register_filter(:identity) { |stream| stream } 150: end
This method processes the DataStream stream with the filters filter1, filter2, …, filterN, in sequence (the output of each filter is used as input for the next one. stream can be provided either as a DataStream or as a String and a Hash (see DataStream.new).
# File lib/rbot/core/utils/filters.rb, line 63 63: def filter(*args) 64: @filters ||= {} 65: if Hash === args.last 66: # the stream is a Hash, check if the previous element is not a Symbol 67: if Symbol === args[-2] 68: ds = DataStream.new(args.pop) 69: else 70: ds = DataStream.new(*args.slice!(-2, 2)) 71: end 72: else 73: # the stream is just whatever else 74: ds = DataStream.new(args.pop) 75: end 76: names = args.dup 77: return ds if names.empty? 78: # check if filters exist 79: missing = names - @filters.keys 80: raise "Missing filters: #{missing.join(', ')}" unless missing.empty? 81: fs = @filters.values_at(*names) 82: fs.inject(ds) { |mid, f| mid = f.call(mid) } 83: end
This method is used to retrieve the filter names (in a given group)
# File lib/rbot/core/utils/filters.rb, line 124 124: def filter_names(group=nil) 125: if group 126: gkey = group.to_sym 127: return [] unless defined? @filter_group and @filter_group.key?(gkey) 128: return @filter_group[gkey].keys 129: else 130: return [] unless defined? @filters 131: return @filters.keys 132: end 133: end
This method is used to register a new filter
# File lib/rbot/core/utils/filters.rb, line 103 103: def register_filter(name, group=nil, &block) 104: raise "No block provided" unless block_given? 105: @filters ||= {} 106: tlkey = global_filter_name(name, group) 107: key = name.to_sym 108: if has_filter?(tlkey) 109: debug "Overwriting filter #{tlkey}" 110: end 111: @filters[tlkey] = DataFilter.new(&block) 112: if group 113: gkey = group.to_sym 114: @filter_group ||= {} 115: @filter_group[gkey] ||= {} 116: if @filter_group[gkey].key?(key) 117: debug "Overwriting filter #{key} in group #{gkey}" 118: end 119: @filter_group[gkey][key] = @filters[tlkey] 120: end 121: end
The bot also manages a single (for the moment) remote dispatcher. This method makes it accessible to the outside world, creating it if necessary.
# File lib/rbot/core/remote.rb, line 241 241: def remote_dispatcher 242: if defined? @remote_dispatcher 243: @remote_dispatcher 244: else 245: @remote_dispatcher = RemoteDispatcher.new(self) 246: end 247: end
The bot also manages a single (for the moment) remote object. This method makes it accessible to the outside world, creating it if necessary.
# File lib/rbot/core/remote.rb, line 252 252: def remote_object 253: if defined? @remote_object 254: @remote_object 255: else 256: @remote_object = RemoteObject.new(self) 257: end 258: end