Class: KAG::Gather::Queue
- Inherits:
-
Object
- Object
- KAG::Gather::Queue
- Defined in:
- lib/kag/gather/queue.rb
Instance Attribute Summary collapse
-
#players ⇒ Object
Returns the value of attribute players.
Instance Method Summary collapse
- #add(user) ⇒ Object
- #check_for_afk(gather) ⇒ Object
- #has_player?(user) ⇒ Boolean
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #length ⇒ Object
- #list ⇒ Object
- #remove(user) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
7 8 9 |
# File 'lib/kag/gather/queue.rb', line 7 def initialize self.players = {} end |
Instance Attribute Details
#players ⇒ Object
Returns the value of attribute players.
5 6 7 |
# File 'lib/kag/gather/queue.rb', line 5 def players @players end |
Instance Method Details
#add(user) ⇒ Object
11 12 13 14 15 |
# File 'lib/kag/gather/queue.rb', line 11 def add(user) return false unless user.authname and !user.authname.to_s.empty? self.players[user.authname.to_sym] = user true end |
#check_for_afk(gather) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kag/gather/queue.rb', line 48 def check_for_afk(gather) max_idle = (KAG::Config.instance[:idle][:max] or 1800) max_idle = max_idle.to_i begin self.players.each do |authname,user| user.refresh if user.idle > max_idle self.remove(user) gather.send_channels_msg "Removed #{user.authname} from queue (#{KAG::Gather::Match.type_as_string}) for being idle too long [#{self.length}]" end end rescue Exception => e puts e. puts e.backtrace.join("\n") false end end |
#has_player?(user) ⇒ Boolean
35 36 37 38 |
# File 'lib/kag/gather/queue.rb', line 35 def has_player?(user) return false unless user.authname and !user.authname.to_s.empty? self.players.has_key?(user.authname.to_sym) end |
#length ⇒ Object
40 41 42 |
# File 'lib/kag/gather/queue.rb', line 40 def length self.players.length end |
#list ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/kag/gather/queue.rb', line 27 def list m = [] self.players.each do |authname,user| m << user.authname end m.join(", ") end |
#remove(user) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/kag/gather/queue.rb', line 17 def remove(user) return false unless user.authname and !user.authname.to_s.empty? if has_player?(user) self.players.delete(user.authname.to_sym) true else false end end |
#reset ⇒ Object
44 45 46 |
# File 'lib/kag/gather/queue.rb', line 44 def reset self.players = {} end |