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
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 0.0.1 Release
2
+ * Initial release. No changes to report.
data/INSTALL ADDED
@@ -0,0 +1,9 @@
1
+ Install:
2
+
3
+ gem install --include-dependencies mod_spox
4
+
5
+ Requirements include:
6
+ * sequel
7
+ * fastthread
8
+ * termios
9
+ * Ruby >= 1.8.4
data/README ADDED
@@ -0,0 +1,33 @@
1
+ mod_spox
2
+ http://modspox.rubyforge.org
3
+ Author: spox
4
+
5
+ == Description
6
+
7
+ A Ruby IRC bot
8
+
9
+ == Usage
10
+
11
+ Configuration:
12
+
13
+ mod_spox --config
14
+
15
+ Running:
16
+
17
+ mod_spox
18
+
19
+ == Requirements
20
+
21
+ * fastthread
22
+ * sequel
23
+ * termios
24
+
25
+ == Install
26
+
27
+ gem install --include-dependencies mod_spox
28
+
29
+ == License
30
+
31
+ mod_spox is licensed under the GPLv3
32
+
33
+ Copyright (c) 2008 spox <spox@modspox.com>
data/bin/mod_spox ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## include our needed libraries ##
4
+
5
+ ['rubygems', 'sequel', 'fastthread',
6
+ 'thread', 'etc', 'getoptlong'].each{|file|
7
+ begin
8
+ require file
9
+ rescue Object => boom
10
+ puts "ERROR: Failed to load required library: #{file}"
11
+ exit 1
12
+ end
13
+ }
14
+
15
+ $BOTVERSION='0.0.1'
16
+ $VERBOSITY = 0
17
+
18
+ begin
19
+ require 'mod_spox/Loader'
20
+ rescue
21
+ p 'ERROR: Failed to load mod_spox'
22
+ exit 1
23
+ end
24
+ include ModSpox
25
+
26
+ opts = GetoptLong.new(
27
+ ['--config', '-c', GetoptLong::NO_ARGUMENT],
28
+ ['--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT],
29
+ ['--version', '-v', GetoptLong::NO_ARGUMENT],
30
+ ['--help', '-h', GetoptLong::NO_ARGUMENT]
31
+ )
32
+ verbose = 0
33
+ opts.each do |opt, arg|
34
+ case opt
35
+ when '--help'
36
+ p 'Usage: mod_spox [opts]'
37
+ p '--config -c: starts configuration wizard'
38
+ p '--debug -d: turns on debugging (include number >0 for more info)'
39
+ p '--version -V: output bot version information'
40
+ p '--help -h: print this help message'
41
+ exit
42
+ when '--version'
43
+ p "mod_spox IRC bot version: #{$BOTVERSION}"
44
+ p 'http://dev.modspox.com'
45
+ exit
46
+ when '--debug'
47
+ if(arg && arg =~ /^[0-9]+/)
48
+ $VERBOSITY = arg.to_i
49
+ end
50
+ when '--config'
51
+ require 'mod_spox/ConfigurationWizard'
52
+ wizard = ConfigurationWizard.new
53
+ wizard.run
54
+ exit
55
+ end
56
+ end
57
+
58
+ initialize_bot
59
+ bot = Bot.new
60
+ bot.run
@@ -0,0 +1,14 @@
1
+ class Tester < Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ Models::Signature.find_or_create(:signature => 'tester', :plugin => name, :method => 'test',
6
+ :description => 'List all available plugins')
7
+ Models::Group.find_or_create(:name => 'testgroup')
8
+ Models::Group.find_or_create(:name => 'anonymous')
9
+ end
10
+
11
+ def test(message, params)
12
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'This is a test')
13
+ end
14
+ end
@@ -0,0 +1,245 @@
1
+ class Authenticator < ModSpox::Plugin
2
+ def initialize(pipeline)
3
+ super(pipeline)
4
+ group = Models::Group.filter(:name => 'admin').first
5
+ Models::Signature.find_or_create(:signature => 'auth (\S+)', :plugin => name, :method => 'authenticate',
6
+ :description => 'Authenticate with bot using a password').params = [:password]
7
+ Models::Signature.find_or_create(:signature => 'ident', :plugin => name, :method => 'send_whois',
8
+ :description => 'Instructs the bot to check your NickServ status')
9
+ Models::Signature.find_or_create(:signature => 'auth mask add (\S+) (\S+)', :plugin => name, :method => 'add_mask',
10
+ :group_id => group.pk, :description => 'Add authentication mask and set initial group').params = [:mask, :group]
11
+ Models::Signature.find_or_create(:signature => 'auth mask set (\d+) (.+)', :plugin => name, :method => 'set_mask_groups',
12
+ :group_id => group.pk, :description => 'Set groups for the given mask').params = [:id, :group_ids]
13
+ Models::Signature.find_or_create(:signature => 'auth mask unset (\d+) (.+)', :plugin => name, :method => 'del_mask_groups',
14
+ :group_id => group.pk, :description => 'Remove groups for the given mask').params = [:id, :groups]
15
+ Models::Signature.find_or_create(:signature => 'auth mask remove (\d+)', :plugin => name, :method => 'remove_mask',
16
+ :group_id => group.pk, :description => 'Remove authentication mask').params = [:id]
17
+ Models::Signature.find_or_create(:signature => 'auth mask list', :plugin => name, :method => 'list_mask',
18
+ :group_id => group.pk, :description => 'List all available authentication masks')
19
+ Models::Signature.find_or_create(:signature => 'auth nick ident (\S+) (true|false)', :plugin => name, :method => 'nick_ident',
20
+ :group_id => group.pk, :description => 'Allow authentication to nicks identified to NickServ').params = [:nick, :ident]
21
+ Models::Signature.find_or_create(:signature => 'auth nick password (\S+) (\S+)', :plugin => name, :method => 'nick_pass',
22
+ :group_id => group.pk, :description => 'Set authentication password for nick').params = [:nick, :password]
23
+ Models::Signature.find_or_create(:signature => 'auth nick clear password (\S+)', :plugin => name, :method => 'clear_pass',
24
+ :group_id => group.pk, :description => 'Clear nicks authentication password').params = [:nick]
25
+ Models::Signature.find_or_create(:signature => 'auth nick info (\S+)', :plugin => name, :method => 'nick_info',
26
+ :group_id => group.pk, :description => 'Return authentication information about given nick').params = [:nick]
27
+ Models::Signature.find_or_create(:signature => 'auth nick set (\S+) (\S+)', :plugin => name, :method => 'set_nick',
28
+ :group_id => group.pk, :description => 'Set the group for a given nick').params = [:nick, :group]
29
+ Models::Signature.find_or_create(:signature => 'auth nick unset (\S+) (\S+)', :plugin => name, :method => 'unset_nick',
30
+ :group_id => group.pk, :description => 'Unset the group for a given nick').params = [:nick, :group]
31
+ Models::Signature.find_or_create(:signature => 'auth group list', :plugin => name, :method => 'list_groups',
32
+ :group_id => group.pk, :description => 'List available authentication groups')
33
+ Models::Signature.find_or_create(:signature => 'auth group info (\S+)', :plugin => name, :method => 'group_info',
34
+ :group_id => group.pk, :description => 'List members of given group').params = [:group]
35
+ end
36
+
37
+ # message:: ModSpox::Messages::Incoming::Privmsg
38
+ # params:: Signature parameters
39
+ # Authenticate a user by password
40
+ def authenticate(message, params)
41
+ if(message.is_private? && message.source.auth.check_password(params[:password]))
42
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'Authentication was successful')
43
+ else
44
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'Authentication failed')
45
+ end
46
+ end
47
+
48
+ # message:: ModSpox::Messages::Incoming::Privmsg
49
+ # params:: Signature parameters
50
+ # Add an authentication mask
51
+ def add_mask(message, params)
52
+ begin
53
+ group = Models::Group.filter(:name => params[:group]).first
54
+ raise Exception.new("Failed to find group") unless group
55
+ a = Models::Auth.find_or_create(:mask => Regexp.new(params[:mask]).source)
56
+ a.group = group
57
+ a.save
58
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'Mask has been successfully added to authentication table')
59
+ rescue Object => boom
60
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Authentication failed to add mask. Reason: #{boom}")
61
+ end
62
+ end
63
+
64
+ # message:: ModSpox::Messages::Incoming::Privmsg
65
+ # params:: Signature parameters
66
+ # Add an authentication group to a given mask
67
+ def set_mask_groups(message, params)
68
+ auth = Models::Auth[params[:id]]
69
+ if(auth)
70
+ params[:groups].split(/\s/).each do |g|
71
+ group = Models::Group.filter(:name => g).first
72
+ auth.group = group if group
73
+ end
74
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Mask groups have been updated")
75
+ else
76
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find mask with ID: #{params[:id]}")
77
+ end
78
+ end
79
+
80
+ # message:: ModSpox::Messages::Incoming::Privmsg
81
+ # params:: Signature parameters
82
+ # Remove an authentication group from a given mask
83
+ def del_mask_groups(message, params)
84
+ auth = Models::Auth[params[:id]]
85
+ if(auth)
86
+ params[:groups].split(/\s/).each do |g|
87
+ group = Models::Group.filter(:name => g).first
88
+ auth.remove_group(group) if group
89
+ end
90
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Mask groups have been updated")
91
+ else
92
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find mask with ID: #{params[:id]}")
93
+ end
94
+ end
95
+
96
+ # message:: ModSpox::Messages::Incoming::Privmsg
97
+ # params:: Signature parameters
98
+ # List all authentication masks
99
+ def list_mask(message, params)
100
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'Authentication Mask Listing:')
101
+ auths = []
102
+ Models::Auth.where('mask is not null').each{|a| auths << a}
103
+ auths.each do |a|
104
+ groups = []
105
+ a.groups.each{|g| groups << g.name}
106
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2ID:\2 #{a.pk}: \2mask:\2 #{a.mask} \2groups:\2 #{groups.join(', ')}")
107
+ end
108
+ end
109
+
110
+ # message:: ModSpox::Messages::Incoming::Privmsg
111
+ # params:: Signature parameters
112
+ # Remove given authentication mask
113
+ def remove_mask(message, params)
114
+ auth = Models::Auth[params[:id].to_i]
115
+ if(auth)
116
+ auth.destroy
117
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Authentication mask with ID #{params[:id]} was deleted")
118
+ else
119
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2Failed\2: Could not find an authentication mask with ID: #{params[:id]}")
120
+ end
121
+ end
122
+
123
+ # message:: ModSpox::Messages::Incoming::Privmsg
124
+ # params:: Signature parameters
125
+ # Set nick authentication by NickServ
126
+ def nick_ident(message, params)
127
+ nick = Models::Nick.find_or_create(:nick => params[:nick])
128
+ if(params[:ident] == 'true')
129
+ nick.auth.set(:services => true)
130
+ else
131
+ nick.auth.set(:services => false)
132
+ end
133
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Nick #{params[:nick]} has been updated. Services for authentication has been set to #{params[:ident]}")
134
+ end
135
+
136
+
137
+ # message:: ModSpox::Messages::Incoming::Privmsg
138
+ # params:: Signature parameters
139
+ # Set password for given nick
140
+ def nick_pass(message, params)
141
+ nick = Models::Nick.find_or_create(:nick => params[:nick])
142
+ nick.auth.password = params[:password]
143
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Nick #{params[:nick]} has been updated. Password has been set.")
144
+ end
145
+
146
+ # message:: ModSpox::Messages::Incoming::Privmsg
147
+ # params:: Signature parameters
148
+ # Clear password field for given nick
149
+ def nick_clear(message, params)
150
+ nick = Models::Nick.find_or_create(:nick => params[:nick])
151
+ nick.auth.password = nil
152
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Nick #{params[:nick]} has been updated. Password has been set.")
153
+ end
154
+
155
+ # message:: ModSpox::Messages::Incoming::Privmsg
156
+ # params:: Signature parameters
157
+ # Display info for given nick
158
+ def nick_info(message, params)
159
+ nick = Models::Nick.filter(:nick => params[:nick]).first
160
+ if(nick)
161
+ info = []
162
+ info << "\2INFO [#{nick.nick}]:\2"
163
+ groups = []
164
+ nick.auth_groups.each{|g| groups << g.name}
165
+ info << "Groups: #{groups.join(', ')}."
166
+ nick.auth.password.nil? ? info << 'Password has not been set.' : info << 'Password has been set.'
167
+ nick.auth.services ? info << 'Nickserv ident is enabled.' : info << 'Nickserv ident is disabled.'
168
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "#{info.join(' ')}")
169
+ else
170
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "I have no record of nick: #{params[:nick]}")
171
+ end
172
+ end
173
+
174
+ # message:: ModSpox::Messages::Incoming::Privmsg
175
+ # params:: Signature parameters
176
+ # Add given nick to authentication group
177
+ def set_nick(message, params)
178
+ group = Models::Group.filter(:name => params[:group]).first
179
+ nick = Models::Nick.find_or_create(:nick => params[:nick])
180
+ if(group)
181
+ nick.group = group
182
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Nick #{params[:nick]} has been added to the group: #{params[:group]}")
183
+ else
184
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find authentication group: #{params[:group]}")
185
+
186
+ end
187
+ end
188
+
189
+ # message:: ModSpox::Messages::Incoming::Privmsg
190
+ # params:: Signature parameters
191
+ # Remove given nick from authenticationg group
192
+ def unset_nick(message, params)
193
+ group = Models::Group.filter(:name => params[:group]).first
194
+ nick = Models::Nick.filter(:nick => params[:nick]).first
195
+ if(group && nick)
196
+ nick.remove_group(group)
197
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Removed #{params[:nick]} from the #{params[:group]} authentication group.")
198
+ else
199
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find nick: #{params[:nick]}") unless nick
200
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find group: #{params[:group]}") unless group
201
+ end
202
+ end
203
+
204
+ # message:: ModSpox::Messages::Incoming::Privmsg
205
+ # params:: Signature parameters
206
+ # Send WHOIS for nick
207
+ def send_whois(message, params)
208
+ @pipeline << Messages::Outgoing::Whois.new(message.source.nick)
209
+ end
210
+
211
+ # message:: ModSpox::Messages::Incoming::Privmsg
212
+ # params:: Signature parameters
213
+ # Display all available authentication groups
214
+ def list_groups(message, params)
215
+ groups = []
216
+ Models::Group.all.each{|g| groups << g.name}
217
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2Groups:\2 #{groups.join(', ')}")
218
+ end
219
+
220
+ # message:: ModSpox::Messages::Incoming::Privmsg
221
+ # params:: Signature parameters
222
+ # Display info about given group
223
+ def group_info(message, params)
224
+ group = Models::Group.filter(:name => params[:group]).first
225
+ if(group)
226
+ nicks = []
227
+ masks = []
228
+ Models::AuthGroup.filter(:group_id => group.pk).each do |ag|
229
+ if(ag.auth.nick)
230
+ nicks << ag.auth.nick.nick
231
+ end
232
+ if(ag.auth.mask)
233
+ masks << ag.auth.mask
234
+ end
235
+ end
236
+ output = []
237
+ output << "\2Nicks:\2 #{nicks.join(', ')}" if nicks.size > 0
238
+ output << "\2Masks:\2 #{masks.join(' | ')}" if masks.size > 0
239
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2Group #{params[:group]}:\2 #{output.join('. ')}")
240
+ else
241
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find group named: #{params[:group]}")
242
+ end
243
+ end
244
+
245
+ end
@@ -0,0 +1,18 @@
1
+ class BotNick < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ @pipeline.hook(self, :shutdown, :Internal_Shutdown)
6
+ end
7
+
8
+ def shutdown(message)
9
+ clear_nicks
10
+ end
11
+
12
+ private
13
+
14
+ def clear_nicks
15
+ Models::Nick.filter(:botnick => true).each{|nick| nick.botnick = false; nick.save}
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ class Initializer < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ @pipeline.hook(self, :connect, :Internal_BotInitialized)
6
+ @pipeline.hook(self, :send_info, :Internal_Connected)
7
+ @pipeline.hook(self, :reconnect, :Internal_ConnectionFailed)
8
+ @pipeline.hook(self, :reconnect, :Internal_Disconnected)
9
+ @servers = Array.new
10
+ end
11
+
12
+ # message:: ModSpox::Messages::Internal::BotInitialized
13
+ # Instructs bot to connect to server
14
+ def connect(message)
15
+ populate_servers if @servers.empty?
16
+ s = @servers.pop
17
+ @pipeline << Messages::Internal::EstablishConnection.new(s.host, s.port)
18
+ end
19
+
20
+ # message:: ModSpox::Messages::Internal::Connected
21
+ # Send bot information to server when connection is established
22
+ def send_info(message)
23
+ @pipeline << Messages::Outgoing::Nick.new(Models::Config[:bot_nick])
24
+ @pipeline << Messages::Outgoing::User.new(Models::Config[:bot_username], Models::Config[:bot_realname], 8)
25
+ end
26
+
27
+ # message:: ModSpox::Messages::Internal::ConnectionFailed or ModSpox::Messages::Internal::Disconnected
28
+ # Reconnect to server on disconnection or connection failure
29
+ def reconnect(message)
30
+ @pipeline << Messages::Internal::TimerAdd.new(self, Models::Config[:reconnect_wait].to_i, nil, true){ connect(nil) }
31
+ end
32
+
33
+ private
34
+
35
+ def populate_servers
36
+ Models::Server.order(:priority.DESC).each{|s|
37
+ @servers << s
38
+ }
39
+ end
40
+
41
+ end
@@ -0,0 +1,13 @@
1
+ class Joiner < ModSpox::Plugin
2
+ def initialize(pipeline)
3
+ super(pipeline)
4
+ admin = Models::Group.filter(:name => 'admin').first
5
+ Models::Signature.find_or_create(:signature => 'join (\S+)', :plugin => name, :method => 'join', :group_id => admin.pk).params = [:channel]
6
+ end
7
+
8
+ # message:: ModSpox::Messages::Incoming::Privmsg
9
+ # Join the given channel
10
+ def join(message, params)
11
+ @pipeline << Messages::Outgoing::Join.new(params[:channel])
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ class Parter < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ admin = Models::Group.filter(:name => 'admin').first
6
+ Models::Signature.find_or_create(:signature => 'part (\S+)', :plugin => name, :method => 'part', :group_id => admin.pk).params = [:channel]
7
+ Models::Signature.find_or_create(:signature => 'part', :plugin => name, :method => 'direct_part', :group_id => admin.pk)
8
+ end
9
+
10
+ # message:: ModSpox::Messages::Incoming::Privmsg
11
+ # Bot will part from given channel
12
+ def part(message, params)
13
+ @pipeline << Messages::Outgoing::Part.new(params[:channel])
14
+ end
15
+
16
+ # message:: ModSpox::Messages::Incoming::Privmsg
17
+ # Bot will part from channel command is issued within
18
+ def direct_part(message, params)
19
+ @pipeline << Messages::Outgoing::Part.new(message.target)
20
+ end
21
+
22
+ end
@@ -0,0 +1,136 @@
1
+ class PluginLoader < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ admin = Models::Group.filter(:name => 'admin').first
6
+ Models::Signature.find_or_create(:signature => 'plugins available', :plugin => name, :method => 'available_plugins',
7
+ :group_id => admin.pk, :description => 'List all available plugins')
8
+ Models::Signature.find_or_create(:signature => 'plugins loaded', :plugin => name, :method => 'loaded_plugins',
9
+ :group_id => admin.pk, :description => 'List all plugins currently loaded')
10
+ Models::Signature.find_or_create(:signature => 'plugins load (\S+)', :plugin => name, :method => 'load_plugin',
11
+ :group_id => admin.pk, :description => 'Load the given plugin').params = [:plugin]
12
+ Models::Signature.find_or_create(:signature => 'plugins unload (\S+)', :plugin => name, :method => 'unload_plugin',
13
+ :group_id => admin.pk, :description => 'Unload given plugin').params = [:plugin]
14
+ Models::Signature.find_or_create(:signature => 'plugins reload', :plugin => name, :method => 'reload_plugin',
15
+ :group_id => admin.pk, :description => 'Reload plugins')
16
+ @pipeline.hook(self, :get_module, :Internal_PluginModuleResponse)
17
+ @plugins_mod = nil
18
+ end
19
+
20
+ # message:: ModSpox::Messages::Incoming::Privmsg
21
+ # params:: matching signature params
22
+ # Output currently available plugins for loading
23
+ def available_plugins(message, params)
24
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2Currently available plugins:\2")
25
+ find_plugins.each_pair do | plugin, path |
26
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2#{plugin}:\2 #{path}")
27
+ end
28
+ end
29
+
30
+ # message:: ModSpox::Messages::Incoming::Privmsg
31
+ # params:: matching signature params
32
+ # Output currently loaded plugins
33
+ def loaded_plugins(message, params)
34
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "\2Currently loaded plugins:\2 #{plugin_list.join(', ')}")
35
+ end
36
+ # message:: ModSpox::Messages::Incoming::Privmsg
37
+ # params:: matching signature params
38
+ # Load the given plugin
39
+ def load_plugin(message, params)
40
+ plugins = find_plugins
41
+ if(plugins.has_key?(params[:plugin]))
42
+ name = plugin_discovery(BotConfig[:pluginextraspath]).keys.include?(params[:plugin]) ? nil : "#{params[:plugin]}.rb"
43
+ @pipeline << Messages::Internal::PluginLoadRequest.new(self, plugins[params[:plugin]], name)
44
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Okay")
45
+ else
46
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find plugin: #{params[:plugin]}")
47
+ end
48
+ end
49
+
50
+ # message:: ModSpox::Messages::Incoming::Privmsg
51
+ # params:: matching signature params
52
+ # Unload the given plugin
53
+ def unload_plugin(message, params)
54
+ path = loaded_path(params[:plugin])
55
+ unless(path.nil?)
56
+ name = plugin_discovery(BotConfig[:pluginextraspath]).keys.include?(params[:plugin]) ? nil : ".#{params[:plugin]}.rb"
57
+ @pipeline << Messages::Internal::PluginUnloadRequest.new(self, path, name)
58
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Okay")
59
+ else
60
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, "Failed to find loaded plugin named: #{params[:plugin]}")
61
+ end
62
+ end
63
+
64
+ # message:: ModSpox::Messages::Incoming::Privmsg
65
+ # params:: matching signature params
66
+ # Reloads plugins
67
+ def reload_plugin(message, params)
68
+ @pipeline << Messages::Internal::PluginReload.new
69
+ @pipeline << Messages::Outgoing::Privmsg.new(message.source.nick, 'Okay')
70
+ end
71
+
72
+ # message:: ModSpox::Messages::Internal::PluginModuleResponse
73
+ # Receives the plugins module
74
+ def get_module(message)
75
+ @plugins_mod = message.module
76
+ end
77
+
78
+ private
79
+
80
+ # Returns the list of currently loaded plugins
81
+ def plugin_list
82
+ plug = []
83
+ @pipeline << Messages::Internal::PluginModuleRequest.new(self)
84
+ sleep(0.01) while @plugins_mod.nil?
85
+ @plugins_mod.constants.sort.each do |const|
86
+ klass = @plugins_mod.const_get(const)
87
+ if(klass < Plugin)
88
+ plug << const
89
+ end
90
+ end
91
+ @plugins_mod = nil
92
+ return plug
93
+ end
94
+
95
+ # Finds available plugins for loading
96
+ def find_plugins
97
+ users = plugin_discovery(BotConfig[:userpluginpath])
98
+ extras = plugin_discovery(BotConfig[:pluginextraspath])
99
+ plugins = users.merge(extras)
100
+ plugin_list.each do |name|
101
+ plugins.delete(name) if plugins.has_key?(name)
102
+ end
103
+ return plugins
104
+ end
105
+
106
+ # path:: path to directory
107
+ # Discovers any plugins within the files in the given path
108
+ def plugin_discovery(path)
109
+ plugins = Hash.new
110
+ Dir.new(path).each do |file|
111
+ next unless file =~ /\.rb$/
112
+ sandbox = Module.new
113
+ sandbox.module_eval(IO.readlines("#{path}/#{file}").join("\n"))
114
+ sandbox.constants.each do |const|
115
+ klass = sandbox.const_get(const)
116
+ plugins[const] = "#{path}/#{file}" if klass < Plugin
117
+ end
118
+ end
119
+ return plugins
120
+ end
121
+
122
+ # name:: plugin name
123
+ # Returns the file path the given plugin originated from
124
+ def loaded_path(name)
125
+ Dir.new(BotConfig[:userpluginpath]).each do |file|
126
+ next unless file =~ /\.rb$/
127
+ sandbox = Module.new
128
+ sandbox.module_eval(IO.readlines("#{BotConfig[:userpluginpath]}/#{file}").join("\n"))
129
+ sandbox.constants.each do |const|
130
+ return "#{BotConfig[:userpluginpath]}/#{file}" if const == name
131
+ end
132
+ end
133
+ return nil
134
+ end
135
+
136
+ end
@@ -0,0 +1,14 @@
1
+ class Ponger < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ @pipeline.hook(self, :ping, :Incoming_Ping)
6
+ end
7
+
8
+ # message:: ModSpox::Messages::Incoming::Ping
9
+ # Sends responding pongs to server pings
10
+ def ping(message)
11
+ @pipeline << Messages::Outgoing::Pong.new(message.server, message.string)
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ class Quitter < ModSpox::Plugin
2
+
3
+ def initialize(pipeline)
4
+ super(pipeline)
5
+ Models::Signature.find_or_create(:signature => 'quit\s(.*)', :plugin => name, :method => 'quit',
6
+ :group_id => Models::Group.filter(:name => 'admin').first.pk).params = [:channel, :message]
7
+ end
8
+
9
+ # message:: ModSpox::Messages::Incoming::Privmsg
10
+ # Instructs the bot to shutdown
11
+ def quit(message, params)
12
+ @pipeline << Messages::Internal::HaltBot.new
13
+ end
14
+ end