mod_spox 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. data/CHANGELOG +31 -1
  2. data/LICENSE +674 -0
  3. data/README.rdoc +73 -0
  4. data/bin/mod_spox +28 -28
  5. data/data/mod_spox/extras/AOLSpeak.rb +2 -3
  6. data/data/mod_spox/extras/AutoKick.rb +10 -23
  7. data/data/mod_spox/extras/AutoMode.rb +12 -23
  8. data/data/mod_spox/extras/Bash.rb +55 -0
  9. data/data/mod_spox/extras/Bouncer.rb +85 -57
  10. data/data/mod_spox/extras/Bullshit.rb +1 -1
  11. data/data/mod_spox/extras/Bytes.rb +1 -2
  12. data/data/mod_spox/extras/Confess.rb +27 -29
  13. data/data/mod_spox/extras/DCC.rb +11 -20
  14. data/data/mod_spox/extras/DevWatch.rb +21 -23
  15. data/data/mod_spox/extras/DownForEveryoneOrJustMe.rb +47 -0
  16. data/data/mod_spox/extras/EightBall.rb +1 -1
  17. data/data/mod_spox/extras/FML.rb +35 -0
  18. data/data/mod_spox/extras/Headers.rb +31 -50
  19. data/data/mod_spox/extras/Karma.rb +81 -29
  20. data/data/mod_spox/extras/Logger.rb +2 -2
  21. data/data/mod_spox/extras/LolSpeak.rb +1 -2
  22. data/data/mod_spox/extras/PhpCli.rb +138 -8
  23. data/data/mod_spox/extras/PhpFuncLookup.rb +20 -23
  24. data/data/mod_spox/extras/Pinger.rb +1 -1
  25. data/data/mod_spox/extras/Quotes.rb +8 -10
  26. data/data/mod_spox/extras/RegexTracker.rb +2 -4
  27. data/data/mod_spox/extras/Roulette.rb +20 -27
  28. data/data/mod_spox/extras/RubyCli.rb +93 -0
  29. data/data/mod_spox/extras/Search.rb +17 -3
  30. data/data/mod_spox/extras/Seen.rb +150 -0
  31. data/data/mod_spox/extras/SlashdotHeadlineGenerator.rb +500 -0
  32. data/data/mod_spox/extras/Talk.rb +2 -4
  33. data/data/mod_spox/extras/Topten.rb +10 -12
  34. data/data/mod_spox/extras/TracTicket.rb +3 -5
  35. data/data/mod_spox/extras/Translate.rb +20 -22
  36. data/data/mod_spox/extras/Twitter.rb +118 -33
  37. data/data/mod_spox/extras/UrbanDictionary.rb +8 -17
  38. data/data/mod_spox/extras/Weather.rb +1 -2
  39. data/data/mod_spox/plugins/Authenticator.rb +93 -98
  40. data/data/mod_spox/plugins/Banner.rb +26 -56
  41. data/data/mod_spox/plugins/Helper.rb +5 -6
  42. data/data/mod_spox/plugins/Initializer.rb +4 -14
  43. data/data/mod_spox/plugins/Joiner.rb +1 -1
  44. data/data/mod_spox/plugins/Nicker.rb +13 -0
  45. data/data/mod_spox/plugins/Parter.rb +2 -2
  46. data/data/mod_spox/plugins/Permissions.rb +60 -0
  47. data/data/mod_spox/plugins/PluginLoader.rb +7 -12
  48. data/data/mod_spox/plugins/Ponger.rb +51 -0
  49. data/data/mod_spox/plugins/Quitter.rb +1 -2
  50. data/data/mod_spox/plugins/Servers.rb +57 -0
  51. data/data/mod_spox/plugins/Status.rb +3 -2
  52. data/data/mod_spox/plugins/Triggers.rb +9 -9
  53. data/lib/mod_spox/Bot.rb +109 -33
  54. data/lib/mod_spox/BotConfig.rb +2 -2
  55. data/lib/mod_spox/ConfigurationWizard.rb +12 -12
  56. data/lib/mod_spox/Database.rb +1 -4
  57. data/lib/mod_spox/Exceptions.rb +26 -0
  58. data/lib/mod_spox/Helpers.rb +29 -68
  59. data/lib/mod_spox/Loader.rb +23 -24
  60. data/lib/mod_spox/Logger.rb +19 -17
  61. data/lib/mod_spox/MessageFactory.rb +50 -24
  62. data/lib/mod_spox/Pipeline.rb +21 -7
  63. data/lib/mod_spox/Plugin.rb +27 -3
  64. data/lib/mod_spox/PluginManager.rb +28 -15
  65. data/lib/mod_spox/PriorityQueue.rb +69 -0
  66. data/lib/mod_spox/Socket.rb +93 -51
  67. data/lib/mod_spox/Sockets.rb +76 -63
  68. data/lib/mod_spox/Timer.rb +21 -141
  69. data/lib/mod_spox/Version.rb +14 -0
  70. data/lib/mod_spox/handlers/BadNick.rb +1 -1
  71. data/lib/mod_spox/handlers/Bounce.rb +5 -5
  72. data/lib/mod_spox/handlers/Created.rb +13 -5
  73. data/lib/mod_spox/handlers/Handler.rb +12 -3
  74. data/lib/mod_spox/handlers/Invite.rb +14 -8
  75. data/lib/mod_spox/handlers/Join.rb +24 -20
  76. data/lib/mod_spox/handlers/Kick.rb +22 -13
  77. data/lib/mod_spox/handlers/Mode.rb +42 -36
  78. data/lib/mod_spox/handlers/Motd.rb +4 -0
  79. data/lib/mod_spox/handlers/Names.rb +66 -39
  80. data/lib/mod_spox/handlers/Nick.rb +20 -14
  81. data/lib/mod_spox/handlers/Part.rb +25 -8
  82. data/lib/mod_spox/handlers/Ping.rb +11 -5
  83. data/lib/mod_spox/handlers/Pong.rb +9 -5
  84. data/lib/mod_spox/handlers/Privmsg.rb +25 -17
  85. data/lib/mod_spox/handlers/Quit.rb +13 -8
  86. data/lib/mod_spox/handlers/Topic.rb +4 -0
  87. data/lib/mod_spox/handlers/Welcome.rb +16 -24
  88. data/lib/mod_spox/handlers/Who.rb +64 -48
  89. data/lib/mod_spox/handlers/Whois.rb +92 -60
  90. data/lib/mod_spox/messages/incoming/Nick.rb +2 -2
  91. data/lib/mod_spox/messages/incoming/Privmsg.rb +1 -1
  92. data/lib/mod_spox/messages/incoming/Whois.rb +1 -0
  93. data/lib/mod_spox/messages/internal/EstablishConnection.rb +1 -1
  94. data/lib/mod_spox/messages/internal/PluginsReady.rb +10 -0
  95. data/lib/mod_spox/messages/internal/QueueSocket.rb +8 -0
  96. data/lib/mod_spox/messages/internal/Reconnect.rb +8 -0
  97. data/lib/mod_spox/messages/internal/UnqueueSocket.rb +8 -0
  98. data/lib/mod_spox/migrations/002_persistent_sigs.rb +14 -0
  99. data/lib/mod_spox/migrations/003_auth_restructure.rb +31 -0
  100. data/lib/mod_spox/migrations/004_mode_index_fix.rb +18 -0
  101. data/lib/mod_spox/migrations/005_nick_mode_nopark.rb +18 -0
  102. data/lib/mod_spox/models/Auth.rb +16 -46
  103. data/lib/mod_spox/models/AuthMask.rb +13 -0
  104. data/lib/mod_spox/models/Channel.rb +46 -27
  105. data/lib/mod_spox/models/Config.rb +10 -19
  106. data/lib/mod_spox/models/Group.rb +20 -8
  107. data/lib/mod_spox/models/Models.rb +1 -1
  108. data/lib/mod_spox/models/Nick.rb +105 -113
  109. data/lib/mod_spox/models/NickMode.rb +23 -9
  110. data/lib/mod_spox/models/Server.rb +12 -1
  111. data/lib/mod_spox/models/Setting.rb +12 -16
  112. data/lib/mod_spox/models/Signature.rb +28 -8
  113. data/tests/BotHolder.rb +24 -0
  114. data/tests/handlers/tc_BadNick.rb +21 -0
  115. data/tests/handlers/tc_Created.rb +24 -0
  116. data/tests/handlers/tc_Invite.rb +50 -0
  117. data/tests/handlers/tc_Join.rb +33 -0
  118. data/tests/handlers/tc_Kick.rb +32 -0
  119. data/tests/handlers/tc_Mode.rb +85 -0
  120. data/tests/handlers/tc_Names.rb +35 -0
  121. data/tests/handlers/tc_Nick.rb +55 -0
  122. data/tests/handlers/tc_Part.rb +44 -0
  123. data/tests/handlers/tc_Ping.rb +40 -0
  124. data/tests/handlers/tc_Pong.rb +28 -0
  125. data/tests/handlers/tc_Privmsg.rb +85 -0
  126. data/tests/handlers/tc_Quit.rb +40 -0
  127. data/tests/handlers/tc_Who.rb +50 -0
  128. data/tests/handlers/tc_Whois.rb +61 -0
  129. data/tests/models/tc_Auth.rb +34 -0
  130. data/tests/models/tc_Channel.rb +52 -0
  131. data/tests/models/tc_Config.rb +19 -0
  132. data/tests/models/tc_Nick.rb +142 -0
  133. data/tests/models/tc_NickMode.rb +40 -0
  134. data/tests/models/tc_Setting.rb +21 -0
  135. data/tests/models/tc_Signature.rb +14 -0
  136. data/tests/run_tests.rb +4 -0
  137. metadata +284 -212
  138. data/README +0 -36
  139. data/lib/mod_spox/Cache.rb +0 -57
  140. data/lib/mod_spox/Monitors.rb +0 -84
  141. data/lib/mod_spox/Pool.rb +0 -164
  142. data/lib/mod_spox/models/AuthGroup.rb +0 -16
  143. data/lib/mod_spox/models/ChannelMode.rb +0 -14
  144. data/lib/mod_spox/models/NickChannel.rb +0 -45
  145. data/lib/mod_spox/models/NickGroup.rb +0 -16
@@ -1,4 +1,4 @@
1
1
  # Quick loader for all models
2
- Dir.new(File.dirname(__FILE__)).each do |f|
2
+ Dir.new(File.dirname(__FILE__)).each do |f|
3
3
  require File.dirname(__FILE__) + '/' + f if f =~ /\.rb$/
4
4
  end
@@ -1,4 +1,10 @@
1
1
  require 'socket'
2
+ require 'mod_spox/models/Auth'
3
+ require 'mod_spox/models/Channel'
4
+ require 'mod_spox/models/NickMode'
5
+ require 'mod_spox/models/AuthMask'
6
+
7
+
2
8
 
3
9
  module ModSpox
4
10
  module Models
@@ -15,13 +21,29 @@ module ModSpox
15
21
  # visible:: can the bot see the user (is in a channel the bot is parked)
16
22
  # away:: is nick away
17
23
  # botnick:: is the nick of the bot
18
-
24
+
19
25
  class Nick < Sequel::Model
20
26
 
21
- set_cache Database.cache, :ttl => 3600 unless Database.cache.nil?
27
+ one_to_many :auths, :one_to_one => true, :class => 'ModSpox::Models::Auth'
28
+ many_to_many :channels, :join_table => :nick_channels, :class => 'ModSpox::Models::Channel'
29
+ one_to_many :modes, :class => 'ModSpox::Models::NickMode'
30
+ many_to_many :auth_masks, :join_table => :auth_masks_nicks, :class => 'ModSpox::Models::AuthMask'
22
31
 
32
+ # nick_name:: nick of user
33
+ # override to downcase nick
23
34
  def nick=(nick_name)
24
- values[:nick] = nick_name.downcase
35
+ nick_name.downcase!
36
+ super(nick_name)
37
+ end
38
+
39
+ def Nick.find_or_create(args)
40
+ args[:nick].downcase! if args[:nick]
41
+ super(args)
42
+ end
43
+
44
+ def Nick.filter(args)
45
+ args[:nick].downcase! if args[:nick]
46
+ super(args)
25
47
  end
26
48
 
27
49
  def Nick.locate(string, create = true)
@@ -33,169 +55,139 @@ module ModSpox
33
55
  end
34
56
  return nick
35
57
  end
36
-
37
- def address=(address)
38
- return if (!values[:address].nil? && !values[:host].nil?) && (values[:address] == address || values[:host] == address)
58
+
59
+ # addr: users address
60
+ # make sure everything is set properly
61
+ # when the address is set
62
+ def address=(addr)
63
+ return if (!values[:address].nil? && !values[:host].nil?) && (values[:address] == addr || values[:host] == addr)
39
64
  oldaddress = values[:address]
40
65
  begin
41
66
  info = Object::Socket.getaddrinfo(address, nil)
42
- update_values :address => info[0][3]
43
- update_values :host => info[0][2]
67
+ addr = info[0][3]
68
+ update :host => info[0][2]
69
+ super(addr)
44
70
  rescue Object => boom
45
- update_values :address => address
46
- update_values :host => address
71
+ super(addr)
72
+ update :host => address
47
73
  ensure
48
74
  if values[:address] != oldaddress
49
- clear_auth
75
+ auth.update(:authed => false)
50
76
  end
51
77
  end
52
78
  end
53
79
 
80
+ # val:: bool
81
+ # sets if nick is currently visible. if
82
+ # not all relating information is cleared
54
83
  def visible=(val)
55
84
  unless(val)
56
- update_with_params :username => nil
57
- update_with_params :real_name => nil
58
- update_with_params :address => nil
59
- update_with_params :source => nil
60
- update_with_params :connected_at => nil
61
- update_with_params :connected_to => nil
62
- update_with_params :seconds_idle => nil
63
- update_with_params :away => false
85
+ update :username => nil
86
+ update :real_name => nil
87
+ update :address => nil
88
+ update :source => nil
89
+ update :connected_at => nil
90
+ update :connected_to => nil
91
+ update :seconds_idle => nil
92
+ update :away => false
93
+ remove_all_channels
94
+ auth.update(:authed => false)
64
95
  end
65
- update_values :visible => val
66
- end
67
-
68
- def source=(mask)
69
- super
96
+ super(val)
70
97
  end
71
98
 
72
99
  # Auth model associated with nick
73
100
  def auth
74
- Auth.find_or_create(:nick_id => pk)
101
+ if(auths.empty?)
102
+ a = Auth.find_or_create(:nick_id => pk)
103
+ add_auth(a)
104
+ end
105
+ auths[0].refresh
106
+ return auths[0]
75
107
  end
76
108
 
77
109
  # AuthGroups nick is authed to
78
110
  def auth_groups
79
- nickgroups = NickGroup.filter(:nick_id => pk)
80
- if(nickgroups.size < 1)
81
- populate_groups
82
- nickgroups = NickGroup.filter(:nick_id => pk)
83
- end
84
- groups = []
85
- NickGroup.filter(:nick_id => pk).each do | nickgroup |
86
- groups << nickgroup.group
111
+ g = (auth.groups.empty? || !auth.authed) ? [] : auth.groups
112
+ unless(auth_masks.empty?)
113
+ auth_masks.each{|am| g += am.groups}
87
114
  end
88
- return groups
115
+ return g
89
116
  end
90
117
 
91
- def populate_groups
92
- auth_ids = []
93
- group_ids = []
94
- auth = Auth.filter('nick_id = ?', pk).filter('authed = ?', true).first
95
- if(auth)
96
- auth.groups.each do |group|
97
- NickGroup.find_or_create(:nick_id => pk, :group_id => group.pk)
98
- end
118
+ # Checks nick's source against available
119
+ # authentication masks
120
+ def check_masks
121
+ AuthMask.all.each do |am|
122
+ add_auth_mask(am) if source =~ /#{am.mask}/ && !auth_masks.include?(am)
99
123
  end
100
- Auth.where('mask is not null').each do |a|
101
- [source, "#{nick}!#{username}@#{host}", "#{nick}!#{username}@#{address}"].each do |chk_src|
102
- Logger.info("Matching AUTH - #{chk_src} against #{a.mask}")
103
- if(chk_src =~ /#{a.mask}/)
104
- auth_ids << a.pk unless auth_ids.include?(a.pk)
105
- end
106
- end
107
- end
108
- auth_ids.each{|id| AuthGroup.filter(:auth_id => id).each{|ag| group_ids << ag.group_id}}
109
- group_ids.uniq.each{|id| NickGroup.find_or_create(:nick_id => pk, :group_id => id)}
110
- end
111
-
112
- # Set nick as member of given group
113
- def group=(group)
114
- auth.group = group
115
124
  end
116
125
 
126
+ # group:: Models::Group
127
+ # Return if nick is member of given group
117
128
  def in_group?(group)
118
129
  group = Group.filter(:name => group).first if group.is_a?(String)
119
130
  return group.nil? ? false : auth_groups.include?(group)
120
131
  end
121
132
 
122
- # Remove nick from given group
123
- def remove_group(group)
124
- auth.remove_group(group)
125
- end
126
-
127
- # Clear this nick's auth status
128
- def clear_auth
129
- auth.authenticated(false)
130
- NickGroup.filter(:nick_id => pk).destroy
131
- end
132
-
133
133
  # Modes associated with this nick
134
134
  def nick_modes
135
- NickMode.filter(:nick_id => pk)
136
- end
137
-
138
- # Add channel nick is found in
139
- def channel_add(channel)
140
- NickChannel.find_or_create(:nick_id => pk, :channel_id => channel.pk)
141
- end
142
-
143
- # Remove channel nick is no longer found in
144
- def channel_remove(channel)
145
- NickChannel.filter(:nick_id => pk, :channel_id => channel.pk).first.destroy
146
- if(NickChannel.filter(:nick_id => pk).count < 1)
147
- clear_auth
148
- visible = false
149
- end
135
+ modes
150
136
  end
151
137
 
152
138
  # Remove all channels
153
139
  def clear_channels
154
- NickChannel.filter(:nick_id => pk).destroy
140
+ remove_all_channels
155
141
  visible = false
156
- clear_auth
157
- end
158
-
159
- # Channels nick is currently in
160
- def channels
161
- chans = []
162
- NickChannel.filter(:nick_id => pk).each do |nc|
163
- chans << nc.channel
164
- end
165
- return chans
166
142
  end
167
143
 
168
144
  # channel:: Models::Channel
169
145
  # Return if nick is operator in given channel
170
146
  def is_op?(channel)
171
- NickMode.filter(:channel_id => channel.pk, :nick_id => pk).each do |mode|
172
- return true if mode.mode == 'o'
173
- end
174
- return false
147
+ raise Exceptions::NotInChannel.new(channel) unless channels_dataset.filter(:channel_id => channel.pk).count > 0
148
+ m = NickMode.filter(:nick_id => pk, :channel_id => channel.pk).first
149
+ return m ? m.set?('o') : false
175
150
  end
176
151
 
177
152
  # channel:: Models::Channel
178
153
  # Return if nick is voiced in given channel
179
154
  def is_voice?(channel)
180
- NickMode.filter(:channel_id => channel.pk, :nick_id => pk).each do |mode|
181
- return true if mode.mode == 'v'
155
+ raise Exceptions::NotInChannel.new(channel) unless channels_dataset.filter(:channel_id => channel.pk).count > 0
156
+ m = NickMode.filter(:nick_id => pk, :channel_id => channel.pk).first
157
+ return m ? m.set?('v') : false
158
+ end
159
+
160
+ def set_mode(m)
161
+ m.each_char do |c|
162
+ update(:mode => "#{mode}#{c}") if mode.index(c).nil?
163
+ end
164
+ end
165
+
166
+ def unset_mode(m)
167
+ m.each_char do |c|
168
+ update(:mode => mode.gsub(c,'')) unless mode.index(c).nil?
169
+ end
170
+ end
171
+
172
+ def mode_set?(m)
173
+ return !mode.index(m).nil?
174
+ end
175
+
176
+ def add_channel(c)
177
+ unless(channels_dataset.filter(:channel_id => c.pk).count > 0)
178
+ super(c)
179
+ end
180
+ end
181
+
182
+ def remove_channel(c)
183
+ if(channels_dataset.filter(:channel_id => c.pk).count > 0)
184
+ super(c)
182
185
  end
183
- return false
184
186
  end
185
187
 
188
+ # TODO: rewrite this to work
186
189
  def Nick.transfer_groups(old_nick, new_nick)
187
- NickGroup.filter(:nick_id => old_nick.pk).update(:nick_id => new_nick.pk)
188
- end
189
-
190
- # Purge all nick information
191
- def self.clean
192
- Nick.set(:username => nil, :real_name => nil, :address => nil,
193
- :source => nil, :connected_at => nil, :connected_to => nil,
194
- :seconds_idle => nil, :away => false, :visible => false, :botnick => false)
195
- NickMode.destroy_all
196
- NickChannel.destroy_all
197
- NickGroup.destroy_all
198
- Auth.set(:authed => false)
190
+ # do nothing
199
191
  end
200
192
 
201
193
  end
@@ -1,17 +1,31 @@
1
+ require 'mod_spox/models/Nick'
2
+ require 'mod_spox/models/Channel'
1
3
  module ModSpox
2
4
  module Models
3
- # Attributes provided by model:
4
- # mode:: Mode that is set
5
- class NickMode < Sequel::Model
6
5
 
7
- # Nick mode is associated with
8
- def nick
9
- return Nick[nick_id]
6
+ class NickMode < Sequel::Model
7
+ many_to_one :nick, :class => 'ModSpox::Models::Nick'
8
+ many_to_one :channel, :class => 'ModSpox::Models::Channel'
9
+
10
+ # m:: mode character
11
+ # add a mode for a nick channel combo
12
+ def set_mode(m)
13
+ update(:mode => "#{values[:mode]}#{m}") if values[:mode].nil? || values[:mode].index(m).nil?
14
+ end
15
+
16
+ # m:: mode character
17
+ # remove a mode for a nick channel combo
18
+ def unset_mode(m)
19
+ update(:mode => values[:mode].gsub(m, ''))
10
20
  end
11
21
 
12
- # Channel mode is associated with
13
- def channel
14
- return Channel[channel_id]
22
+ def set?(m)
23
+ return mode.nil? ? false : !mode.index(m).nil?
24
+ end
25
+
26
+ # clear all modes for a nick channel combo
27
+ def clear_modes
28
+ update(:mode => '')
15
29
  end
16
30
  end
17
31
  end
@@ -7,8 +7,19 @@ module ModSpox
7
7
  # connected:: bot is connected to this server
8
8
  class Server < Sequel::Model
9
9
 
10
+ def Server.filter(args={})
11
+ args[:host].downcase! if args.has_key?(:host)
12
+ super(args)
13
+ end
14
+
15
+ def Server.find_or_create(args={})
16
+ args[:host].downcase! if args.has_key?(:host)
17
+ super(args)
18
+ end
19
+
10
20
  def host=(host_name)
11
- update_values :host => host_name.downcase
21
+ host_name.downcase!
22
+ super(host_name)
12
23
  end
13
24
 
14
25
  end
@@ -6,38 +6,34 @@ module ModSpox
6
6
  #
7
7
  # This model can be used to store complex objects. These objects are dumped
8
8
  # and stored for later retrieval
9
+ # TODO: remove [] from any usage
9
10
  class Setting < Sequel::Model
10
11
 
11
12
  #serialize(:value, :format => :marshal)
12
13
 
13
14
  def name=(setting_name)
14
- update_values :name => setting_name.downcase
15
+ setting_name.downcase!
16
+ super(setting_name)
15
17
  end
16
18
 
17
19
  def value=(val)
18
- update_values(:value => [Marshal.dump(val.dup)].pack('m'))
20
+ val = [Marshal.dump(val.dup)].pack('m')
21
+ super(val)
19
22
  end
20
23
 
21
24
  def value
22
25
  return values[:value] ? Marshal.load(values[:value].unpack('m')[0]) : nil
23
26
  end
24
27
 
25
- # key:: name of the setting
26
- # Returns the setting with the given name
27
- def self.[](key)
28
- key = key.to_s if key.is_a?(Symbol)
29
- setting = Setting.filter(:name => key).first
30
- return setting ? setting.value : nil
28
+ def Setting.set(sym, value)
29
+ s = Setting.find_or_create(:name => "#{sym}")
30
+ s.value = value
31
+ s.save
31
32
  end
32
33
 
33
- # key:: name of the setting
34
- # val:: value of the setting
35
- # Stores the val in setting named by the given key
36
- # Note: Will fail if attempting to save hashes. Must set value explicitly
37
- def self.[]=(key, val)
38
- key = key.to_s if key.is_a?(Symbol)
39
- model = Setting.find_or_create(:name => key)
40
- model.update_with_params(:value => [Marshal.dump(val.dup)].pack('m'))
34
+ def Setting.val(sym)
35
+ s = Setting.filter(:name => "#{sym}").first
36
+ return s ? s.value : nil
41
37
  end
42
38
  end
43
39
  end
@@ -1,3 +1,5 @@
1
+ require 'mod_spox/models/Group'
2
+
1
3
  module ModSpox
2
4
  module Models
3
5
  # Attributes provided by model:
@@ -8,23 +10,41 @@ module ModSpox
8
10
  # description:: description of trigger
9
11
  class Signature < Sequel::Model
10
12
 
11
- serialize(:signature, :format => :marshal)
13
+ many_to_one :group, :class => 'ModSpox::Models::Group'
12
14
 
13
15
  def params=(prms)
14
- raise InvalidType.new('Parameter names must be provided in an array') unless prms.kind_of?(Array)
15
- update_values(:params => prms.join('|'))
16
+ raise Exceptions::InvalidType.new('Parameter names must be provided in an array') unless prms.nil? || prms.kind_of?(Array)
17
+ prms = prms.join('|') unless prms.nil?
18
+ super(prms)
16
19
  end
17
20
 
18
21
  def params
19
22
  return values[:params].nil? ? [] : values[:params].split('|')
20
23
  end
21
24
 
22
- def group
23
- Group[group_id]
25
+ def signature=(v)
26
+ v = [Marshal.dump(v)].pack('m')
27
+ super(v)
24
28
  end
25
-
26
- def group=(group)
27
- update_values :group_id => group.pk
29
+
30
+ def signature
31
+ values[:signature] ? Marshal.load(values[:signature].unpack('m')[0]) : nil
32
+ end
33
+
34
+ def Signature.find_or_create(args)
35
+ t = nil
36
+ if(args.has_key?(:signature) && args.has_key?(:params) && args.has_key?(:method) && args.has_key?(:plugin))
37
+ args[:params] = [] if args[:params].nil?
38
+ Signature.filter(:method => args[:method], :plugin => args[:plugin], :params => args[:params].join('|')).each do |s|
39
+ t = s if s.signature == args[:signature]
40
+ end
41
+ args[:params] = nil if args[:params].empty?
42
+ end
43
+ unless(t)
44
+ t = create(args)
45
+ end
46
+ t.update(:enabled => true)
47
+ return t
28
48
  end
29
49
 
30
50
  end