mod_spox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/CHANGELOG +2 -0
  2. data/INSTALL +9 -0
  3. data/README +33 -0
  4. data/bin/mod_spox +60 -0
  5. data/data/mod_spox/extras/Tester.rb +14 -0
  6. data/data/mod_spox/plugins/Authenticator.rb +245 -0
  7. data/data/mod_spox/plugins/BotNick.rb +18 -0
  8. data/data/mod_spox/plugins/Initializer.rb +41 -0
  9. data/data/mod_spox/plugins/Joiner.rb +13 -0
  10. data/data/mod_spox/plugins/Parter.rb +22 -0
  11. data/data/mod_spox/plugins/PluginLoader.rb +136 -0
  12. data/data/mod_spox/plugins/Ponger.rb +14 -0
  13. data/data/mod_spox/plugins/Quitter.rb +14 -0
  14. data/lib/mod_spox/Action.rb +73 -0
  15. data/lib/mod_spox/BaseConfig.rb +48 -0
  16. data/lib/mod_spox/Bot.rb +472 -0
  17. data/lib/mod_spox/BotConfig.rb +54 -0
  18. data/lib/mod_spox/ConfigurationWizard.rb +178 -0
  19. data/lib/mod_spox/Database.rb +25 -0
  20. data/lib/mod_spox/Exceptions.rb +35 -0
  21. data/lib/mod_spox/Helpers.rb +35 -0
  22. data/lib/mod_spox/Loader.rb +79 -0
  23. data/lib/mod_spox/Logger.rb +31 -0
  24. data/lib/mod_spox/MessageFactory.rb +73 -0
  25. data/lib/mod_spox/Monitors.rb +59 -0
  26. data/lib/mod_spox/Pipeline.rb +148 -0
  27. data/lib/mod_spox/Plugin.rb +18 -0
  28. data/lib/mod_spox/PluginManager.rb +105 -0
  29. data/lib/mod_spox/Pool.rb +50 -0
  30. data/lib/mod_spox/Socket.rb +171 -0
  31. data/lib/mod_spox/Timer.rb +138 -0
  32. data/lib/mod_spox/handlers/BadNick.rb +16 -0
  33. data/lib/mod_spox/handlers/Bounce.rb +15 -0
  34. data/lib/mod_spox/handlers/Created.rb +16 -0
  35. data/lib/mod_spox/handlers/Handler.rb +31 -0
  36. data/lib/mod_spox/handlers/Invite.rb +19 -0
  37. data/lib/mod_spox/handlers/Join.rb +30 -0
  38. data/lib/mod_spox/handlers/Kick.rb +24 -0
  39. data/lib/mod_spox/handlers/LuserChannels.rb +16 -0
  40. data/lib/mod_spox/handlers/LuserClient.rb +16 -0
  41. data/lib/mod_spox/handlers/LuserMe.rb +14 -0
  42. data/lib/mod_spox/handlers/LuserOp.rb +16 -0
  43. data/lib/mod_spox/handlers/LuserUnknown.rb +16 -0
  44. data/lib/mod_spox/handlers/Mode.rb +47 -0
  45. data/lib/mod_spox/handlers/Motd.rb +30 -0
  46. data/lib/mod_spox/handlers/MyInfo.rb +21 -0
  47. data/lib/mod_spox/handlers/Names.rb +54 -0
  48. data/lib/mod_spox/handlers/Nick.rb +24 -0
  49. data/lib/mod_spox/handlers/NickInUse.rb +16 -0
  50. data/lib/mod_spox/handlers/Notice.rb +32 -0
  51. data/lib/mod_spox/handlers/Part.rb +19 -0
  52. data/lib/mod_spox/handlers/Ping.rb +16 -0
  53. data/lib/mod_spox/handlers/Pong.rb +16 -0
  54. data/lib/mod_spox/handlers/Privmsg.rb +27 -0
  55. data/lib/mod_spox/handlers/Quit.rb +21 -0
  56. data/lib/mod_spox/handlers/Topic.rb +29 -0
  57. data/lib/mod_spox/handlers/Welcome.rb +34 -0
  58. data/lib/mod_spox/handlers/Who.rb +60 -0
  59. data/lib/mod_spox/handlers/Whois.rb +63 -0
  60. data/lib/mod_spox/handlers/YourHost.rb +17 -0
  61. data/lib/mod_spox/messages/incoming/BadNick.rb +15 -0
  62. data/lib/mod_spox/messages/incoming/Bounce.rb +17 -0
  63. data/lib/mod_spox/messages/incoming/Created.rb +14 -0
  64. data/lib/mod_spox/messages/incoming/Invite.rb +20 -0
  65. data/lib/mod_spox/messages/incoming/Join.rb +18 -0
  66. data/lib/mod_spox/messages/incoming/Kick.rb +25 -0
  67. data/lib/mod_spox/messages/incoming/LuserChannels.rb +14 -0
  68. data/lib/mod_spox/messages/incoming/LuserClient.rb +23 -0
  69. data/lib/mod_spox/messages/incoming/LuserMe.rb +17 -0
  70. data/lib/mod_spox/messages/incoming/LuserOp.rb +14 -0
  71. data/lib/mod_spox/messages/incoming/LuserUnknown.rb +14 -0
  72. data/lib/mod_spox/messages/incoming/Message.rb +22 -0
  73. data/lib/mod_spox/messages/incoming/Mode.rb +41 -0
  74. data/lib/mod_spox/messages/incoming/Motd.rb +17 -0
  75. data/lib/mod_spox/messages/incoming/MyInfo.rb +23 -0
  76. data/lib/mod_spox/messages/incoming/Names.rb +23 -0
  77. data/lib/mod_spox/messages/incoming/Nick.rb +25 -0
  78. data/lib/mod_spox/messages/incoming/NickInUse.rb +14 -0
  79. data/lib/mod_spox/messages/incoming/Notice.rb +8 -0
  80. data/lib/mod_spox/messages/incoming/Part.rb +20 -0
  81. data/lib/mod_spox/messages/incoming/Ping.rb +17 -0
  82. data/lib/mod_spox/messages/incoming/Pong.rb +8 -0
  83. data/lib/mod_spox/messages/incoming/Privmsg.rb +64 -0
  84. data/lib/mod_spox/messages/incoming/Quit.rb +17 -0
  85. data/lib/mod_spox/messages/incoming/Topic.rb +20 -0
  86. data/lib/mod_spox/messages/incoming/TopicInfo.rb +20 -0
  87. data/lib/mod_spox/messages/incoming/Welcome.rb +26 -0
  88. data/lib/mod_spox/messages/incoming/Who.rb +17 -0
  89. data/lib/mod_spox/messages/incoming/Whois.rb +47 -0
  90. data/lib/mod_spox/messages/incoming/YourHost.rb +17 -0
  91. data/lib/mod_spox/messages/internal/BotInitialized.rb +11 -0
  92. data/lib/mod_spox/messages/internal/ChangeNick.rb +15 -0
  93. data/lib/mod_spox/messages/internal/Connected.rb +20 -0
  94. data/lib/mod_spox/messages/internal/ConnectionFailed.rb +23 -0
  95. data/lib/mod_spox/messages/internal/Disconnected.rb +8 -0
  96. data/lib/mod_spox/messages/internal/Disconnecting.rb +8 -0
  97. data/lib/mod_spox/messages/internal/EstablishConnection.rb +22 -0
  98. data/lib/mod_spox/messages/internal/HaltBot.rb +8 -0
  99. data/lib/mod_spox/messages/internal/NickRequest.rb +8 -0
  100. data/lib/mod_spox/messages/internal/NickResponse.rb +14 -0
  101. data/lib/mod_spox/messages/internal/PluginLoadRequest.rb +20 -0
  102. data/lib/mod_spox/messages/internal/PluginLoadResponse.rb +16 -0
  103. data/lib/mod_spox/messages/internal/PluginModuleRequest.rb +13 -0
  104. data/lib/mod_spox/messages/internal/PluginModuleResponse.rb +17 -0
  105. data/lib/mod_spox/messages/internal/PluginReload.rb +8 -0
  106. data/lib/mod_spox/messages/internal/PluginRequest.rb +17 -0
  107. data/lib/mod_spox/messages/internal/PluginResponse.rb +20 -0
  108. data/lib/mod_spox/messages/internal/PluginUnloadRequest.rb +8 -0
  109. data/lib/mod_spox/messages/internal/PluginUnloadResponse.rb +8 -0
  110. data/lib/mod_spox/messages/internal/Request.rb +15 -0
  111. data/lib/mod_spox/messages/internal/Response.rb +15 -0
  112. data/lib/mod_spox/messages/internal/Shutdown.rb +8 -0
  113. data/lib/mod_spox/messages/internal/SignaturesUpdate.rb +8 -0
  114. data/lib/mod_spox/messages/internal/StatusRequest.rb +9 -0
  115. data/lib/mod_spox/messages/internal/StatusResponse.rb +17 -0
  116. data/lib/mod_spox/messages/internal/TimerAdd.rb +27 -0
  117. data/lib/mod_spox/messages/internal/TimerClear.rb +8 -0
  118. data/lib/mod_spox/messages/internal/TimerRemove.rb +15 -0
  119. data/lib/mod_spox/messages/internal/TimerResponse.rb +26 -0
  120. data/lib/mod_spox/messages/internal/TriggersUpdate.rb +8 -0
  121. data/lib/mod_spox/messages/outgoing/Admin.rb +15 -0
  122. data/lib/mod_spox/messages/outgoing/Away.rb +10 -0
  123. data/lib/mod_spox/messages/outgoing/ChannelMode.rb +25 -0
  124. data/lib/mod_spox/messages/outgoing/Connect.rb +24 -0
  125. data/lib/mod_spox/messages/outgoing/Die.rb +9 -0
  126. data/lib/mod_spox/messages/outgoing/Info.rb +15 -0
  127. data/lib/mod_spox/messages/outgoing/Invite.rb +19 -0
  128. data/lib/mod_spox/messages/outgoing/Ison.rb +15 -0
  129. data/lib/mod_spox/messages/outgoing/Join.rb +19 -0
  130. data/lib/mod_spox/messages/outgoing/Kick.rb +23 -0
  131. data/lib/mod_spox/messages/outgoing/Kill.rb +19 -0
  132. data/lib/mod_spox/messages/outgoing/Links.rb +19 -0
  133. data/lib/mod_spox/messages/outgoing/List.rb +19 -0
  134. data/lib/mod_spox/messages/outgoing/Lusers.rb +19 -0
  135. data/lib/mod_spox/messages/outgoing/Motd.rb +16 -0
  136. data/lib/mod_spox/messages/outgoing/Names.rb +20 -0
  137. data/lib/mod_spox/messages/outgoing/Nick.rb +16 -0
  138. data/lib/mod_spox/messages/outgoing/Notice.rb +11 -0
  139. data/lib/mod_spox/messages/outgoing/Oper.rb +19 -0
  140. data/lib/mod_spox/messages/outgoing/Part.rb +19 -0
  141. data/lib/mod_spox/messages/outgoing/Pass.rb +16 -0
  142. data/lib/mod_spox/messages/outgoing/Ping.rb +10 -0
  143. data/lib/mod_spox/messages/outgoing/Pong.rb +17 -0
  144. data/lib/mod_spox/messages/outgoing/Privmsg.rb +19 -0
  145. data/lib/mod_spox/messages/outgoing/Quit.rb +10 -0
  146. data/lib/mod_spox/messages/outgoing/Rehash.rb +9 -0
  147. data/lib/mod_spox/messages/outgoing/Restart.rb +9 -0
  148. data/lib/mod_spox/messages/outgoing/ServList.rb +19 -0
  149. data/lib/mod_spox/messages/outgoing/Simple.rb +12 -0
  150. data/lib/mod_spox/messages/outgoing/Squery.rb +19 -0
  151. data/lib/mod_spox/messages/outgoing/Squit.rb +19 -0
  152. data/lib/mod_spox/messages/outgoing/Stats.rb +18 -0
  153. data/lib/mod_spox/messages/outgoing/Summon.rb +23 -0
  154. data/lib/mod_spox/messages/outgoing/Time.rb +15 -0
  155. data/lib/mod_spox/messages/outgoing/Topic.rb +19 -0
  156. data/lib/mod_spox/messages/outgoing/Trace.rb +15 -0
  157. data/lib/mod_spox/messages/outgoing/Unaway.rb +9 -0
  158. data/lib/mod_spox/messages/outgoing/User.rb +23 -0
  159. data/lib/mod_spox/messages/outgoing/UserHost.rb +15 -0
  160. data/lib/mod_spox/messages/outgoing/UserMode.rb +19 -0
  161. data/lib/mod_spox/messages/outgoing/Users.rb +15 -0
  162. data/lib/mod_spox/messages/outgoing/Version.rb +16 -0
  163. data/lib/mod_spox/messages/outgoing/Who.rb +19 -0
  164. data/lib/mod_spox/messages/outgoing/WhoWas.rb +23 -0
  165. data/lib/mod_spox/messages/outgoing/Whois.rb +19 -0
  166. data/lib/mod_spox/migration/001_create_auths.rb +13 -0
  167. data/lib/mod_spox/migration/001_create_channel.rb +13 -0
  168. data/lib/mod_spox/migration/001_create_channel_modes.rb +13 -0
  169. data/lib/mod_spox/migration/001_create_config.rb +13 -0
  170. data/lib/mod_spox/migration/001_create_nick_channels.rb +13 -0
  171. data/lib/mod_spox/migration/001_create_nick_modes.rb +13 -0
  172. data/lib/mod_spox/migration/001_create_nicks.rb +13 -0
  173. data/lib/mod_spox/migration/001_create_servers.rb +13 -0
  174. data/lib/mod_spox/migration/001_create_settings.rb +13 -0
  175. data/lib/mod_spox/migration/001_create_signatures.rb +13 -0
  176. data/lib/mod_spox/migration/001_create_triggers.rb +13 -0
  177. data/lib/mod_spox/models/Auth.rb +79 -0
  178. data/lib/mod_spox/models/AuthGroup.rb +15 -0
  179. data/lib/mod_spox/models/Channel.rb +47 -0
  180. data/lib/mod_spox/models/ChannelMode.rb +14 -0
  181. data/lib/mod_spox/models/Config.rb +31 -0
  182. data/lib/mod_spox/models/Group.rb +13 -0
  183. data/lib/mod_spox/models/Nick.rb +110 -0
  184. data/lib/mod_spox/models/NickChannel.rb +43 -0
  185. data/lib/mod_spox/models/NickMode.rb +18 -0
  186. data/lib/mod_spox/models/Server.rb +12 -0
  187. data/lib/mod_spox/models/Setting.rb +40 -0
  188. data/lib/mod_spox/models/Signature.rb +30 -0
  189. data/lib/mod_spox/models/Trigger.rb +9 -0
  190. data/lib/mod_spox/rfc2812.rb +171 -0
  191. metadata +261 -0
@@ -0,0 +1,31 @@
1
+ module ModSpox
2
+ module Handlers
3
+
4
+ class Handler
5
+
6
+ def process(data)
7
+ raise Exceptions::NotImplemented.new('Method has not been implemented')
8
+ end
9
+
10
+ protected
11
+
12
+ def find_model(string)
13
+ if(string =~ /^[A-Za-z\|\\\{\}\[\]\^`~_\-]+$/)
14
+ Logger.log("Model: #{string} -> Nick")
15
+ return Models::Nick.find_or_create(:nick => string)
16
+ elsif(string =~ /^[&#+!]/)
17
+ Logger.log("Model: #{string} -> Channel")
18
+ return Models::Channel.find_or_create(:name => string)
19
+ elsif(model = Models::Server.filter(:host => string, :connected => true).first)
20
+ Logger.log("Model: #{string} -> Server")
21
+ return model
22
+ else
23
+ Logger.log("FAIL Model: #{string} -> No match")
24
+ return string
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Invite < Handler
4
+ def initialize(handlers)
5
+ handlers[:INVITE] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^(.+?)!.*?INVITE\s(\S+)\s(.+)$/)
9
+ source = find_model($1)
10
+ target = find_model($2)
11
+ channel = find_model($3)
12
+ return Messages::Incoming::Invite(string, source, target, channel)
13
+ else
14
+ Logger.log('Failed to parse INVITE message')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Join < Handler
4
+ def initialize(handlers)
5
+ handlers[:JOIN] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:(\S+)\sJOIN :(\S+)$/)
9
+ source = $1
10
+ chan = $2
11
+ if(source =~ /^(.+?)!(.+?)@(.+)$/)
12
+ nick = find_model($1)
13
+ nick.username = $2
14
+ nick.address = $3
15
+ nick.source = source
16
+ nick.visible = true
17
+ nick.save
18
+ channel = find_model(chan)
19
+ channel.nick_add(nick)
20
+ return Messages::Incoming::Join.new(string, channel, nick)
21
+ else
22
+ Logger.log('Failed to parse source on JOIN message')
23
+ end
24
+ else
25
+ Logger.log('Failed to parse JOIN message')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Kick < Handler
4
+ def initialize(handlers)
5
+ handlers[:KICK] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:(\S+)\sKICK\s(\S+)\s(\S+)\s:(.+)$/)
9
+ source = $1
10
+ chan = $2
11
+ kicked = $3
12
+ reason = $4
13
+ kicker = find_model(source.gsub(/!.+$/, ''))
14
+ channel = find_model(chan)
15
+ kickee = find_model(kicked)
16
+ channel.nick_remove(kickee)
17
+ return Messages::Incoming::Kick(string, channel, kicker, kickee, reason)
18
+ else
19
+ Logger.log('Failed to process KICK message')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class LuserChannels < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_LUSERCHANNELS] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /(\d+)\s:channels/)
9
+ return Messages::Incoming::LuserChannels.new(string, $1.to_i)
10
+ else
11
+ Logger.log('Failed to match RPL_LUSERCHANNELS message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class LuserClient < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_LUSERCLIENT] = self
6
+ end
7
+ def process(string)
8
+ users = string =~ /(\d+) users/ ? $1 : 0
9
+ invis = string =~ /(\d+) invisible/ ? $1 : 0
10
+ servs = string =~ /(\d+) servers/ ? $1 : 0
11
+ services = string =~ /(\d+) services/ ? $1 : 0
12
+ return Messages::Incoming::LuserClient.new(string, users, invis, servs, services)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class LuserMe < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_LUSERME] = self
6
+ end
7
+ def process(string)
8
+ clients = string =~ /(\d+) clients/ ? $1.to_i : 0
9
+ servers = string =~ /(\d+) server/ ? $1.to_i : 0
10
+ return Messages::Incoming::LuserMe.new(string, clients, servers)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class LuserOp < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_LUSEROP] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /(\d+) :.*?\s*[oO]perators/)
9
+ return Messages::Incoming::LuserOp(string, $1.to_i)
10
+ else
11
+ Logger.log('Failed to match RPL_LUSEROP message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class LuserUnknown < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_LUSERUNKNOWN] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /(\d+) :.*[Uu]nknown/)
9
+ return Messages::Incoming::LuserUnknown(string, $1.to_i)
10
+ else
11
+ Logger.log('Failed to match RPL_LUSERUNKNOWN message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Mode < Handler
4
+ def initialize(handlers)
5
+ handlers[:MODE] = self
6
+ end
7
+
8
+ def process(string)
9
+ if(string =~ /^:([^!]+)!.+?MODE\s(\S+)\s(\S+)$/) # this is for modes applied to the channel
10
+ source = find_model($1)
11
+ channel = find_model($2)
12
+ full_mode = $3
13
+ action = full_mode[0].chr
14
+ full_mode.slice(0).each_char{|c|
15
+ Models::ChannelMode.find_or_create(:channel_id => channel.pk, :mode => c) if action == '+'
16
+ if(action == '-' && model = Models::ChannelMode.filter(:channel_id => channel.pk, :mode => c).first)
17
+ model.destroy!
18
+ end
19
+ }
20
+ return Messages::Incoming::Mode.new(string, full_mode, source, nil, channel)
21
+ elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(.+)$/) # this is for modes applied to nick
22
+ # implement later #
23
+ elsif(string =~ /^:([^!]+)!.+MODE\s(\S+)\s(\S+)\s(.+)$/)
24
+ source = find_model($1)
25
+ channel = find_model($2)
26
+ full_modes = $3
27
+ targets = $4
28
+ action = full_mode[0].chr
29
+ nicks = Array.new
30
+ full_mode.slice(0).length.times{|i|
31
+ nick = find_model(targets.scan(/\S+/)[i])
32
+ nicks << nick
33
+ mode = full_mode[i + 1].chr
34
+ Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode) if action == '+'
35
+ if(action == '-' && model = Models::NickMode.filter(:channel_id => channel.pk, :nick_id => nick.pk, :mode => mode).first)
36
+ model.destroy!
37
+ end
38
+ }
39
+ nicks = nicks[0] if nicks.size == 1
40
+ return Messages::Incoming::Mode.new(string, full_mode, source, nicks, channel)
41
+ else
42
+ Logger.log('Failed to parse MODE message')
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Motd < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_MOTDSTART] = self
6
+ handlers[RPL_MOTD] = self
7
+ handlers[RPL_ENDOFMOTD] = self
8
+ @motds = Hash.new
9
+ @raw = Hash.new
10
+ end
11
+ def process(string)
12
+ if(string =~ /^:(\S+) #{RPL_MOTDSTART.to_s}.*?:-\s?(\S+)/)
13
+ @motds[$1] = Array.new
14
+ @raw[$1] = [string]
15
+ return
16
+ elsif(string =~ /^:(\S+) #{RPL_MOTD.to_s}.*?:-\s?(.+)$/)
17
+ @motds[$1] << $2
18
+ @raw[$1] << string
19
+ return
20
+ elsif(string =~ /^:(\S+) #{RPL_ENDOFMOTD.to_s}/)
21
+ @raw[$1] << string
22
+ message = Messages::Incoming::Motd.new(@raw[$1].join("\n"), @motds[$1].join("\n"), $1)
23
+ @motds.delete($1)
24
+ @raw.delete($1)
25
+ return message
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class MyInfo < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_MYINFO] = self
6
+ end
7
+
8
+ def process(string)
9
+ if(string =~ /^:\S+ \S+ \S+ (\S+) (\S+) (\S+) (\S+)/)
10
+ servername = $1
11
+ version = $2
12
+ usermodes = $3
13
+ channelmodes = $4
14
+ return Messages::Incoming::MyInfo.new(string, servername, version, usermodes, channelmodes)
15
+ else
16
+ Logger.log('Failed to match My Info message')
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,54 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Names < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_NAMREPLY] = self
6
+ handlers[RPL_ENDOFNAMES] = self
7
+ @names = Hash.new
8
+ @raw = Hash.new
9
+ end
10
+
11
+ def process(string)
12
+ if(string =~ /#{RPL_NAMREPLY}.*?(\S+) :(.+)$/)
13
+ chan = $1
14
+ nicks = $2
15
+ @names[chan] = Array.new unless @names[chan]
16
+ if(@raw[chan])
17
+ @raw[chan] << string
18
+ else
19
+ @raw[chan] = [string]
20
+ end
21
+ @names[chan] += nicks.split(' ')
22
+ return nil
23
+ elsif(string =~ /#{RPL_ENDOFNAMES}.*?(\S+) :/)
24
+ chan = $1
25
+ @raw[chan] << string
26
+ channel = find_model(chan)
27
+ nicks = Array.new
28
+ ops = Array.new
29
+ voice = Array.new
30
+ raw = @raw[chan].join(' ')
31
+ @names[chan].each{|n|
32
+ nick = Models::Nick.find_or_create(:nick => n.gsub(/^[@+]/, ''))
33
+ nicks << nick
34
+ if(n[0].chr == '@')
35
+ ops << nick
36
+ Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk, :mode => 'o')
37
+ elsif(n[0].chr == '+')
38
+ voice << nick
39
+ Models::NickMode.find_or_create(:nick_id => nick.pk, :channel_id => channel.pk, :mode => 'v')
40
+ else
41
+ Models::NickMode.filter(:nick_id => nick.pk, :channel_id => channel.pk).each{|m|
42
+ m.destroy
43
+ }
44
+ end
45
+ channel.nick_add(nick)
46
+ }
47
+ @names.delete(chan)
48
+ @raw.delete(chan)
49
+ return Messages::Incoming::Names.new(raw, channel, nicks, ops, voice)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,24 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Nick < Handler
4
+ def initialize(handlers)
5
+ handlers[:NICK] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:([^!]+)!\S+\sNICK\s:(.+)$/)
9
+ old_nick = find_model($1)
10
+ new_nick = find_model($2)
11
+ if(old_nick.botnick == true)
12
+ old_nick.botnick = false
13
+ old_nick.save
14
+ new_nick.botnick = true
15
+ new_nick.save
16
+ end
17
+ return Messages::Incoming::Nick.new(string, old_nick, new_nick)
18
+ else
19
+ Logger.log('Failed to parse NICK message')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class NickInUse < Handler
4
+ def initialize(handlers)
5
+ handlers[:RPL_NICKNAMEINUSE] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /#{RPL_NICKNAMEINUSE}\s\S+\s(\S+)\s:/)
9
+ return Messages::Incoming::NickInUse.new(string, $1)
10
+ else
11
+ Logger.log('Failed to parse RPL_NICKNAMEINUSE message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Notice < Handler
4
+ def initialize(handlers)
5
+ handlers[:NOTICE] = self
6
+ end
7
+
8
+ def process(string)
9
+ if(string =~ /:(\S+)\sNOTICE\s(\S+)\s:(.+)$/)
10
+ base_source = $1
11
+ target = $2
12
+ message = $3
13
+ if(base_source =~ /\!/)
14
+ source = find_model(base_source.gsub(/!.+$/, ''))
15
+ if(base_source =~ /!(.+)@(.+)$/)
16
+ source.username = $1
17
+ source.address = $2
18
+ source.source = base_source
19
+ source.save
20
+ end
21
+ target = find_model(target)
22
+ else
23
+ source = base_source
24
+ end
25
+ return Messages::Incoming::Notice.new(string, source, target, message)
26
+ else
27
+ Logger.log('Failed to match NOTICE message')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Part < Handler
4
+ def initialize(handlers)
5
+ handlers[:PART] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:(\S+) PART (\S+) :(.*)$/)
9
+ channel = find_model($2)
10
+ nick = find_model($1.gsub(/!.+$/, ''))
11
+ channel.nick_remove(nick)
12
+ return Messages::Incoming::Part.new(string, channel, nick, $3)
13
+ else
14
+ Logger.log('Failed to parse PART message')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Ping < Handler
4
+ def initialize(handlers)
5
+ handlers[:PING] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^PING\s:(.+)$/)
9
+ return Messages::Incoming::Ping.new(string, $1, nil)
10
+ else
11
+ Logger.log('Failed to match PING message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Pong < Handler
4
+ def initialize(handlers)
5
+ handlers[:PONG] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:\S+\sPONG\s(\S+)\s:(.+)$/)
9
+ return Messages::Incoming::Pong.new(string, $1, $2)
10
+ else
11
+ Logger.log('Failed to parse PONG message')
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Privmsg < Handler
4
+ def initialize(handlers)
5
+ handlers[:PRIVMSG] = self
6
+ end
7
+
8
+ def process(string)
9
+ if(string =~ /^:(\S+)\sPRIVMSG\s(\S+)\s:(.+)$/)
10
+ message = $3
11
+ target = find_model($2)
12
+ base_source = $1
13
+ source = find_model(base_source.gsub(/!.+$/, ''))
14
+ if(base_source =~ /!(.+)@(.+)$/)
15
+ source.username = $1
16
+ source.address = $2
17
+ source.source = base_source
18
+ source.save
19
+ end
20
+ return Messages::Incoming::Privmsg.new(string, source, target, message)
21
+ else
22
+ Logger.log('Failed to match PRIVMSG message')
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Quit < Handler
4
+ def initialize(handlers)
5
+ handlers[:QUIT] = self
6
+ end
7
+ def process(string)
8
+ if(string =~ /^:(\S+)\sQUIT\s:(.+)$/)
9
+ reason = $2
10
+ nick = find_model($1.gsub(/!.+$/, ''))
11
+ nick.clear_channels
12
+ nick.visible = false
13
+ nick.save
14
+ return Messages::Incoming::Quit.new(string, nick, reason)
15
+ else
16
+ Logger.log('Failed to parse KICK message')
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Topic < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_TOPIC] = self
6
+ handlers[RPL_NOTOPIC] = self
7
+ handlers[RPL_TOPICINFO] = self
8
+ @topics = Hash.new
9
+ end
10
+ def process(string)
11
+ if(string =~ /#{RPL_TOPIC}.+?(\S+)\s:(.+)$/)
12
+ channel = find_model($1)
13
+ return Messages::Incoming::Topic.new(string, channel, $2)
14
+ elsif(string =~ /#{RPL_NOTOPIC}.+?(\S+)\s:/)
15
+ channel = find_model($1)
16
+ return Messages::Incoming::Topic.new(string, channel, nil)
17
+ elsif(string =~ /#{RPL_TOPICINFO}\s\S+\s(\S+)\s(\S+)\s(.+)$/)
18
+ channel = find_model($1)
19
+ nick = find_model($1)
20
+ time = Time.at($3.to_i)
21
+ return Messages::Incoming::TopicInfo.new(string, channel, nick, time)
22
+ else
23
+ Logger.log('Failed to parse TOPIC type string')
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,34 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Welcome < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_WELCOME] = self
6
+ end
7
+
8
+ def process(string)
9
+ if(string =~ /:(\S+)\s(\S+).+?(\S+)$/)
10
+ server = $1
11
+ message = $2
12
+ userstring = $3
13
+ if(userstring =~ /^(.+?)!(.+?)@(.+?)$/)
14
+ Models::Nick.filter(:botnick => true).each{|n| n.botnick = false; n.save}
15
+ nick = $1
16
+ username = $2
17
+ hostname = $3
18
+ nick = Models::Nick.find_or_create(:nick => nick)
19
+ nick.botnick = true
20
+ nick.username = username
21
+ nick.address = hostname
22
+ nick.source = userstring
23
+ nick.save
24
+ return Messages::Incoming::Welcome.new(string, server, message, nick, username, hostname)
25
+ else
26
+ Logger.log('Failed to match user string in welcome message')
27
+ end
28
+ else
29
+ Logger.log('Failed to match welcome message')
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ module ModSpox
2
+ module Handlers
3
+ class Who < Handler
4
+ def initialize(handlers)
5
+ handlers[RPL_WHOREPLY] = self
6
+ handlers[RPL_ENDOFWHO] = self
7
+ @cache = Hash.new
8
+ @raw_cache = Hash.new
9
+ end
10
+ def process(string)
11
+ if(string =~ /#{RPL_WHOREPLY}\s\S+\s(\S+|\*|\*\s\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s:(\d)\s(.+)$/)
12
+ # Items matched are as follows:
13
+ # 1: location
14
+ # 2: username
15
+ # 3: host
16
+ # 4: server
17
+ # 5: nick
18
+ # 6: info
19
+ # 7: hops
20
+ # 8: realname
21
+ location = $1 unless location.include?('*')
22
+ location = $5 if location == '*'
23
+ location = $1.gsub(/\*\s/, '') if location.include?('* ')
24
+ info = $6
25
+ nick = find_model($5)
26
+ nick.username = $2
27
+ nick.address = $3
28
+ nick.real_name = $8
29
+ nick.connected_to = $4
30
+ nick.away = info =~ /G/ ? true : false
31
+ nick.save
32
+ @cache[location] = Array.new unless @cache[location]
33
+ @cache[location] << nick
34
+ @raw_cache[location] = Array.new unless @raw_cache[location]
35
+ @raw_cache[location] << string
36
+ if(location[0].chr !~ /[A-Za-z]/)
37
+ channel = find_model(location)
38
+ if(info.include?('+'))
39
+ Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nick.pk, :mode => 'v')
40
+ elsif(info.include?('@'))
41
+ Models::NickMode.find_or_create(:channel_id => channel.pk, :nick_id => nick.pk, :mode => 'o')
42
+ else
43
+ Models::NickMode.filter(:channel_id => channel.pk, :nick_id => nick.pk).each{|m| m.destroy}
44
+ end
45
+ end
46
+ elsif(string =~ /#{RPL_ENDWHO}\s\S+\s(\S+)\s/)
47
+ location = $1
48
+ loc = find_model(location)
49
+ @raw_cache[location] << string
50
+ message = Messages::Incoming::Who.new(@raw_cache.join("\n"), loc, @cache[location])
51
+ @raw_cache.delete(location)
52
+ @cache.delete(location)
53
+ return message
54
+ else
55
+ Logger.log('Failed to match RPL_WHO type message')
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end