mod_spox 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +31 -1
  2. data/LICENSE +674 -0
  3. data/README.rdoc +73 -0
  4. data/bin/mod_spox +28 -28
  5. data/data/mod_spox/extras/AOLSpeak.rb +2 -3
  6. data/data/mod_spox/extras/AutoKick.rb +10 -23
  7. data/data/mod_spox/extras/AutoMode.rb +12 -23
  8. data/data/mod_spox/extras/Bash.rb +55 -0
  9. data/data/mod_spox/extras/Bouncer.rb +85 -57
  10. data/data/mod_spox/extras/Bullshit.rb +1 -1
  11. data/data/mod_spox/extras/Bytes.rb +1 -2
  12. data/data/mod_spox/extras/Confess.rb +27 -29
  13. data/data/mod_spox/extras/DCC.rb +11 -20
  14. data/data/mod_spox/extras/DevWatch.rb +21 -23
  15. data/data/mod_spox/extras/DownForEveryoneOrJustMe.rb +47 -0
  16. data/data/mod_spox/extras/EightBall.rb +1 -1
  17. data/data/mod_spox/extras/FML.rb +35 -0
  18. data/data/mod_spox/extras/Headers.rb +31 -50
  19. data/data/mod_spox/extras/Karma.rb +81 -29
  20. data/data/mod_spox/extras/Logger.rb +2 -2
  21. data/data/mod_spox/extras/LolSpeak.rb +1 -2
  22. data/data/mod_spox/extras/PhpCli.rb +138 -8
  23. data/data/mod_spox/extras/PhpFuncLookup.rb +20 -23
  24. data/data/mod_spox/extras/Pinger.rb +1 -1
  25. data/data/mod_spox/extras/Quotes.rb +8 -10
  26. data/data/mod_spox/extras/RegexTracker.rb +2 -4
  27. data/data/mod_spox/extras/Roulette.rb +20 -27
  28. data/data/mod_spox/extras/RubyCli.rb +93 -0
  29. data/data/mod_spox/extras/Search.rb +17 -3
  30. data/data/mod_spox/extras/Seen.rb +150 -0
  31. data/data/mod_spox/extras/SlashdotHeadlineGenerator.rb +500 -0
  32. data/data/mod_spox/extras/Talk.rb +2 -4
  33. data/data/mod_spox/extras/Topten.rb +10 -12
  34. data/data/mod_spox/extras/TracTicket.rb +3 -5
  35. data/data/mod_spox/extras/Translate.rb +20 -22
  36. data/data/mod_spox/extras/Twitter.rb +118 -33
  37. data/data/mod_spox/extras/UrbanDictionary.rb +8 -17
  38. data/data/mod_spox/extras/Weather.rb +1 -2
  39. data/data/mod_spox/plugins/Authenticator.rb +93 -98
  40. data/data/mod_spox/plugins/Banner.rb +26 -56
  41. data/data/mod_spox/plugins/Helper.rb +5 -6
  42. data/data/mod_spox/plugins/Initializer.rb +4 -14
  43. data/data/mod_spox/plugins/Joiner.rb +1 -1
  44. data/data/mod_spox/plugins/Nicker.rb +13 -0
  45. data/data/mod_spox/plugins/Parter.rb +2 -2
  46. data/data/mod_spox/plugins/Permissions.rb +60 -0
  47. data/data/mod_spox/plugins/PluginLoader.rb +7 -12
  48. data/data/mod_spox/plugins/Ponger.rb +51 -0
  49. data/data/mod_spox/plugins/Quitter.rb +1 -2
  50. data/data/mod_spox/plugins/Servers.rb +57 -0
  51. data/data/mod_spox/plugins/Status.rb +3 -2
  52. data/data/mod_spox/plugins/Triggers.rb +9 -9
  53. data/lib/mod_spox/Bot.rb +109 -33
  54. data/lib/mod_spox/BotConfig.rb +2 -2
  55. data/lib/mod_spox/ConfigurationWizard.rb +12 -12
  56. data/lib/mod_spox/Database.rb +1 -4
  57. data/lib/mod_spox/Exceptions.rb +26 -0
  58. data/lib/mod_spox/Helpers.rb +29 -68
  59. data/lib/mod_spox/Loader.rb +23 -24
  60. data/lib/mod_spox/Logger.rb +19 -17
  61. data/lib/mod_spox/MessageFactory.rb +50 -24
  62. data/lib/mod_spox/Pipeline.rb +21 -7
  63. data/lib/mod_spox/Plugin.rb +27 -3
  64. data/lib/mod_spox/PluginManager.rb +28 -15
  65. data/lib/mod_spox/PriorityQueue.rb +69 -0
  66. data/lib/mod_spox/Socket.rb +93 -51
  67. data/lib/mod_spox/Sockets.rb +76 -63
  68. data/lib/mod_spox/Timer.rb +21 -141
  69. data/lib/mod_spox/Version.rb +14 -0
  70. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  71. data/lib/mod_spox/handlers/Bounce.rb +5 -5
  72. data/lib/mod_spox/handlers/Created.rb +13 -5
  73. data/lib/mod_spox/handlers/Handler.rb +12 -3
  74. data/lib/mod_spox/handlers/Invite.rb +14 -8
  75. data/lib/mod_spox/handlers/Join.rb +24 -20
  76. data/lib/mod_spox/handlers/Kick.rb +22 -13
  77. data/lib/mod_spox/handlers/Mode.rb +42 -36
  78. data/lib/mod_spox/handlers/Motd.rb +4 -0
  79. data/lib/mod_spox/handlers/Names.rb +66 -39
  80. data/lib/mod_spox/handlers/Nick.rb +20 -14
  81. data/lib/mod_spox/handlers/Part.rb +25 -8
  82. data/lib/mod_spox/handlers/Ping.rb +11 -5
  83. data/lib/mod_spox/handlers/Pong.rb +9 -5
  84. data/lib/mod_spox/handlers/Privmsg.rb +25 -17
  85. data/lib/mod_spox/handlers/Quit.rb +13 -8
  86. data/lib/mod_spox/handlers/Topic.rb +4 -0
  87. data/lib/mod_spox/handlers/Welcome.rb +16 -24
  88. data/lib/mod_spox/handlers/Who.rb +64 -48
  89. data/lib/mod_spox/handlers/Whois.rb +92 -60
  90. data/lib/mod_spox/messages/incoming/Nick.rb +2 -2
  91. data/lib/mod_spox/messages/incoming/Privmsg.rb +1 -1
  92. data/lib/mod_spox/messages/incoming/Whois.rb +1 -0
  93. data/lib/mod_spox/messages/internal/EstablishConnection.rb +1 -1
  94. data/lib/mod_spox/messages/internal/PluginsReady.rb +10 -0
  95. data/lib/mod_spox/messages/internal/QueueSocket.rb +8 -0
  96. data/lib/mod_spox/messages/internal/Reconnect.rb +8 -0
  97. data/lib/mod_spox/messages/internal/UnqueueSocket.rb +8 -0
  98. data/lib/mod_spox/migrations/002_persistent_sigs.rb +14 -0
  99. data/lib/mod_spox/migrations/003_auth_restructure.rb +31 -0
  100. data/lib/mod_spox/migrations/004_mode_index_fix.rb +18 -0
  101. data/lib/mod_spox/migrations/005_nick_mode_nopark.rb +18 -0
  102. data/lib/mod_spox/models/Auth.rb +16 -46
  103. data/lib/mod_spox/models/AuthMask.rb +13 -0
  104. data/lib/mod_spox/models/Channel.rb +46 -27
  105. data/lib/mod_spox/models/Config.rb +10 -19
  106. data/lib/mod_spox/models/Group.rb +20 -8
  107. data/lib/mod_spox/models/Models.rb +1 -1
  108. data/lib/mod_spox/models/Nick.rb +105 -113
  109. data/lib/mod_spox/models/NickMode.rb +23 -9
  110. data/lib/mod_spox/models/Server.rb +12 -1
  111. data/lib/mod_spox/models/Setting.rb +12 -16
  112. data/lib/mod_spox/models/Signature.rb +28 -8
  113. data/tests/BotHolder.rb +24 -0
  114. data/tests/handlers/tc_BadNick.rb +21 -0
  115. data/tests/handlers/tc_Created.rb +24 -0
  116. data/tests/handlers/tc_Invite.rb +50 -0
  117. data/tests/handlers/tc_Join.rb +33 -0
  118. data/tests/handlers/tc_Kick.rb +32 -0
  119. data/tests/handlers/tc_Mode.rb +85 -0
  120. data/tests/handlers/tc_Names.rb +35 -0
  121. data/tests/handlers/tc_Nick.rb +55 -0
  122. data/tests/handlers/tc_Part.rb +44 -0
  123. data/tests/handlers/tc_Ping.rb +40 -0
  124. data/tests/handlers/tc_Pong.rb +28 -0
  125. data/tests/handlers/tc_Privmsg.rb +85 -0
  126. data/tests/handlers/tc_Quit.rb +40 -0
  127. data/tests/handlers/tc_Who.rb +50 -0
  128. data/tests/handlers/tc_Whois.rb +61 -0
  129. data/tests/models/tc_Auth.rb +34 -0
  130. data/tests/models/tc_Channel.rb +52 -0
  131. data/tests/models/tc_Config.rb +19 -0
  132. data/tests/models/tc_Nick.rb +142 -0
  133. data/tests/models/tc_NickMode.rb +40 -0
  134. data/tests/models/tc_Setting.rb +21 -0
  135. data/tests/models/tc_Signature.rb +14 -0
  136. data/tests/run_tests.rb +4 -0
  137. metadata +284 -212
  138. data/README +0 -36
  139. data/lib/mod_spox/Cache.rb +0 -57
  140. data/lib/mod_spox/Monitors.rb +0 -84
  141. data/lib/mod_spox/Pool.rb +0 -164
  142. data/lib/mod_spox/models/AuthGroup.rb +0 -16
  143. data/lib/mod_spox/models/ChannelMode.rb +0 -14
  144. data/lib/mod_spox/models/NickChannel.rb +0 -45
  145. data/lib/mod_spox/models/NickGroup.rb +0 -16
@@ -1,16 +1,24 @@
1
1
  require 'mod_spox/handlers/Handler'
2
+ require 'time'
2
3
  module ModSpox
3
4
  module Handlers
4
5
  class Created < Handler
5
6
  def initialize(handlers)
6
7
  handlers[RPL_CREATED] = self
7
8
  end
9
+ # :not.configured 003 spox :This server was created Tue Mar 24 2009 at 15:42:36 PDT'
8
10
  def process(string)
9
- if(string =~ /#{RPL_CREATED.to_s}.+?:created\s(.+)$/)
10
- return Messages::Incoming::Created.new(string, $1)
11
- else
12
- Logger.warn('Failed to parse RPL_CREATED message')
13
- return nil
11
+ string = string.dup
12
+ begin
13
+ orig = string.dup
14
+ 2.times{string.slice!(0..string.index(':'))}
15
+ 4.times{string.slice!(0..string.index(' '))}
16
+ time = Time.parse(string)
17
+ time = nil if Time.now == time
18
+ return time.nil? ? nil : Messages::Incoming::Created.new(orig, time)
19
+ rescue Object => boom
20
+ Logger.error("Failed to parse RPL_CREATED message: #{orig}")
21
+ raise boom
14
22
  end
15
23
  end
16
24
  end
@@ -1,12 +1,19 @@
1
1
  require 'mod_spox/rfc2812'
2
+ require 'mod_spox/Helpers'
2
3
  module ModSpox
3
4
  module Handlers
4
5
 
5
6
  class Handler
6
-
7
+
8
+ # handlers:: array of handlers
9
+ # initialize handler and add self to available
10
+ # handlers
7
11
  def initialize(handlers)
12
+ raise Exceptions::NotImplemented.new('Method has not been implemented')
8
13
  end
9
-
14
+
15
+ # data:: string of data
16
+ # Process the string and create the proper object
10
17
  def process(data)
11
18
  raise Exceptions::NotImplemented.new('Method has not been implemented')
12
19
  end
@@ -18,7 +25,9 @@ module ModSpox
18
25
  end
19
26
 
20
27
  protected
21
-
28
+
29
+ # deprecated. here basically so old handlers
30
+ # don't break
22
31
  def find_model(string)
23
32
  Helpers.find_model(string)
24
33
  end
@@ -5,15 +5,21 @@ module ModSpox
5
5
  def initialize(handlers)
6
6
  handlers[:INVITE] = self
7
7
  end
8
+ # :spax!~spox@host INVITE spox :#m
8
9
  def process(string)
9
- if(string =~ /^(.+?)!.*?INVITE\s(\S+)\s(.+)$/)
10
- source = find_model($1)
11
- target = find_model($2)
12
- channel = find_model($3)
13
- return Messages::Incoming::Invite.new(string, source, target, channel)
14
- else
15
- Logger.warn('Failed to parse INVITE message')
16
- return nil
10
+ orig = string.dup
11
+ string = string.dup
12
+ begin
13
+ string.slice!(0)
14
+ source = find_model(string.slice!(0..string.index('!')-1))
15
+ 2.times{ string.slice!(0..string.index(' ')) }
16
+ target = find_model(string.slice!(0..string.index(' ')-1))
17
+ string.slice!(0..string.index(':'))
18
+ channel = find_model(string.strip)
19
+ return Messages::Incoming::Invite.new(orig, source, target, channel)
20
+ rescue Object => boom
21
+ Logger.error("Failed to parse INVITE message: #{orig}")
22
+ raise boom
17
23
  end
18
24
  end
19
25
  end
@@ -5,27 +5,31 @@ module ModSpox
5
5
  def initialize(handlers)
6
6
  handlers[:JOIN] = self
7
7
  end
8
+
9
+ # :mod_spox!~mod_spox@host JOIN :#m
10
+
8
11
  def process(string)
9
- if(string =~ /^:(\S+)\sJOIN :(\S+)$/)
10
- source = $1
11
- chan = $2
12
- if(source =~ /^(.+?)!(.+?)@(.+)$/)
13
- nick = find_model($1)
14
- nick.username == $2
15
- nick.address = $3
16
- nick.source = source
17
- nick.visible = true
18
- nick.save_changes
19
- channel = find_model(chan)
20
- channel.nick_add(nick)
21
- return Messages::Incoming::Join.new(string, channel, nick)
22
- else
23
- Logger.warn('Failed to parse source on JOIN message')
24
- return nil
25
- end
26
- else
27
- Logger.warn('Failed to parse JOIN message')
28
- return nil
12
+ orig = string.dup
13
+ string = string.dup
14
+ begin
15
+ string.slice!(0)
16
+ source = string.slice!(0..string.index(' ')-1)
17
+ string.slice!(0..string.index(':'))
18
+ channel = find_model(string.strip)
19
+ nick = find_model(source.slice(0..source.index('!')-1))
20
+ nick.source = source.dup
21
+ source.slice!(0..source.index('!'))
22
+ nick.username = source.slice!(0..source.index('@')-1)
23
+ source.slice!(0)
24
+ nick.address = source.slice!(0..source.size)
25
+ nick.visible = true
26
+ nick.save_changes
27
+ channel.add_nick(nick)
28
+ channel.save
29
+ return Messages::Incoming::Join.new(orig, channel, nick)
30
+ rescue Object => boom
31
+ Logger.warn("Failed to parse JOIN message: #{orig}")
32
+ raise boom
29
33
  end
30
34
  end
31
35
  end
@@ -5,20 +5,29 @@ module ModSpox
5
5
  def initialize(handlers)
6
6
  handlers[:KICK] = self
7
7
  end
8
+ # :spax!~spox@host KICK #m spox :foo
8
9
  def process(string)
9
- if(string =~ /^:(\S+)\sKICK\s(\S+)\s(\S+)\s:(.+)$/)
10
- source = $1
11
- chan = $2
12
- kicked = $3
13
- reason = $4
14
- kicker = find_model(source.gsub(/!.+$/, ''))
15
- channel = find_model(chan)
16
- kickee = find_model(kicked)
17
- channel.nick_remove(kickee)
18
- return Messages::Incoming::Kick.new(string, channel, kicker, kickee, reason)
19
- else
20
- Logger.warn('Failed to process KICK message')
21
- return nil
10
+ orig = string.dup
11
+ string = string.dup
12
+ begin
13
+ string.slice!(0)
14
+ source = string.slice!(0..string.index(' ')-1)
15
+ 2.times{string.slice!(0..string.index(' '))}
16
+ channel = string.slice!(0..string.index(' ')-1)
17
+ string.slice!(0)
18
+ kickee = string.slice!(0..string.index(' ')-1)
19
+ string.slice!(0..string.index(':'))
20
+ kicker = find_model(source[0..source.index('!')-1])
21
+ channel = find_model(channel)
22
+ kickee = find_model(kickee)
23
+ channel.remove_nick(kickee)
24
+ kickee.visible = false if kickee.channels.empty?
25
+ kickee.save_changes
26
+ channel.save_changes
27
+ return Messages::Incoming::Kick.new(orig, channel, kicker, kickee, string)
28
+ rescue Object => boom
29
+ Logger.warn("Failed to parse KICK message: #{orig}")
30
+ raise boom
22
31
  end
23
32
  end
24
33
  end
@@ -5,50 +5,56 @@ module ModSpox
5
5
  def initialize(handlers)
6
6
  handlers[:MODE] = self
7
7
  end
8
-
8
+
9
+ # :spax!~spox@host MODE #m +o spax
10
+ # :spax MODE spax :+iw
9
11
  def process(string)
12
+ orig = string.dup
13
+ string = string.dup
10
14
  begin
11
- if(string =~ /^:([^!]+)!.+?MODE\s(\S+)\s(\S+)$/) # this is for modes applied to the channel
12
- source = find_model($1)
13
- channel = find_model($2)
14
- full_mode = $3
15
- action = full_mode[0].chr
16
- full_mode.slice(0).each_char{|c|
17
- Models::ChannelMode.find_or_create(:channel_id => channel.pk, :mode => c) if action == '+'
18
- if(action == '-' && model = Models::ChannelMode.filter(:channel_id => channel.pk, :mode => c).first)
19
- model.destroy
15
+ string.slice!(0)
16
+ if(string.index('!').nil?) # looks like self mode
17
+ source = find_model(string.slice!(0..string.index(' ')-1))
18
+ 2.times{string.slice!(0..string.index(' '))}
19
+ target = find_model(string.slice!(0..string.index(' ')-1))
20
+ string.slice!(0..string.index(':'))
21
+ action = string.slice!(0)
22
+ action == '+' ? target.set_mode(string) : target.unset_mode(string)
23
+ return Messages::Incoming::Mode.new(orig, "#{action}#{string}", source, target, nil)
24
+ else
25
+ source = find_model(string.slice!(0..string.index('!')-1))
26
+ 2.times{string.slice!(0..string.index(' '))}
27
+ channel = find_model(string.slice!(0..string.index(' ')-1))
28
+ string.slice!(0)
29
+ modes = string.index(' ').nil? ? string.dup : string.slice!(0..string.index(' ')-1)
30
+ string[0] == ' ' ? string.slice!(0) : string = ''
31
+ action = modes.slice!(0)
32
+ if(string.size > 0) #nick modes
33
+ nicks = []
34
+ string.split.each do |n|
35
+ ni = find_model(n)
36
+ ni.add_channel(channel)
37
+ nicks << ni
38
+ end
39
+ i = 0
40
+ modes.each_char do |m|
41
+ nm = Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nicks[i].pk)
42
+ action == '+' ? nm.set_mode(m) : nm.unset_mode(m)
43
+ i += 1
20
44
  end
21
- }
22
- return Messages::Incoming::Mode.new(string, full_mode, source, nil, channel)
23
- #elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(.+)$/) # this is for modes applied to nick
24
- # raise Exceptions::BotException.new("Matched unimplemented mode string")
25
- elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(\S+)\s(.+)$/)
26
- source = find_model($1)
27
- channel = find_model($2)
28
- full_modes = $3
29
- targets = $4
30
- action = full_modes[0].chr
31
- nicks = Array.new
32
- full_modes.sub(/^./, '').length.times do |i|
33
- nick = find_model(targets.scan(/\S+/)[i])
34
- nicks << nick
35
- if(nick.is_a?(Models::Nick))
36
- mode = full_modes[i + 1].chr
37
- Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode) if action == '+'
38
- if(action == '-' && model = Models::NickMode.filter(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode).first)
39
- model.destroy
40
- end
45
+ nicks = nicks[0] if nicks.size == 1
46
+ return Messages::Incoming::Mode.new(orig, "#{action}#{modes}", source, nicks, channel)
47
+ else #channel modes
48
+ modes.each_char do |m|
49
+ action == '+' ? channel.set_mode(m) : channel.unset_mode(c)
41
50
  end
51
+ return Messages::Incoming::Mode.new(orig, "#{action}#{modes}", source, nil, channel)
42
52
  end
43
- nicks = nicks[0] if nicks.size == 1
44
- return Messages::Incoming::Mode.new(string, full_modes, source, nicks, channel)
45
- else
46
- Logger.warn('Failed to parse MODE message')
47
53
  end
48
54
  rescue Object => boom
49
- Logger.warn("Failed to process MODE message. Reason: #{boom}")
55
+ Logger.warn("Failed to parse MODE message: #{orig}")
56
+ raise boom
50
57
  end
51
- return nil
52
58
  end
53
59
  end
54
60
  end
@@ -15,10 +15,14 @@ module ModSpox
15
15
  @raw[$1] = [string]
16
16
  return nil
17
17
  elsif(string =~ /^:(\S+) #{RPL_MOTD.to_s}.*?:-\s?(.+)$/)
18
+ @motds[$1] ||= []
19
+ @raw[$1] ||= []
18
20
  @motds[$1] << $2
19
21
  @raw[$1] << string
20
22
  return nil
21
23
  elsif(string =~ /^:(\S+) #{RPL_ENDOFMOTD.to_s}/)
24
+ @raw[$1] ||= []
25
+ @motds[$1] ||= []
22
26
  @raw[$1] << string
23
27
  message = Messages::Incoming::Motd.new(@raw[$1].join("\n"), @motds[$1].join("\n"), $1)
24
28
  @motds.delete($1)
@@ -8,49 +8,76 @@ module ModSpox
8
8
  @names = Hash.new
9
9
  @raw = Hash.new
10
10
  end
11
-
11
+
12
12
  def process(string)
13
- if(string =~ /#{RPL_NAMREPLY}.*?(\S+) :(.+)$/)
14
- chan = $1
15
- nicks = $2
16
- @names[chan] = Array.new unless @names[chan]
17
- @raw[chan] = Array.new unless @raw[chan]
18
- if(@raw[chan])
19
- @raw[chan] << string
13
+ orig = string.dup
14
+ string = string.dup
15
+ begin
16
+ string.slice!(0..string.index(' '))
17
+ type = string.slice!(0..string.index(' ')-1)
18
+ if(type == RPL_NAMREPLY)
19
+ 3.times{ string.slice!(0..string.index(' ')) }
20
+ chan = string.slice!(0..string.index(' ')-1)
21
+ string.slice!(0..string.index(':'))
22
+ @names[chan] = Array.new unless @names[chan]
23
+ @raw[chan] = Array.new unless @raw[chan]
24
+ @raw[chan] << orig
25
+ @names[chan] += string.split
26
+ return nil
20
27
  else
21
- @raw[chan] = [string]
28
+ 2.times{ string.slice!(0..string.index(' ')) }
29
+ chan = string.slice!(0..string.index(' ')-1)
30
+ channel = find_model(chan)
31
+ @raw[chan] << orig if @raw[chan]
32
+ nicks = Array.new
33
+ ops = Array.new
34
+ voice = Array.new
35
+ raw = @raw[chan].dup if @raw[chan]
36
+ @names[chan] = [] unless @names[chan].is_a?(Array)
37
+ @names[chan].each do |n|
38
+ nick = Models::Nick.find_or_create(:nick => n.gsub(/^[@+]/, ''))
39
+ nick.visible = true
40
+ nicks << nick
41
+ if(n[0] == '@')
42
+ ops << nick
43
+ m = Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk)
44
+ m.set_mode('o')
45
+ elsif(n[0] == '+')
46
+ voice << nick
47
+ m = Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk)
48
+ m.set_mode('v')
49
+ else
50
+ m = Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk)
51
+ m.clear_modes
52
+ end
53
+ nick.add_channel(channel)
54
+ nick.refresh
55
+ channel.refresh
56
+ end
57
+ check_visibility(nicks, channel)
58
+ @names.delete(chan)
59
+ @raw.delete(chan)
60
+ return Messages::Incoming::Names.new(raw, channel, nicks, ops, voice)
22
61
  end
23
- @names[chan] += nicks.split(' ')
24
- return nil
25
- elsif(string =~ /#{RPL_ENDOFNAMES}.*?(\S+) :/)
26
- chan = $1
27
- @raw[chan] << string if @raw.has_key?(chan)
28
- channel = find_model(chan)
29
- nicks = Array.new
30
- ops = Array.new
31
- voice = Array.new
32
- raw = @raw[chan]
33
- @names[chan].each{|n|
34
- nick = Models::Nick.locate(n.gsub(/^[@+]/, ''))
35
- nicks << nick
36
- if(n[0].chr == '@')
37
- ops << nick
38
- Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk, :mode => 'o')
39
- elsif(n[0].chr == '+')
40
- voice << nick
41
- Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk, :mode => 'v')
42
- else
43
- Models::NickMode.filter(:nick_id => nick.pk, :channel_id => channel.pk).each{|m|
44
- m.destroy
45
- }
62
+ rescue Object => boom
63
+ Logger.error("Failed to parse NAMES message: #{orig}")
64
+ raise boom
65
+ end
66
+ end
67
+
68
+ # nicks:: list of nicks in channel
69
+ # channel:: channel nicks are in
70
+ # Remove visibility from any nicks that aren't really
71
+ # in the channel
72
+ def check_visibility(nicks, channel)
73
+ channel.nicks.each do |nick|
74
+ unless(nicks.include?(nick))
75
+ channel.remove_nick(nick)
76
+ unless(nick.botnick)
77
+ nick.refresh
78
+ nick.update(:visible => false) if (Models::Nick.filter(:botnick => true).first.channels & nick.channels).empty?
46
79
  end
47
- channel.nick_add(nick)
48
- }
49
- @names.delete(chan)
50
- @raw.delete(chan)
51
- return Messages::Incoming::Names.new(raw, channel, nicks, ops, voice)
52
- else
53
- return nil
80
+ end
54
81
  end
55
82
  end
56
83
  end
@@ -5,16 +5,23 @@ module ModSpox
5
5
  def initialize(handlers)
6
6
  handlers[:NICK] = self
7
7
  end
8
+ # :spox!~spox@some.random.host NICK :flock_of_deer
8
9
  def process(string)
9
- if(string =~ /^:([^!]+)!\S+\sNICK\s:(.+)$/)
10
- old_nick = find_model($1)
11
- new_nick = find_model($2)
12
- new_nick.visible = true
10
+ orig = string.dup
11
+ string = string.dup
12
+ begin
13
+ string.slice!(0)
14
+ old_nick = find_model(string.slice!(0..string.index('!')-1))
15
+ string.slice!(0..string.index(':'))
16
+ new_nick = find_model(string)
13
17
  old_nick.channels.each do |channel|
14
- new_nick.channel_add(channel)
15
- Models::NickMode.find_or_create(:nick_id => new_nick.pk, :channel_id => channel.pk, :mode => 'o') if old_nick.is_op?(channel)
16
- Models::NickMode.find_or_create(:nick_id => new_nick.pk, :channel_id => channel.pk, :mode => 'v') if old_nick.is_voice?(channel)
17
- Models::NickMode.filter(:nick_id => old_nick.pk, :channel_id => channel.pk).destroy
18
+ channel.remove_nick(old_nick)
19
+ channel.add_nick(new_nick)
20
+ m = Models::NickMode.filter(:nick_id => old_nick.pk, :channel_id => channel.pk).first
21
+ if(m)
22
+ m.nick_id = new_nick.pk
23
+ m.save
24
+ end
18
25
  end
19
26
  new_nick.username = old_nick.username
20
27
  new_nick.address = old_nick.address
@@ -23,19 +30,18 @@ module ModSpox
23
30
  new_nick.away = old_nick.away
24
31
  new_nick.visible = true
25
32
  new_nick.save_changes
26
- Models::Nick.transfer_groups(old_nick, new_nick)
27
33
  old_nick.visible = false
28
- old_nick.clear_channels
34
+ old_nick.remove_all_channels
29
35
  if(old_nick.botnick == true)
30
36
  old_nick.botnick = false
31
37
  new_nick.botnick = true
32
38
  end
33
39
  new_nick.save
34
40
  old_nick.save
35
- return Messages::Incoming::Nick.new(string, old_nick, new_nick)
36
- else
37
- Logger.warn('Failed to parse NICK message')
38
- return nil
41
+ return Messages::Incoming::Nick.new(orig, old_nick, new_nick)
42
+ rescue Object => boom
43
+ Logger.error("Failed to parse NICK message: #{orig}")
44
+ raise boom
39
45
  end
40
46
  end
41
47
  end