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
@@ -4,8 +4,7 @@ class Weather < ModSpox::Plugin
4
4
 
5
5
  def initialize(pipeline)
6
6
  super
7
- Signature.find_or_create(:signature => 'weather (\d+)', :plugin => name, :method => 'weather',
8
- :description => 'Show weather for given zipcode').params = [:zipcode]
7
+ add_sig(:sig => 'weather (\d+)', :method => :weather, :desc => 'Show weather for given zipcode', :params => [:zipcode])
9
8
  end
10
9
 
11
10
  def weather(message, params)
@@ -2,44 +2,29 @@ class Authenticator < ModSpox::Plugin
2
2
  def initialize(pipeline)
3
3
  super(pipeline)
4
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, :groups]
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
- Models::Signature.find_or_create(:signature => 'groups', :plugin => name, :method => 'show_groups',
36
- :description => 'Show user groups they are currently a member of')
37
- @whois_cache = []
5
+ add_sig(:sig => 'auth (\S+)', :method => :authenticate, :desc => 'Authenticate with bot using a password', :params => [:password])
6
+ add_sig(:sig => 'ident', :method => :do_ident, :desc => 'Instructs the bot to check your NickServ status')
7
+ add_sig(:sig => 'auth mask add (\S+) (\S+)', :method => :add_mask, :group => group, :desc => 'Add authentication mask and set initial group', :params => [:mask, :group])
8
+ add_sig(:sig => 'auth mask set (\d+) (.+)', :method => :set_mask_groups, :group => group, :desc => 'Set groups for the given mask', :params => [:id, :groups])
9
+ add_sig(:sig => 'auth mask unset (\d+) (.+)', :method => :del_mask_groups, :group => group, :desc => 'Remove groups for the given mask', :params => [:id, :groups])
10
+ add_sig(:sig => 'auth mask remove (\d+)', :method => :remove_mask, :group => group, :desc => 'Remove authentication mask', :params => [:id])
11
+ add_sig(:sig => 'auth mask list', :method => :list_mask, :group => group, :desc => 'List all available authentication masks')
12
+ add_sig(:sig => 'auth nick ident (\S+) (true|false)', :method => :nick_ident, :group => group, :desc => 'Allow authentication to nicks identified to NickServ', :params => [:nick, :ident])
13
+ add_sig(:sig => 'auth nick password (\S+) (\S+)', :method => :nick_pass, :group => group, :desc => 'Set authentication password for nick', :params => [:nick, :password])
14
+ add_sig(:sig => 'auth nick clear password (\S+)', :method => :clear_pass, :group => group, :desc => 'Clear nicks authentication password', :params => [:nick])
15
+ add_sig(:sig => 'auth nick info (\S+)', :method => :nick_info, :group => group, :desc => 'Return authentication information about given nick', :params => [:nick])
16
+ add_sig(:sig => 'auth nick set (\S+) (\S+)', :method => :set_nick, :group => group, :desc => 'Set the group for a given nick', :params => [:nick, :group])
17
+ add_sig(:sig => 'auth nick unset (\S+) (\S+)', :method => :unset_nick, :group => group, :desc => 'Unset the group for a given nick', :params => [:nick, :group])
18
+ add_sig(:sig => 'auth group list', :method => :list_groups, :group => group, :desc => 'List available authentication groups')
19
+ add_sig(:sig => 'auth group info (\S+)', :method => :group_info, :group => group, :desc => 'List members of given group', :params => [:group])
20
+ add_sig(:sig => 'groups', :method => :show_groups, :desc => 'Show user groups they are currently a member of')
38
21
  @nickserv_nicks = []
22
+ @nickserv_cache = []
39
23
  populate_nickserv
40
24
  @pipeline.hook(self, :check_join, :Incoming_Join)
41
25
  @pipeline.hook(self, :check_nicks, :Incoming_Who)
42
26
  @pipeline.hook(self, :check_nicks, :Incoming_Names)
27
+ @pipeline.hook(self, :check_notice, :Incoming_Notice)
43
28
  end
44
29
 
45
30
  # message:: ModSpox::Messages::Incoming::Privmsg
@@ -48,9 +33,9 @@ class Authenticator < ModSpox::Plugin
48
33
  def authenticate(message, params)
49
34
  return unless message.is_private?
50
35
  if(message.is_private? && message.source.auth.check_password(params[:password]))
51
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, 'Authentication was successful')
36
+ information message.replyto, 'Authentication was successful'
52
37
  else
53
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, 'Authentication failed')
38
+ error message.replyto, 'Authentication failed'
54
39
  end
55
40
  end
56
41
 
@@ -61,12 +46,12 @@ class Authenticator < ModSpox::Plugin
61
46
  begin
62
47
  group = Models::Group.filter(:name => params[:group]).first
63
48
  raise Exception.new("Failed to find group") unless group
64
- a = Models::Auth.find_or_create(:mask => Regexp.new(params[:mask]).source)
65
- a.group = group
49
+ a = Models::AuthMask.find_or_create(:mask => Regexp.new(params[:mask]).source)
50
+ a.add_group(group)
66
51
  a.save
67
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, 'Mask has been successfully added to authentication table')
52
+ information message.replyto, 'Mask has been successfully added to authentication table'
68
53
  rescue Object => boom
69
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Authentication failed to add mask. Reason: #{boom}")
54
+ error message.replyto, "Authentication failed to add mask. Reason: #{boom}"
70
55
  end
71
56
  end
72
57
 
@@ -74,15 +59,15 @@ class Authenticator < ModSpox::Plugin
74
59
  # params:: Signature parameters
75
60
  # Add an authentication group to a given mask
76
61
  def set_mask_groups(message, params)
77
- auth = Models::Auth[params[:id]]
62
+ auth = Models::AuthMask[params[:id].to_i]
78
63
  if(auth)
79
64
  params[:groups].split(/\s/).each do |g|
80
65
  group = Models::Group.filter(:name => g).first
81
- auth.group = group if group
66
+ auth.add_group(group) if group
82
67
  end
83
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Mask groups have been updated")
68
+ information message.replyto, "Mask groups have been updated"
84
69
  else
85
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find mask with ID: #{params[:id]}")
70
+ error message.replyto, "Failed to find mask with ID: #{params[:id]}"
86
71
  end
87
72
  end
88
73
 
@@ -90,15 +75,15 @@ class Authenticator < ModSpox::Plugin
90
75
  # params:: Signature parameters
91
76
  # Remove an authentication group from a given mask
92
77
  def del_mask_groups(message, params)
93
- auth = Models::Auth[params[:id]]
78
+ auth = Models::AuthMask[params[:id].to_i]
94
79
  if(auth)
95
80
  params[:groups].split(/\s/).each do |g|
96
81
  group = Models::Group.filter(:name => g).first
97
82
  auth.remove_group(group) if group
98
83
  end
99
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Mask groups have been updated")
84
+ information message.replyto, "Mask groups have been updated"
100
85
  else
101
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find mask with ID: #{params[:id]}")
86
+ error message.replyto, "Failed to find mask with ID: #{params[:id]}"
102
87
  end
103
88
  end
104
89
 
@@ -106,26 +91,25 @@ class Authenticator < ModSpox::Plugin
106
91
  # params:: Signature parameters
107
92
  # List all authentication masks
108
93
  def list_mask(message, params)
109
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, 'Authentication Mask Listing:')
110
- auths = []
111
- Models::Auth.where('mask is not null').each{|a| auths << a}
112
- auths.each do |a|
94
+ output = ["\2Authentication Mask Listing:\2"]
95
+ Models::AuthMask.all.each do |a|
113
96
  groups = []
114
97
  a.groups.each{|g| groups << g.name}
115
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "\2ID:\2 #{a.pk}: \2mask:\2 #{a.mask} \2groups:\2 #{groups.join(', ')}")
98
+ output << "\2ID:\2 #{a.pk}: \2mask:\2 #{a.mask} \2groups:\2 #{groups.join(', ')}"
116
99
  end
100
+ reply message.replyto, output
117
101
  end
118
102
 
119
103
  # message:: ModSpox::Messages::Incoming::Privmsg
120
104
  # params:: Signature parameters
121
105
  # Remove given authentication mask
122
106
  def remove_mask(message, params)
123
- auth = Models::Auth[params[:id].to_i]
107
+ auth = Models::AuthMask[params[:id].to_i]
124
108
  if(auth)
125
109
  auth.destroy
126
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Authentication mask with ID #{params[:id]} was deleted")
110
+ information message.replyto, "Authentication mask with ID #{params[:id]} was deleted"
127
111
  else
128
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "\2Failed\2: Could not find an authentication mask with ID: #{params[:id]}")
112
+ error message.replyto, "\2Failed\2: Could not find an authentication mask with ID: #{params[:id]}"
129
113
  end
130
114
  end
131
115
 
@@ -135,11 +119,12 @@ class Authenticator < ModSpox::Plugin
135
119
  def nick_ident(message, params)
136
120
  nick = Models::Nick.locate(params[:nick])
137
121
  if(params[:ident] == 'true')
138
- nick.auth.update_with_params(:services => true)
122
+ nick.auth.update(:services => true)
139
123
  else
140
- nick.auth.update_with_params(:services => false)
124
+ nick.auth.update(:services => false)
141
125
  end
142
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Nick #{params[:nick]} has been updated. Services for authentication has been set to #{params[:ident]}")
126
+ populate_nickserv
127
+ information message.replyto, "Nick #{params[:nick]} has been updated. Services for authentication has been set to #{params[:ident]}"
143
128
  end
144
129
 
145
130
 
@@ -149,7 +134,7 @@ class Authenticator < ModSpox::Plugin
149
134
  def nick_pass(message, params)
150
135
  nick = Models::Nick.locate(params[:nick])
151
136
  nick.auth.password = params[:password]
152
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Nick #{params[:nick]} has been updated. Password has been set.")
137
+ information message.replyto, "Nick #{params[:nick]} has been updated. Password has been set."
153
138
  end
154
139
 
155
140
  # message:: ModSpox::Messages::Incoming::Privmsg
@@ -158,7 +143,8 @@ class Authenticator < ModSpox::Plugin
158
143
  def clear_pass(message, params)
159
144
  nick = Models::Nick.locate(params[:nick])
160
145
  nick.auth.password = nil
161
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Nick #{params[:nick]} has been updated. Password has been unset.")
146
+ nick.auth.save
147
+ information message.replyto, "Nick #{params[:nick]} has been updated. Password has been unset."
162
148
  end
163
149
 
164
150
  # message:: ModSpox::Messages::Incoming::Privmsg
@@ -170,25 +156,24 @@ class Authenticator < ModSpox::Plugin
170
156
  info = []
171
157
  info << "\2INFO [#{nick.nick}]:\2"
172
158
  groups = []
173
- Models::AuthGroup.filter(:auth_id => nick.auth.pk).each do |ag|
174
- groups << ag.group.name
159
+ nick.auth.groups.each do |ag|
160
+ groups << ag.name
175
161
  end
176
162
  info << "Groups: #{groups.uniq.sort.join(', ')}."
177
- nick.auth.password.nil? ? info << 'Password has not been set.' : info << 'Password has been set.'
163
+ nick.auth.password.nil? || nick.auth.password.empty? ? info << 'Password has not been set.' : info << 'Password has been set.'
178
164
  nick.auth.services ? info << 'Nickserv ident is enabled.' : info << 'Nickserv ident is disabled.'
179
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "#{info.join(' ')}")
165
+ information message.replyto, "#{info.join(' ')}"
180
166
  else
181
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "I have no record of nick: #{params[:nick]}")
167
+ error message.replyto, "I have no record of nick: #{params[:nick]}"
182
168
  end
183
169
  end
184
170
 
185
171
  def show_groups(message, params)
186
- groups = []
187
- message.source.auth_groups.each{|g| groups << g.name}
188
- if(groups.empty?)
172
+ groups = message.source.auth_groups.map{|g| g.name}
173
+ if(groups.nil? || groups.empty?)
189
174
  reply message.replyto, "You are not currently a member of any groups"
190
175
  else
191
- reply message.replyto, "\2Groups (#{message.source.nick}):\2 #{groups.join(', ')}"
176
+ reply message.replyto, "\2Groups (#{message.source.nick}):\2 #{groups.sort.join(', ')}"
192
177
  end
193
178
  end
194
179
 
@@ -199,11 +184,10 @@ class Authenticator < ModSpox::Plugin
199
184
  group = Models::Group.filter(:name => params[:group]).first
200
185
  nick = Models::Nick.locate(params[:nick])
201
186
  if(group)
202
- nick.auth.group = group
203
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Nick #{params[:nick]} has been added to the group: #{params[:group]}")
187
+ nick.auth.add_group(group)
188
+ information message.replyto, "Nick #{params[:nick]} has been added to the group: #{params[:group]}"
204
189
  else
205
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find authentication group: #{params[:group]}")
206
-
190
+ error message.replyto, "Failed to find authentication group: #{params[:group]}"
207
191
  end
208
192
  end
209
193
 
@@ -214,29 +198,29 @@ class Authenticator < ModSpox::Plugin
214
198
  group = Models::Group.filter(:name => params[:group]).first
215
199
  nick = Helpers.find_model(params[:nick], false)
216
200
  if(group && nick)
217
- nick.remove_group(group)
218
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Removed #{params[:nick]} from the #{params[:group]} authentication group.")
201
+ nick.auth.remove_group(group)
202
+ information message.replyto, "Removed #{params[:nick]} from the #{params[:group]} authentication group."
219
203
  else
220
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find nick: #{params[:nick]}") unless nick
221
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find group: #{params[:group]}") unless group
204
+ error message.replyto, "Failed to find nick: #{params[:nick]}" unless nick
205
+ error message.replyto, "Failed to find group: #{params[:group]}" unless group
222
206
  end
223
207
  end
224
208
 
225
209
  # message:: ModSpox::Messages::Incoming::Privmsg
226
210
  # params:: Signature parameters
227
211
  # Send WHOIS for nick
228
- def send_whois(message, params)
229
- message.source.clear_auth
230
- @pipeline << Messages::Outgoing::Whois.new(message.source.nick)
212
+ def do_ident(message, params)
213
+ message.source.check_masks
214
+ check_nickserv(message.source, true)
215
+ #@pipeline << Messages::Outgoing::Whois.new(message.source.nick)
231
216
  end
232
217
 
233
218
  # message:: ModSpox::Messages::Incoming::Privmsg
234
219
  # params:: Signature parameters
235
220
  # Display all available authentication groups
236
221
  def list_groups(message, params)
237
- groups = []
238
- Models::Group.all.each{|g| groups << g.name}
239
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "\2Groups:\2 #{groups.join(', ')}")
222
+ groups = Models::Group.all.map{|g| g.name}
223
+ information message.replyto, "\2Groups:\2 #{groups.sort.join(', ')}"
240
224
  end
241
225
 
242
226
  # message:: ModSpox::Messages::Incoming::Privmsg
@@ -246,46 +230,57 @@ class Authenticator < ModSpox::Plugin
246
230
  group = Models::Group.filter(:name => params[:group]).first
247
231
  if(group)
248
232
  nicks = []
233
+ group.auths.each{|a| nicks << a.nick.nick}
249
234
  masks = []
250
- Models::AuthGroup.filter(:group_id => group.pk).each do |ag|
251
- if(ag.auth.nick)
252
- nicks << ag.auth.nick.nick
253
- end
254
- if(ag.auth.mask)
255
- masks << ag.auth.mask
256
- end
257
- end
235
+ group.auth_masks.each{|a| masks << a.map}
258
236
  output = []
259
237
  output << "\2Nicks:\2 #{nicks.join(', ')}" if nicks.size > 0
260
238
  output << "\2Masks:\2 #{masks.join(' | ')}" if masks.size > 0
261
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "\2Group #{params[:group]}:\2 #{output.join('. ')}")
239
+ information message.replyto, "\2Group #{params[:group]}:\2 #{output.join('. ')}"
262
240
  else
263
- @pipeline << Messages::Outgoing::Privmsg.new(message.replyto, "Failed to find group named: #{params[:group]}")
241
+ error message.replyto, "Failed to find group named: #{params[:group]}"
242
+ end
243
+ end
244
+
245
+ def check_notice(m)
246
+ if(m.source.is_a?(Models::Nick) && m.source.nick.downcase == 'nickserv' && m.source.host == 'dal.net')
247
+ message = m.message.dup
248
+ nick = message.slice!(0..message.index(' ')-1)
249
+ message.slice!(0)
250
+ message.slice!(0..message.index(' '))
251
+ setting = message.to_i
252
+ if(setting == 3)
253
+ user = Helpers.find_model(nick)
254
+ user.auth.services_identified = true
255
+ Logger.info("User has been authenticated through NickServ services. (#{user.nick})")
256
+ end
264
257
  end
265
258
  end
266
259
 
267
260
  # Populates array with nicks that authenticate by nickserv
268
261
  def populate_nickserv
262
+ @nickserv_nicks.clear
269
263
  Models::Auth.filter('services = ?', true).each do |auth|
270
264
  @nickserv_nicks << auth.nick.nick.downcase
271
265
  end
272
266
  end
273
267
 
274
- def check_nickserv(nick)
268
+ def check_nickserv(nick, force=false)
269
+ populate_nickserv if @nickserv_nicks.empty?
275
270
  if(@nickserv_nicks.include?(nick.nick.downcase))
276
- if(!nick.auth.authed && !@whois_cache.include?(nick.nick.downcase))
277
- @pipeline << Messages::Outgoing::Whois.new(nick)
278
- @whois_cache << nick.nick.downcase
271
+ if(force || (!nick.auth.authed && !@nickserv_cache.include?(nick.nick.downcase)))
272
+ @nickserv_cache << nick.nick.downcase unless @nickserv_cache.include?(nick.nick.downcase)
273
+ @pipeline << Messages::Outgoing::Raw.new("nickserv ACC #{nick.nick}")
279
274
  end
280
275
  end
281
276
  end
282
277
 
283
278
  def check_join(message)
284
- check_nickserv(message.nick)
279
+ check_nickserv(message.nick) unless message.nick == me
285
280
  end
286
281
 
287
282
  def check_nicks(message)
288
- message.nicks.each{|nick| check_nickserv(nick) }
283
+ @pipeline << Messages::Internal::TimerAdd.new(self, 20, nil, true){ message.nicks.each{|nick| check_nickserv(nick) } }
289
284
  end
290
285
 
291
286
  end
@@ -6,33 +6,19 @@ class Banner < ModSpox::Plugin
6
6
  def initialize(pipeline)
7
7
  super
8
8
  admin = Group.find_or_create(:name => 'banner')
9
- Signature.find_or_create(:signature => 'ban (\S+)', :plugin => name, :method => 'default_ban', :group_id => admin.pk,
10
- :description => 'Kickban given nick from current channel').params = [:nick]
11
- Signature.find_or_create(:signature => 'ban (\S+) (\S+)', :plugin => name, :method => 'channel_ban', :group_id => admin.pk,
12
- :description => 'Kickban given nick from given channel').params = [:nick, :channel]
13
- Signature.find_or_create(:signature => 'ban (\S+) (\S+) (\d+) ?(.+)?', :plugin => name, :method => 'full_ban', :group_id => admin.pk,
14
- :description => 'Kickban given nick from given channel for given number of seconds').params = [:nick, :channel, :time, :message]
15
- Signature.find_or_create(:signature => 'banmask (\S+) (\S+) (\d+) ?(.+)?', :plugin => name, :method => 'message_mask_ban', :group_id => admin.pk,
16
- :description => 'Kickban given mask from given channel for given number of seconds providing an optional message'
17
- ).params = [:mask, :channel, :time, :message]
18
- Signature.find_or_create(:signature => 'banmask list', :plugin => name, :method => 'mask_list', :group_id => admin.pk,
19
- :description => 'List all currently active banmasks')
20
- Signature.find_or_create(:signature => 'banmask remove (\d+)', :plugin => name, :method => 'mask_remove', :group_id => admin.pk,
21
- :description => 'Remove a currently enabled ban mask').params = [:id]
22
- Signature.find_or_create(:signature => 'banlist', :plugin => name, :method => 'ban_list', :group_id => admin.pk,
23
- :description => 'List all currently active bans generated from the bot')
24
- Signature.find_or_create(:signature => 'banlist remove (\d+)', :plugin => name, :method => 'ban_remove', :group_id => admin.pk,
25
- :description => 'Remove a current ban').params = [:id]
26
- Signature.find_or_create(:signature => 'exempt mode ([ov]) ?(\S+)?', :plugin => name, :method => 'exempt_mode', :group_id => admin.pk,
27
- :description => 'Exempt given modes from kick. Apply to all channels if one is not provided').params = [:mode, :channel]
28
- Signature.find_or_create(:signature => 'exempt nick (\S+) ?(\S+)?', :plugin => name, :method => 'exempt_nick', :group_id => admin.pk,
29
- :description => 'Exempt a nick from kicks globally or per channel').params = [:nick, :channel]
30
- Signature.find_or_create(:signature => 'exempt source (\S+)', :plugin => name, :method => 'exempt_source', :group_id => admin.pk,
31
- :description => 'Exempt a source from kicks globally or per channel').params = [:source, :channel]
32
- Signature.find_or_create(:signature => 'exempt list (nick|mode|source)', :plugin => name, :method => 'exempt_list', :group_id => admin.pk,
33
- :description => 'List current exemptions of given type').params = [:type]
34
- Signature.find_or_create(:signature => 'exempt remove (nick|mode|source) (\d+)', :plugin => name, :method => 'exempt_remove', :group_id => admin.pk,
35
- :description => 'Remove exemption from given type').params = [:type, :id]
9
+ add_sig(:sig => 'ban (\S+)', :method => :default_ban, :group => admin, :desc => 'Kickban given nick from current channel', :params => [:nick])
10
+ add_sig(:sig => 'ban (\S+) (\S+)', :method => :channel_ban, :group => admin, :desc => 'Kickban given nick from given channel', :params => [:nick, :channel])
11
+ add_sig(:sig => 'ban (\S+) (\S+) (\d+) ?(.+)?', :method => :full_ban, :group => admin, :desc => 'Kickban given nick from given channel for given number of seconds', :params => [:nick, :channel, :time, :message])
12
+ add_sig(:sig => 'banmask (\S+) (\S+) (\d+) ?(.+)?', :method => :message_mask_ban, :group => admin, :desc => 'Kickban given mask from given channel for given number of seconds providing an optional message', :params => [:mask, :channel, :time, :message])
13
+ add_sig(:sig => 'banmask list', :method => :mask_list, :group => admin, :desc => 'List all currently active banmasks')
14
+ add_sig(:sig => 'banmask remove (\d+)', :method => :mask_remove, :group => admin, :desc => 'Remove a currently enabled ban mask', :params => [:id])
15
+ add_sig(:sig => 'banlist', :method => :ban_list, :group => admin, :desc => 'List all currently active bans generated from the bot')
16
+ add_sig(:sig => 'banlist remove (\d+)', :method => :ban_remove, :group => admin, :desc => 'Remove a current ban', :params => [:id])
17
+ add_sig(:sig => 'exempt mode ([ov]) ?(\S+)?', :method => :exempt_mode, :group => admin, :desc => 'Exempt given modes from kick. Apply to all channels if one is not provided', :params => [:mode, :channel])
18
+ add_sig(:sig => 'exempt nick (\S+) ?(\S+)?', :method => :exempt_nick, :group => admin, :desc => 'Exempt a nick from kicks globally or per channel', :params => [:nick, :channel])
19
+ add_sig(:sig => 'exempt source (\S+)', :method => :exempt_source, :group => admin, :desc => 'Exempt a source from kicks globally or per channel', :params => [:source, :channel])
20
+ add_sig(:sig => 'exempt list (nick|mode|source)', :method => :exempt_list, :group => admin, :desc => 'List current exemptions of given type', :params => [:type])
21
+ add_sig(:sig => 'exempt remove (nick|mode|source) (\d+)', :method => :exempt_remove, :group => admin, :desc => 'Remove exemption from given type', :params => [:type, :id])
36
22
  @pipeline.hook(self, :mode_check, :Incoming_Mode)
37
23
  @pipeline.hook(self, :join_check, :Incoming_Join)
38
24
  @pipeline.hook(self, :who_check, :Incoming_Who)
@@ -197,7 +183,7 @@ class Banner < ModSpox::Plugin
197
183
  # List all currently active bans originating from the bot
198
184
  def ban_list(message, params)
199
185
  set = BanRecord.filter(:removed => false)
200
- if(set.size > 0)
186
+ if(set.count > 0)
201
187
  reply(message.replyto, "Currently active bans:")
202
188
  set.each do |record|
203
189
  remains = record.remaining.to_i - (Object::Time.now.to_i - @time.to_i)
@@ -477,16 +463,11 @@ class Banner < ModSpox::Plugin
477
463
  foreign_key :nick_id, :null => false, :table => :nicks, :key => :id
478
464
  end
479
465
 
480
- before_create do
481
- update_values(:stamp => Object::Time.now)
482
- end
483
-
484
- def channel
485
- ModSpox::Models::Channel[channel_id]
486
- end
466
+ many_to_one :channel, :class => ModSpox::Models::Channel
467
+ many_to_one :nick, :class => ModSpox::Models::Nick
487
468
 
488
- def nick
489
- ModSpox::Models::Nick[nick_id]
469
+ def before_create
470
+ update(:stamp => Object::Time.now)
490
471
  end
491
472
  end
492
473
 
@@ -500,9 +481,7 @@ class Banner < ModSpox::Plugin
500
481
  foreign_key :channel_id, :null => false, :table => :channels, :key => :id
501
482
  end
502
483
 
503
- def channel
504
- ModSpox::Models::Channel[channel_id]
505
- end
484
+ many_to_one :channel, :class => ModSpox::Models::Channel
506
485
 
507
486
  def self.map_masks
508
487
  masks = {}
@@ -521,14 +500,9 @@ class Banner < ModSpox::Plugin
521
500
  foreign_key :nick_id, :table => :nicks, :null => false, :key => :id
522
501
  foreign_key :channel_id, :table => :channels, :key => :id
523
502
  end
524
-
525
- def nick
526
- return Models::Nick[nick_id]
527
- end
528
-
529
- def channel
530
- return Models::Channel[channel_id]
531
- end
503
+
504
+ many_to_one :nick, :class => ModSpox::Models::Nick
505
+ many_to_one :channel, :class => ModSpox::Models::Channel
532
506
  end
533
507
 
534
508
  class BanSourceExempt < Sequel::Model
@@ -538,16 +512,14 @@ class Banner < ModSpox::Plugin
538
512
  foreign_key :channel_id, :table => :channels, :key => :id
539
513
  end
540
514
 
541
- def channel
542
- return Models::Channel[channel_id]
543
- end
515
+ many_to_one :channel, :class => ModSpox::Models::Channel
544
516
 
545
517
  def mask
546
518
  return values[:source] ? Marshal.load(values[:source].unpack('m')[0]) : nil
547
519
  end
548
520
 
549
521
  def mask=(val)
550
- update_values(:source => [Marshal.dump(val)].pack('m'))
522
+ update(:source => [Marshal.dump(val)].pack('m'))
551
523
  end
552
524
 
553
525
  end
@@ -559,10 +531,8 @@ class Banner < ModSpox::Plugin
559
531
  foreign_key :channel_id, :table => :channels, :key => :id
560
532
  index [:channel_id, :mode]
561
533
  end
562
-
563
- def channel
564
- return Models::Channel[channel_id]
565
- end
534
+
535
+ many_to_one :channel, :class => ModSpox::Models::Channel
566
536
  end
567
537
 
568
538
  class NotOperator < Exceptions::BotException