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,23 @@
1
+ module ModSpox
2
+ module Messages
3
+ module Outgoing
4
+ class WhoWas
5
+ # nick to whowas
6
+ attr_reader :nick
7
+ # number of entries to return
8
+ attr_reader :count
9
+ # target server
10
+ attr_reader :target
11
+ # nick:: nick to whowas
12
+ # count:: number of entries to return
13
+ # target:: target server
14
+ # Information about a nick that no longer exists
15
+ def initialize(nick, count='', target='')
16
+ @nick = nick
17
+ @count = count
18
+ @target = target
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module ModSpox
2
+ module Messages
3
+ module Outgoing
4
+ class Whois
5
+ # nick to whois
6
+ attr_reader :nick
7
+ # server to query
8
+ attr_reader :target_server
9
+ # nick:: nick to whois
10
+ # target_server:: server to query
11
+ # Query information about a user
12
+ def initialize(nick, target_server='')
13
+ @nick = nick
14
+ @target_server = target_server
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateAuths < Sequel::Migration
4
+ def up
5
+ Models::Auth.create_table unless Models::Auth.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Auth.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateChannels < Sequel::Migration
4
+ def up
5
+ Models::Channel.create_table unless Models::Channel.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Channel.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateChannelModes < Sequel::Migration
4
+ def up
5
+ Models::ChannelMode.create_table unless Models::ChannelMode.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::ChannelMode.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateConfigs < Sequel::Migration
4
+ def up
5
+ Models::Config.create_table unless Models::Config.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Config.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateNickChannels < Sequel::Migration
4
+ def up
5
+ Models::NickChannel.create_table unless Models::NickChannel.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::NickChannel.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateNickModes < Sequel::Migration
4
+ def up
5
+ Models::NickMode.create_table unless Models::NickMode.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::NickMode.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateNicks < Sequel::Migration
4
+ def up
5
+ Models::Nick.create_table unless Models::Nick.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Nick.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateServers < Sequel::Migration
4
+ def up
5
+ Models::Server.create_table unless Models::Server.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Server.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateSettings < Sequel::Migration
4
+ def up
5
+ Models::Setting.create_table unless Models::Setting.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Setting.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateSignatures < Sequel::Migration
4
+ def up
5
+ Models::Signature.create_table unless Models::Signature.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Signature.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Migrators
3
+ class CreateTriggers < Sequel::Migration
4
+ def up
5
+ Models::Trigger.create_table unless Models::Trigger.table_exists?
6
+ end
7
+
8
+ def down
9
+ Models::Trigger.drop_table
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,79 @@
1
+ require 'digest/sha1'
2
+ module ModSpox
3
+ module Models
4
+
5
+ # Attributes provided by model:
6
+ # password:: Password to autenticate against
7
+ # services:: Authentication by nickserv
8
+ # mask:: Mask to authenticate source against
9
+ # authed:: Nick has authenticated
10
+ class Auth < Sequel::Model(:auths)
11
+
12
+ # Nick associated with this Auth
13
+ def nick
14
+ Nick[nick_id]
15
+ end
16
+
17
+ def services
18
+ s = values[:services]
19
+ if(s == 0 || s == '0' || !s)
20
+ return false
21
+ else
22
+ return true
23
+ end
24
+ end
25
+
26
+ # Groups this auth is a member of
27
+ def groups
28
+ # we grab IDs, then the object. Otherwise we get sync problems
29
+ group_id = []
30
+ AuthGroup.filter(:auth_id => pk).each do |ag|
31
+ group_id << ag.group_id
32
+ end
33
+ group = []
34
+ group_id.each{|id| group << Group[id]}
35
+ return group
36
+ end
37
+
38
+ # Add group to this auth's list
39
+ def group=(group)
40
+ AuthGroup.find_or_create(:auth_id => pk, :group_id => group.pk)
41
+ end
42
+
43
+ # Remove given group from auth
44
+ def remove_group(group)
45
+ AuthGroup.filter(:auth_id => pk, :group_id => group.pk).each{|g|g.destroy}
46
+ end
47
+
48
+ # Set services (nickserv) identification
49
+ def services_identified=(val)
50
+ set :authed => true if val && services
51
+ end
52
+
53
+ # pass:: password to compare
54
+ # Check and authenticate against password
55
+ def check_password(pass)
56
+ if(Digest::SHA1.hexdigest(pass) == password)
57
+ set :authed => true
58
+ return true
59
+ else
60
+ return false
61
+ end
62
+ end
63
+
64
+ def password=(pass)
65
+ set :password => Digest::SHA1.hexdigest(pass)
66
+ end
67
+
68
+ # source:: source to apply mask to
69
+ # Check and authenticate by mask against source
70
+ def check_mask(source)
71
+ if(source =~ /^#{mask}$/)
72
+ set :authed => true
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,15 @@
1
+ module ModSpox
2
+ module Models
3
+ class AuthGroup < Sequel::Model(:auth_groups)
4
+ set_primary_key [:group_id, :auth_id]
5
+
6
+ def auth
7
+ Auth[auth_id]
8
+ end
9
+
10
+ def group
11
+ Group[group_id]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module ModSpox
2
+ module Models
3
+
4
+ # Attributes provided by model:
5
+ # name:: Channel name
6
+ # password:: Channel password
7
+ # autojoin:: Set bot to autojoin this channel
8
+ # topic:: Channel topic
9
+ # quiet:: Silence the bot in this channel
10
+ # parked:: Bot is currently in this channel
11
+ class Channel < Sequel::Model(:channels)
12
+
13
+ # Modes for this channel
14
+ def channel_modes
15
+ ChannelMode.filter(:channel_id => pk)
16
+ end
17
+
18
+ # Nicks residing within this channel
19
+ def nicks
20
+ NickChannel.filter(:channel_id => pk)
21
+ end
22
+
23
+ # Adds a nick to this channel
24
+ def nick_add(nick)
25
+ NickChannel.find_or_create(:channel_id => pk, :nick_id => nick.pk)
26
+ end
27
+
28
+ # Removes a nick from this channel
29
+ def nick_remove(nick)
30
+ NickChannel.filter(:channel_id => pk, :nick_id => nick.pk).first.destroy
31
+ end
32
+
33
+ # Removes all nicks from this channel
34
+ def clear_nicks
35
+ NickChannel.filter(:channel_id => pk, :nick_id => nick.pk).each{|o| o.destroy}
36
+ end
37
+
38
+ # Purges all channel information
39
+ def self.clean
40
+ Channel.set(:topic => nil, :parked => false)
41
+ ChannelMode.destroy_all
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attribute provided by model:
4
+ # mode:: mode that is set
5
+ class ChannelMode < Sequel::Model(:channel_modes)
6
+
7
+ # Channel this mode is associated to
8
+ def channel
9
+ Channel[channel_id]
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # name:: name of the config item
5
+ # value:: value of the config item
6
+ #
7
+ # It is important to note this model is for storing configuration
8
+ # values only. It will only store strings, not complex objects. If
9
+ # you need to store an object, use the Setting model.
10
+ class Config < Sequel::Model(:configs)
11
+
12
+ # key:: name of the config item
13
+ # Returns the value of config item named the given key
14
+ def self.[](key)
15
+ key = key.to_s if key.is_a?(Symbol)
16
+ match = Config.filter(:name => key).first
17
+ return match ? match.value : nil
18
+ end
19
+
20
+ # key:: name of the config item
21
+ # val:: value of the config item
22
+ # Modifies or creates config item and stores the value
23
+ def self.[]=(key, val)
24
+ key = key.to_s if key.is_a?(Symbol)
25
+ model = Config.find_or_create(:name => key)
26
+ model.value = val
27
+ model.save
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module ModSpox
2
+ module Models
3
+ class Group < Sequel::Model(:groups)
4
+ def auths
5
+ auth = []
6
+ AuthGroup.filter(:group_id => pk).each do |ag|
7
+ auth << ag.auth
8
+ end
9
+ return auth
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,110 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # nick:: nick string
5
+ # username:: username of the user
6
+ # real_name:: real name of the user
7
+ # address:: hostname/ip of the user
8
+ # source:: full source string of the user
9
+ # connected_at:: time user connected
10
+ # connected_to:: server user connected to
11
+ # seconds_idle:: seconds user has been idle
12
+ # visible:: can the bot see the user (is in a channel the bot is parked)
13
+ # away:: is nick away
14
+ # botnick:: is the nick of the bot
15
+
16
+ # TODO: for nick field -> "tack a COLLATE NOCASE onto the columns"
17
+ class Nick < Sequel::Model(:nicks)
18
+
19
+ def visible=(val)
20
+ unless(val)
21
+ set :username => nil
22
+ set :real_name => nil
23
+ set :address => nil
24
+ set :source => nil
25
+ set :connected_at => nil
26
+ set :connected_to => nil
27
+ set :seconds_idle => nil
28
+ set :away => false
29
+ end
30
+ set :visible => val
31
+ end
32
+
33
+ def source=(mask)
34
+ set :source => mask
35
+ auth.check_mask(mask)
36
+ end
37
+
38
+ # Auth model associated with nick
39
+ def auth
40
+ Auth.find_or_create(:nick_id => pk)
41
+ end
42
+
43
+ # AuthGroups nick is authed to
44
+ def auth_groups
45
+ groups = []
46
+ auth_ids = []
47
+ group_ids = []
48
+ auth = Auth.filter(:nick_id => pk, :authed => true).first
49
+ if(auth)
50
+ groups = auth.groups
51
+ end
52
+ Auth.where('mask is not null').each do |a|
53
+ Logger.log("Matching AUTH against #{a.mask}", 30)
54
+ if(source =~ /#{a.mask}/)
55
+ auth_ids << a.pk
56
+ end
57
+ end
58
+ auth_ids.each{|id| AuthGroup.filter(:auth_id => id).each{|ag| group_ids << ag.group_id}}
59
+ group_ids.each{|id| groups << Group[id]}
60
+ groups.uniq!
61
+ return groups
62
+ end
63
+
64
+ # Set nick as member of given group
65
+ def group=(group)
66
+ auth.group = group
67
+ end
68
+
69
+ # Remove nick from given group
70
+ def remove_group(group)
71
+ auth.remove_group(group)
72
+ end
73
+
74
+ # Modes associated with this nick
75
+ def nick_modes
76
+ NickMode.filter(:nick_id => pk)
77
+ end
78
+
79
+ # Add channel nick is found in
80
+ def channel_add(channel)
81
+ NickChannel.find_or_create(:nick_id => pk, :channel_id => channel.pk)
82
+ end
83
+
84
+ # Remove channel nick is no longer found in
85
+ def channel_remove(channel)
86
+ NickChannel.filter(:nick_id => pk, :channel_id => channel.pk).first.destroy
87
+ end
88
+
89
+ # Remove all channels
90
+ def clear_channels
91
+ NickChannel.filter(:nick_id => pk).each{|o|o.destroy}
92
+ end
93
+
94
+ # Channels nick is currently in
95
+ def channels
96
+ NickChannel.filter(:nick_id => pk)
97
+ end
98
+
99
+ # Purge all nick information
100
+ def self.clean
101
+ Nick.set(:username => nil, :real_name => nil, :address => nil,
102
+ :source => nil, :connected_at => nil, :connected_to => nil,
103
+ :seconds_idle => nil, :away => false, :visible => false, :botnick => false)
104
+ NickMode.destroy_all
105
+ Auth.set(:authed => false)
106
+ end
107
+
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,43 @@
1
+ module ModSpox
2
+ module Models
3
+ # This model is for internal use only to provide a
4
+ # proper relation between Nick and Channel
5
+ class NickChannel < Sequel::Model(:nick_channels)
6
+
7
+ set_primary_key [:nick_id, :channel_id]
8
+
9
+ after_save do
10
+ c = Channel[channel_id]
11
+ n = Nick[nick_id]
12
+ n.visible = true
13
+ n.save
14
+ c.parked = true
15
+ c.save
16
+ end
17
+
18
+ after_destroy do
19
+ c = Channel[channel_id]
20
+ n = Nick[nick_id]
21
+ if(n.channels.size < 1)
22
+ n.visible = false
23
+ n.save
24
+ NickMode.filter(:nick_id => nick_id).each{|n|n.destroy}
25
+ end
26
+ if(c.nicks.size < 1)
27
+ c.parked = false
28
+ c.save
29
+ NickMode.filter(:channel_id => channel_id).each{|n|n.destroy}
30
+ ChannelMode.filter(:channel_id => channel_id).each{|n|n.destroy}
31
+ end
32
+ end
33
+
34
+ def nick
35
+ Nick[nick_id]
36
+ end
37
+
38
+ def channel
39
+ Channel[channel_id]
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # mode:: Mode that is set
5
+ class NickMode < Sequel::Model(:nick_modes)
6
+
7
+ # Nick mode is associated with
8
+ def nick
9
+ return Nick[nick_id]
10
+ end
11
+
12
+ # Channel mode is associated with
13
+ def channel
14
+ return Channel[channel_id]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # host:: hostname of server
5
+ # port:: port to connect to
6
+ # priority:: priority of this entry (higher number == greater priority)
7
+ # connected:: bot is connected to this server
8
+ class Server < Sequel::Model(:servers)
9
+ set_primary_key [:host, :port]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ require 'base64'
2
+
3
+ module ModSpox
4
+ module Models
5
+ # Attributes provided by model:
6
+ # name:: name of the setting
7
+ # value:: value of the setting
8
+ #
9
+ # This model can be used to store complex objects. These objects are dumped
10
+ # and stored for later retrieval
11
+ class Setting < Sequel::Model(:settings)
12
+
13
+ def value=(val)
14
+ set(:value => Base64.encode64(Marshal.dump(val)))
15
+ end
16
+
17
+ def value
18
+ return values[:value] ? Marshal.load(Base64.decode64(values[:value])) : nil
19
+ end
20
+
21
+ # key:: name of the setting
22
+ # Returns the setting with the given name
23
+ def self.[](key)
24
+ key = key.to_s if key.is_a?(Symbol)
25
+ setting = Setting.filter(:name => key).first
26
+ return setting ? setting.value : nil
27
+ end
28
+
29
+ # key:: name of the setting
30
+ # val:: value of the setting
31
+ # Stores the val in setting named by the given key
32
+ def self.[]=(key, val)
33
+ key = key.to_s if key.is_a?(Symbol)
34
+ model = Setting.find_or_create(:name => key)
35
+ model.value = val
36
+ model.save
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # signature:: regex signature
5
+ # params:: Array of parameters to match in signature
6
+ # method:: method to call when matched
7
+ # plugin:: plugin to call when matched
8
+ # description:: description of trigger
9
+ class Signature < Sequel::Model(:signatures)
10
+
11
+ def params=(prms)
12
+ raise InvalidType.new('Parameter names must be provided in an array') unless prms.kind_of?(Array)
13
+ set(:params => prms.reverse.join('|'))
14
+ end
15
+
16
+ def params
17
+ return values[:params].nil? ? [] : values[:params].split('|')
18
+ end
19
+
20
+ def group
21
+ Group[group_id]
22
+ end
23
+
24
+ def group=(group)
25
+ set :group_id => group.pk
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module ModSpox
2
+ module Models
3
+ # Attributes provided by model:
4
+ # trigger:: trigger to match
5
+ # active:: trigger is active
6
+ class Trigger < Sequel::Model(:triggers)
7
+ end
8
+ end
9
+ end