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
@@ -0,0 +1,28 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestPongHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @test = {
9
+ :good => ':swiftco.wa.us.dal.net PONG swiftco.wa.us.dal.net :FOO',
10
+ :bad => ':bad PONG fail'
11
+ }
12
+ end
13
+
14
+ def test_expected
15
+ assert_equal(:PONG, @bot.factory.find_key(@test[:good]))
16
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:good])].process(@test[:good])
17
+ assert_kind_of(ModSpox::Messages::Incoming::Ping, result)
18
+ assert_equal(@test[:good], result.raw_content)
19
+ assert_kind_of(String, result.string)
20
+ assert_kind_of(String, result.server)
21
+ assert_equal('swiftco.wa.us.dal.net', result.server)
22
+ assert_equal('FOO', result.string)
23
+ end
24
+
25
+ def test_unexpected
26
+ assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad]))
27
+ end
28
+ end
@@ -0,0 +1,85 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestPrivmsgHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @test = {
9
+ :nick_to_channel => ':spox!~spox@host PRIVMSG #m :foobar',
10
+ :nick_to_nick => ':spox!~spox@host PRIVMSG mod_spox :foobar',
11
+ :nick_to_channel_addressed => ':spox!~spox@host PRIVMSG #m :mod_spox: foobar',
12
+ :bad => ':fubared PRIVMSG fail whale'
13
+ }
14
+ end
15
+
16
+ def test_nick_to_channel
17
+ assert_equal(:PRIVMSG, @bot.factory.find_key(@test[:nick_to_channel]))
18
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:nick_to_channel])].process(@test[:nick_to_channel])
19
+ assert_kind_of(ModSpox::Messages::Incoming::Privmsg, result)
20
+ assert_equal(@test[:nick_to_channel], result.raw_content)
21
+ assert_kind_of(ModSpox::Models::Channel, result.target)
22
+ assert_equal('#m', result.target.name)
23
+ assert_kind_of(ModSpox::Models::Nick, result.source)
24
+ assert_equal('spox', result.source.nick)
25
+ assert_kind_of(String, result.message)
26
+ assert_equal('foobar', result.message)
27
+ assert(!result.is_private?)
28
+ assert(result.is_public?)
29
+ assert(!result.addressed?)
30
+ assert(!result.is_action?)
31
+ assert(!result.is_colored?)
32
+ assert(!result.is_ctcp?)
33
+ assert(!result.is_dcc?)
34
+ assert_equal(result.message_nocolor, result.message)
35
+ assert_equal(result.target, result.replyto)
36
+ end
37
+
38
+ def test_nick_to_channel_addressed
39
+ assert_equal(:PRIVMSG, @bot.factory.find_key(@test[:nick_to_channel_addressed]))
40
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:nick_to_channel_addressed])].process(@test[:nick_to_channel_addressed])
41
+ assert_kind_of(ModSpox::Messages::Incoming::Privmsg, result)
42
+ assert_equal(@test[:nick_to_channel_addressed], result.raw_content)
43
+ assert_kind_of(ModSpox::Models::Channel, result.target)
44
+ assert_equal('#m', result.target.name)
45
+ assert_kind_of(ModSpox::Models::Nick, result.source)
46
+ assert_equal('spox', result.source.nick)
47
+ assert_kind_of(String, result.message)
48
+ assert_equal('mod_spox: foobar', result.message)
49
+ assert(!result.is_private?)
50
+ assert(result.is_public?)
51
+ assert(result.addressed?)
52
+ assert(!result.is_action?)
53
+ assert(!result.is_colored?)
54
+ assert(!result.is_ctcp?)
55
+ assert(!result.is_dcc?)
56
+ assert_equal(result.message_nocolor, result.message)
57
+ assert_equal(result.target, result.replyto)
58
+ end
59
+
60
+ def test_nick_to_nick
61
+ assert_equal(:PRIVMSG, @bot.factory.find_key(@test[:nick_to_nick]))
62
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:nick_to_nick])].process(@test[:nick_to_nick])
63
+ assert_kind_of(ModSpox::Messages::Incoming::Privmsg, result)
64
+ assert_equal(@test[:nick_to_nick], result.raw_content)
65
+ assert_kind_of(ModSpox::Models::Nick, result.target)
66
+ assert_equal('mod_spox', result.target.nick)
67
+ assert_kind_of(ModSpox::Models::Nick, result.source)
68
+ assert_equal('spox', result.source.nick)
69
+ assert_kind_of(String, result.message)
70
+ assert_equal('foobar', result.message)
71
+ assert(result.is_private?)
72
+ assert(!result.is_public?)
73
+ assert(result.addressed?)
74
+ assert(!result.is_action?)
75
+ assert(!result.is_colored?)
76
+ assert(!result.is_ctcp?)
77
+ assert(!result.is_dcc?)
78
+ assert_equal(result.message_nocolor, result.message)
79
+ assert_equal(result.source, result.replyto)
80
+ end
81
+
82
+ def test_unexpected
83
+ assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad]))
84
+ end
85
+ end
@@ -0,0 +1,40 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestQuitHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @test = {
9
+ :w_message => ':spox!~spox@host QUIT :Ping timeout',
10
+ :wo_message => ':spox!~spox@host QUIT :',
11
+ :bad => ':not.configured QUIT fail whale'
12
+ }
13
+ end
14
+
15
+ def test_wo_message
16
+ assert_equal(:QUIT, @bot.factory.find_key(@test[:wo_message]))
17
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:wo_message])].process(@test[:wo_message])
18
+ assert_kind_of(ModSpox::Messages::Incoming::Quit, result)
19
+ assert_equal(@test[:wo_message], result.raw_content)
20
+ assert_kind_of(ModSpox::Models::Nick, result.nick)
21
+ assert_equal('spox', result.nick.nick)
22
+ assert_kind_of(String, result.message)
23
+ assert_equal('', result.message)
24
+ end
25
+
26
+ def test_w_message
27
+ assert_equal(:QUIT, @bot.factory.find_key(@test[:w_message]))
28
+ result = @bot.factory.handlers[@bot.factory.find_key(@test[:w_message])].process(@test[:w_message])
29
+ assert_kind_of(ModSpox::Messages::Incoming::Quit, result)
30
+ assert_equal(@test[:w_message], result.raw_content)
31
+ assert_kind_of(ModSpox::Models::Nick, result.nick)
32
+ assert_equal('spox', result.nick.nick)
33
+ assert_kind_of(String, result.message)
34
+ assert_equal('Ping timeout', result.message)
35
+ end
36
+
37
+ def test_unexpected
38
+ assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:bad])].process(@test[:bad]))
39
+ end
40
+ end
@@ -0,0 +1,50 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestWhoHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @test = {
9
+ :good => [],
10
+ :bad => ':host 352 fail whale'
11
+ }
12
+ @test[:good] << ':host 352 spox #mod_spox ~pizza_ host.1 punch.va.us.dal.net pizza_ H@ :5 pizza_'
13
+ @test[:good] << ':host 352 spox #mod_spox ~pizza_ host.2 punch.va.us.dal.net pizza__ H :5 pizza_'
14
+ @test[:good] << ':host 352 spox #mod_spox ~mod_spox host.3 mozilla.se.eu.dal.net mod_spox H@ :6 mod_spox IRC bot'
15
+ @test[:good] << ':host 352 spox #mod_spox ~spox host.4 swiftco.wa.us.dal.net spox H@ :0 spox'
16
+ @test[:good] << ':host 315 spox #mod_spox :End of /WHO list.'
17
+ @queue = Queue.new
18
+ @bot.pipeline.hook(self, :gather, :Incoming_Who)
19
+ @nicks = ['pizza_', 'pizza__', 'spox', 'mod_spox']
20
+ @ops = ['pizza_', 'spox', 'mod_spox']
21
+ end
22
+
23
+ def gather(m)
24
+ @queue << m
25
+ end
26
+
27
+ def test_expected
28
+ 4.times{ @bot.factory << @test[:good].shift }
29
+ sleep(0.5) # wait for much longer than needed to check queue
30
+ assert_equal(0, @queue.size)
31
+ @bot.factory << @test[:good].shift
32
+ sleep(0.1)
33
+ assert_equal(1, @queue.size)
34
+ m = @queue.pop
35
+ assert_kind_of(ModSpox::Messages::Incoming::Who, m)
36
+ assert_kind_of(ModSpox::Models::Channel, m.location)
37
+ assert_equal('#mod_spox', m.location.name)
38
+ assert_kind_of(Array, m.nicks)
39
+ assert_equal(4, m.nicks.size)
40
+ m.nicks.each do |nick|
41
+ assert(@nicks.include?(nick.nick))
42
+ assert(nick.channels.map{|c|c.name}.include?('#mod_spox'))
43
+ assert_equal(@ops.include?(nick.nick), nick.is_op?(m.location))
44
+ end
45
+ end
46
+
47
+ def test_unexpected
48
+ assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:bad].dup)].process(@test[:bad].dup))
49
+ end
50
+ end
@@ -0,0 +1,61 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestWhoHandler < Test::Unit::TestCase
4
+
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @test = {
9
+ :good => [],
10
+ :bad => ':host 319 fail whale'
11
+ }
12
+ @test[:good] << ':swiftco.wa.us.dal.net 311 spox spox ~spox myhost.com * :spox'
13
+ @test[:good] << ':swiftco.wa.us.dal.net 319 spox spox :@#php #python +#!php +#ruby #mysql @#mod_spox'
14
+ @test[:good] << ':swiftco.wa.us.dal.net 312 spox spox swiftco.wa.us.dal.net :www.swiftco.net - Swift Communications'
15
+ @test[:good] << ':swiftco.wa.us.dal.net 307 spox spox :has identified for this nick'
16
+ @test[:good] << ':swiftco.wa.us.dal.net 317 spox spox 176 1242140666 :seconds idle, signon time'
17
+ @test[:good] << ':swiftco.wa.us.dal.net 318 spox spox :End of /WHOIS list.'
18
+ @queue = Queue.new
19
+ @bot.pipeline.hook(self, :gather, :Incoming_Whois)
20
+ @voice = ['#ruby', '#!php']
21
+ @ops = ['#php', '#mod_spox']
22
+ nick = ModSpox::Models::Nick.find_or_create(:nick => 'spox')
23
+ nick.auth.services = true
24
+ nick.auth.save
25
+ @con = Time.at(1242140666)
26
+ end
27
+
28
+ def gather(m)
29
+ @queue << m
30
+ end
31
+
32
+ def test_expected
33
+ 5.times{ @bot.factory << @test[:good].shift }
34
+ sleep(0.5) # wait for much longer than needed to check queue
35
+ assert_equal(0, @queue.size)
36
+ @bot.factory << @test[:good].shift
37
+ sleep(0.1) # make sure the message is waiting for us
38
+ assert_equal(1, @queue.size)
39
+ m = @queue.pop
40
+ assert_kind_of(ModSpox::Messages::Incoming::Whois, m)
41
+ assert_equal('spox', m.nick.nick)
42
+ assert_equal(6, m.channels.size)
43
+ assert(m.nick.auth.services)
44
+ @voice.each do |chan|
45
+ assert(m.nick.is_voice?(ModSpox::Helpers.find_model(chan)))
46
+ end
47
+ @ops.each do |chan|
48
+ assert(m.nick.is_op?(ModSpox::Helpers.find_model(chan)))
49
+ end
50
+ assert_equal(@con, m.nick.connected_at)
51
+ assert_equal(176, m.nick.seconds_idle)
52
+ assert_equal('swiftco.wa.us.dal.net', m.nick.connected_to)
53
+ assert_equal('~spox', m.nick.username)
54
+ assert_equal('myhost.com', m.nick.host)
55
+ assert_equal('spox', m.nick.real_name)
56
+ end
57
+
58
+ def test_unexpected
59
+ assert_nil(@bot.factory.handlers[@bot.factory.find_key(@test[:bad].dup)].process(@test[:bad].dup))
60
+ end
61
+ end
@@ -0,0 +1,34 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+ require 'digest/sha1'
3
+
4
+ class TestAuthModel < Test::Unit::TestCase
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ @nick = ModSpox::Models::Nick.find_or_create(:nick => 'foobar')
9
+ end
10
+
11
+ def teardown
12
+ @nick.auth.authed = false
13
+ end
14
+
15
+ def test_create
16
+ assert_kind_of(ModSpox::Models::Auth, @nick.auth)
17
+ end
18
+
19
+ def test_password
20
+ password = 'password'
21
+ c_pass = Digest::SHA1.hexdigest(password)
22
+ @nick.auth.password = password
23
+ assert_equal(c_pass, @nick.auth.password)
24
+ @nick.check_password(password)
25
+ assert(@nick.auth.authed)
26
+ end
27
+
28
+ def test_services
29
+ @nick.auth.services = true
30
+ @nick.auth.services_identified = true
31
+ assert(@nick.auth.authed)
32
+ end
33
+
34
+ end
@@ -0,0 +1,52 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestNickModel < Test::Unit::TestCase
4
+ def setup
5
+ h = BotHolder.instance
6
+ @bot = h.bot
7
+ @nick = ModSpox::Models::Nick.find_or_create(:nick => 'foobar')
8
+ @channel = ModSpox::Models::Channel.find_or_create(:name => '#test')
9
+ end
10
+
11
+ def teardown
12
+ @channel.remove_all_nicks
13
+ end
14
+
15
+ def test_create
16
+ assert_kind_of(ModSpox::Models::Channel, @channel)
17
+ assert_equal('#test', @channel.name)
18
+ end
19
+
20
+ def test_create_case
21
+ t = ModSpox::Models::Channel.find_or_create(:name => '#TEst')
22
+ assert_equal('#test', t.name)
23
+ end
24
+
25
+ def test_single_mode
26
+ @channel.set_mode('s')
27
+ assert(@channel.set?('s'))
28
+ @channel.unset_mode('s')
29
+ assert(!@channel.set?('s'))
30
+ end
31
+
32
+ def test_multiple_mode
33
+ @channel.set_mode('stn')
34
+ assert(@channel.set?('s'))
35
+ assert(@channel.set?('t'))
36
+ assert(@channel.set?('n'))
37
+ @channel.clear_modes
38
+ assert(!@channel.set?('s'))
39
+ assert(!@channel.set?('t'))
40
+ assert(!@channel.set?('n'))
41
+ end
42
+
43
+ def test_nick
44
+ @channel.add_nick(@nick)
45
+ assert(@nick.channels.include?(@channel))
46
+ assert(@channel.nicks.include?(@nick))
47
+ @channel.remove_nick(@nick)
48
+ assert(!@nick.channels.include?(@channel))
49
+ assert(!@channel.nicks.include?(@nick))
50
+ end
51
+
52
+ end
@@ -0,0 +1,19 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+ require 'digest/sha1'
3
+
4
+ class TestConfigModel < Test::Unit::TestCase
5
+ def setup
6
+ h = BotHolder.instance
7
+ @bot = h.bot
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ def test_signature
14
+ ModSpox::Models::Config.set(:testing, 'a test')
15
+ assert_equal('a test', ModSpox::Models::Config.val(:testing))
16
+ assert(ModSpox::Models::Config.val(:testing) == 'a test')
17
+ end
18
+
19
+ end
@@ -0,0 +1,142 @@
1
+ require "#{File.dirname(__FILE__)}/../BotHolder.rb"
2
+
3
+ class TestNickModel < Test::Unit::TestCase
4
+ def setup
5
+ h = BotHolder.instance
6
+ @bot = h.bot
7
+ @nick = ModSpox::Models::Nick.find_or_create(:nick => 'foobar')
8
+ @group = ModSpox::Models::Group.find_or_create(:name => 'test')
9
+ @channel = ModSpox::Models::Channel.find_or_create(:name => '#test')
10
+ end
11
+
12
+ def teardown
13
+ @nick.auth.authed = false
14
+ @nick.auth.remove_all_groups
15
+ @nick.clear_channels
16
+ end
17
+
18
+ def test_nick
19
+ assert_equal('foobar', @nick.nick)
20
+ end
21
+
22
+ def test_nick_case
23
+ nick = ModSpox::Models::Nick.find_or_create(:nick => 'FooBaR')
24
+ nick.refresh
25
+ assert_equal('foobar', nick.nick)
26
+ end
27
+
28
+ def test_address
29
+ @nick.address = 'some.domain'
30
+ assert_equal('some.domain', @nick.address)
31
+ assert_equal('some.domain', @nick.host)
32
+ end
33
+
34
+ def test_visible
35
+ @nick.visible = true
36
+ @nick.address = 'some.domain'
37
+ @nick.real_name = 'foo bar'
38
+ @nick.username = '~spox'
39
+ @nick.source = 'spox!~spox@some.domain'
40
+ @nick.connected_at = Time.now
41
+ @nick.connected_to = 'irc.domain'
42
+ @nick.seconds_idle = 10
43
+ @nick.away = true
44
+ @nick.save_changes
45
+ @nick.refresh
46
+ @nick.visible = false
47
+ @nick.refresh
48
+ assert_nil(@nick.address)
49
+ assert_nil(@nick.real_name)
50
+ assert_nil(@nick.username)
51
+ assert_nil(@nick.source)
52
+ assert_nil(@nick.connected_at)
53
+ assert_nil(@nick.connected_to)
54
+ assert_nil(@nick.seconds_idle)
55
+ assert(!@nick.away)
56
+ end
57
+
58
+ def test_auth
59
+ assert_kind_of(ModSpox::Models::Auth, @nick.auth)
60
+ end
61
+
62
+ def test_auth_groups
63
+ assert_kind_of(Array, @nick.auth_groups)
64
+ assert(@nick.auth_groups.empty?)
65
+ end
66
+
67
+ def test_add_group
68
+ @nick.auth.add_group(@group)
69
+ @nick.auth.authed = true
70
+ assert(@nick.auth_groups.include?(@group))
71
+ end
72
+
73
+ def test_in_group
74
+ @nick.auth.add_group(@group)
75
+ @nick.auth.authed = true
76
+ assert(@nick.in_group?(@group))
77
+ end
78
+
79
+ def test_not_in_group
80
+ assert(!@nick.in_group?(@group))
81
+ end
82
+
83
+ def test_clear_channels
84
+ @nick.visible = true
85
+ @nick.refresh
86
+ @nick.add_channel(@channel)
87
+ assert_equal(1, @nick.channels.size)
88
+ @nick.clear_channels
89
+ assert(!@nick.visible)
90
+ assert_equal(0, @nick.channels.size)
91
+ end
92
+
93
+ def test_channel_op
94
+ @nick.visible = true
95
+ @nick.add_channel(@channel)
96
+ assert(!@nick.is_op?(@channel))
97
+ m = ModSpox::Models::NickMode.find_or_create(:nick_id => @nick.pk, :channel_id => @channel.pk)
98
+ m.set_mode('o')
99
+ assert(@nick.is_op?(@channel))
100
+ end
101
+
102
+ def test_channel_voice
103
+ @nick.visible = true
104
+ @nick.add_channel(@channel)
105
+ assert(!@nick.is_voice?(@channel))
106
+ m = ModSpox::Models::NickMode.find_or_create(:nick_id => @nick.pk, :channel_id => @channel.pk)
107
+ m.set_mode('v')
108
+ assert(@nick.is_voice?(@channel))
109
+ end
110
+
111
+ def test_nochannel_op_voice
112
+ assert_raise(ModSpox::Exceptions::NotInChannel){@nick.is_voice?(@channel)}
113
+ assert_raise(ModSpox::Exceptions::NotInChannel){@nick.is_op?(@channel)}
114
+ end
115
+
116
+ def test_set_mode
117
+ @nick.set_mode('ir')
118
+ assert(@nick.mode_set?('i'))
119
+ assert(@nick.mode_set?('r'))
120
+ assert(!@nick.mode_set?('o'))
121
+ end
122
+
123
+ def test_unset_mode
124
+ @nick.set_mode('ir')
125
+ assert(@nick.mode_set?('i'))
126
+ assert(@nick.mode_set?('r'))
127
+ @nick.unset_mode('ir')
128
+ assert(!@nick.mode_set?('i'))
129
+ assert(!@nick.mode_set?('r'))
130
+ end
131
+
132
+ def test_channel
133
+ @nick.add_channel(@channel)
134
+ assert(@nick.channels.include?(@channel))
135
+ assert(@channel.nicks.include?(@nick))
136
+ @nick.remove_channel(@channel)
137
+ assert(!@nick.channels.include?(@channel))
138
+ assert(!@channel.nicks.include?(@nick))
139
+ end
140
+
141
+
142
+ end