Class: ModSpox::Handlers::Mode
- Defined in:
- lib/mod_spox/handlers/Mode.rb
Instance Method Summary collapse
-
#initialize(handlers) ⇒ Mode
constructor
A new instance of Mode.
- #process(string) ⇒ Object
Constructor Details
#initialize(handlers) ⇒ Mode
Returns a new instance of Mode.
4 5 6 |
# File 'lib/mod_spox/handlers/Mode.rb', line 4 def initialize(handlers) handlers[:MODE] = self end |
Instance Method Details
#process(string) ⇒ Object
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 |
# File 'lib/mod_spox/handlers/Mode.rb', line 8 def process(string) begin if(string =~ /^:([^!]+)!.+?MODE\s(\S+)\s(\S+)$/) # this is for modes applied to the channel source = find_model($1) channel = find_model($2) full_mode = $3 action = full_mode[0].chr full_mode.slice(0).each_char{|c| Models::ChannelMode.find_or_create(:channel_id => channel.pk, :mode => c) if action == '+' if(action == '-' && model = Models::ChannelMode.filter(:channel_id => channel.pk, :mode => c).first) model.destroy end } return Messages::Incoming::Mode.new(string, full_mode, source, nil, channel) #elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(.+)$/) # this is for modes applied to nick # raise Exceptions::BotException.new("Matched unimplemented mode string") elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(\S+)\s(.+)$/) source = find_model($1) channel = find_model($2) full_modes = $3 targets = $4 action = full_modes[0].chr nicks = Array.new full_modes.sub(/^./, '').length.times do |i| nick = find_model(targets.scan(/\S+/)[i]) nicks << nick if(nick.is_a?(Models::Nick)) mode = full_modes[i + 1].chr Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode) if action == '+' if(action == '-' && model = Models::NickMode.filter(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode).first) model.destroy end end end nicks = nicks[0] if nicks.size == 1 return Messages::Incoming::Mode.new(string, full_modes, source, nicks, channel) else Logger.log('Failed to parse MODE message') end rescue Object => boom Logger.log("Failed to process MODE message. Reason: #{boom}") end end |