minecraft 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,18 @@
1
+ 0.3.0 (2011-08-29)
2
+ ------------------
3
+
4
+ * Added `!warptime`, `!stop`, `!welcome`, `!memo`, `!disco`, `!dnd`, `!disturb`, `!printdnd`, `!todo`, `!finished`.
5
+ * Moved time commands out of `method_missing`.
6
+ * Added capability for users to not be disturbed by teleporting or `all` commands.
7
+ * Removed `add_command` calls, now indexes information from source code on initialization.
8
+ * Added more documentation (back at 100% coverage).
9
+ * Added many more test suites.
10
+ * Misc. bug fixes including lots of command feedback.
11
+ * Shortcuts and kits can now be accessed with `:` instead of `!s` or `!kit`.
12
+ * `!help` is now dynamic and includes command-specific help.
13
+ * Coloured terminal output.
14
+ * Basic word wrapped output.
15
+
1
16
  0.2.1 (2011-08-22)
2
17
  ------------------
3
18
 
data/README.md CHANGED
@@ -70,6 +70,18 @@ Please refer to `Minecraft::Extensions#initialize`.
70
70
  !board <user> # Check a users points.
71
71
  !board # View the leaderboard of points.
72
72
  !om <noms> # Give golden apples equivalent to the number of noms.
73
+ !warptime # Prints the current time rate.
74
+ !warptime <rate> # Adds <rate> seconds every ten seconds to time.
75
+ !stop # Stops all the users timers.
76
+ !welcome # Changes the welcome message during runtime.
77
+ !memo <user> <message> # Leaves a memo for the user.
78
+ !disco # Turns time into a dancefloor.
79
+ !dnd # Toggles the users do-not-disturb status.
80
+ !disturb <user> # An op can remove a user from the DND list.
81
+ !printdnd # Prints the list of do-not-disturbed users.
82
+ !todo # Prints the list of items todo.
83
+ !todo <item> # Adds a todo list item.
84
+ !finished <item> # Removes an item from the todo list.
73
85
 
74
86
  Development Path
75
87
  ----------------
@@ -19,6 +19,7 @@ opts = Slop.parse :help => true do
19
19
  banner "Usage: minecraft [options]"
20
20
 
21
21
  option :n, :no_run, "Don't run the Minecraft server instance."
22
+ option :no_colour, "Don't have coloured output on the server side."
22
23
  option :u, :update, "Download the latest version of the Minecraft server jarfile."
23
24
  option :s, :min_memory, "Specify the minimum amount of memory to allocate.", :optional => true
24
25
  option :x, :max_memory, "Specify the maximum amount of memory to allocate.", :optional => true
@@ -4,6 +4,189 @@ module Minecraft
4
4
  module Commands
5
5
  include Data
6
6
 
7
+ # Allows a user to specify a periodic (once every ten seconds) time change.
8
+ #
9
+ # @param [String] user The requesting user.
10
+ # @param [Integer] time_change Amount of time to add (can be negative or
11
+ # positive) every ten seconds.
12
+ # @example
13
+ # warptime("basicxman", "5")
14
+ # warptime("basicxman")
15
+ # @note ops: op
16
+ def warptime(user, time_change = nil)
17
+ if time_change.nil?
18
+ return @server.puts "say Current rate: #{@time_change} every ten seconds." if @time_change
19
+ return @server.puts "say No custom rate specified."
20
+ end
21
+
22
+ time_change = time_change.to_i
23
+ if time_change < 0
24
+ @time_change = [-1000, time_change].max
25
+ else
26
+ @time_change = [1000, time_change].min
27
+ end
28
+ @server.puts "say New rate: #{@time_change} every ten seconds."
29
+ end
30
+
31
+ # Adds a memo for the specified user.
32
+ #
33
+ # @param [String] user The requesting user.
34
+ # @param [String] target_user The target user.
35
+ # @param args The memo.
36
+ # @example
37
+ # memo("basicxman", "mike_n_7", "Hi!")
38
+ # @note ops: none
39
+ def memo(user, target_user, *args)
40
+ target_user = target_user.downcase
41
+ if @memos.has_key? target_user and @memos[target_user].length == 5
42
+ return @server.puts "say #{target_user} has too many memos already!"
43
+ end
44
+
45
+ @memos[target_user] ||= []
46
+ @memos[target_user] << [user, args.join(" ")]
47
+ say "Memo for #{target_user} added. Will be printed next time s/he logs in."
48
+ end
49
+
50
+ # Stops all timers for a user.
51
+ #
52
+ # @param [String] user The requesting user.
53
+ # @example
54
+ # stop("basicxman")
55
+ # @note ops: hop
56
+ def stop(user)
57
+ @timers.delete user
58
+ @server.puts "say #{user} has stopped all his/her timers."
59
+ end
60
+
61
+ # Changes or appends to the welcome message. Use !welcome + foo to add foo.
62
+ #
63
+ # @param [String] user The requesting user.
64
+ # @param args The welcome message.
65
+ # @example
66
+ # welcome("basicxman", "Welcome", "to", "the", "server")
67
+ # welcome("basicxman", "+", "%")
68
+ # @note ops: op
69
+ def welcome(user, *args)
70
+ if args.first == "+"
71
+ @welcome_message += " " + args[1..-1].join(" ")
72
+ @server.puts "say Appended to welcome message."
73
+ else
74
+ @welcome_message = args.join(" ")
75
+ @server.puts "say Changed welcome message."
76
+ end
77
+ display_welcome_message("basicxman")
78
+ end
79
+
80
+ # Changes to dawn.
81
+ #
82
+ # @example
83
+ # dawn()
84
+ # @note ops: op
85
+ def dawn()
86
+ change_time(:dawn)
87
+ end
88
+
89
+ # Changes to dusk.
90
+ #
91
+ # @example
92
+ # dusk()
93
+ # @note ops: op
94
+ def dusk()
95
+ change_time(:dusk)
96
+ end
97
+
98
+ # Changes to day.
99
+ #
100
+ # @example
101
+ # day()
102
+ # @note ops: op
103
+ def day()
104
+ change_time(:day)
105
+ end
106
+
107
+ # Changes to night.
108
+ #
109
+ # @example
110
+ # night()
111
+ # @note ops: op
112
+ def night()
113
+ change_time(:night)
114
+ end
115
+
116
+ # Changes to morning.
117
+ #
118
+ # @example
119
+ # morning()
120
+ # @note ops: op
121
+ def morning()
122
+ change_time(:morning)
123
+ end
124
+
125
+ # Changes to evening.
126
+ #
127
+ # @example
128
+ # evening()
129
+ # @note ops: op
130
+ def evening()
131
+ change_time(:evening)
132
+ end
133
+
134
+ # Toggles disco.
135
+ #
136
+ # @param [String] user The requesting user.
137
+ # @example
138
+ # disco("basicxman")
139
+ # @note ops: op
140
+ def disco(user)
141
+ @disco ||= false
142
+ if @disco
143
+ @server.puts "say Disco ends."
144
+ @disco = false
145
+ else
146
+ @server.puts "say #{user} has requested disco, s/he likely can't actually dance."
147
+ @disco = true
148
+ end
149
+ end
150
+
151
+ # Stops users from disturbing you.
152
+ #
153
+ # @param [String] user The requesting user.
154
+ # @example
155
+ # dnd("basicxman")
156
+ # @note ops: none
157
+ def dnd(user)
158
+ user.downcase!
159
+ if @userdnd.include? user
160
+ @server.puts "say #{user} is ready to be disturbed. *cough*"
161
+ @userdnd.reject! { |u| u == user }
162
+ else
163
+ @server.puts "say #{user} does not wish to be disturbed."
164
+ @userdnd << user
165
+ end
166
+ end
167
+
168
+ # Removes somebody from the DND list.
169
+ #
170
+ # @param [String] user The requesting user.
171
+ # @param [String] target_user The target user.
172
+ # @example
173
+ # disturb("basicxman", "mike_n_7")
174
+ # @note ops: op
175
+ def disturb(user, target_user)
176
+ @server.puts "say #{target_user} is being disturbed by #{user}!"
177
+ @userdnd.reject! { |u| u == target_user.downcase }
178
+ end
179
+
180
+ # Prints the users who do not wish to be disturbed.
181
+ #
182
+ # @param [String] user The requesting user.
183
+ # @example
184
+ # printdnd()
185
+ # @note: ops: op
186
+ def printdnd()
187
+ @server.puts "say #{@userdnd.join(", ")}"
188
+ end
189
+
7
190
  # Gives a user a specific amount of points, the quantity is capped
8
191
  # depending on the privileges of the user.
9
192
  #
@@ -13,13 +196,22 @@ module Minecraft
13
196
  # @example
14
197
  # points("basicxman", "mike_n_7")
15
198
  # points("basicxman", "mike_n_7", "50")
199
+ # @note ops: none
16
200
  def points(user, target_user, num_points = 1)
17
- if user.downcase == target_user.downcase
201
+ target_user = target_user.downcase
202
+ num_points = num_points.to_i
203
+ if user.downcase == target_user
18
204
  @server.puts "say Did you just try to give yourself points? Sure, minus twenty."
19
205
  @userpoints[target_user] ||= 0
20
206
  @userpoints[target_user] -= 20
207
+ return
208
+ elsif num_points < 0
209
+ @server.puts "say Subtracting points? For shame."
210
+ @userpoints[user] ||= 0
211
+ @userpoints[user] -= num_points
212
+ return
21
213
  end
22
- num_points = [num_points.to_i, cap_points(user)].min
214
+ num_points = [num_points, cap_points(user)].min
23
215
  @userpoints[target_user] ||= 0
24
216
  @userpoints[target_user] += num_points
25
217
  @server.puts "say #{user} has given #{target_user} #{num_points} points for a total of #{@userpoints[target_user]}."
@@ -32,6 +224,7 @@ module Minecraft
32
224
  # @example
33
225
  # board("basicxman")
34
226
  # board("basicxman", "mike_n_7")
227
+ # @note ops: none
35
228
  def board(user, target_user = nil)
36
229
  if target_user.nil?
37
230
  leaderboard = {}
@@ -54,18 +247,6 @@ module Minecraft
54
247
  end
55
248
  end
56
249
 
57
- # Caps the quantity of points able to be given based on requesting user.
58
- #
59
- # @param [String] user The requesting user.
60
- # @return [Integer] Maximum quantity of points.
61
- # @example
62
- # cap_points("basicxman")
63
- def cap_points(user)
64
- return 1000 if is_op? user
65
- return 500 if is_hop? user
66
- return 1
67
- end
68
-
69
250
  # Initiates or votes for a specific user to be kicked, since half-ops and
70
251
  # regular connected players cannot kick users they can initiate a vote
71
252
  # instead.
@@ -76,6 +257,7 @@ module Minecraft
76
257
  # @example
77
258
  # kickvote("basicxman", "blizzard4U")
78
259
  # kickvote("basicxman")
260
+ # @note ops: none
79
261
  def kickvote(user, target_user = nil)
80
262
  return @server.puts "say No user #{target_user} exists." unless @users.include? target_user
81
263
  return vote(user) if target_user.nil?
@@ -96,6 +278,7 @@ module Minecraft
96
278
  # @param [String] user The requesting user.
97
279
  # @example
98
280
  # vote("basicxman")
281
+ # @note ops: none
99
282
  def vote(user)
100
283
  unless submit_vote(user, @last_kick_vote)
101
284
  @server.puts "say No kickvote was initiated, dummy."
@@ -108,6 +291,7 @@ module Minecraft
108
291
  # @param [String] target_user The user which currently has a kickvote.
109
292
  # @example
110
293
  # cancelvote("basicxman", "blizzard4U")
294
+ # @note ops: op
111
295
  def cancelvote(user, target_user)
112
296
  if @kickvotes.has_key? target_user
113
297
  @kickvotes.delete(target_user)
@@ -122,77 +306,20 @@ module Minecraft
122
306
  # @param [String] user The requesting user.
123
307
  # @example
124
308
  # kickvotes("basicxman")
309
+ # @note ops: op
125
310
  def kickvotes(user)
126
311
  @kickvotes.each do |target_user, data|
127
312
  @server.puts "say #{target_user}: #{data[:tally]} #{data[:votes].map { |u| u[0] + u[-1] }.join(", ")}"
128
313
  end
129
314
  end
130
315
 
131
- # Submits a kickvote.
132
- #
133
- # @param [String] user The requesting user who is voting.
134
- # @param [String] target_user The user being voted against.
135
- # @return [Boolean] Returns true if the kickvote has been initiated yet.
136
- # @example
137
- # submit_vote("basicxman", "blizzard4U")
138
- def submit_vote(user, target_user)
139
- return unless @users.include? target_user
140
- if @kickvotes.has_key? target_user
141
- if @kickvotes[target_user][:votes].include? user
142
- @server.puts "say You have already voted."
143
- else
144
- @kickvotes[target_user][:votes] << user
145
- @kickvotes[target_user][:tally] += kick_influence(user)
146
- check_kickvote(target_user)
147
- end
148
- return true
149
- else
150
- return false
151
- end
152
- end
153
-
154
- # Checks a kickvote entry to see if the tally number has crossed the
155
- # threshold, if so, kicks the user.
156
- #
157
- # @param [String] user The specified user.
158
- # @example
159
- # check_kickvote("blizzard4U")
160
- def check_kickvote(user)
161
- if @kickvotes[user][:tally] >= @vote_threshold
162
- @server.puts "say Enough votes have been given to kick #{user}."
163
- @server.puts "kick #{user}"
164
- @kickvotes.delete(user)
165
- end
166
- end
167
-
168
- # Computes the influence a user has for kickvotes.
169
- #
170
- # @param [String] user The specified user.
171
- # @return [Integer] The influence level.
172
- # @example
173
- # kick_influence("basicxman")
174
- def kick_influence(user)
175
- return 3 if is_op? user
176
- return 2 if is_hop? user
177
- return 1
178
- end
179
-
180
- # Checks to see if any kickvotes are expired.
181
- def expire_kickvotes
182
- @kickvotes.each do |target_user, data|
183
- if Time.now > data[:start] + @vote_expiration
184
- @server.puts "say The kickvote for #{target_user} has expired."
185
- @kickvotes.delete(target_user)
186
- end
187
- end
188
- end
189
-
190
316
  # Kicks a random person, the requesting user has a higher cance of being
191
317
  # picked.
192
318
  #
193
319
  # @param [String] user The requesting user.
194
320
  # @example
195
321
  # roulette("basicxman")
322
+ # @note ops: op
196
323
  def roulette(user)
197
324
  users = @users + [user] * 3
198
325
  picked_user = users.sample
@@ -200,24 +327,13 @@ module Minecraft
200
327
  @server.puts "kick #{picked_user}"
201
328
  end
202
329
 
203
- # Changes the time of day.
204
- #
205
- # @param [String] time The time of day to change it to.
206
- # @example
207
- # change_time("morning")
208
- def change_time(time)
209
- return false unless TIME.include? time
210
- @server.puts "time set #{TIME[time]}"
211
- @server.puts "say #{TIME_QUOTES[time]}" unless TIME_QUOTES[time] == ""
212
- return true
213
- end
214
-
215
330
  # Gives half-op privileges to the target user.
216
331
  #
217
332
  # @param [String] user The requesting user.
218
333
  # @param [String] target_user The target user to be hop'ed.
219
334
  # @example
220
335
  # hop("basicxman", "blizzard4U")
336
+ # @note ops: op
221
337
  def hop(user, target_user)
222
338
  @hops << target_user.downcase unless @hops.include? target_user.downcase
223
339
  @server.puts "#{target_user} is now a hop, thanks #{user}!"
@@ -229,6 +345,7 @@ module Minecraft
229
345
  # @param [String] target_user The target user to be de-hop'ed.
230
346
  # @example
231
347
  # dehop("basicxman", "blizzard4U")
348
+ # @note ops: op
232
349
  def dehop(user, target_user)
233
350
  @hops.reject! { |u| u == target_user.downcase }
234
351
  @server.puts "#{target_user} has been de-hoped, thanks #{user}!"
@@ -244,6 +361,8 @@ module Minecraft
244
361
  # give("basicxman", "cobblestone", "9m")
245
362
  # give("basicxman", "flint", "and", "steel", "1")
246
363
  # give("basicxman", "4")
364
+ # @note ops: hop
365
+ # @note all: is putting out.
247
366
  def give(user, *args)
248
367
  item, quantity = items_arg(1, args)
249
368
  item = resolve_item(item)
@@ -251,14 +370,6 @@ module Minecraft
251
370
  construct_give(user, item, quantity)
252
371
  end
253
372
 
254
- # Validates a kit group, if the kit cannot be found it executes the
255
- # !kitlist command.
256
- def validate_kit(group = "")
257
- return true if KITS.include? group.to_sym
258
- @server.puts "say #{group} is not a valid kit."
259
- kitlist
260
- end
261
-
262
373
  # Kit command takes a group name and gives the contents of the kit to the
263
374
  # target user.
264
375
  #
@@ -266,6 +377,8 @@ module Minecraft
266
377
  # @param [String] group Label of the kit.
267
378
  # @example
268
379
  # give("basicxman", "diamond")
380
+ # @note ops: hop
381
+ # @note all: is providing kits to all.
269
382
  def kit(user, group)
270
383
  KITS[group.to_sym].each do |item|
271
384
  if item.is_a? Array
@@ -282,7 +395,10 @@ module Minecraft
282
395
  # @param [String] target User to teleport to.
283
396
  # @example
284
397
  # tp("basicxman", "mike_n_7")
398
+ # @note ops: hop
399
+ # @note all: is teleporting all users to their location.
285
400
  def tp(user, target)
401
+ return if check_dnd(target)
286
402
  @server.puts "tp #{user} #{target}"
287
403
  end
288
404
 
@@ -290,9 +406,9 @@ module Minecraft
290
406
  #
291
407
  # @param [String] user Current (target) user.
292
408
  # @example
293
- # tp("basicxman")
294
- def tpall(user, *args)
295
- @users.each { |u| tp(u, user) }
409
+ # tpall("basicxman")
410
+ def tpall(user)
411
+ @users.each { |u| tp(u, user) unless @userdnd.include? u.downcase }
296
412
  end
297
413
 
298
414
  # Gives a golden apple to the specified user.
@@ -300,6 +416,8 @@ module Minecraft
300
416
  # @param [String] user Target user.
301
417
  # @example
302
418
  # nom("basicxman")
419
+ # @note ops: hop
420
+ # @note all: is providing noms to all.
303
421
  def nom(user)
304
422
  @server.puts "give #{user} 322 1"
305
423
  end
@@ -310,6 +428,8 @@ module Minecraft
310
428
  # @param args noms!
311
429
  # @example
312
430
  # om("basicxman", "nom", "nom", "nom")
431
+ # @note ops: hop
432
+ # @note all: is noming everybody, gross.
313
433
  def om(user, *args)
314
434
  args.length.times { nom(user) }
315
435
  end
@@ -321,6 +441,7 @@ module Minecraft
321
441
  # @example
322
442
  # property("basicxman", "spawn-monsters")
323
443
  # property("basicxman")
444
+ # @note ops: op
324
445
  def property(user, key = nil)
325
446
  if key.nil?
326
447
  (@server_properties.length / 3.0).ceil.times do |n|
@@ -340,6 +461,7 @@ module Minecraft
340
461
  # @example
341
462
  # uptime("basicxman")
342
463
  # uptime("basicxman", "mike_n_7")
464
+ # @note ops: none
343
465
  def uptime(user, target_user = nil)
344
466
  target_user ||= user
345
467
  unless @users.include? target_user
@@ -362,7 +484,8 @@ module Minecraft
362
484
  #
363
485
  # @example
364
486
  # rules()
365
- def rules(*args)
487
+ # @note ops: none
488
+ def rules()
366
489
  @server.puts "say #{@rules}"
367
490
  end
368
491
 
@@ -372,6 +495,7 @@ module Minecraft
372
495
  # @param [String] user The requesting user.
373
496
  # @example
374
497
  # list("basicxman")
498
+ # @note ops: none
375
499
  def list(user)
376
500
  l = @users.inject("") do |s, u|
377
501
  pre, suf = "", ""
@@ -397,9 +521,11 @@ module Minecraft
397
521
  # @example
398
522
  # addtimer("basicxman", "cobblestone")
399
523
  # addtimer("basicxman", "arrow", "10")
524
+ # @note ops: hop
400
525
  def addtimer(user, *args)
401
526
  item, duration = items_arg(30, args)
402
527
  item = resolve_item(item)
528
+ return @server.puts "say Timer was not added." if item.nil?
403
529
  @timers[user] ||= {}
404
530
  @timers[user][item] = duration
405
531
  @server.puts "say Timer added for #{user}. Giving item id #{item} every #{duration} seconds."
@@ -411,10 +537,16 @@ module Minecraft
411
537
  # @param args item
412
538
  # @example
413
539
  # deltimer("basicxman", "cobblestone")
540
+ # @note ops: hop
414
541
  def deltimer(user, *args)
415
542
  item = args.join(" ")
416
543
  item = resolve_item(item)
417
- @timers[user][item] = nil if @timers.has_key? user
544
+ if @timers.has_key? user
545
+ @timers[user].delete item
546
+ @server.puts "say #{item} timer is deleted."
547
+ else
548
+ @server.puts "say #{item} timer did not exist."
549
+ end
418
550
  end
419
551
 
420
552
  # Prints the requesting users current timers.
@@ -422,6 +554,7 @@ module Minecraft
422
554
  # @param [String] user The requesting user.
423
555
  # @example
424
556
  # printtimer("basicxman")
557
+ # @note ops: hop
425
558
  def printtimer(user)
426
559
  unless @timers.has_key? user || @timers[user].length == 0
427
560
  @server.puts "say No timers have been added for #{user}."
@@ -436,8 +569,9 @@ module Minecraft
436
569
  # initialized).
437
570
  #
438
571
  # @example
439
- # printtimer("basicxman")
440
- def printtime(user)
572
+ # printtimer()
573
+ # @note ops: op
574
+ def printtime()
441
575
  @server.puts "say Timer is at #{@counter}."
442
576
  end
443
577
 
@@ -450,12 +584,14 @@ module Minecraft
450
584
  # @example
451
585
  # s("basicxman", "cobble", "give", "cobblestone", "64")
452
586
  # s("basicxman", "mike", "tp", "mike_n_7")
587
+ # @note ops: hop
453
588
  def s(user, *args)
454
- return @server.puts "say You need to specify a shortcut silly!" if args.length == 0
455
-
456
589
  shortcut_name = args.slice! 0
457
590
  if args.length == 0
458
- @server.puts "say #{shortcut_name} is not a valid shortcut for #{user}." unless @shortcuts.has_key? user and @shortcuts[user].has_key? shortcut_name
591
+ unless @shortcuts.has_key? user and @shortcuts[user].has_key? shortcut_name
592
+ return kit(user, shortcut_name) if KITS.include? shortcut_name.to_sym
593
+ @server.puts "say #{shortcut_name} is not a valid shortcut for #{user}."
594
+ end
459
595
  return call_command(user, @shortcuts[user][shortcut_name].first, *@shortcuts[user][shortcut_name][1..-1]) if args.length == 0
460
596
  end
461
597
 
@@ -470,7 +606,8 @@ module Minecraft
470
606
  # @param [String] user The requesting user.
471
607
  # @example
472
608
  # shortcuts("basicxman")
473
- def shortcuts(user, *args)
609
+ # @note ops: hop
610
+ def shortcuts(user)
474
611
  labels = @shortcuts[user].keys.join(", ") if @shortcuts.has_key? user
475
612
  @server.puts "say Shortcuts for #{user}: #{labels}."
476
613
  end
@@ -480,7 +617,15 @@ module Minecraft
480
617
  # @param [String] user The requesting user.
481
618
  # @example
482
619
  # help("basicxman")
483
- def help(user)
620
+ # @note ops: none
621
+ def help(user, command = nil)
622
+ unless command.nil?
623
+ return @server.puts "say #{command} does not exist." unless @commands.has_key? command.to_sym
624
+ command_signature(command.to_sym)
625
+ say(@commands[command.to_sym][:help])
626
+ return
627
+ end
628
+
484
629
  commands = @commands.keys.inject([]) { |arr, key|
485
630
  priv = @commands[key][:ops]
486
631
  if is_op? user
@@ -491,17 +636,205 @@ module Minecraft
491
636
  priv == :none ? arr << key : arr
492
637
  end
493
638
  }.map { |s| "!" + s.to_s }
494
- @server.puts "say Commands: #{commands.join(", ")}"
639
+ say(commands.join(", "))
495
640
  end
496
641
 
497
642
  # Prints the list of available kits to the connected players.
498
643
  #
499
644
  # @example
500
645
  # kitlist()
501
- def kitlist(*args)
646
+ # @note ops: none
647
+ def kitlist()
502
648
  @server.puts "say Kits: #{KITS.keys.join(", ")}"
503
649
  end
504
650
 
651
+ # Adds or prints the current todo list items.
652
+ #
653
+ # @param [String] user The requesting user.
654
+ # @param args The item.
655
+ # @example
656
+ # todo("basicxman", "foo")
657
+ # todo("basicxman")
658
+ # @note ops: none
659
+ def todo(user, *args)
660
+ if args.length == 0
661
+ @todo_items.each_with_index do |item, index|
662
+ @server.puts "say #{index + 1}. #{item}"
663
+ end
664
+ return
665
+ end
666
+
667
+ item = args.join(" ")
668
+ @todo_items << item
669
+ @server.puts "say Added item."
670
+ end
671
+
672
+ # Removes an item from the todo list.
673
+ #
674
+ # @param [String] user The requesting user.
675
+ # @param args The item.
676
+ # @example
677
+ # finished("basicxman", "foo")
678
+ # finished("basicxman", "2")
679
+ # @note ops: none
680
+ def finished(user, *args)
681
+ item = args.join(" ")
682
+ if item.to_i.to_s == item
683
+ index = item.to_i - 1
684
+ else
685
+ index = @todo_items.find_index(item)
686
+ end
687
+ return @server.puts "say Item does not exist." if index.nil? or @todo_items[index].nil?
688
+ @todo_items.slice! index
689
+ @server.puts "say Hurray!"
690
+ end
691
+
692
+ private
693
+
694
+ # Prints the command signature options for a specified command.
695
+ #
696
+ # @param [Symbol] command The command method.
697
+ # @example
698
+ # command_signature(:give)
699
+ def command_signature(command)
700
+ params = method(command).parameters || []
701
+
702
+ return if params.length == 0
703
+ params.slice! 0 if params[0][1] == :user
704
+ if params.length == 1
705
+ name = params[0][1].to_s.gsub("_", " ")
706
+ type = params[0][0]
707
+ case type
708
+ when :opt
709
+ say("!#{command}")
710
+ say("!#{command} '#{name}'")
711
+ when :rest
712
+ say("!#{command} 'arguments', '...'")
713
+ when :req
714
+ say("!#{command} '#{name}'")
715
+ end
716
+ elsif params.length == 2
717
+ first_name = params[0][1].to_s.gsub("_", " ")
718
+ second_name = params[1][1].to_s.gsub("_", " ")
719
+ type = params[1][0]
720
+ case type
721
+ when :rest
722
+ say("!#{command} '#{first_name}', 'arguments', '...'")
723
+ when :opt
724
+ say("!#{command} '#{first_name}'")
725
+ say("!#{command} '#{first_name}', '#{second_name}'")
726
+ end
727
+ end
728
+ end
729
+
730
+ # Checks if the user does not wish to be disturbed and prints an error
731
+ # notice if so.
732
+ #
733
+ # @param [String] user The requesting user.
734
+ # @return [Boolean] Returns true if the user does not wish to be disturbed
735
+ # (should cancel action).
736
+ # @example
737
+ # check_dnd("basicxman")
738
+ def check_dnd(user)
739
+ if @userdnd.include? user.downcase
740
+ say("#{user} does not wish to be disturbed, don't be a jerk!")
741
+ return true
742
+ else
743
+ return false
744
+ end
745
+ end
746
+
747
+ # Validates a kit group, if the kit cannot be found it executes the
748
+ # !kitlist command.
749
+ def validate_kit(group = "")
750
+ return true if KITS.include? group.to_sym
751
+ @server.puts "say #{group} is not a valid kit."
752
+ kitlist
753
+ end
754
+
755
+ # Changes the time of day.
756
+ #
757
+ # @param [String] time The time of day to change it to.
758
+ # @example
759
+ # change_time("morning")
760
+ def change_time(time)
761
+ return false unless TIME.include? time
762
+ @server.puts "time set #{TIME[time]}"
763
+ @server.puts "say #{TIME_QUOTES[time]}" unless TIME_QUOTES[time] == ""
764
+ return true
765
+ end
766
+
767
+ # Checks a kickvote entry to see if the tally number has crossed the
768
+ # threshold, if so, kicks the user.
769
+ #
770
+ # @param [String] user The specified user.
771
+ # @example
772
+ # check_kickvote("blizzard4U")
773
+ def check_kickvote(user)
774
+ if @kickvotes[user][:tally] >= @vote_threshold
775
+ @server.puts "say Enough votes have been given to kick #{user}."
776
+ @server.puts "kick #{user}"
777
+ @kickvotes.delete(user)
778
+ end
779
+ end
780
+
781
+ # Computes the influence a user has for kickvotes.
782
+ #
783
+ # @param [String] user The specified user.
784
+ # @return [Integer] The influence level.
785
+ # @example
786
+ # kick_influence("basicxman")
787
+ def kick_influence(user)
788
+ return 3 if is_op? user
789
+ return 2 if is_hop? user
790
+ return 1
791
+ end
792
+
793
+ # Checks to see if any kickvotes are expired.
794
+ def expire_kickvotes
795
+ @kickvotes.each do |target_user, data|
796
+ if Time.now > data[:start] + @vote_expiration
797
+ @server.puts "say The kickvote for #{target_user} has expired."
798
+ @kickvotes.delete(target_user)
799
+ end
800
+ end
801
+ end
802
+
803
+ # Submits a kickvote.
804
+ #
805
+ # @param [String] user The requesting user who is voting.
806
+ # @param [String] target_user The user being voted against.
807
+ # @return [Boolean] Returns true if the kickvote has been initiated yet.
808
+ # @example
809
+ # submit_vote("basicxman", "blizzard4U")
810
+ def submit_vote(user, target_user)
811
+ return unless @users.include? target_user
812
+ if @kickvotes.has_key? target_user
813
+ if @kickvotes[target_user][:votes].include? user
814
+ @server.puts "say You have already voted."
815
+ else
816
+ @kickvotes[target_user][:votes] << user
817
+ @kickvotes[target_user][:tally] += kick_influence(user)
818
+ check_kickvote(target_user)
819
+ end
820
+ return true
821
+ else
822
+ return false
823
+ end
824
+ end
825
+
826
+ # Caps the quantity of points able to be given based on requesting user.
827
+ #
828
+ # @param [String] user The requesting user.
829
+ # @return [Integer] Maximum quantity of points.
830
+ # @example
831
+ # cap_points("basicxman")
832
+ def cap_points(user)
833
+ return 1000 if is_op? user
834
+ return 500 if is_hop? user
835
+ return 1
836
+ end
837
+
505
838
  # Helper method for printing the final give statements to the server. If a
506
839
  # quantity is above the default upper bound (64) it will print multiple
507
840
  # statements.