mod_spox 0.1.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG +36 -0
  2. data/INSTALL +2 -2
  3. data/README +0 -1
  4. data/bin/mod_spox +51 -12
  5. data/data/mod_spox/extras/AOLSpeak.rb +5 -18
  6. data/data/mod_spox/extras/AutoKick.rb +44 -23
  7. data/data/mod_spox/extras/AutoMode.rb +2 -5
  8. data/data/mod_spox/extras/AutoRejoin.rb +21 -0
  9. data/data/mod_spox/extras/Bouncer.rb +10 -10
  10. data/data/mod_spox/extras/Bytes.rb +12 -0
  11. data/data/mod_spox/extras/Confess.rb +131 -52
  12. data/data/mod_spox/extras/DCC.rb +189 -0
  13. data/data/mod_spox/extras/DevWatch.rb +32 -33
  14. data/data/mod_spox/extras/FloodKicker.rb +129 -0
  15. data/data/mod_spox/extras/GoogleIt.rb +13 -0
  16. data/data/mod_spox/extras/Headers.rb +31 -4
  17. data/data/mod_spox/extras/Karma.rb +103 -49
  18. data/data/mod_spox/extras/Logger.rb +45 -30
  19. data/data/mod_spox/extras/LolSpeak.rb +1 -1
  20. data/data/mod_spox/extras/NickServ.rb +83 -0
  21. data/data/mod_spox/extras/PhpCli.rb +12 -15
  22. data/data/mod_spox/extras/PhpFuncLookup.rb +57 -25
  23. data/data/mod_spox/extras/Quotes.rb +5 -4
  24. data/data/mod_spox/extras/RegexTracker.rb +160 -0
  25. data/data/mod_spox/extras/Roulette.rb +22 -23
  26. data/data/mod_spox/extras/Search.rb +3 -2
  27. data/data/mod_spox/extras/Slashdot.rb +35 -0
  28. data/data/mod_spox/extras/Topten.rb +5 -5
  29. data/data/mod_spox/extras/TracTicket.rb +68 -0
  30. data/data/mod_spox/extras/Translate.rb +69 -30
  31. data/data/mod_spox/extras/Twitter.rb +372 -0
  32. data/data/mod_spox/extras/UrbanDictionary.rb +21 -12
  33. data/data/mod_spox/extras/Weather.rb +1 -1
  34. data/data/mod_spox/plugins/Authenticator.rb +63 -30
  35. data/data/mod_spox/plugins/Banner.rb +164 -151
  36. data/data/mod_spox/plugins/Helper.rb +18 -7
  37. data/data/mod_spox/plugins/PluginLoader.rb +46 -22
  38. data/data/mod_spox/plugins/PoolConfig.rb +52 -0
  39. data/data/mod_spox/plugins/Quitter.rb +1 -1
  40. data/data/mod_spox/plugins/Status.rb +28 -0
  41. data/lib/mod_spox/Action.rb +20 -3
  42. data/lib/mod_spox/BaseConfig.rb +1 -0
  43. data/lib/mod_spox/Bot.rb +98 -75
  44. data/lib/mod_spox/BotConfig.rb +14 -6
  45. data/lib/mod_spox/ConfigurationWizard.rb +94 -105
  46. data/lib/mod_spox/Database.rb +33 -13
  47. data/lib/mod_spox/Helpers.rb +67 -38
  48. data/lib/mod_spox/Loader.rb +25 -5
  49. data/lib/mod_spox/Logger.rb +20 -62
  50. data/lib/mod_spox/MessageFactory.rb +34 -25
  51. data/lib/mod_spox/Monitors.rb +5 -0
  52. data/lib/mod_spox/Pipeline.rb +40 -51
  53. data/lib/mod_spox/Plugin.rb +40 -9
  54. data/lib/mod_spox/PluginManager.rb +46 -38
  55. data/lib/mod_spox/Pool.rb +129 -143
  56. data/lib/mod_spox/Socket.rb +41 -50
  57. data/lib/mod_spox/Sockets.rb +211 -0
  58. data/lib/mod_spox/Timer.rb +86 -69
  59. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  60. data/lib/mod_spox/handlers/Created.rb +1 -1
  61. data/lib/mod_spox/handlers/Handler.rb +9 -0
  62. data/lib/mod_spox/handlers/Invite.rb +1 -1
  63. data/lib/mod_spox/handlers/Join.rb +2 -2
  64. data/lib/mod_spox/handlers/Kick.rb +1 -1
  65. data/lib/mod_spox/handlers/LuserChannels.rb +1 -1
  66. data/lib/mod_spox/handlers/LuserOp.rb +1 -1
  67. data/lib/mod_spox/handlers/LuserUnknown.rb +1 -1
  68. data/lib/mod_spox/handlers/Mode.rb +2 -2
  69. data/lib/mod_spox/handlers/MyInfo.rb +1 -1
  70. data/lib/mod_spox/handlers/Names.rb +1 -1
  71. data/lib/mod_spox/handlers/Nick.rb +20 -3
  72. data/lib/mod_spox/handlers/NickInUse.rb +3 -3
  73. data/lib/mod_spox/handlers/Notice.rb +5 -15
  74. data/lib/mod_spox/handlers/Part.rb +1 -1
  75. data/lib/mod_spox/handlers/Ping.rb +1 -1
  76. data/lib/mod_spox/handlers/Pong.rb +1 -1
  77. data/lib/mod_spox/handlers/Privmsg.rb +2 -2
  78. data/lib/mod_spox/handlers/Quit.rb +1 -1
  79. data/lib/mod_spox/handlers/Topic.rb +2 -1
  80. data/lib/mod_spox/handlers/Welcome.rb +3 -3
  81. data/lib/mod_spox/handlers/Who.rb +9 -7
  82. data/lib/mod_spox/handlers/Whois.rb +29 -16
  83. data/lib/mod_spox/handlers/YourHost.rb +1 -1
  84. data/lib/mod_spox/messages/incoming/Privmsg.rb +38 -19
  85. data/lib/mod_spox/messages/internal/DCCListener.rb +12 -0
  86. data/lib/mod_spox/messages/internal/DCCRequest.rb +12 -0
  87. data/lib/mod_spox/messages/internal/DCCSocket.rb +19 -0
  88. data/lib/mod_spox/messages/internal/StatusRequest.rb +2 -1
  89. data/lib/mod_spox/messages/outgoing/Privmsg.rb +21 -5
  90. data/lib/mod_spox/migrations/001_initialize_models.rb +115 -0
  91. data/lib/mod_spox/models/Auth.rb +24 -16
  92. data/lib/mod_spox/models/AuthGroup.rb +4 -3
  93. data/lib/mod_spox/models/Channel.rb +20 -12
  94. data/lib/mod_spox/models/ChannelMode.rb +2 -2
  95. data/lib/mod_spox/models/Config.rb +11 -3
  96. data/lib/mod_spox/models/Group.rb +6 -1
  97. data/lib/mod_spox/models/Nick.rb +93 -33
  98. data/lib/mod_spox/models/NickChannel.rb +8 -6
  99. data/lib/mod_spox/models/NickGroup.rb +16 -0
  100. data/lib/mod_spox/models/NickMode.rb +3 -3
  101. data/lib/mod_spox/models/Server.rb +6 -2
  102. data/lib/mod_spox/models/Setting.rb +12 -6
  103. data/lib/mod_spox/models/Signature.rb +7 -13
  104. data/lib/mod_spox/models/Trigger.rb +1 -1
  105. metadata +125 -100
@@ -4,10 +4,19 @@ module ModSpox
4
4
 
5
5
  class Handler
6
6
 
7
+ def initialize(handlers)
8
+ end
9
+
7
10
  def process(data)
8
11
  raise Exceptions::NotImplemented.new('Method has not been implemented')
9
12
  end
10
13
 
14
+ # data:: any expected data
15
+ # Preprocessing allows for actions to be taken
16
+ # while messages are still in a synchronized state
17
+ def preprocess(data)
18
+ end
19
+
11
20
  protected
12
21
 
13
22
  def find_model(string)
@@ -12,7 +12,7 @@ module ModSpox
12
12
  channel = find_model($3)
13
13
  return Messages::Incoming::Invite.new(string, source, target, channel)
14
14
  else
15
- Logger.log('Failed to parse INVITE message')
15
+ Logger.warn('Failed to parse INVITE message')
16
16
  return nil
17
17
  end
18
18
  end
@@ -20,11 +20,11 @@ module ModSpox
20
20
  channel.nick_add(nick)
21
21
  return Messages::Incoming::Join.new(string, channel, nick)
22
22
  else
23
- Logger.log('Failed to parse source on JOIN message')
23
+ Logger.warn('Failed to parse source on JOIN message')
24
24
  return nil
25
25
  end
26
26
  else
27
- Logger.log('Failed to parse JOIN message')
27
+ Logger.warn('Failed to parse JOIN message')
28
28
  return nil
29
29
  end
30
30
  end
@@ -17,7 +17,7 @@ module ModSpox
17
17
  channel.nick_remove(kickee)
18
18
  return Messages::Incoming::Kick.new(string, channel, kicker, kickee, reason)
19
19
  else
20
- Logger.log('Failed to process KICK message')
20
+ Logger.warn('Failed to process KICK message')
21
21
  return nil
22
22
  end
23
23
  end
@@ -9,7 +9,7 @@ module ModSpox
9
9
  if(string =~ /(\d+)\s:channels/)
10
10
  return Messages::Incoming::LuserChannels.new(string, $1.to_i)
11
11
  else
12
- Logger.log('Failed to match RPL_LUSERCHANNELS message')
12
+ Logger.warn('Failed to match RPL_LUSERCHANNELS message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module ModSpox
9
9
  if(string =~ /(\d+) :.*?\s*[oO]perators/)
10
10
  return Messages::Incoming::LuserOp.new(string, $1.to_i)
11
11
  else
12
- Logger.log('Failed to match RPL_LUSEROP message')
12
+ Logger.warn('Failed to match RPL_LUSEROP message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module ModSpox
9
9
  if(string =~ /(\d+) :.*[Uu]nknown/)
10
10
  return Messages::Incoming::LuserUnknown.new(string, $1.to_i)
11
11
  else
12
- Logger.log('Failed to match RPL_LUSERUNKNOWN message')
12
+ Logger.warn('Failed to match RPL_LUSERUNKNOWN message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -43,10 +43,10 @@ module ModSpox
43
43
  nicks = nicks[0] if nicks.size == 1
44
44
  return Messages::Incoming::Mode.new(string, full_modes, source, nicks, channel)
45
45
  else
46
- Logger.log('Failed to parse MODE message')
46
+ Logger.warn('Failed to parse MODE message')
47
47
  end
48
48
  rescue Object => boom
49
- Logger.log("Failed to process MODE message. Reason: #{boom}")
49
+ Logger.warn("Failed to process MODE message. Reason: #{boom}")
50
50
  end
51
51
  return nil
52
52
  end
@@ -14,7 +14,7 @@ module ModSpox
14
14
  channelmodes = $4
15
15
  return Messages::Incoming::MyInfo.new(string, servername, version, usermodes, channelmodes)
16
16
  else
17
- Logger.log('Failed to match My Info message')
17
+ Logger.warn('Failed to match My Info message')
18
18
  return nil
19
19
  end
20
20
  end
@@ -31,7 +31,7 @@ module ModSpox
31
31
  voice = Array.new
32
32
  raw = @raw[chan]
33
33
  @names[chan].each{|n|
34
- nick = Models::Nick.find_or_create(:nick => n.gsub(/^[@+]/, ''))
34
+ nick = Models::Nick.locate(n.gsub(/^[@+]/, ''))
35
35
  nicks << nick
36
36
  if(n[0].chr == '@')
37
37
  ops << nick
@@ -9,15 +9,32 @@ module ModSpox
9
9
  if(string =~ /^:([^!]+)!\S+\sNICK\s:(.+)$/)
10
10
  old_nick = find_model($1)
11
11
  new_nick = find_model($2)
12
+ new_nick.visible = true
13
+ 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
+ end
19
+ new_nick.username = old_nick.username
20
+ new_nick.address = old_nick.address
21
+ new_nick.real_name = old_nick.real_name
22
+ new_nick.connected_to = old_nick.connected_to
23
+ new_nick.away = old_nick.away
24
+ new_nick.visible = true
25
+ new_nick.save_changes
26
+ Models::Nick.transfer_groups(old_nick, new_nick)
27
+ old_nick.visible = false
28
+ old_nick.clear_channels
12
29
  if(old_nick.botnick == true)
13
30
  old_nick.botnick = false
14
- old_nick.save
15
31
  new_nick.botnick = true
16
- new_nick.save
17
32
  end
33
+ new_nick.save
34
+ old_nick.save
18
35
  return Messages::Incoming::Nick.new(string, old_nick, new_nick)
19
36
  else
20
- Logger.log('Failed to parse NICK message')
37
+ Logger.warn('Failed to parse NICK message')
21
38
  return nil
22
39
  end
23
40
  end
@@ -3,13 +3,13 @@ module ModSpox
3
3
  module Handlers
4
4
  class NickInUse < Handler
5
5
  def initialize(handlers)
6
- handlers[:RPL_NICKNAMEINUSE] = self
6
+ handlers[ERR_NICKNAMEINUSE] = self
7
7
  end
8
8
  def process(string)
9
- if(string =~ /#{RPL_NICKNAMEINUSE}\s\S+\s(\S+)\s:/)
9
+ if(string =~ /#{ERR_NICKNAMEINUSE}\s\S+\s(\S+)\s:/)
10
10
  return Messages::Incoming::NickInUse.new(string, $1)
11
11
  else
12
- Logger.log('Failed to parse RPL_NICKNAMEINUSE message')
12
+ Logger.warn('Failed to parse ERR_NICKNAMEINUSE message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -14,20 +14,10 @@ module ModSpox
14
14
  if(base_source =~ /\!/)
15
15
  source = find_model(base_source.gsub(/!.+$/, ''))
16
16
  if(base_source =~ /!(.+)@(.+)$/)
17
- do_save = false
18
- unless(source.username == $1)
19
- source.username == $1
20
- do_save = true
21
- end
22
- unless(source.address == $2)
23
- source.address = $2
24
- do_save = true
25
- end
26
- unless(source.source == base_source)
27
- source.source = base_source
28
- do_save = true
29
- end
30
- source.save if do_save
17
+ source.username == $1
18
+ source.address = $2
19
+ source.source = base_source
20
+ source.save_changes
31
21
  end
32
22
  target = find_model(target)
33
23
  else
@@ -35,7 +25,7 @@ module ModSpox
35
25
  end
36
26
  return Messages::Incoming::Notice.new(string, source, target, message)
37
27
  else
38
- Logger.log('Failed to match NOTICE message')
28
+ Logger.warn('Failed to match NOTICE message')
39
29
  return nil
40
30
  end
41
31
  end
@@ -12,7 +12,7 @@ module ModSpox
12
12
  channel.nick_remove(nick)
13
13
  return Messages::Incoming::Part.new(string, channel, nick, $3)
14
14
  else
15
- Logger.log('Failed to parse PART message')
15
+ Logger.warn('Failed to parse PART message')
16
16
  return nil
17
17
  end
18
18
  end
@@ -9,7 +9,7 @@ module ModSpox
9
9
  if(string =~ /^PING\s:(.+)$/)
10
10
  return Messages::Incoming::Ping.new(string, $1, nil)
11
11
  else
12
- Logger.log('Failed to match PING message')
12
+ Logger.warn('Failed to match PING message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module ModSpox
9
9
  if(string =~ /^:\S+\sPONG\s(\S+)\s:(.+)$/)
10
10
  return Messages::Incoming::Pong.new(string, $1, $2)
11
11
  else
12
- Logger.log('Failed to parse PONG message')
12
+ Logger.warn('Failed to parse PONG message')
13
13
  return nil
14
14
  end
15
15
  end
@@ -13,7 +13,7 @@ module ModSpox
13
13
  base_source = $1
14
14
  source = find_model(base_source.gsub(/!.+$/, ''))
15
15
  if(base_source =~ /!(.+)@(.+)$/)
16
- source.username == $1
16
+ source.username = $1
17
17
  source.address = $2
18
18
  source.source = base_source
19
19
  source.save_changes
@@ -21,7 +21,7 @@ module ModSpox
21
21
  Models::NickChannel.find_or_create(:channel_id => target.pk, :nick_id => source.pk) if target.is_a?(ModSpox::Models::Channel)
22
22
  return Messages::Incoming::Privmsg.new(string, source, target, message)
23
23
  else
24
- Logger.log('Failed to match PRIVMSG message')
24
+ Logger.warn('Failed to match PRIVMSG message')
25
25
  return nil
26
26
  end
27
27
  end
@@ -14,7 +14,7 @@ module ModSpox
14
14
  nick.save
15
15
  return Messages::Incoming::Quit.new(string, nick, reason)
16
16
  else
17
- Logger.log('Failed to parse KICK message')
17
+ Logger.warn('Failed to parse KICK message')
18
18
  return nil
19
19
  end
20
20
  end
@@ -11,6 +11,7 @@ module ModSpox
11
11
  def process(string)
12
12
  if(string =~ /#{RPL_TOPIC}.+?(\S+)\s:(.+)$/)
13
13
  channel = find_model($1)
14
+ channel.update(:topic => $2)
14
15
  return Messages::Incoming::Topic.new(string, channel, $2)
15
16
  elsif(string =~ /#{RPL_NOTOPIC}.+?(\S+)\s:/)
16
17
  channel = find_model($1)
@@ -21,7 +22,7 @@ module ModSpox
21
22
  time = Time.at($3.to_i)
22
23
  return Messages::Incoming::TopicInfo.new(string, channel, nick, time)
23
24
  else
24
- Logger.log('Failed to parse TOPIC type string')
25
+ Logger.warn('Failed to parse TOPIC type string')
25
26
  return nil
26
27
  end
27
28
  end
@@ -16,7 +16,7 @@ module ModSpox
16
16
  nick = $1
17
17
  username = $2
18
18
  hostname = $3
19
- nick = Models::Nick.find_or_create(:nick => nick)
19
+ nick = Models::Nick.locate(nick)
20
20
  nick.botnick = true
21
21
  nick.username = username
22
22
  nick.address = hostname
@@ -24,11 +24,11 @@ module ModSpox
24
24
  nick.save
25
25
  return Messages::Incoming::Welcome.new(string, server, message, nick, username, hostname)
26
26
  else
27
- Logger.log('Failed to match user string in welcome message')
27
+ Logger.warn('Failed to match user string in welcome message')
28
28
  return nil
29
29
  end
30
30
  else
31
- Logger.log('Failed to match welcome message')
31
+ Logger.warn('Failed to match welcome message')
32
32
  return nil
33
33
  end
34
34
  end
@@ -1,4 +1,5 @@
1
- require 'mod_spox/handlers/Handler'
1
+ ['mod_spox/handlers/Handler', 'mod_spox/Monitors'].each{|f|require f}
2
+
2
3
  module ModSpox
3
4
  module Handlers
4
5
  class Who < Handler
@@ -8,9 +9,8 @@ module ModSpox
8
9
  @cache = Hash.new
9
10
  @raw_cache = Hash.new
10
11
  end
12
+
11
13
  def process(string)
12
- # :not.configured 352 mod_spox #foobar ~mod_spox 192.168.0.25 not.configured mod_spox H :0 mod_spox IRC bot
13
- # :not.configured 352 mod_spox * ~mod_spox 192.168.0.25 not.configured mod_spox H :0 mod_spox IRC bot
14
14
  if(string =~ /#{RPL_WHOREPLY}\s\S+\s(\S+|\*|\*\s\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s:(\d)\s(.+)$/)
15
15
  # Items matched are as follows:
16
16
  # 1: location
@@ -29,11 +29,12 @@ module ModSpox
29
29
  nick.real_name = $8
30
30
  nick.connected_to = $4
31
31
  nick.away = info =~ /G/ ? true : false
32
- nick.save
32
+ nick.visible = true
33
+ nick.save_changes
33
34
  key = location.nil? ? nick.nick : location
34
- @cache[key] = Array.new unless @cache[location]
35
+ @cache[key] = Array.new unless @cache[key]
35
36
  @cache[key] << nick
36
- @raw_cache[key] = Array.new unless @raw_cache[location]
37
+ @raw_cache[key] = Array.new unless @raw_cache[key]
37
38
  @raw_cache[key] << string
38
39
  unless(location.nil?)
39
40
  channel = find_model(location)
@@ -56,10 +57,11 @@ module ModSpox
56
57
  @cache.delete(location)
57
58
  return message
58
59
  else
59
- Logger.log('Failed to match RPL_WHO type message')
60
+ Logger.warn('Failed to match RPL_WHO type message')
60
61
  return nil
61
62
  end
62
63
  end
64
+
63
65
  end
64
66
  end
65
67
  end
@@ -16,53 +16,66 @@ module ModSpox
16
16
 
17
17
  def process(string)
18
18
  if(string =~ /#{RPL_WHOISUSER}\s\S+\s(\S+)\s(\S+)\s(\S+)\s\*\s:(.+)$/)
19
+ key = $1
19
20
  nick = find_model($1)
20
21
  nick.username = $2
21
22
  nick.address = $3
22
23
  nick.real_name = $4
24
+ nick.save_changes
23
25
  @cache[$1] = Messages::Incoming::Whois.new(nick)
24
26
  @cache[$1].raw_push(string)
25
27
  return nil
26
28
  elsif(string =~ /#{RPL_WHOISCHANNELS}\s\S+\s(\S+)\s:(.+)$/)
27
29
  nick = $1
30
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
31
+ @cache[$1].raw_push(string)
28
32
  $2.split(/\s/).each{|chan|
29
33
  channel = find_model(chan.gsub(/^[@\+]/, ''))
30
34
  @cache[nick].channels_push(channel)
31
35
  if(chan[0].chr == '@')
32
- Models::NickMode.find_or_create(:nick_id => @cache[nick].pk, :mode => 'o', :channel_id => channel.pk)
36
+ Models::NickMode.find_or_create(:nick_id => @cache[nick].nick.pk, :mode => 'o', :channel_id => channel.pk)
33
37
  elsif(chan[0].chr == '+')
34
- Models::NickMode.find_or_create(:nick_id => @cache[nick].pk, :mode => 'v', :channel_id => channel.pk)
38
+ Models::NickMode.find_or_create(:nick_id => @cache[nick].nick.pk, :mode => 'v', :channel_id => channel.pk)
35
39
  else
36
40
  Models::NickMode.filter(:nick_id => @cache[nick].nick.pk, :channel_id => channel.pk).each{|m| m.destroy}
37
41
  end
38
42
  }
39
- @cache[$1].raw_push(string)
40
43
  return nil
41
44
  elsif(string =~ /#{RPL_WHOISSERVER}\s\S+\s(\S+)\s(\S+)\s:(.+)$/)
42
- @cache[$1].nick.connected_to = $2
43
- @cache[$1].raw_push(string)
45
+ nick = $1
46
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
47
+ @cache[nick].nick.connected_to = $2
48
+ @cache[nick].raw_push(string)
44
49
  return nil
45
50
  elsif(string =~ /#{RPL_WHOISIDENTIFIED}\s\S+\s(\S+)\s/)
46
- @cache[$1].nick.auth.services_identified = true
47
- @cache[$1].raw_push(string)
51
+ nick = $1
52
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
53
+ @cache[nick].nick.auth.services_identified = true
54
+ @cache[nick].raw_push(string)
48
55
  return nil
49
56
  elsif(string =~ /#{RPL_WHOISIDLE}\s\S+\s(\S+)\s(\d+)\s(\d+)\s:(.+?),(.+?)/)
50
- @cache[$1].nick.seconds_idle = $2.to_i
51
- @cache[$1].nick.connected_at = Time.at($3.to_i)
52
- @cache[$1].raw_push(string)
57
+ nick = $1
58
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
59
+ @cache[nick].nick.seconds_idle = $2.to_i
60
+ @cache[nick].nick.connected_at = Time.at($3.to_i)
61
+ @cache[nick].raw_push(string)
53
62
  return nil
54
63
  elsif(string =~ /#{RPL_WHOISOPERATOR}\s\S+\s(\S+)/)
55
- @cache[$1].raw_push(string)
64
+ nick = $1
65
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
66
+ @cache[nick].raw_push(string)
56
67
  return nil
57
68
  elsif(string =~ /#{RPL_ENDOFWHOIS}\s\S+\s(\S+)\s:/)
58
- @cache[$1].raw_push(string)
59
- message = @cache[$1]
69
+ nick = $1
70
+ @cache[nick] = Messages::Incoming::Whois.new(find_model(nick)) unless @cache[nick]
71
+ @cache[nick].raw_push(string)
72
+ message = @cache[nick]
60
73
  message.lock
61
- @cache[$1].nick.save
62
- @cache.delete($1)
74
+ @cache[nick].nick.save
75
+ @cache.delete(nick)
63
76
  return message
64
77
  else
65
- Logger.log('Failed to parse WHOIS type reply')
78
+ Logger.warn('Failed to parse WHOIS type reply')
66
79
  return nil
67
80
  end
68
81
  end
@@ -10,7 +10,7 @@ module ModSpox
10
10
  if(string =~ /:Your host is (\S+), running version (.+)$/)
11
11
  return Messages::Incoming::YourHost.new(string, $1, $2)
12
12
  else
13
- Logger.log('Failed to match Your Host message')
13
+ Logger.warn('Failed to match Your Host message')
14
14
  return nil
15
15
  end
16
16
  end
@@ -3,23 +3,29 @@ module ModSpox
3
3
  module Messages
4
4
  module Incoming
5
5
  class Privmsg < Message
6
-
6
+
7
7
  # source of the message
8
8
  attr_reader :source
9
9
  # target of the message
10
10
  attr_reader :target
11
- # the message sent
12
- attr_reader :message
11
+ # message is CTCP
12
+ attr_reader :ctcp
13
+ # message CTCP type
14
+ attr_reader :ctcp_type
13
15
  def initialize(raw, source, target, message)
14
16
  super(raw)
15
17
  @source = source
16
18
  @target = target
17
- if(message =~ /^\001ACTION\s(.+)\001/)
18
- @message = $1
19
- @action = true
19
+ @ctcp = false
20
+ @ctcp_type = nil
21
+ @action = false
22
+ if(@raw_content =~ /\x01(\S+)\s(.+)\x01/)
23
+ @ctcp = true
24
+ @ctcp_type = $1
25
+ @message = $2
26
+ @action = @ctcp_type.downcase == 'action'
20
27
  else
21
28
  @message = message
22
- @action = false
23
29
  end
24
30
  botnick = Models::Nick.filter(:botnick => true).first
25
31
  if(botnick)
@@ -28,43 +34,56 @@ module ModSpox
28
34
  @addressed = false
29
35
  end
30
36
  end
31
-
37
+
32
38
  # Is message addressing the bot
33
39
  def addressed?
34
40
  return @addressed || is_private?
35
41
  end
36
-
42
+
37
43
  # Is this is private message
38
44
  def is_private?
39
- return @target.is_a?(Models::Nick)
45
+ return @target.is_a?(Models::Nick) || @target.is_a?(String)
46
+ end
47
+
48
+ # Is this a DCC message
49
+ def is_dcc?
50
+ return @target.is_a?(String)
40
51
  end
41
-
52
+
42
53
  # Is this a public message
43
54
  def is_public?
44
55
  return @target.is_a?(Models::Channel)
45
56
  end
46
-
57
+
47
58
  # Does the message contain colors
48
59
  def is_colored?
49
60
  return @message =~ /\cC\d\d?(?:,\d\d?)?/
50
61
  end
51
-
62
+
52
63
  # Message with coloring stripped
53
64
  def message_nocolor
54
- return @message.gsub(/\cC\d\d?(?:,\d\d?)?/, '')
65
+ return @message.gsub(/\cC\d\d?(?:,\d\d?)?/, '').tr("\x00-\x1f", '')
55
66
  end
56
-
67
+
68
+ # the message sent
69
+ def message(color=false)
70
+ return color ? @message : message_nocolor
71
+ end
72
+
57
73
  # Is this message an action message
58
74
  def is_action?
59
75
  @action
60
76
  end
61
-
77
+
78
+ def is_ctcp?
79
+ @ctcp
80
+ end
81
+
62
82
  # Convinence method for replying to the correct place
63
83
  def replyto
64
- return @source if is_private?
65
- return @target if is_public?
84
+ return is_public? || is_dcc? ? @target : @source
66
85
  end
67
-
86
+
68
87
  end
69
88
  end
70
89
  end
@@ -0,0 +1,12 @@
1
+ module ModSpox
2
+ module Messages
3
+ module Internal
4
+ class DCCListener
5
+ attr_reader :nick
6
+ def initialize(nick)
7
+ @nick = nick
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ModSpox
2
+ module Messages
3
+ module Internal
4
+ class DCCRequest
5
+ attr_reader :socket_id
6
+ def initialize(id)
7
+ @socket_id = id
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module ModSpox
2
+ module Messages
3
+ module Internal
4
+ class DCCSocket
5
+ # ID of the contained socket
6
+ attr_reader :socket_id
7
+ # Models::Nick this socket is connected to
8
+ attr_reader :nick
9
+ # socket
10
+ attr_reader :socket
11
+ def initialize(id, nick, socket)
12
+ @socket_id = id
13
+ @nick = nick
14
+ @socket = socket
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,8 +1,9 @@
1
+ require 'mod_spox/messages/internal/Request'
1
2
  module ModSpox
2
3
  module Messages
3
4
  module Internal
4
5
  # Request current bot status
5
- class Status < Request
6
+ class StatusRequest < Request
6
7
  end
7
8
  end
8
9
  end