minecraft 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +8 -0
- data/lib/minecraft/commands.rb +49 -51
- data/lib/minecraft/extensions.rb +14 -14
- data/lib/minecraft/version.rb +1 -1
- data/test/commands_test.rb +219 -249
- data/test/extensions_test.rb +38 -55
- data/test/helper.rb +29 -1
- metadata +2 -2
data/CHANGES.md
CHANGED
data/lib/minecraft/commands.rb
CHANGED
@@ -143,7 +143,7 @@ module Minecraft
|
|
143
143
|
@server.puts "say Disco ends."
|
144
144
|
@disco = false
|
145
145
|
else
|
146
|
-
|
146
|
+
say("#{user} has requested disco, s/he likely can't actually dance.")
|
147
147
|
@disco = true
|
148
148
|
end
|
149
149
|
end
|
@@ -157,10 +157,10 @@ module Minecraft
|
|
157
157
|
def dnd(user)
|
158
158
|
user.downcase!
|
159
159
|
if @userdnd.include? user
|
160
|
-
|
160
|
+
say("#{user} is ready to be disturbed. *cough*")
|
161
161
|
@userdnd.reject! { |u| u == user }
|
162
162
|
else
|
163
|
-
|
163
|
+
say("#{user} does not wish to be disturbed.")
|
164
164
|
@userdnd << user
|
165
165
|
end
|
166
166
|
end
|
@@ -173,7 +173,7 @@ module Minecraft
|
|
173
173
|
# disturb("basicxman", "mike_n_7")
|
174
174
|
# @note ops: op
|
175
175
|
def disturb(user, target_user)
|
176
|
-
|
176
|
+
say("#{target_user} is being disturbed by #{user}!")
|
177
177
|
@userdnd.reject! { |u| u == target_user.downcase }
|
178
178
|
end
|
179
179
|
|
@@ -182,7 +182,7 @@ module Minecraft
|
|
182
182
|
# @param [String] user The requesting user.
|
183
183
|
# @example
|
184
184
|
# printdnd()
|
185
|
-
# @note
|
185
|
+
# @note ops: op
|
186
186
|
def printdnd()
|
187
187
|
@server.puts "say #{@userdnd.join(", ")}"
|
188
188
|
end
|
@@ -201,7 +201,7 @@ module Minecraft
|
|
201
201
|
target_user = target_user.downcase
|
202
202
|
num_points = num_points.to_i
|
203
203
|
if user.downcase == target_user
|
204
|
-
|
204
|
+
say("Did you just try to give yourself points? Sure, minus twenty.")
|
205
205
|
@userpoints[target_user] ||= 0
|
206
206
|
@userpoints[target_user] -= 20
|
207
207
|
return
|
@@ -214,7 +214,7 @@ module Minecraft
|
|
214
214
|
num_points = [num_points, cap_points(user)].min
|
215
215
|
@userpoints[target_user] ||= 0
|
216
216
|
@userpoints[target_user] += num_points
|
217
|
-
|
217
|
+
say("#{user} has given #{target_user} #{num_points} points for a total of #{@userpoints[target_user]}.")
|
218
218
|
end
|
219
219
|
|
220
220
|
# Checks a users points or displays the leaderboard.
|
@@ -262,14 +262,14 @@ module Minecraft
|
|
262
262
|
return @server.puts "say No user #{target_user} exists." unless @users.include? target_user
|
263
263
|
return vote(user) if target_user.nil?
|
264
264
|
unless submit_vote(user, target_user)
|
265
|
-
@
|
265
|
+
@userkickvotes[target_user] = {
|
266
266
|
:tally => kick_influence(user),
|
267
267
|
:votes => [user],
|
268
268
|
:start => Time.now
|
269
269
|
}
|
270
270
|
@last_kick_vote = target_user
|
271
|
-
|
272
|
-
|
271
|
+
say("A kickvote has been initiated for #{target_user}.")
|
272
|
+
say("To vote enter !kickvote #{target_user}.")
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
@@ -293,11 +293,11 @@ module Minecraft
|
|
293
293
|
# cancelvote("basicxman", "blizzard4U")
|
294
294
|
# @note ops: op
|
295
295
|
def cancelvote(user, target_user)
|
296
|
-
if @
|
297
|
-
@
|
298
|
-
|
296
|
+
if @userkickvotes.has_key? target_user
|
297
|
+
@userkickvotes.delete(target_user)
|
298
|
+
say("#{user} has cancelled the kickvote on #{target_user}.")
|
299
299
|
else
|
300
|
-
|
300
|
+
say("There is no kickvote against #{target_user} dummy.")
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
@@ -308,8 +308,8 @@ module Minecraft
|
|
308
308
|
# kickvotes("basicxman")
|
309
309
|
# @note ops: op
|
310
310
|
def kickvotes(user)
|
311
|
-
@
|
312
|
-
|
311
|
+
@userkickvotes.each do |target_user, data|
|
312
|
+
say("#{target_user}: #{data[:tally]} #{data[:votes]}")
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
@@ -323,7 +323,7 @@ module Minecraft
|
|
323
323
|
def roulette(user)
|
324
324
|
users = @users + [user] * 3
|
325
325
|
picked_user = users.sample
|
326
|
-
|
326
|
+
say("#{user} has requested a roulette kick, s/he has a higher chance of being kicked.")
|
327
327
|
@server.puts "kick #{picked_user}"
|
328
328
|
end
|
329
329
|
|
@@ -450,11 +450,9 @@ module Minecraft
|
|
450
450
|
# @note ops: op
|
451
451
|
def property(user, key = nil)
|
452
452
|
if key.nil?
|
453
|
-
(@server_properties.
|
454
|
-
@server.puts "say #{@server_properties.keys[n * 3, 3].join(", ")}"
|
455
|
-
end
|
453
|
+
say(@server_properties.keys.join(", "))
|
456
454
|
else
|
457
|
-
|
455
|
+
say ("#{key} is currently #{@server_properties[key]}") if @server_properties.include? key
|
458
456
|
end
|
459
457
|
end
|
460
458
|
|
@@ -472,9 +470,9 @@ module Minecraft
|
|
472
470
|
target_user ||= user
|
473
471
|
unless @users.include? target_user
|
474
472
|
if @userlog.has_key? target_user
|
475
|
-
|
473
|
+
say("#{target_user} has #{format_uptime(@userlog[target_user])} minutes of logged time.")
|
476
474
|
else
|
477
|
-
|
475
|
+
say("#{target_user} Does not exist.")
|
478
476
|
end
|
479
477
|
return
|
480
478
|
end
|
@@ -483,7 +481,7 @@ module Minecraft
|
|
483
481
|
if @userlog.has_key? target_user
|
484
482
|
total = " Out of a total of #{format_uptime(@userlog[target_user] + time_spent)} minutes."
|
485
483
|
end
|
486
|
-
|
484
|
+
say("#{target_user} has been online for #{format_uptime(time_spent)} minutes.#{total}")
|
487
485
|
end
|
488
486
|
|
489
487
|
# Will print the server rules to all connected players.
|
@@ -492,7 +490,7 @@ module Minecraft
|
|
492
490
|
# rules()
|
493
491
|
# @note ops: none
|
494
492
|
def rules()
|
495
|
-
|
493
|
+
say(@rules)
|
496
494
|
end
|
497
495
|
|
498
496
|
# Lists the currently connecting players, noting which is the requesting
|
@@ -514,7 +512,7 @@ module Minecraft
|
|
514
512
|
s + "#{", " unless s.empty?}#{pre}#{u}#{suf}"
|
515
513
|
end
|
516
514
|
|
517
|
-
|
515
|
+
say(l)
|
518
516
|
end
|
519
517
|
|
520
518
|
# Adds a timer to the requesting users timers, the item and frequency in
|
@@ -534,7 +532,7 @@ module Minecraft
|
|
534
532
|
return @server.puts "say Timer was not added." if item.nil?
|
535
533
|
@timers[user] ||= {}
|
536
534
|
@timers[user][item] = duration
|
537
|
-
|
535
|
+
say("Timer added for #{user}. Giving item id #{item} every #{duration} seconds.")
|
538
536
|
end
|
539
537
|
|
540
538
|
# Deletes a timer from the requesting user.
|
@@ -594,17 +592,17 @@ module Minecraft
|
|
594
592
|
def s(user, *args)
|
595
593
|
shortcut_name = args.slice! 0
|
596
594
|
if args.length == 0
|
597
|
-
unless @
|
595
|
+
unless @usershortcuts.has_key? user and @usershortcuts[user].has_key? shortcut_name
|
598
596
|
return kit(user, shortcut_name) if KITS.include? shortcut_name.to_sym
|
599
|
-
|
597
|
+
return say("#{shortcut_name} is not a valid shortcut for #{user}.")
|
600
598
|
end
|
601
|
-
return call_command(user, @
|
599
|
+
return call_command(user, @usershortcuts[user][shortcut_name].first, *@usershortcuts[user][shortcut_name][1..-1]) if args.length == 0
|
602
600
|
end
|
603
601
|
|
604
602
|
command_string = args
|
605
|
-
@
|
606
|
-
@
|
607
|
-
|
603
|
+
@usershortcuts[user] ||= {}
|
604
|
+
@usershortcuts[user][shortcut_name] = command_string
|
605
|
+
say("Shortcut labelled #{shortcut_name} for #{user} has been added.")
|
608
606
|
end
|
609
607
|
|
610
608
|
# Prints the requested users shortcuts.
|
@@ -614,8 +612,8 @@ module Minecraft
|
|
614
612
|
# shortcuts("basicxman")
|
615
613
|
# @note ops: hop
|
616
614
|
def shortcuts(user)
|
617
|
-
labels = @
|
618
|
-
|
615
|
+
labels = @usershortcuts[user].keys.join(", ") if @usershortcuts.has_key? user
|
616
|
+
say("Shortcuts for #{user}: #{labels}.")
|
619
617
|
end
|
620
618
|
|
621
619
|
# Prints the available commands for the user.
|
@@ -734,6 +732,14 @@ module Minecraft
|
|
734
732
|
end
|
735
733
|
end
|
736
734
|
|
735
|
+
# Validates a kit group, if the kit cannot be found it executes the
|
736
|
+
# !kitlist command.
|
737
|
+
def validate_kit(group = "")
|
738
|
+
return true if KITS.include? group.to_sym
|
739
|
+
@server.puts "say #{group} is not a valid kit."
|
740
|
+
kitlist
|
741
|
+
end
|
742
|
+
|
737
743
|
private
|
738
744
|
|
739
745
|
# Prints the command signature options for a specified command.
|
@@ -789,14 +795,6 @@ module Minecraft
|
|
789
795
|
end
|
790
796
|
end
|
791
797
|
|
792
|
-
# Validates a kit group, if the kit cannot be found it executes the
|
793
|
-
# !kitlist command.
|
794
|
-
def validate_kit(group = "")
|
795
|
-
return true if KITS.include? group.to_sym
|
796
|
-
@server.puts "say #{group} is not a valid kit."
|
797
|
-
kitlist
|
798
|
-
end
|
799
|
-
|
800
798
|
# Changes the time of day.
|
801
799
|
#
|
802
800
|
# @param [String] time The time of day to change it to.
|
@@ -816,10 +814,10 @@ module Minecraft
|
|
816
814
|
# @example
|
817
815
|
# check_kickvote("blizzard4U")
|
818
816
|
def check_kickvote(user)
|
819
|
-
if @
|
817
|
+
if @userkickvotes[user][:tally] >= @vote_threshold
|
820
818
|
@server.puts "say Enough votes have been given to kick #{user}."
|
821
819
|
@server.puts "kick #{user}"
|
822
|
-
@
|
820
|
+
@userkickvotes.delete(user)
|
823
821
|
end
|
824
822
|
end
|
825
823
|
|
@@ -837,10 +835,10 @@ module Minecraft
|
|
837
835
|
|
838
836
|
# Checks to see if any kickvotes are expired.
|
839
837
|
def expire_kickvotes
|
840
|
-
@
|
838
|
+
@userkickvotes.each do |target_user, data|
|
841
839
|
if Time.now > data[:start] + @vote_expiration
|
842
840
|
@server.puts "say The kickvote for #{target_user} has expired."
|
843
|
-
@
|
841
|
+
@userkickvotes.delete(target_user)
|
844
842
|
end
|
845
843
|
end
|
846
844
|
end
|
@@ -854,12 +852,12 @@ module Minecraft
|
|
854
852
|
# submit_vote("basicxman", "blizzard4U")
|
855
853
|
def submit_vote(user, target_user)
|
856
854
|
return unless @users.include? target_user
|
857
|
-
if @
|
858
|
-
if @
|
855
|
+
if @userkickvotes.has_key? target_user
|
856
|
+
if @userkickvotes[target_user][:votes].include? user
|
859
857
|
@server.puts "say You have already voted."
|
860
858
|
else
|
861
|
-
@
|
862
|
-
@
|
859
|
+
@userkickvotes[target_user][:votes] << user
|
860
|
+
@userkickvotes[target_user][:tally] += kick_influence(user)
|
863
861
|
check_kickvote(target_user)
|
864
862
|
end
|
865
863
|
return true
|
data/lib/minecraft/extensions.rb
CHANGED
@@ -13,9 +13,9 @@ module Minecraft
|
|
13
13
|
def initialize(server, opts)
|
14
14
|
@ops = File.readlines("ops.txt").map { |s| s.chomp } if File.exists? "ops.txt"
|
15
15
|
get_json :hops, []
|
16
|
-
get_json :
|
16
|
+
get_json :useruptime
|
17
17
|
get_json :timers
|
18
|
-
get_json :
|
18
|
+
get_json :usershortcuts
|
19
19
|
get_json :userlog
|
20
20
|
get_json :userpoints
|
21
21
|
get_json :userdnd, []
|
@@ -26,7 +26,7 @@ module Minecraft
|
|
26
26
|
@counter = 0
|
27
27
|
@logon_time = {}
|
28
28
|
@server = server
|
29
|
-
@
|
29
|
+
@userkickvotes = {}
|
30
30
|
@last_kick_vote = nil
|
31
31
|
load_server_properties
|
32
32
|
|
@@ -40,19 +40,19 @@ module Minecraft
|
|
40
40
|
# Initialize the set of commands.
|
41
41
|
@commands = {}
|
42
42
|
commands = Minecraft::Commands.public_instance_methods
|
43
|
-
@command_info = File.read(method(commands.first).source_location.first).split(
|
43
|
+
@command_info = File.read(method(commands.first).source_location.first).split(/$/)
|
44
44
|
@enums = [ :ops ]
|
45
45
|
commands.each do |sym|
|
46
46
|
next if sym.to_s.end_with? "all"
|
47
|
-
meth
|
47
|
+
meth = method(sym)
|
48
48
|
src_b, src_e = get_comment_range(meth.source_location.last)
|
49
49
|
|
50
50
|
@commands[sym] = {
|
51
51
|
:help => "",
|
52
|
-
:ops => :none,
|
53
52
|
:params => meth.parameters
|
54
53
|
}
|
55
54
|
parse_comments(src_b, src_e, sym)
|
55
|
+
@commands.delete sym if @commands[sym][:ops].nil?
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -105,7 +105,7 @@ module Minecraft
|
|
105
105
|
# Save instance variables to their respective JSON files.
|
106
106
|
def save
|
107
107
|
save_file :timers
|
108
|
-
save_file :
|
108
|
+
save_file :usershortcuts
|
109
109
|
save_file :hops
|
110
110
|
save_file :userpoints
|
111
111
|
save_file :userdnd
|
@@ -176,7 +176,7 @@ module Minecraft
|
|
176
176
|
return unless send("validate_" + root.to_s, *args)
|
177
177
|
end
|
178
178
|
|
179
|
-
is_all =
|
179
|
+
is_all = !@commands[root][:all].nil? if is_all
|
180
180
|
rest_param = @commands[root][:params].count { |a| a.first == :rest }
|
181
181
|
reg_params = @commands[root][:params].count { |a| a.last != :user }
|
182
182
|
|
@@ -213,15 +213,15 @@ module Minecraft
|
|
213
213
|
params = @commands[command.to_sym][:params][1..-1].map { |a| [a[0], a[1].to_s.gsub("_", " ")] }
|
214
214
|
return unless args.length < reg_params
|
215
215
|
|
216
|
-
return
|
216
|
+
return say("Expected at least one argument.") if rest_param == 1
|
217
217
|
req_params = params.count { |a| a.first == :req }
|
218
218
|
if args.length < req_params
|
219
219
|
args.length.times { params.slice! 0 }
|
220
220
|
if params.length == 1
|
221
|
-
return
|
221
|
+
return say("Expected the argument '#{params[0][1]}'")
|
222
222
|
else
|
223
223
|
temp = params.map { |a| "'#{a[1]}'" }
|
224
|
-
return
|
224
|
+
return say("Expected additional arguments, #{temp.join(", ")}")
|
225
225
|
end
|
226
226
|
end
|
227
227
|
end
|
@@ -411,7 +411,7 @@ module Minecraft
|
|
411
411
|
time_spent = calculate_uptime(user)
|
412
412
|
@userlog[user] ||= 0
|
413
413
|
@userlog[user] += time_spent
|
414
|
-
|
414
|
+
say("#{user} spent #{format_uptime(time_spent)} minutes in the server, totalling to #{format_uptime(@userlog[user])}.")
|
415
415
|
save_file :userlog
|
416
416
|
end
|
417
417
|
|
@@ -475,7 +475,7 @@ module Minecraft
|
|
475
475
|
# @return [Boolean] Returns true if the user is an op.
|
476
476
|
def validate_ops(user, command, message = true)
|
477
477
|
return true if is_op? user.downcase
|
478
|
-
|
478
|
+
say("#{user} is not an op, cannot use !#{command}.") if message
|
479
479
|
end
|
480
480
|
|
481
481
|
# Check if a user has half op privileges and print a privilege error if not.
|
@@ -485,7 +485,7 @@ module Minecraft
|
|
485
485
|
# @return [Boolean] Returns true if the user is an op.
|
486
486
|
def validate_hops(user, command, message = true)
|
487
487
|
return true if is_hop? user.downcase
|
488
|
-
|
488
|
+
say("#{user} is not a half-op, cannot use !#{command}.") if message
|
489
489
|
end
|
490
490
|
|
491
491
|
# An error message for invalid commands.
|
data/lib/minecraft/version.rb
CHANGED
data/test/commands_test.rb
CHANGED
@@ -82,46 +82,42 @@ eof
|
|
82
82
|
end
|
83
83
|
|
84
84
|
sandbox_test "give command should give kits for wools" do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
assert_match "give basicxman 35 64", t
|
90
|
-
assert_match "give basicxman 351", t
|
85
|
+
ext :hops => ["basicxman"]
|
86
|
+
call "basicxman give lightgray 2m"
|
87
|
+
assert_match "give basicxman 35 64", output_line
|
88
|
+
assert_match "give basicxman 351", output_line
|
91
89
|
end
|
92
90
|
|
93
91
|
# User points system testing.
|
94
92
|
sandbox_test "should give a user points" do
|
95
|
-
|
96
|
-
|
97
|
-
@ext.ops = ["basicxman"]
|
98
|
-
@ext.hops = ["mike_n_7"]
|
99
|
-
@ext.call_command("basicxman", "points", "Ian_zers", "1001")
|
93
|
+
ext :ops => ["basicxman"], :hops => ["mike_n_7"], :users => ["blizzard4U", "Ian_zers"]
|
94
|
+
call "basicxman points Ian_zers 1001"
|
100
95
|
assert_equal 1000, @ext.userpoints["ian_zers"]
|
101
|
-
|
96
|
+
|
97
|
+
call "mike_n_7 points Ian_zers 501"
|
102
98
|
assert_equal 1500, @ext.userpoints["ian_zers"]
|
103
|
-
|
99
|
+
|
100
|
+
call "blizzard4U points Ian_zers 2"
|
104
101
|
assert_equal 1501, @ext.userpoints["ian_zers"]
|
105
102
|
end
|
106
103
|
|
107
104
|
sandbox_test "should not a let a user give herself points" do
|
108
|
-
|
109
|
-
@ext.users = ["basicxman"]
|
105
|
+
ext :users => ["basicxman"]
|
110
106
|
@ext.userpoints = { "basicxman" => 0 }
|
111
|
-
|
107
|
+
call "basicxman points basicxman"
|
112
108
|
assert @ext.userpoints["basicxman"] < 0
|
113
109
|
end
|
114
110
|
|
115
111
|
sandbox_test "should print a users points" do
|
116
|
-
|
112
|
+
ext :users => ["basicxman"]
|
117
113
|
@ext.userpoints = { "basicxman" => 50 }
|
118
|
-
|
119
|
-
assert_match "basicxman",
|
120
|
-
assert_match "50",
|
114
|
+
call "basicxman board"
|
115
|
+
assert_match "basicxman", output
|
116
|
+
assert_match "50", output
|
121
117
|
end
|
122
118
|
|
123
119
|
sandbox_test "should print a leaderboard" do
|
124
|
-
|
120
|
+
ext
|
125
121
|
@ext.userpoints = {
|
126
122
|
"basicxman" => 150,
|
127
123
|
"mike_n_7" => 150,
|
@@ -131,7 +127,7 @@ eof
|
|
131
127
|
"someguy" => 10
|
132
128
|
}
|
133
129
|
@ext.board("basicxman")
|
134
|
-
leaderboard =
|
130
|
+
leaderboard = output_lines
|
135
131
|
assert_match "150", leaderboard[0]
|
136
132
|
assert_match "150", leaderboard[1]
|
137
133
|
assert_match "Ian_zers", leaderboard[2]
|
@@ -141,247 +137,207 @@ eof
|
|
141
137
|
|
142
138
|
# Kickvote testing.
|
143
139
|
sandbox_test "should initiate a kickvote against a user" do
|
144
|
-
|
145
|
-
|
146
|
-
@ext.
|
147
|
-
@ext.hops = ["mike_n_7"]
|
148
|
-
@ext.call_command("basicxman", "kickvote", "blizzard4U")
|
149
|
-
assert_equal 3, @ext.kickvotes["blizzard4U"][:tally]
|
140
|
+
ext :ops => ["basicxman"], :hops => ["mike_n_7"], :users => ["blizzard4U", "Ian_zers"]
|
141
|
+
call "basicxman kickvote blizzard4U"
|
142
|
+
assert_equal 3, @ext.userkickvotes["blizzard4U"][:tally]
|
150
143
|
assert_equal "blizzard4U", @ext.last_kick_vote
|
151
144
|
end
|
152
145
|
|
153
146
|
sandbox_test "should expire a kickvote against a user" do
|
154
|
-
|
155
|
-
|
156
|
-
@ext.call_command("basicxman", "kickvote", "blizzard4U")
|
147
|
+
ext :users => ["basicxman", "blizzard4U"]
|
148
|
+
call "basicxman kickvote blizzard4U"
|
157
149
|
@ext.counter = 9
|
158
|
-
@ext.
|
150
|
+
@ext.userkickvotes["blizzard4U"][:start] = Time.now - 300
|
159
151
|
@ext.periodic
|
160
|
-
assert_match "expire",
|
152
|
+
assert_match "expire", output
|
161
153
|
end
|
162
154
|
|
163
155
|
sandbox_test "should add the correct number of votes per user type" do
|
164
|
-
|
165
|
-
@ext.users = ["basicxman", "mike_n_7", "blizzard4U", "Ian_zers"]
|
166
|
-
@ext.ops = ["basicxman"]
|
167
|
-
@ext.hops = ["mike_n_7"]
|
156
|
+
ext :ops => ["basicxman"], :hops => ["mike_n_7"], :users => ["blizzard4U", "Ian_zers"]
|
168
157
|
@ext.vote_threshold = 7
|
169
|
-
|
170
|
-
assert_equal 1, @ext.
|
171
|
-
|
172
|
-
|
173
|
-
@ext.
|
174
|
-
|
158
|
+
call "Ian_zers kickvote blizzard4U"
|
159
|
+
assert_equal 1, @ext.userkickvotes["blizzard4U"][:tally]
|
160
|
+
|
161
|
+
call "mike_n_7 vote"
|
162
|
+
assert_equal 3, @ext.userkickvotes["blizzard4U"][:tally]
|
163
|
+
|
164
|
+
call "basicxman vote"
|
165
|
+
assert_equal 6, @ext.userkickvotes["blizzard4U"][:tally]
|
175
166
|
end
|
176
167
|
|
177
168
|
sandbox_test "should kick a user who has enough votes" do
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
@ext.call_command("basicxman", "kickvote", "Ian_zers")
|
183
|
-
@ext.call_command("mike_n_7", "vote")
|
184
|
-
assert_match "kick Ian_zers", @ext.server.string
|
169
|
+
ext :ops => ["basicxman"], :hops => ["mike_n_7"], :users => ["blizzard4U", "Ian_zers"]
|
170
|
+
call "basicxman kickvote Ian_zers"
|
171
|
+
call "mike_n_7 vote"
|
172
|
+
assert_match "kick Ian_zers", output
|
185
173
|
end
|
186
174
|
|
187
175
|
# Timer test.
|
188
176
|
sandbox_test "should not add a timer if the item does not exist" do
|
189
|
-
|
190
|
-
|
191
|
-
@ext.call_command("basicxman", "addtimer", "foo")
|
177
|
+
ext :hops => ["basicxman"]
|
178
|
+
call "basicxman addtimer foo"
|
192
179
|
assert_nil @ext.timers["basicxman"]
|
193
|
-
assert_match "not added",
|
180
|
+
assert_match "not added", output
|
194
181
|
end
|
195
182
|
|
196
183
|
# Stop timer test.
|
197
184
|
sandbox_test "should stop all timers" do
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
@ext.call_command("basicxman", "stop")
|
185
|
+
ext :hops => ["basicxman"]
|
186
|
+
call "basicxman addtimer cobblestone"
|
187
|
+
call "basicxman addtimer arrow"
|
188
|
+
clear
|
189
|
+
|
190
|
+
call "basicxman stop"
|
205
191
|
assert_nil @ext.timers["basicxman"]
|
206
|
-
assert_match "stopped",
|
192
|
+
assert_match "stopped", output
|
207
193
|
end
|
208
194
|
|
209
195
|
# Time commands.
|
210
196
|
sandbox_test "should change time with time commands" do
|
211
|
-
|
212
|
-
@ext.ops = ["basicxman"]
|
197
|
+
ext :ops => ["basicxman"]
|
213
198
|
%w( morning evening night dawn dusk day ).each do |time|
|
214
|
-
|
215
|
-
assert_match "time set #{Minecraft::Data::TIME[time.to_sym]}",
|
216
|
-
|
199
|
+
call "basicxman #{time}"
|
200
|
+
assert_match "time set #{Minecraft::Data::TIME[time.to_sym]}", output
|
201
|
+
clear
|
217
202
|
end
|
218
203
|
end
|
219
204
|
|
220
205
|
# Half op privileges and !list.
|
221
206
|
sandbox_test "should revoke and add half op privileges" do
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
@
|
228
|
-
@ext.call_command("basicxman", "list")
|
229
|
-
assert_match "[@basicxman], blizzard4U, %mike_n_7", @ext.server.string.split("\n").last
|
207
|
+
ext :ops => ["basicxman"], :users => ["blizzard4U", "mike_n_7"]
|
208
|
+
call "basicxman hop blizzard4U"
|
209
|
+
call "basicxman hop mike_n_7"
|
210
|
+
call "basicxman dehop blizzard4U"
|
211
|
+
call "basicxman list"
|
212
|
+
assert_match "[@basicxman], blizzard4U, %mike_n_7", output_lines.last
|
230
213
|
end
|
231
214
|
|
232
215
|
# Help command.
|
233
216
|
sandbox_test "should display help contents for regular users" do
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
|
217
|
+
ext :users => ["blizzard4U"]
|
218
|
+
call "blizzard4U help"
|
219
|
+
t = output_line.gsub("say", "")
|
238
220
|
assert_match "rules", t
|
239
221
|
assert_match "list", t
|
240
222
|
refute_match "give", t
|
241
223
|
end
|
242
224
|
|
243
225
|
sandbox_test "should display help contents for half ops" do
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
@ext.call_command("mike_n_7", "help")
|
248
|
-
t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
|
226
|
+
ext :hops => ["mike_n_7"]
|
227
|
+
call "mike_n_7 help"
|
228
|
+
t = output_line.gsub("say", "")
|
249
229
|
assert_match "rules", t
|
250
230
|
assert_match "give", t
|
251
231
|
refute_match "morning", t
|
252
232
|
end
|
253
233
|
|
254
234
|
sandbox_test "should display help contents for ops" do
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
@ext.call_command("basicxman", "help")
|
259
|
-
t = @ext.server.string.gsub("\n", "").gsub("say", "").gsub(" ", "")
|
235
|
+
ext :ops => ["basicxman"]
|
236
|
+
call "basicxman help"
|
237
|
+
t = output_line.gsub("say", "")
|
260
238
|
assert_match "rules", t
|
261
239
|
assert_match "give", t
|
262
240
|
assert_match "morning", t
|
263
241
|
end
|
264
242
|
|
265
243
|
sandbox_test "should display help contents for a specific command" do
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
assert_match "privileges to the target user", @ext.server.string.gsub("\n", "")
|
244
|
+
ext :users => ["basicxman"]
|
245
|
+
call "basicxman help hop"
|
246
|
+
assert_match "privileges to the target user", output_line
|
270
247
|
end
|
271
248
|
|
272
249
|
sandbox_test "should display command syntaxes" do
|
273
|
-
|
274
|
-
@ext.ops = ["basicxman"]
|
250
|
+
ext :ops => ["basicxman"]
|
275
251
|
|
276
252
|
# opt
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
assert_equal "say !warptime",
|
281
|
-
assert_equal "say !warptime 'time change'", t[1]
|
253
|
+
clear
|
254
|
+
call "basicxman help warptime"
|
255
|
+
assert_equal "say !warptime", output_lines[0]
|
256
|
+
assert_equal "say !warptime 'time change'", output_lines[1]
|
282
257
|
|
283
258
|
# rest
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
assert_equal "say !welcome 'arguments', '...'", t[0]
|
259
|
+
clear
|
260
|
+
call "basicxman help welcome"
|
261
|
+
assert_equal "say !welcome 'arguments', '...'", output_lines[0]
|
288
262
|
|
289
263
|
# req, rest
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
assert_equal "say !memo 'target user', 'arguments', '...'", t[0]
|
264
|
+
clear
|
265
|
+
call "basicxman help memo"
|
266
|
+
assert_equal "say !memo 'target user', 'arguments', '...'", output_lines[0]
|
294
267
|
|
295
268
|
# req
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
assert_equal "say !disturb 'target user'", t[0]
|
269
|
+
clear
|
270
|
+
call "basicxman help disturb"
|
271
|
+
assert_equal "say !disturb 'target user'", output_lines[0]
|
300
272
|
|
301
273
|
# req, opt
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
assert_equal "say !points 'target user'",
|
306
|
-
assert_equal "say !points 'target user', 'num points'", t[1]
|
274
|
+
clear
|
275
|
+
call "basicxman help points"
|
276
|
+
assert_equal "say !points 'target user'", output_lines[0]
|
277
|
+
assert_equal "say !points 'target user', 'num points'", output_lines[1]
|
307
278
|
end
|
308
279
|
|
309
280
|
# Do not disturb testing.
|
310
281
|
sandbox_test "should not allow users in dnd to be teleported to" do
|
311
|
-
|
312
|
-
|
313
|
-
@ext.hops = ["mike_n_7"]
|
314
|
-
@ext.call_command("basicxman", "dnd")
|
282
|
+
ext :hops => ["mike_n_7"], :users => ["basicxman"]
|
283
|
+
call "basicxman dnd"
|
315
284
|
assert_equal ["basicxman"], @ext.userdnd
|
316
|
-
|
317
|
-
|
318
|
-
assert_match "disturbed",
|
319
|
-
|
285
|
+
clear
|
286
|
+
call "mike_n_7 tp basicxman"
|
287
|
+
assert_match "disturbed", output
|
288
|
+
call "basicxman dnd"
|
320
289
|
assert_equal [], @ext.userdnd
|
321
290
|
end
|
322
291
|
|
323
292
|
sandbox_test "should allow ops to use the disturb command against users" do
|
324
|
-
|
325
|
-
|
326
|
-
@ext.ops = ["basicxman"]
|
327
|
-
@ext.call_command("mike_n_7", "dnd")
|
293
|
+
ext :ops => ["basicxman"], :users => ["mike_n_7"]
|
294
|
+
call "mike_n_7 dnd"
|
328
295
|
assert_equal ["mike_n_7"], @ext.userdnd
|
329
|
-
|
296
|
+
call "basicxman disturb mike_n_7"
|
330
297
|
assert_equal [], @ext.userdnd
|
331
298
|
end
|
332
299
|
|
333
300
|
# Disco.
|
334
301
|
sandbox_test "should start the disco" do
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
assert_match "disco", @ext.server.string
|
340
|
-
@ext.server.string = ""
|
302
|
+
ext :ops => ["basicxman"]
|
303
|
+
call "basicxman disco"
|
304
|
+
assert_match "disco", output
|
305
|
+
clear
|
341
306
|
12.times { @ext.periodic }
|
342
|
-
assert_match "time set 0",
|
343
|
-
assert_match "time set 16000",
|
307
|
+
assert_match "time set 0", output
|
308
|
+
assert_match "time set 16000", output
|
344
309
|
end
|
345
310
|
|
346
311
|
# Teleport all.
|
347
312
|
sandbox_test "should teleport all users to an op" do
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
assert_match "
|
353
|
-
assert_match "blizzard4U", @ext.server.string
|
354
|
-
assert_match "Ian_zers", @ext.server.string
|
313
|
+
ext :ops => ["basicxman"], :users => ["mike_n_7", "blizzard4U", "Ian_zers"]
|
314
|
+
call "basicxman tpall"
|
315
|
+
assert_match "mike_n_7", output
|
316
|
+
assert_match "blizzard4U", output
|
317
|
+
assert_match "Ian_zers", output
|
355
318
|
end
|
356
319
|
|
357
320
|
# Welcome message runtime change test.
|
358
321
|
sandbox_test "should change welcome message during runtime" do
|
359
|
-
|
360
|
-
|
361
|
-
@ext.call_command("basicxman", "welcome", "Foo bar.")
|
322
|
+
ext :ops => ["basicxman"]
|
323
|
+
call "basicxman welcome Foo bar."
|
362
324
|
assert_equal "Foo bar.", @ext.welcome_message
|
363
325
|
|
364
|
-
|
326
|
+
call "basicxman welcome + %"
|
365
327
|
assert_equal "Foo bar. %", @ext.welcome_message
|
366
|
-
assert_match "basicxman",
|
328
|
+
assert_match "basicxman", output
|
367
329
|
end
|
368
330
|
|
369
331
|
# Memos.
|
370
332
|
sandbox_test "should allow users to set memos" do
|
371
|
-
|
372
|
-
|
373
|
-
@ext.call_command("basicxman", "memo", "mike_n_7", "Hi")
|
333
|
+
ext :users => ["basicxman"]
|
334
|
+
call "basicxman memo mike_n_7 Hi"
|
374
335
|
assert_equal ["basicxman", "Hi"], @ext.memos["mike_n_7"][0]
|
375
|
-
|
376
|
-
#@ext.check_memos("mike_n_7")
|
377
|
-
#assert_match "Hi", @ext.server.string
|
378
|
-
#assert_equal 0, @ext.memos["mike_n_7"].length
|
379
336
|
end
|
380
337
|
|
381
338
|
sandbox_test "should add and print multiple memos" do
|
382
|
-
|
383
|
-
|
384
|
-
3.times { @ext.call_command("basicxman", "memo", "mike_n_7", "Hi") }
|
339
|
+
ext :users => ["basicxman"]
|
340
|
+
3.times { call "basicxman memo mike_n_7 Hi" }
|
385
341
|
assert_equal 3, @ext.memos["mike_n_7"].length
|
386
342
|
|
387
343
|
@ext.check_memos("mike_n_7")
|
@@ -389,140 +345,154 @@ eof
|
|
389
345
|
end
|
390
346
|
|
391
347
|
sandbox_test "should only allow five memos per user" do
|
392
|
-
|
393
|
-
|
394
|
-
10.times { @ext.call_command("basicxman", "memo", "mike_n_7", "Hi") }
|
348
|
+
ext :users => ["basicxman"]
|
349
|
+
10.times { call "basicxman memo mike_n_7 Hi" }
|
395
350
|
assert_equal 5, @ext.memos["mike_n_7"].length
|
396
351
|
end
|
397
352
|
|
398
353
|
# Warping time.
|
399
354
|
sandbox_test "should warp time" do
|
400
|
-
|
401
|
-
|
402
|
-
@ext.call_command("basicxman", "warptime", "100")
|
355
|
+
ext :ops => ["basicxman"]
|
356
|
+
call "basicxman warptime 100"
|
403
357
|
40.times { @ext.periodic }
|
404
|
-
assert_match "time add 100",
|
358
|
+
assert_match "time add 100", output_line
|
405
359
|
end
|
406
360
|
|
407
361
|
# Todo command tests.
|
408
362
|
sandbox_test "should add, list and remove global todo items" do
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
assert_match "Added",
|
363
|
+
ext :users => ["basicxman"]
|
364
|
+
call "basicxman todo foo bar"
|
365
|
+
call "basicxman todo bar"
|
366
|
+
assert_match "Added", output
|
413
367
|
assert_equal "foo bar", @ext.todo_items[0]
|
414
368
|
|
415
|
-
|
416
|
-
assert_match "1. foo bar",
|
417
|
-
assert_match "2. bar",
|
369
|
+
call "basicxman todo"
|
370
|
+
assert_match "1. foo bar", output_lines[-2]
|
371
|
+
assert_match "2. bar", output_lines[-1]
|
418
372
|
|
419
|
-
|
420
|
-
|
421
|
-
assert_match "Hurray!",
|
373
|
+
call "basicxman finished foo bar"
|
374
|
+
call "basicxman finished 1"
|
375
|
+
assert_match "Hurray!", output
|
422
376
|
assert_equal 0, @ext.todo_items.length
|
423
377
|
|
424
|
-
|
425
|
-
|
426
|
-
assert_match "not exist",
|
427
|
-
|
428
|
-
|
429
|
-
assert_match "not exist",
|
378
|
+
clear
|
379
|
+
call "basicxman finished 2"
|
380
|
+
assert_match "not exist", output
|
381
|
+
clear
|
382
|
+
call "basicxman finished lolcats"
|
383
|
+
assert_match "not exist", output
|
430
384
|
end
|
431
385
|
|
432
386
|
# Command history.
|
433
387
|
sandbox_test "should keep track of command history and allow users to use previous commands" do
|
434
|
-
|
435
|
-
@ext.ops = ["basicxman"]
|
388
|
+
ext :ops => ["basicxman"]
|
436
389
|
@ext.command_history = {}
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
390
|
+
call "basicxman dusk"
|
391
|
+
call "basicxman dawn"
|
392
|
+
clear
|
393
|
+
call "basicxman last"
|
394
|
+
call "basicxman last 2"
|
442
395
|
@ext.info_command("2011-08-30 15:52:55 [INFO] <basicxman> !")
|
443
396
|
@ext.info_command("2011-08-30 15:52:55 [INFO] <basicxman> !!")
|
444
|
-
t =
|
397
|
+
t = output_lines
|
445
398
|
assert_match "time set 0", t[0]
|
446
399
|
assert_match "time set 12000", t[1]
|
447
400
|
assert_match "time set 0", t[2]
|
448
401
|
assert_match "time set 12000", t[3]
|
449
402
|
|
450
|
-
|
451
|
-
|
452
|
-
assert_match "No command found",
|
403
|
+
clear
|
404
|
+
call "basicxman last 3"
|
405
|
+
assert_match "No command found", output
|
453
406
|
end
|
454
407
|
|
455
408
|
sandbox_test "should print users command history" do
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
t = @ext.server.string.split("\n")
|
409
|
+
ext :ops => ["basicxman"]
|
410
|
+
call "basicxman dawn"
|
411
|
+
call "basicxman dusk"
|
412
|
+
call "basicxman help list"
|
413
|
+
call "basicxman give 4 64"
|
414
|
+
clear
|
415
|
+
call "basicxman history"
|
416
|
+
t = output_lines
|
465
417
|
assert_match "1. give 4 64", t[0]
|
466
418
|
assert_match "2. help list", t[1]
|
467
419
|
assert_match "3. dusk", t[2]
|
468
420
|
end
|
469
421
|
|
470
422
|
sandbox_test "should not add the same command to history twice in a row" do
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
@ext.call_command("basicxman", "day")
|
423
|
+
ext :ops => ["basicxman"]
|
424
|
+
call "basicxman day"
|
425
|
+
call "basicxman day"
|
475
426
|
assert_equal [["day"]], @ext.command_history["basicxman"]
|
476
427
|
end
|
477
428
|
|
478
429
|
sandbox_test "should not add command history from shortucts" do
|
479
|
-
|
480
|
-
|
481
|
-
|
430
|
+
ext :users => ["basicxan"]
|
431
|
+
call "basicxman s foo day"
|
432
|
+
call "basicxman s foo"
|
482
433
|
assert_nil @ext.command_history["basicxman"]
|
483
434
|
end
|
484
435
|
|
436
|
+
# Shortcuts
|
437
|
+
sandbox_test "should allow hops to specify and use shortcuts" do
|
438
|
+
ext :hops => ["basicxman"]
|
439
|
+
call "basicxman s ga give cobblestone"
|
440
|
+
call "basicxman s ga give arrow 2m" # Should override
|
441
|
+
call "basicxman s ka kit armour"
|
442
|
+
assert_match "labelled", output
|
443
|
+
assert_equal ["give", "arrow", "2m"], @ext.usershortcuts["basicxman"]["ga"]
|
444
|
+
clear
|
445
|
+
|
446
|
+
call "basicxman s ga"
|
447
|
+
assert_match "give basicxman 262 64", output_line
|
448
|
+
clear
|
449
|
+
|
450
|
+
call "basicxman shortcuts"
|
451
|
+
assert_match "ka", output_line
|
452
|
+
assert_match "ga", output_line
|
453
|
+
end
|
454
|
+
|
455
|
+
sandbox_test "should fall back on a kit or print an error message for shortcuts" do
|
456
|
+
ext :hops => ["basicxman"]
|
457
|
+
call "basicxman s diamond"
|
458
|
+
assert_match "give basicxman 278", output_line
|
459
|
+
clear
|
460
|
+
|
461
|
+
call "basicxman s foo"
|
462
|
+
assert_match "not a valid shortcut", output_line
|
463
|
+
end
|
464
|
+
|
465
|
+
# Kits
|
466
|
+
sandbox_test "should print available kits" do
|
467
|
+
ext :hops => ["basicxman"]
|
468
|
+
call "basicxman kitlist"
|
469
|
+
assert_match "diamond", output_line
|
470
|
+
clear
|
471
|
+
|
472
|
+
call "basicxman kit diamond"
|
473
|
+
assert_match "give basicxman 278", output_line
|
474
|
+
clear
|
475
|
+
|
476
|
+
call "basicxman kit doesnotexist"
|
477
|
+
assert_match "diamond", output_line
|
478
|
+
end
|
479
|
+
|
485
480
|
# Remaining commands testing (should test to ensure no errors are thrown in
|
486
481
|
# the command execution).
|
487
482
|
sandbox_test "should run commands without failure" do
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
@ext.call_command("basicxman", "roulette")
|
503
|
-
@ext.call_command("basicxman", "hop", "Ian_zers")
|
504
|
-
@ext.call_command("basicxman", "dehop", "Ian_zers")
|
505
|
-
@ext.call_command("basicxman", "kit", "diamond")
|
506
|
-
@ext.call_command("basicxman", "tp", "Ian_zers")
|
507
|
-
@ext.call_command("basicxman", "tpall")
|
508
|
-
@ext.call_command("basicxman", "nom")
|
509
|
-
@ext.call_command("basicxman", "om", "nom", "nom")
|
510
|
-
@ext.call_command("basicxman", "property", "spawn-monsters")
|
511
|
-
@ext.call_command("basicxman", "property")
|
512
|
-
@ext.call_command("basicxman", "uptime")
|
513
|
-
@ext.call_command("basicxman", "uptime", "mike_n_7")
|
514
|
-
@ext.call_command("basicxman", "rules")
|
515
|
-
@ext.call_command("basicxman", "list")
|
516
|
-
@ext.call_command("basicxman", "addtimer", "cobblestone")
|
517
|
-
@ext.call_command("basicxman", "addtimer", "4", "60")
|
518
|
-
@ext.call_command("basicxman", "deltimer", "4")
|
519
|
-
@ext.call_command("basicxman", "printtimer")
|
520
|
-
@ext.call_command("basicxman", "printtime")
|
521
|
-
@ext.call_command("basicxman", "s", "foo", "give", "cobblestone")
|
522
|
-
@ext.call_command("basicxman", "s", "foo")
|
523
|
-
@ext.call_command("basicxman", "shortcuts")
|
524
|
-
@ext.call_command("basicxman", "help")
|
525
|
-
@ext.call_command("basicxman", "help", "give")
|
526
|
-
@ext.call_command("basicxman", "kitlist")
|
483
|
+
ext :ops => ["basicxman"], :hops => ["mike_n_7"], :users => ["blizzard4U", "Ian_zers"]
|
484
|
+
call "basicxman printdnd"
|
485
|
+
call "basicxman roulette"
|
486
|
+
call "basicxman kit diamond"
|
487
|
+
call "basicxman tp Ian_zers"
|
488
|
+
call "basicxman tpall"
|
489
|
+
call "basicxman nom"
|
490
|
+
call "basicxman om nom nom"
|
491
|
+
call "basicxman property spawn-monsters"
|
492
|
+
call "basicxman property"
|
493
|
+
call "basicxman rules"
|
494
|
+
call "basicxman printtimer"
|
495
|
+
call "basicxman printtime"
|
496
|
+
call "basicxman kitlist"
|
527
497
|
end
|
528
498
|
end
|
data/test/extensions_test.rb
CHANGED
@@ -4,7 +4,7 @@ require "minecraft"
|
|
4
4
|
class ExtensionsTest < Test
|
5
5
|
# Coloured line testing.
|
6
6
|
sandbox_test "should colour server side lines properly" do
|
7
|
-
|
7
|
+
ext
|
8
8
|
result = "\033[0;37m2011-08-21 13:45:13\033[0m [INFO] Starting minecraft server version Beta 1.7.3"
|
9
9
|
assert_equal result, @ext.colour("2011-08-21 13:45:13 [INFO] Starting minecraft server version Beta 1.7.3")
|
10
10
|
|
@@ -23,90 +23,73 @@ class ExtensionsTest < Test
|
|
23
23
|
|
24
24
|
# call_comamnd testing.
|
25
25
|
sandbox_test "should call a command for a regular user" do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
assert_equal 0, @ext.server.string.index("say")
|
26
|
+
ext :users => ["basicxman"]
|
27
|
+
call "basicxman list"
|
28
|
+
assert_equal 0, output.index("say")
|
30
29
|
end
|
31
30
|
|
32
31
|
sandbox_test "should not call an all command for a regular user" do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
assert_match "not a", @ext.server.string
|
32
|
+
ext :users => ["basicxman"]
|
33
|
+
call "basicxman giveall cobblestone"
|
34
|
+
assert_match "not a", output
|
37
35
|
end
|
38
36
|
|
39
37
|
sandbox_test "should not let regular users run privileged commands" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
assert_match "not a", @ext.server.string
|
38
|
+
ext :users => ["blizzard4U"]
|
39
|
+
call "blizzard4U give cobblestone"
|
40
|
+
assert_match "not a", output
|
44
41
|
end
|
45
42
|
|
46
43
|
sandbox_test "should not call an all command if not available" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@ext.call_command("basicxman", "rouletteall")
|
51
|
-
assert_equal 2, @ext.server.string.split("\n").length
|
44
|
+
ext :users => ["blizzard4U", "mike_n_7"], :ops => ["basicxman"]
|
45
|
+
call "basicxman rouletteall"
|
46
|
+
refute_match "basicxman is", output_line
|
52
47
|
end
|
53
48
|
|
54
49
|
sandbox_test "should let ops execute an all command" do
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@ext.call_command("basicxman", "giveall", "cobblestone")
|
59
|
-
assert_match "basicxman is", @ext.server.string
|
50
|
+
ext :users => ["blizzard4U", "mike_n_7"], :ops => ["basicxman"]
|
51
|
+
call "basicxman giveall cobblestone"
|
52
|
+
assert_match "basicxman is", output
|
60
53
|
end
|
61
54
|
|
62
55
|
sandbox_test "should not let hops or execute an all command" do
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@ext.call_command("mike_n_7", "giveall", "cobblestone")
|
67
|
-
assert_match "not a", @ext.server.string
|
56
|
+
ext :users => ["blizzard4U", "basicxman"], :hops => ["mike_n_7"]
|
57
|
+
call "mike_n_7 giveall cobblestone"
|
58
|
+
assert_match "not a", output
|
68
59
|
end
|
69
60
|
|
70
61
|
sandbox_test "should not let hops run op commands" do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
assert_match "not a", @ext.server.string
|
62
|
+
ext :hops => ["mike_n_7"]
|
63
|
+
call "mike_n_7 morning"
|
64
|
+
assert_match "not a", output
|
75
65
|
end
|
76
66
|
|
77
67
|
sandbox_test "should let ops run op privileged commands" do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
refute_match "not a", @ext.server.string
|
68
|
+
ext :ops => ["basicxman"]
|
69
|
+
call "basicxman morning"
|
70
|
+
refute_match "not a", output
|
82
71
|
end
|
83
72
|
|
84
73
|
sandbox_test "should remove excess arguments" do
|
85
|
-
|
86
|
-
|
87
|
-
refute_empty
|
74
|
+
ext :users => ["basicxman"]
|
75
|
+
call "basicxman help foo bar"
|
76
|
+
refute_empty output
|
88
77
|
|
89
|
-
|
90
|
-
refute_empty
|
78
|
+
call "basicxman day foo"
|
79
|
+
refute_empty output
|
91
80
|
end
|
92
81
|
|
93
82
|
# Command valiation testing.
|
94
83
|
sandbox_test "should print an arguments error if not enough arguments are given" do
|
95
84
|
ts, $stderr = $stderr, StringIO.new
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
assert_match "
|
104
|
-
assert_match "group", @ext.server.string
|
105
|
-
@ext.server.string = ""
|
106
|
-
|
107
|
-
@ext.call_command("basicxman", "hop")
|
108
|
-
assert_match "Expected", @ext.server.string
|
109
|
-
assert_match "target user", @ext.server.string
|
85
|
+
ext :ops => ["basicxman"]
|
86
|
+
call "basicxman give"
|
87
|
+
assert_match "at least one argument", output
|
88
|
+
clear
|
89
|
+
|
90
|
+
call "basicxman hop"
|
91
|
+
assert_match "Expected", output
|
92
|
+
assert_match "target user", output
|
110
93
|
$stderr = ts
|
111
94
|
end
|
112
95
|
end
|
data/test/helper.rb
CHANGED
@@ -10,7 +10,7 @@ require "turn"
|
|
10
10
|
|
11
11
|
module Minecraft
|
12
12
|
class Extensions
|
13
|
-
attr_accessor :commands, :users, :ops, :hops, :counter, :server, :
|
13
|
+
attr_accessor :commands, :users, :ops, :hops, :counter, :server, :userkickvotes, :last_kick_vote, :useruptime, :timers, :usershortcuts, :userlog, :userpoints, :vote_threshold, :userdnd, :welcome_message, :memos, :todo_items, :command_history
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -34,4 +34,32 @@ class Test < MiniTest::Unit::TestCase
|
|
34
34
|
end
|
35
35
|
define_method("test_#{name.gsub(/\W/, '_')}", p)
|
36
36
|
end
|
37
|
+
|
38
|
+
def ext(opts = {})
|
39
|
+
@ext = Minecraft::Extensions.new(StringIO.new, {})
|
40
|
+
@ext.ops = opts[:ops] || []
|
41
|
+
@ext.hops = opts[:hops] || []
|
42
|
+
@ext.users = @ext.ops + @ext.hops + (opts[:users] || [])
|
43
|
+
@ext.users.uniq!
|
44
|
+
end
|
45
|
+
|
46
|
+
def call(string)
|
47
|
+
@ext.call_command(*string.split(" "))
|
48
|
+
end
|
49
|
+
|
50
|
+
def output
|
51
|
+
@ext.server.string
|
52
|
+
end
|
53
|
+
|
54
|
+
def output_lines
|
55
|
+
output.split("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def output_line
|
59
|
+
output.gsub("\n", "")
|
60
|
+
end
|
61
|
+
|
62
|
+
def clear
|
63
|
+
@ext.server.string = ""
|
64
|
+
end
|
37
65
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: minecraft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Andrew Horsman
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-09-03 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|