def handle_reorder( m, params ) name = params[:name].downcase calulate_beat(m, params) unless @stock.has_key?( name ) m.reply( "#{name} does not exist." ); return end if @stock[name].deliverybeat != nil m.reply( "#{m.sourcenick}: #{name} has already been ordered." ); return end if @stock[name].amount.to_f >= ((@stock[name].max.to_f * 25) / 100) m.reply( " #{m.sourcenick}: We still have enough #{name}, no need to reorder." ); return end # run calculation after checks to save resources if not needed deliverybeat = cur_beat.to_i + (@stock[name].beats.to_i * @stock[name].max.to_i) @stock[name].deliverybeat = deliverybeat @registry[:stock] = @stock m.reply( "Billy Kay is on it's way to the supplier....") end def calulate_beat( m, params ) cur_y = Time.new.strftime '%Y' cur_d = Time.new.strftime '%j' cur_h = Time.new.strftime '%H' cur_m = Time.new.strftime '%M' cur_s = Time.new.strftime '%S' cur_beat = ((cur_y.to_i * 31536000) + (cur_d.to_i * 86400) + (cur_h.to_i * 3600) + (cur_m.to_i * 60) + cur_s.to_i) end